use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.
the class Joiner method queryClass.
/**
* Implements join and selection for a Class Query.
* Algorithm:
* 1. If indexed selection(s) are used, determine the possible URIs for the result
* set of this Class Query from the intersection of the selection criteria.
* 2. Execute the class query (joining with a previous class if specified).
* 3. Do all the selctions (including those that are not indexed.)
*
* @param jc
*/
private void queryClass(JClass jc) {
// Handle an indexed selections.
// All the index selections are logically ANDed together.
Set<URI> selectionUris = null;
List<JSelection> selectionList = jc.getSelections();
for (JSelection js : selectionList) {
// id field is a special case; no need to query anything; just add the id field values to selectionURI's
Set<URI> allValueUris = new HashSet<URI>();
if (jc.getMetaData().isId(js.getField())) {
for (Object value : js.getValues()) {
if (value == null || value.equals("")) {
continue;
}
allValueUris.add(URI.create(value.toString()));
}
if (selectionUris == null) {
selectionUris = new HashSet<URI>();
selectionUris.addAll(allValueUris);
} else {
selectionUris = andUriSet(selectionUris, allValueUris);
}
} else if (jc.getMetaData().isAltIdIndex(js.getField()) || jc.getMetaData().isPrefixIndex(js.getField())) {
// Process alternate id indexes. These are logically ANDed together.
for (Object value : js.getValues()) {
if (value == null || value.equals("")) {
continue;
}
Constraint constraint = jc.getMetaData().buildConstraint(js.getField(), value.toString());
allValueUris.addAll(engine.queryByConstraint(constraint));
}
if (selectionUris == null) {
selectionUris = new HashSet<URI>();
selectionUris.addAll(allValueUris);
} else {
selectionUris = andUriSet(selectionUris, allValueUris);
}
}
}
if (jc.getSubJClasses() != null) {
joinSubClasses(jc);
} else if (jc.getJoinToField() != null) {
// join B.id in A.field
joinBid2A(jc, selectionUris);
} else if (jc.getField() != null) {
// join A.id in B.field
joinAid2B(jc, selectionUris);
} else if (jc.getJoinToAlias() == null) {
// Independent query not joining to previous result
Set<URI> uris = selectionUris;
if (uris == null) {
uris = engine.queryByType(jc.getClazz());
}
// Iterate through the URIs for result
Iterator iter = engine.queryIterObject(jc.getClazz(), uris);
jc.setCacheValid(true);
while (iter.hasNext()) {
DataObject dobj = (DataObject) iter.next();
// If selections are specified, make sure they pass.
if (testSelections(jc, dobj) == false) {
continue;
}
jc.addToCache(dobj);
jc.getUris().add(dobj.getId());
}
} else {
throw new JoinerException("Unrecognized join");
}
}
use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.
the class DbClientTest method testPrefixPaginateConstraint.
@Test
public void testPrefixPaginateConstraint() throws Exception {
int objCount = 10;
List<VirtualArray> varrays = createVirtualArrays(10, "foo");
Constraint labelConstraint = PrefixConstraint.Factory.getLabelPrefixConstraint(VirtualArray.class, "foo");
queryInPaginate(labelConstraint, URIQueryResultList.class, objCount, pageSize);
}
use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.
the class DbClientTest method testRemoveIndex.
@Test
public void testRemoveIndex() {
StoragePool pool = createStoragePools(1, "storagepool").iterator().next();
List<Volume> vols = createVolumes(3, "volume", null, pool);
Constraint constraint = ContainmentConstraint.Factory.getVirtualPoolVolumeConstraint(pool.getId());
URIQueryResultList results = new URIQueryResultList();
_dbClient.queryByConstraint(constraint, results);
Assert.assertEquals(size(results), 3);
// delete the index records
if (InternalDbClient.class.isAssignableFrom(_dbClient.getClass())) {
((InternalDbClient) _dbClient).removeFieldIndex(Volume.class, "pool", "RelationIndex");
URIQueryResultList results2 = new URIQueryResultList();
_dbClient.queryByConstraint(constraint, results2);
Assert.assertFalse(results2.iterator().hasNext());
} else {
Assert.fail("testRemoveIndex requires InternalDbClient");
}
}
use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.
the class DbClientTest method testContainmentPaginateConstraint.
@Test
public void testContainmentPaginateConstraint() throws Exception {
TenantOrg tenant = new TenantOrg();
tenant.setId(URIUtil.createId(TenantOrg.class));
_dbClient.createObject(tenant);
int objCount = 10;
List<Project> projects = createProjects(objCount, tenant);
Constraint constraint = ContainmentConstraint.Factory.getTenantOrgProjectConstraint(tenant.getId());
queryInPaginate(constraint, URIQueryResultList.class, objCount, pageSize);
}
use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.
the class DbClientTest method testContainmentPermissionsPaginateConstraint.
@Test
public void testContainmentPermissionsPaginateConstraint() throws Exception {
int objCount = 10;
String indexKey = "indexKey1";
List<TenantOrg> tenants = createTenants(objCount, "test tenant", indexKey);
Constraint constraint = ContainmentPermissionsConstraint.Factory.getTenantsWithPermissionsConstraint(indexKey);
queryInPaginate(constraint, URIQueryResultList.class, objCount, 3, 5);
}
Aggregations