use of com.emc.storageos.db.client.constraint.PrefixConstraint in project coprhd-controller by CoprHD.
the class DbIndexTest method testPrefixIndex.
@Test
public void testPrefixIndex() {
URI id = URIUtil.createId(Volume.class);
String lbl0 = "abcd1234";
String lbl1 = "efgh5678";
PrefixConstraint constraint0 = PrefixConstraint.Factory.getFullMatchConstraint(Volume.class, "label", lbl0);
PrefixConstraint constraint1 = PrefixConstraint.Factory.getFullMatchConstraint(Volume.class, "label", lbl1);
{
Volume obj = new Volume();
obj.setId(id);
obj.setLabel(lbl0);
_dbClient.createObject(obj);
}
verifyContain(constraint0, id, 1);
verifyContain(constraint1, null, 0);
{
Volume obj = _dbClient.queryObject(Volume.class, id);
obj.setLabel(lbl1);
_dbClient.persistObject(obj);
}
verifyContain(constraint1, id, 1);
verifyContain(constraint0, null, 0);
}
use of com.emc.storageos.db.client.constraint.PrefixConstraint in project coprhd-controller by CoprHD.
the class DbIndexTest method testScopedLabelIndex.
@Test
public void testScopedLabelIndex() {
URI id = URIUtil.createId(Volume.class);
URI pid0 = URIUtil.createId(TenantOrg.class);
URI pid1 = URIUtil.createId(TenantOrg.class);
String lbl0 = "abcd1234";
String lbl1 = "efgh5678";
PrefixConstraint constraint0 = new LabelConstraintImpl(pid0, lbl0, TypeMap.getDoType(Volume.class).getColumnField("tags"));
PrefixConstraint constraint1 = new LabelConstraintImpl(pid1, lbl1, TypeMap.getDoType(Volume.class).getColumnField("tags"));
{
Volume obj = new Volume();
obj.setId(id);
obj.setTag(new ScopedLabelSet());
obj.getTag().add(new ScopedLabel(pid0.toString(), lbl0));
_dbClient.createObject(obj);
}
verifyContain(constraint0, id, 1);
verifyContain(constraint1, null, 0);
{
Volume obj = _dbClient.queryObject(Volume.class, id);
obj.getTag().add(new ScopedLabel(pid1.toString(), lbl1));
_dbClient.persistObject(obj);
}
verifyContain(constraint0, id, 1);
verifyContain(constraint1, id, 1);
{
Volume obj = _dbClient.queryObject(Volume.class, id);
obj.getTag().remove(new ScopedLabel(pid0.toString(), lbl0));
_dbClient.persistObject(obj);
}
verifyContain(constraint1, id, 1);
verifyContain(constraint0, null, 0);
}
use of com.emc.storageos.db.client.constraint.PrefixConstraint in project coprhd-controller by CoprHD.
the class VPlexUtil method lookupVplexProject.
/**
* Lookup the Project assigned to this VPlex for its artifact, using the Vplex nativeGuid
* as the project name. If one is found thatbelongs to the root tenant, it is returned.
* Otherwise the project from the protoVolume is returned.
*
* @protoVolume A volume from the backend array.
* If no Vplex project is found, the proto volume's project is returned.
* @param vplexSystem A StorageSystem instance representing a VPlex.
* @param dbClient A reference to a database client.
*
* @return Project instance (vplex project if created, otherwise protoVolume's project).
*/
public static Project lookupVplexProject(Volume protoVolume, StorageSystem vplexSystem, DbClient dbClient) {
BasePermissionsHelper helper = new BasePermissionsHelper(dbClient);
TenantOrg rootTenant = helper.getRootTenant();
PrefixConstraint constraint = PrefixConstraint.Factory.getLabelPrefixConstraint(Project.class, vplexSystem.getNativeGuid());
URIQueryResultList result = new URIQueryResultList();
dbClient.queryByConstraint(constraint, result);
Iterator<URI> iter = result.iterator();
while (iter.hasNext()) {
Project project = dbClient.queryObject(Project.class, iter.next());
if (project == null || project.getInactive() == true) {
continue;
}
if (project.getLabel().equals(vplexSystem.getNativeGuid()) && project.getTenantOrg().getURI().toString().equals(rootTenant.getId().toString())) {
return project;
}
}
// VPlex project not found. Return on from proto volume.
return dbClient.queryObject(Project.class, protoVolume.getProject().getURI());
}
use of com.emc.storageos.db.client.constraint.PrefixConstraint in project coprhd-controller by CoprHD.
the class ModelClientImpl method findByPrefix.
@Override
public <T extends DataObject> List<NamedElement> findByPrefix(Class<T> clazz, String columnField, String prefix) throws DatabaseException {
LOG.debug("findByPrefix({}, {}, {})", new Object[] { clazz, columnField, prefix });
DataObjectType doType = TypeMap.getDoType(clazz);
PrefixConstraint constraint = new PrefixConstraintImpl(prefix, doType.getColumnField(columnField));
return queryNamedElementsByConstraint(constraint);
}
use of com.emc.storageos.db.client.constraint.PrefixConstraint in project coprhd-controller by CoprHD.
the class BourneDbClient method findByPrefix.
public <T extends DataObject> List<NamedElement> findByPrefix(Class<T> clazz, String prefixColumnField, String prefix) throws DataAccessException {
LOG.debug("findByPrefix({}, {}, {})", new Object[] { clazz, prefixColumnField, prefix });
DataObjectType doType = TypeMap.getDoType(clazz);
PrefixConstraint constraint = new PrefixConstraintImpl(prefix, doType.getColumnField(prefixColumnField));
return queryNamedElementsByConstraint(constraint);
}
Aggregations