Search in sources :

Example 26 with StorableKey

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

the class EnvironmentService method removeComponent.

public Component removeComponent(Long componentId) {
    Component component = new Component();
    component.setId(componentId);
    return dao.remove(new StorableKey(COMPONENT_NAMESPACE, component.getPrimaryKey()));
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) Component(com.hortonworks.streamline.streams.cluster.catalog.Component)

Example 27 with StorableKey

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

the class EnvironmentService method removeServiceConfiguration.

public ServiceConfiguration removeServiceConfiguration(Long configurationId) {
    ServiceConfiguration serviceConfiguration = new ServiceConfiguration();
    serviceConfiguration.setId(configurationId);
    return this.dao.remove(new StorableKey(SERVICE_CONFIGURATION_NAMESPACE, serviceConfiguration.getPrimaryKey()));
}
Also used : ServiceConfiguration(com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration) StorableKey(com.hortonworks.registries.storage.StorableKey)

Example 28 with StorableKey

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

the class EnvironmentService method getNamespace.

public Namespace getNamespace(Long namespaceId) {
    Namespace namespace = new Namespace();
    namespace.setId(namespaceId);
    return this.dao.get(new StorableKey(NAMESPACE_NAMESPACE, namespace.getPrimaryKey()));
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) Namespace(com.hortonworks.streamline.streams.cluster.catalog.Namespace)

Example 29 with StorableKey

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

the class JdbcStorageManager method buildStorableKey.

// private helper methods
/**
 * Query parameters are typically specified for a column or key in a database table or storage namespace. Therefore, we build
 * the {@link StorableKey} from the list of query parameters, and then can use {@link SqlSelectQuery} builder to generate the query using
 * the query parameters in the where clause
 *
 * @return {@link StorableKey} with all query parameters that match database columns <br/>
 * null if none of the query parameters specified matches a column in the DB
 */
private StorableKey buildStorableKey(String namespace, List<QueryParam> queryParams) throws Exception {
    final Map<Schema.Field, Object> fieldsToVal = new HashMap<>();
    StorableKey storableKey = null;
    try {
        CaseAgnosticStringSet columnNames = queryExecutor.getColumnNames(namespace);
        for (QueryParam qp : queryParams) {
            if (!columnNames.contains(qp.getName())) {
                log.warn("Query parameter [{}] does not exist for namespace [{}]. Query parameter ignored.", qp.getName(), namespace);
            } else {
                final String val = qp.getValue();
                final Schema.Type typeOfVal = Schema.Type.getTypeOfVal(val);
                fieldsToVal.put(new Schema.Field(qp.getName(), typeOfVal), // instantiates object of the appropriate type
                typeOfVal.getJavaType().getConstructor(String.class).newInstance(val));
            }
        }
        // it is empty when none of the query parameters specified matches a column in the DB
        if (!fieldsToVal.isEmpty()) {
            final PrimaryKey primaryKey = new PrimaryKey(fieldsToVal);
            storableKey = new StorableKey(namespace, primaryKey);
        }
        log.debug("Building StorableKey from QueryParam: \n\tnamespace = [{}]\n\t queryParams = [{}]\n\t StorableKey = [{}]", namespace, queryParams, storableKey);
    } catch (Exception e) {
        log.debug("Exception occurred when attempting to generate StorableKey from QueryParam", e);
        throw new IllegalQueryParameterException(e);
    }
    return storableKey;
}
Also used : HashMap(java.util.HashMap) Schema(com.hortonworks.registries.common.Schema) PrimaryKey(com.hortonworks.registries.storage.PrimaryKey) AlreadyExistsException(com.hortonworks.registries.storage.exception.AlreadyExistsException) StorageException(com.hortonworks.registries.storage.exception.StorageException) IllegalQueryParameterException(com.hortonworks.registries.storage.exception.IllegalQueryParameterException) OrderByField(com.hortonworks.registries.storage.OrderByField) CaseAgnosticStringSet(com.hortonworks.registries.storage.impl.jdbc.util.CaseAgnosticStringSet) QueryParam(com.hortonworks.registries.common.QueryParam) StorableKey(com.hortonworks.registries.storage.StorableKey) IllegalQueryParameterException(com.hortonworks.registries.storage.exception.IllegalQueryParameterException)

Example 30 with StorableKey

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

the class JdbcStorageManager method find.

@Override
public <T extends Storable> Collection<T> find(String namespace, List<QueryParam> queryParams, List<OrderByField> orderByFields) throws StorageException {
    log.debug("Searching for entries in table [{}] that match queryParams [{}] and order by [{}]", namespace, queryParams, orderByFields);
    if (queryParams == null || queryParams.isEmpty()) {
        return list(namespace, orderByFields);
    }
    Collection<T> entries = Collections.emptyList();
    try {
        StorableKey storableKey = buildStorableKey(namespace, queryParams);
        if (storableKey != null) {
            entries = queryExecutor.select(storableKey, orderByFields);
        }
    } catch (Exception e) {
        throw new StorageException(e);
    }
    log.debug("Querying table = [{}]\n\t filter = [{}]\n\t returned [{}]", namespace, queryParams, entries);
    return entries;
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) StorageException(com.hortonworks.registries.storage.exception.StorageException) AlreadyExistsException(com.hortonworks.registries.storage.exception.AlreadyExistsException) StorageException(com.hortonworks.registries.storage.exception.StorageException) IllegalQueryParameterException(com.hortonworks.registries.storage.exception.IllegalQueryParameterException)

Aggregations

StorableKey (com.hortonworks.registries.storage.StorableKey)72 Schema (com.hortonworks.registries.common.Schema)6 OrderByField (com.hortonworks.registries.storage.OrderByField)6 PrimaryKey (com.hortonworks.registries.storage.PrimaryKey)6 HashMap (java.util.HashMap)6 Test (org.junit.Test)5 QueryParam (com.hortonworks.registries.common.QueryParam)4 StorageManager (com.hortonworks.registries.storage.StorageManager)4 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)3 Storable (com.hortonworks.registries.storage.Storable)3 StorageException (com.hortonworks.registries.storage.exception.StorageException)3 Role (com.hortonworks.streamline.streams.security.catalog.Role)3 UserRole (com.hortonworks.streamline.streams.security.catalog.UserRole)3 CacheBuilder (com.google.common.cache.CacheBuilder)2 SchemaVersionInfoCache (com.hortonworks.registries.schemaregistry.cache.SchemaVersionInfoCache)2 CacheBackedStorageManager (com.hortonworks.registries.storage.CacheBackedStorageManager)2 StorageWriter (com.hortonworks.registries.storage.cache.writer.StorageWriter)2 AlreadyExistsException (com.hortonworks.registries.storage.exception.AlreadyExistsException)2 IllegalQueryParameterException (com.hortonworks.registries.storage.exception.IllegalQueryParameterException)2 MySqlSelectQuery (com.hortonworks.registries.storage.impl.jdbc.provider.mysql.query.MySqlSelectQuery)2