Search in sources :

Example 1 with PostgresqlSelectQuery

use of com.hortonworks.registries.storage.impl.jdbc.provider.postgresql.query.PostgresqlSelectQuery in project registry by hortonworks.

the class PostgresSelectQueryTest method testSelectQuery.

@Test
public void testSelectQuery() throws Exception {
    PostgresqlSelectQuery postgresqlSelectQuery = new PostgresqlSelectQuery(nameSpace);
    String parametrizedSql = postgresqlSelectQuery.getParametrizedSql();
    Assert.assertEquals("SELECT * FROM \"topic\"", parametrizedSql);
    Map<Schema.Field, Object> fieldToObjectMap = new HashMap<>();
    fieldToObjectMap.put(new Schema.Field("foo", Schema.Type.LONG), 1);
    postgresqlSelectQuery = new PostgresqlSelectQuery(new StorableKey(nameSpace, new PrimaryKey(fieldToObjectMap)));
    parametrizedSql = postgresqlSelectQuery.getParametrizedSql();
    Assert.assertEquals("SELECT * FROM \"topic\" WHERE \"foo\" = ?", parametrizedSql);
}
Also used : OrderByField(com.hortonworks.registries.storage.OrderByField) HashMap(java.util.HashMap) StorableKey(com.hortonworks.registries.storage.StorableKey) Schema(com.hortonworks.registries.common.Schema) PostgresqlSelectQuery(com.hortonworks.registries.storage.impl.jdbc.provider.postgresql.query.PostgresqlSelectQuery) PrimaryKey(com.hortonworks.registries.storage.PrimaryKey) Test(org.junit.Test)

Example 2 with PostgresqlSelectQuery

use of com.hortonworks.registries.storage.impl.jdbc.provider.postgresql.query.PostgresqlSelectQuery in project registry by hortonworks.

the class PostgresSelectQueryTest method testSelectQueryWithOrderBy.

@Test
public void testSelectQueryWithOrderBy() throws Exception {
    List<OrderByField> orderByFields = Arrays.asList(OrderByField.of("foo", true), OrderByField.of("bar"));
    PostgresqlSelectQuery postgresqlSelectQuery = new PostgresqlSelectQuery("topic", orderByFields);
    String parametrizedSql = postgresqlSelectQuery.getParametrizedSql();
    Assert.assertEquals("SELECT * FROM \"topic\" ORDER BY \"foo\" DESC, ORDER BY \"bar\" ASC", parametrizedSql);
    Map<Schema.Field, Object> fieldToObjectMap = new HashMap<>();
    fieldToObjectMap.put(new Schema.Field("foo", Schema.Type.LONG), 1);
    postgresqlSelectQuery = new PostgresqlSelectQuery(new StorableKey(nameSpace, new PrimaryKey(fieldToObjectMap)), orderByFields);
    parametrizedSql = postgresqlSelectQuery.getParametrizedSql();
    Assert.assertEquals("SELECT * FROM \"topic\" WHERE \"foo\" = ? ORDER BY \"foo\" DESC, ORDER BY \"bar\" ASC", parametrizedSql);
}
Also used : OrderByField(com.hortonworks.registries.storage.OrderByField) OrderByField(com.hortonworks.registries.storage.OrderByField) HashMap(java.util.HashMap) StorableKey(com.hortonworks.registries.storage.StorableKey) Schema(com.hortonworks.registries.common.Schema) PostgresqlSelectQuery(com.hortonworks.registries.storage.impl.jdbc.provider.postgresql.query.PostgresqlSelectQuery) PrimaryKey(com.hortonworks.registries.storage.PrimaryKey) Test(org.junit.Test)

Aggregations

Schema (com.hortonworks.registries.common.Schema)2 OrderByField (com.hortonworks.registries.storage.OrderByField)2 PrimaryKey (com.hortonworks.registries.storage.PrimaryKey)2 StorableKey (com.hortonworks.registries.storage.StorableKey)2 PostgresqlSelectQuery (com.hortonworks.registries.storage.impl.jdbc.provider.postgresql.query.PostgresqlSelectQuery)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2