use of com.emc.storageos.db.client.impl.ColumnField in project coprhd-controller by CoprHD.
the class DataObjectUtils method getPropertyValue.
/**
* This function returns the property value for an object of {@link DataObject} subtype.
*
* @param clzz the object class that should be a subtype of {@link DataObject}
* @param dataObject the instance of clzz
* @param property the string name of the property
* @return the value of the property
*/
public static <T extends DataObject> Object getPropertyValue(Class<T> clzz, DataObject dataObject, String property) {
try {
DataObjectType doType = TypeMap.getDoType(clzz);
ColumnField field = doType.getColumnField(property);
return field.getPropertyDescriptor().getReadMethod().invoke(dataObject);
} catch (Exception ex) {
throw DatabaseException.fatals.failedToReadPropertyValue(clzz, property, ex);
}
}
use of com.emc.storageos.db.client.impl.ColumnField in project coprhd-controller by CoprHD.
the class DbDependencyPurger method purge.
private <T extends DataObject> void purge(T dataObj, Set<URI> visited) throws DatabaseException {
if (dataObj == null || visited.contains(dataObj.getId())) {
return;
}
visited.add(dataObj.getId());
Class<? extends DataObject> type = dataObj.getClass();
List<DependencyTracker.Dependency> dependencyList = _dependencyTracker.getDependencies(type);
try {
for (DependencyTracker.Dependency dependence : dependencyList) {
// Query relational index to see if any dependents exist
Class<? extends DataObject> childType = dependence.getType();
ColumnField childField = dependence.getColumnField();
ContainmentConstraint constraint = new ContainmentConstraintImpl(dataObj.getId(), childType, childField);
URIQueryResultList list = new URIQueryResultList();
_dbClient.queryByConstraint(constraint, list);
if (!list.iterator().hasNext()) {
continue;
}
// used to remove efficiently identical URIs from the list.
HashSet<URI> childSet = new HashSet();
while (list.iterator().hasNext()) {
childSet.clear();
while (list.iterator().hasNext()) {
childSet.add(list.iterator().next());
if (childSet.size() >= MAX_PERSISTENCE_LIMIT) {
break;
}
}
List<URI> childUriList = new ArrayList(childSet);
List<? extends DataObject> children = _dbClient.queryObjectField(childType, childField.getName(), childUriList);
List<DataObject> decommissionedChildren = new ArrayList();
for (DataObject childObj : children) {
switch(childField.getType()) {
case TrackingSet:
case TrackingMap:
// assume @indexByKey is set
java.beans.PropertyDescriptor pd = childField.getPropertyDescriptor();
Object fieldValue = pd.getReadMethod().invoke(childObj);
boolean deactivateChildObj = false;
if (fieldValue != null) {
// should be always true.
if (AbstractChangeTrackingMap.class.isAssignableFrom(pd.getPropertyType())) {
AbstractChangeTrackingMap<?> trackingMap = (AbstractChangeTrackingMap<?>) fieldValue;
trackingMap.remove(dataObj.getId().toString());
if (trackingMap.isEmpty() && childField.deactivateIfEmpty()) {
deactivateChildObj = true;
}
} else if (AbstractChangeTrackingSet.class.isAssignableFrom(pd.getPropertyType())) {
AbstractChangeTrackingSet trackingSet = (AbstractChangeTrackingSet) fieldValue;
trackingSet.remove(dataObj.getId().toString());
if (trackingSet.isEmpty() && childField.deactivateIfEmpty()) {
deactivateChildObj = true;
}
}
if (deactivateChildObj) {
purge(childObj, visited);
childObj.setInactive(true);
_log.info("Deactivated db_object: type = {}, id = {}", childType.toString(), childObj.getId());
}
}
break;
default:
{
purge(childObj, visited);
childObj.setInactive(true);
_log.info("Deactivated db_object: type = {}, id = {}", childType.toString(), childObj.getId());
}
}
decommissionedChildren.add(childObj);
}
_dbClient.persistObject(decommissionedChildren);
}
}
}// should never get here....
catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException e) {
_log.error("Unexpected purge error", e);
throw DatabaseException.fatals.purgeFailed(e);
}
}
use of com.emc.storageos.db.client.impl.ColumnField in project coprhd-controller by CoprHD.
the class DbCli method printFieldsByCf.
/**
* Print the fields' info of column family.
*
* @Param cfName
*/
public void printFieldsByCf(String cfName) {
// fill in type from cfName
final Class clazz = getClassFromCFName(cfName);
if (clazz == null) {
return;
}
if (DataObject.class.isAssignableFrom(clazz)) {
DataObjectType doType = TypeMap.getDoType(clazz);
System.out.println(String.format("Column Family: %s", doType.getCF().getName()));
Collection<ColumnField> cfs = doType.getColumnFields();
Iterator it = cfs.iterator();
while (it.hasNext()) {
ColumnField field = (ColumnField) it.next();
System.out.println(String.format("\tfield=%-30s\ttype=%s", field.getName(), field.getPropertyDescriptor().getPropertyType().toString().substring(6)));
}
}
}
use of com.emc.storageos.db.client.impl.ColumnField in project coprhd-controller by CoprHD.
the class PersistingChangesTest method getIndexRecordCount.
private int getIndexRecordCount(String fieldName) throws ConnectionException {
Keyspace keyspace = ((DbClientTest.DbClientImplUnitTester) dbClient).getLocalContext().getKeyspace();
DataObjectType doType = TypeMap.getDoType(Volume.class);
ColumnField field = doType.getColumnField(fieldName);
ColumnFamilyQuery<String, IndexColumnName> query = keyspace.prepareQuery(field.getIndexCF());
OperationResult<Rows<String, IndexColumnName>> result = query.getAllRows().execute();
int count = 0;
for (Row<String, IndexColumnName> row : result.getResult()) {
_log.debug("{}, RowKey={}, Columns Size={}", ++count, row.getKey(), row.getColumns().size());
for (Column<IndexColumnName> column : row.getColumns()) {
_log.debug("\t, Column Name={}, String Value={}.", column.getName(), column.getStringValue());
}
}
return count;
}
use of com.emc.storageos.db.client.impl.ColumnField in project coprhd-controller by CoprHD.
the class DbIndexTest method apply.
// Returns a list of fields touched
public static void apply(DataObject obj, DataObjectType doType, Object[] ops) {
try {
for (int i = 0; i < ops.length; i++) {
if (!(ops[i] instanceof String)) {
throw new IllegalArgumentException();
}
String op = (String) ops[i];
// Get name of the field
String fieldName = op.substring(0, op.length() - 1);
op = op.substring(op.length() - 1, op.length());
// Get type of the field
ColumnField field = doType.getColumnField(fieldName);
PropertyDescriptor propDesc = field.getPropertyDescriptor();
switch(field.getType()) {
case Primitive:
case NamedURI:
case Id:
case NestedObject:
if (op.charAt(0) != '=') {
throw new IllegalArgumentException();
}
propDesc.getWriteMethod().invoke(obj, ops[++i]);
break;
case TrackingSet:
if (op.charAt(0) == '<') {
AbstractChangeTrackingSet set = (AbstractChangeTrackingSet) propDesc.getReadMethod().invoke(obj);
if (set == null) {
set = (AbstractChangeTrackingSet) propDesc.getPropertyType().getConstructor(new Class<?>[0]).newInstance(new Object[0]);
propDesc.getWriteMethod().invoke(obj, set);
}
set.add(ops[++i]);
} else if (op.charAt(0) == '>') {
AbstractChangeTrackingSet set = (AbstractChangeTrackingSet) propDesc.getReadMethod().invoke(obj);
set.remove(ops[++i]);
} else if (op.charAt(0) == '=') {
propDesc.getWriteMethod().invoke(obj, ops[++i]);
}
break;
case TrackingMap:
if (op.charAt(0) == '<') {
AbstractChangeTrackingMap map = (AbstractChangeTrackingMap) propDesc.getReadMethod().invoke(obj);
if (map == null) {
map = (AbstractChangeTrackingMap) propDesc.getPropertyType().getConstructor(new Class<?>[0]).newInstance(new Object[0]);
propDesc.getWriteMethod().invoke(obj, map);
}
map.put((String) ops[i + 1], ops[i + 2]);
i += 2;
} else if (op.charAt(0) == '>') {
AbstractChangeTrackingMap map = (AbstractChangeTrackingMap) propDesc.getReadMethod().invoke(obj);
map.remove((String) ops[++i]);
} else if (op.charAt(0) == '=') {
propDesc.getWriteMethod().invoke(obj, ops[++i]);
}
break;
case TrackingSetMap:
if (op.charAt(0) == '<') {
AbstractChangeTrackingSetMap setMap = (AbstractChangeTrackingSetMap) propDesc.getReadMethod().invoke(obj);
if (setMap == null) {
setMap = (AbstractChangeTrackingSetMap) propDesc.getPropertyType().getConstructor(new Class<?>[0]).newInstance(new Object[0]);
propDesc.getWriteMethod().invoke(obj, setMap);
}
setMap.put((String) ops[i + 1], ops[i + 2]);
i += 2;
} else if (op.charAt(0) == '>') {
AbstractChangeTrackingSetMap setMap = (AbstractChangeTrackingSetMap) propDesc.getReadMethod().invoke(obj);
setMap.remove((String) ops[i + 1], ops[i + 2]);
i += 2;
} else if (op.charAt(0) == '=') {
propDesc.getWriteMethod().invoke(obj, ops[++i]);
}
break;
default:
break;
}
}
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException | InstantiationException | NoSuchMethodException | SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations