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()));
}
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()));
}
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()));
}
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;
}
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;
}
Aggregations