use of com.emc.storageos.db.common.DataObjectScanner in project coprhd-controller by CoprHD.
the class DBClient method queryAndDeleteObject.
/**
* Query for a record with the given id and type, and print the contents in human readable format
*
* @param id
* @param clazz
* @param <T>
*/
private <T extends DataObject> boolean queryAndDeleteObject(URI id, Class<T> clazz, boolean force) throws Exception {
DependencyTracker dependencyTracker = null;
if (_dependencyChecker == null) {
DataObjectScanner dataObjectscanner = (DataObjectScanner) ctx.getBean("dataObjectScanner");
dependencyTracker = dataObjectscanner.getDependencyTracker();
_dependencyChecker = new DependencyChecker(_dbClient, dependencyTracker);
}
String reference = _dependencyChecker.checkDependencies(id, clazz, false);
if (reference != null) {
if (!force) {
System.err.println(String.format("Failed to delete the object %s: there are active dependencies", id));
printReferenceWhenDeletingFailed(id, clazz, dependencyTracker);
return false;
}
log.info("Force to delete object {} that has active dependencies", id);
}
T object = queryObject(id, clazz);
if (object == null) {
System.err.println(String.format("The object %s has already been deleted", id));
return false;
}
if ((object.canBeDeleted() == null) || force) {
if (object.canBeDeleted() != null) {
log.info("Force to delete object {} that can't be deleted", id);
}
_dbClient.internalRemoveObjects(object);
return true;
}
System.err.println(String.format("The object %s can't be deleted", id));
printReferenceWhenDeletingFailed(id, clazz, dependencyTracker);
return false;
}
Aggregations