Search in sources :

Example 11 with PrimaryKey

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

the class MLModel method getPrimaryKey.

@JsonIgnore
@Override
public PrimaryKey getPrimaryKey() {
    Map<Field, Object> fieldObjectMap = new HashMap<>();
    fieldObjectMap.put(new Schema.Field(ID, Type.LONG), this.id);
    return new PrimaryKey(fieldObjectMap);
}
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)

Example 12 with PrimaryKey

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

the class AbstractSelectQuery method buildSqlWithSearchQuery.

protected String buildSqlWithSearchQuery(SearchQuery searchQuery, Schema schema) {
    String sql = "SELECT * FROM " + fieldEncloser() + tableName + fieldEncloser();
    WhereClause whereClause = searchQuery.getWhereClause();
    Map<Schema.Field, Object> fieldsToValues = new HashMap<>();
    if (whereClause != null) {
        sql += " WHERE ";
        StringBuilder clauseString = new StringBuilder();
        for (PredicateCombinerPair predicateCombinerPair : whereClause.getPredicateCombinerPairs()) {
            WhereClauseCombiner.Operation combinerOperation = predicateCombinerPair.getCombinerOperation();
            Predicate predicate = predicateCombinerPair.getPredicate();
            clauseString.append(generateClauseString(predicate, fieldsToValues, schema));
            if (combinerOperation != null) {
                String opStr;
                switch(combinerOperation) {
                    case ENCL_START:
                        opStr = " ( ";
                        break;
                    case ENCL_FINISH:
                        opStr = " ) ";
                        break;
                    default:
                        opStr = combinerOperation.toString();
                }
                clauseString.append(opStr);
            }
        }
        sql += clauseString;
    }
    List<OrderBy> orderByFields = searchQuery.getOrderByFields();
    if (orderByFields != null && !orderByFields.isEmpty()) {
        sql += " ORDER BY " + join(orderByFields.stream().map(x -> fieldEncloser() + x.getFieldName() + fieldEncloser() + (x.isAsc() ? " ASC " : " DESC ")).collect(Collectors.toList()), ", ");
    }
    primaryKey = new PrimaryKey(fieldsToValues);
    columns = Lists.newArrayList(fieldsToValues.keySet());
    return sql;
}
Also used : OrderBy(com.hortonworks.registries.storage.search.OrderBy) HashMap(java.util.HashMap) WhereClause(com.hortonworks.registries.storage.search.WhereClause) PrimaryKey(com.hortonworks.registries.storage.PrimaryKey) PredicateCombinerPair(com.hortonworks.registries.storage.search.PredicateCombinerPair) Predicate(com.hortonworks.registries.storage.search.Predicate) OrderByField(com.hortonworks.registries.storage.OrderByField) WhereClauseCombiner(com.hortonworks.registries.storage.search.WhereClauseCombiner)

Example 13 with PrimaryKey

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

the class InMemoryStorageManager method update.

@Override
public void update(Storable storable) {
    String namespace = storable.getNameSpace();
    PrimaryKey pk = storable.getPrimaryKey();
    if (!storageMap.containsKey(namespace)) {
        throw new StorageException("Row could not be updated");
    }
    storageMap.get(namespace).put(pk, storable);
}
Also used : PrimaryKey(com.hortonworks.registries.storage.PrimaryKey) StorageException(com.hortonworks.registries.storage.exception.StorageException)

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