Ejemplo n.º 1
2
  @Override
  public java.util.List<gen.model.test.Clicked> search(
      org.revenj.patterns.Specification<gen.model.test.Clicked> specification,
      Integer limit,
      Integer offset) {
    final String selectType = "SELECT it";
    java.util.function.Consumer<java.sql.PreparedStatement> applyFilters = ps -> {};
    java.sql.Connection connection = getConnection();
    try (org.revenj.postgres.PostgresWriter pgWriter =
        org.revenj.postgres.PostgresWriter.create()) {
      String sql;
      if (specification == null) {
        sql = "SELECT r FROM \"test\".\"Clicked_event\" r";
      } else if (specification instanceof gen.model.test.Clicked.BetweenNumbers) {
        gen.model.test.Clicked.BetweenNumbers spec =
            (gen.model.test.Clicked.BetweenNumbers) specification;
        sql = selectType + " FROM \"test\".\"Clicked.BetweenNumbers\"(?, ?, ?) it";

        applyFilters =
            applyFilters.andThen(
                ps -> {
                  try {
                    ps.setBigDecimal(1, spec.getMin());
                  } catch (Exception e) {
                    throw new RuntimeException(e);
                  }
                });
        applyFilters =
            applyFilters.andThen(
                ps -> {
                  try {

                    Object[] __arr = new Object[spec.getInSet().size()];
                    int __ind = 0;
                    for (Object __it : spec.getInSet()) __arr[__ind++] = __it;
                    ps.setArray(2, connection.createArrayOf("numeric", __arr));
                  } catch (Exception e) {
                    throw new RuntimeException(e);
                  }
                });
        applyFilters =
            applyFilters.andThen(
                ps -> {
                  try {
                    if (spec.getEn() == null) ps.setNull(3, java.sql.Types.OTHER);
                    else {
                      org.postgresql.util.PGobject __pgo = new org.postgresql.util.PGobject();
                      __pgo.setType("\"test\".\"En\"");
                      __pgo.setValue(
                          gen.model.test.converters.EnConverter.stringValue(spec.getEn()));
                      ps.setObject(3, __pgo);
                    }
                  } catch (Exception e) {
                    throw new RuntimeException(e);
                  }
                });
      } else {
        org.revenj.patterns.Query<gen.model.test.Clicked> query = query(specification);
        if (offset != null) {
          query = query.skip(offset);
        }
        if (limit != null) {
          query = query.limit(limit);
        }
        try {
          return query.list();
        } catch (java.io.IOException e) {
          throw new RuntimeException(e);
        }
      }
      if (limit != null) {
        sql += " LIMIT " + Integer.toString(limit);
      }
      if (offset != null) {
        sql += " OFFSET " + Integer.toString(offset);
      }
      try (java.sql.PreparedStatement statement = connection.prepareStatement(sql)) {
        applyFilters.accept(statement);
        return readFromDb(statement, new java.util.ArrayList<>());
      } catch (java.sql.SQLException | java.io.IOException e) {
        throw new RuntimeException(e);
      }
    } finally {
      releaseConnection(connection);
    }
  }
Ejemplo n.º 2
0
  @Test
  public void shouldTestFunctionInterfaces() {
    assertThat(f1.apply("kenny"), is(5));
    assertThat(f2.apply("kenny"), is(5));
    assertThat(f3.apply("kenny"), is(5));

    assertThat(c1.compare(1, 2), is(-1));
    assertThat(c2.compare(1, 2), is(-1));
    assertThat(c3.compare("abc", "vcf"), is(-1));

    assertThat(s42.get(), is(42));

    r1.run();
    r2.run();

    List<Item> items = new ArrayList<>();
    for (int i = 1; i < 6; i++) items.add(new Item(i + ""));
    items.forEach(con1.andThen(con2));
    items.forEach(con3);
  }
Ejemplo n.º 3
0
    /**
     * Starts the test app in a background thread.
     *
     * @param args String[] emulating command-line arguments passed to a Java app.
     * @return {@link BQDaemonTestRuntime} instance created by the builder. The caller doesn't need
     *     to shut it down. Usually JUnit lifecycle takes care of it.
     */
    public BQDaemonTestRuntime start(String... args) {

      Consumer<Bootique> localConfigurator = configurator;

      if (!properties.isEmpty()) {

        Consumer<Bootique> propsConfigurator =
            bootique ->
                bootique.module(
                    binder -> {
                      MapBinder<String, String> mapBinder =
                          BQCoreModule.contributeProperties(binder);
                      properties.forEach((k, v) -> mapBinder.addBinding(k).toInstance(v));
                    });

        localConfigurator = localConfigurator.andThen(propsConfigurator);
      }

      BQDaemonTestRuntime runtime = new BQDaemonTestRuntime(localConfigurator, startupCheck, args);
      runtimes.add(runtime);
      runtime.start(startupTimeout, startupTimeoutTimeUnit);
      return runtime;
    }
Ejemplo n.º 4
0
 // this is not really right according to the A+-contract, is should feed the result of onsuccess
 public JsPromise then(JsPromise chainedPromise) {
   onSuccess.andThen(chainedPromise.onSuccess);
   return this;
 }
Ejemplo n.º 5
0
  @Override
  public boolean exists(org.revenj.patterns.Specification<gen.model.test.Clicked> specification) {
    final String selectType = "SELECT exists(SELECT *";
    java.util.function.Consumer<java.sql.PreparedStatement> applyFilters = ps -> {};
    java.sql.Connection connection = getConnection();
    try (org.revenj.postgres.PostgresWriter pgWriter =
        org.revenj.postgres.PostgresWriter.create()) {
      String sql = null;
      if (specification == null) {
        sql = "SELECT exists(SELECT * FROM \"test\".\"Clicked_event\" r";
      } else if (specification instanceof gen.model.test.Clicked.BetweenNumbers) {
        gen.model.test.Clicked.BetweenNumbers spec =
            (gen.model.test.Clicked.BetweenNumbers) specification;
        sql = selectType + " FROM \"test\".\"Clicked.BetweenNumbers\"(?, ?, ?) it";

        applyFilters =
            applyFilters.andThen(
                ps -> {
                  try {
                    ps.setBigDecimal(1, spec.getMin());
                  } catch (Exception e) {
                    throw new RuntimeException(e);
                  }
                });
        applyFilters =
            applyFilters.andThen(
                ps -> {
                  try {

                    Object[] __arr = new Object[spec.getInSet().size()];
                    int __ind = 0;
                    for (Object __it : spec.getInSet()) __arr[__ind++] = __it;
                    ps.setArray(2, connection.createArrayOf("numeric", __arr));
                  } catch (Exception e) {
                    throw new RuntimeException(e);
                  }
                });
        applyFilters =
            applyFilters.andThen(
                ps -> {
                  try {
                    if (spec.getEn() == null) ps.setNull(3, java.sql.Types.OTHER);
                    else {
                      org.postgresql.util.PGobject __pgo = new org.postgresql.util.PGobject();
                      __pgo.setType("\"test\".\"En\"");
                      __pgo.setValue(
                          gen.model.test.converters.EnConverter.stringValue(spec.getEn()));
                      ps.setObject(3, __pgo);
                    }
                  } catch (Exception e) {
                    throw new RuntimeException(e);
                  }
                });
      } else {
        try {
          return query(specification).any();
        } catch (java.io.IOException e) {
          throw new RuntimeException(e);
        }
      }
      try (java.sql.PreparedStatement statement = connection.prepareStatement(sql + ")")) {
        applyFilters.accept(statement);
        try (java.sql.ResultSet rs = statement.executeQuery()) {
          rs.next();
          return rs.getBoolean(1);
        }
      } catch (java.sql.SQLException e) {
        throw new RuntimeException(e);
      }
    } finally {
      releaseConnection(connection);
    }
  }