DataContextImpl(OptiqConnectionImpl connection, List<Object> parameterValues) {
      this.queryProvider = connection;
      this.typeFactory = connection.getTypeFactory();
      this.rootSchema = connection.rootSchema;

      // Store the time at which the query started executing. The SQL
      // standard says that functions such as CURRENT_TIMESTAMP return the
      // same value throughout the query.
      final long time = System.currentTimeMillis();
      final TimeZone timeZone = connection.getTimeZone();
      final long localOffset = timeZone.getOffset(time);
      final long currentOffset = localOffset;

      ImmutableMap.Builder<Object, Object> builder = ImmutableMap.builder();
      builder
          .put("utcTimestamp", time)
          .put("currentTimestamp", time + currentOffset)
          .put("localTimestamp", time + localOffset)
          .put("timeZone", timeZone);
      for (Ord<Object> value : Ord.zip(parameterValues)) {
        Object e = value.e;
        if (e == null) {
          e = AvaticaParameter.DUMMY_VALUE;
        }
        builder.put("?" + value.i, e);
      }
      map = builder.build();
    }
Example #2
0
 /** Creates a JDBC data source with the given specification. */
 public static DataSource dataSource(
     String url, String driverClassName, String username, String password) {
   if (url.startsWith("jdbc:hsqldb:")) {
     // Prevent hsqldb from screwing up java.util.logging.
     System.setProperty("hsqldb.reconfig_logging", "false");
   }
   BasicDataSource dataSource = new BasicDataSource();
   dataSource.setUrl(url);
   dataSource.setUsername(username);
   dataSource.setPassword(password);
   dataSource.setDriverClassName(driverClassName);
   return dataSource;
 }