Search in sources :

Example 6 with PrimaryKey

use of com.hortonworks.registries.storage.PrimaryKey in project registry by hortonworks.

the class MySqlSelectQueryTest method testSelectQuery.

@Test
public void testSelectQuery() throws Exception {
    MySqlSelectQuery mySqlSelectQuery = new MySqlSelectQuery(nameSpace);
    String parametrizedSql = mySqlSelectQuery.getParametrizedSql();
    Assert.assertEquals("SELECT * FROM topic", parametrizedSql);
    Map<Schema.Field, Object> fieldToObjectMap = new HashMap<>();
    fieldToObjectMap.put(new Schema.Field("foo", Schema.Type.LONG), 1);
    mySqlSelectQuery = new MySqlSelectQuery(new StorableKey(nameSpace, new PrimaryKey(fieldToObjectMap)));
    parametrizedSql = mySqlSelectQuery.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) PrimaryKey(com.hortonworks.registries.storage.PrimaryKey) MySqlSelectQuery(com.hortonworks.registries.storage.impl.jdbc.provider.mysql.query.MySqlSelectQuery) Test(org.junit.Test)

Example 7 with PrimaryKey

use of com.hortonworks.registries.storage.PrimaryKey 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 8 with PrimaryKey

use of com.hortonworks.registries.storage.PrimaryKey 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)

Example 9 with PrimaryKey

use of com.hortonworks.registries.storage.PrimaryKey in project registry by hortonworks.

the class GuavaCacheTest method setStorableKey.

private static void setStorableKey() {
    Map<Schema.Field, Object> fieldsToVal = new HashMap<>();
    fieldsToVal.put(new Schema.Field("fn", Schema.Type.STRING), "fv");
    storableKey = new StorableKey("ns", new PrimaryKey(fieldsToVal));
}
Also used : HashMap(java.util.HashMap) StorableKey(com.hortonworks.registries.storage.StorableKey) Schema(com.hortonworks.registries.common.Schema) PrimaryKey(com.hortonworks.registries.storage.PrimaryKey)

Example 10 with PrimaryKey

use of com.hortonworks.registries.storage.PrimaryKey in project streamline by hortonworks.

the class TopologyStream method getPrimaryKey.

@JsonIgnore
@Override
public PrimaryKey getPrimaryKey() {
    Map<Field, Object> fieldToObjectMap = new HashMap<>();
    fieldToObjectMap.put(new Schema.Field(ID, Schema.Type.LONG), this.id);
    fieldToObjectMap.put(new Schema.Field(VERSIONID, Schema.Type.LONG), this.versionId);
    return new PrimaryKey(fieldToObjectMap);
}
Also used : Field(com.hortonworks.registries.common.Schema.Field) HashMap(java.util.HashMap) Schema(com.hortonworks.registries.common.Schema) PrimaryKey(com.hortonworks.registries.storage.PrimaryKey) Field(com.hortonworks.registries.common.Schema.Field) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Aggregations

PrimaryKey (com.hortonworks.registries.storage.PrimaryKey)13 HashMap (java.util.HashMap)10 Schema (com.hortonworks.registries.common.Schema)9 OrderByField (com.hortonworks.registries.storage.OrderByField)7 StorableKey (com.hortonworks.registries.storage.StorableKey)6 Test (org.junit.Test)4 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)3 Field (com.hortonworks.registries.common.Schema.Field)3 StorageException (com.hortonworks.registries.storage.exception.StorageException)3 Storable (com.hortonworks.registries.storage.Storable)2 AlreadyExistsException (com.hortonworks.registries.storage.exception.AlreadyExistsException)2 MySqlSelectQuery (com.hortonworks.registries.storage.impl.jdbc.provider.mysql.query.MySqlSelectQuery)2 PostgresqlSelectQuery (com.hortonworks.registries.storage.impl.jdbc.provider.postgresql.query.PostgresqlSelectQuery)2 QueryParam (com.hortonworks.registries.common.QueryParam)1 IllegalQueryParameterException (com.hortonworks.registries.storage.exception.IllegalQueryParameterException)1 CaseAgnosticStringSet (com.hortonworks.registries.storage.impl.jdbc.util.CaseAgnosticStringSet)1 OrderBy (com.hortonworks.registries.storage.search.OrderBy)1 Predicate (com.hortonworks.registries.storage.search.Predicate)1 PredicateCombinerPair (com.hortonworks.registries.storage.search.PredicateCombinerPair)1 WhereClause (com.hortonworks.registries.storage.search.WhereClause)1