Exemplo 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);
    }
  }
Exemplo n.º 2
0
  public static void __configureConverter(
      org.revenj.postgres.ObjectConverter.Reader<Clicked>[] readers,
      int __index____event_id,
      int __index___QueuedAt,
      int __index___ProcessedAt,
      int __index___date,
      int __index___number,
      int __index___bigint,
      int __index___bool,
      int __index___en) {

    readers[__index____event_id] =
        (item, reader, context) -> {
          item.URI = org.revenj.postgres.converters.StringConverter.parse(reader, context, false);
        };
    readers[__index___QueuedAt] =
        (item, reader, context) -> {
          item.QueuedAt =
              org.revenj.postgres.converters.TimestampConverter.parse(reader, context, false);
        };
    readers[__index___ProcessedAt] =
        (item, reader, context) -> {
          item.ProcessedAt =
              org.revenj.postgres.converters.TimestampConverter.parse(reader, context, true);
        };
    readers[__index___date] =
        (item, reader, context) -> {
          item.date = org.revenj.postgres.converters.DateConverter.parse(reader, true);
        };
    readers[__index___number] =
        (item, reader, context) -> {
          item.number = org.revenj.postgres.converters.DecimalConverter.parse(reader, false);
        };
    readers[__index___bigint] =
        (item, reader, context) -> {
          item.bigint = org.revenj.postgres.converters.LongConverter.parseNullable(reader);
        };
    readers[__index___bool] =
        (item, reader, context) -> {
          {
            java.util.List<Boolean> __list =
                org.revenj.postgres.converters.BoolConverter.parseCollection(
                    reader, context, false);
            if (__list != null) item.bool = new java.util.HashSet<Boolean>(__list);
            else item.bool = new java.util.HashSet<Boolean>(4);
          }
          ;
        };
    readers[__index___en] =
        (item, reader, context) -> {
          item.en = gen.model.test.converters.EnConverter.fromReader(reader);
        };
  }
Exemplo n.º 3
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);
    }
  }