use of org.apache.commons.beanutils.converters.CalendarConverter in project coprhd-controller by CoprHD.
the class DBClient method rebuildIndex.
public boolean rebuildIndex(URI id, Class clazz) {
boolean runResult = false;
try {
DataObject queryObject = queryObject(id, clazz);
if (queryObject != null) {
DataObject newObject = queryObject.getClass().newInstance();
newObject.trackChanges();
ConvertUtils.register(new CalendarConverter(null), Calendar.class);
ConvertUtils.register(new DateConverter(null), Date.class);
BeanUtilsBean notNull = new NullAwareBeanUtilsBean();
notNull.copyProperties(newObject, queryObject);
// special change tracking for customized types
BeanInfo bInfo;
try {
bInfo = Introspector.getBeanInfo(clazz);
} catch (IntrospectionException ex) {
log.error("Unexpected exception getting bean info", ex);
throw new RuntimeException("Unexpected exception getting bean info", ex);
}
PropertyDescriptor[] pds = bInfo.getPropertyDescriptors();
for (PropertyDescriptor pd : pds) {
Object val = pd.getReadMethod().invoke(newObject);
if (val instanceof AbstractChangeTrackingSet) {
AbstractChangeTrackingSet valueSet = (AbstractChangeTrackingSet) val;
valueSet.markAllForOverwrite();
} else if (val instanceof AbstractChangeTrackingMap) {
AbstractChangeTrackingMap valueMap = (AbstractChangeTrackingMap) val;
valueMap.markAllForOverwrite();
} else if (val instanceof AbstractChangeTrackingSetMap) {
AbstractChangeTrackingSetMap valueMap = (AbstractChangeTrackingSetMap) val;
Set<String> keys = valueMap.keySet();
if (keys != null) {
Iterator<String> it = keys.iterator();
while (it.hasNext()) {
String key = it.next();
AbstractChangeTrackingSet valueSet = valueMap.get(key);
valueSet.markAllForOverwrite();
}
}
}
}
_dbClient.updateObject(newObject);
logMsg(String.format("Successfully rebuild index for %s in cf %s", id, clazz));
runResult = true;
} else {
logMsg(String.format("Could not find data object record for %s in cf %s, no need to rebuild index. Mark as success too.", id, clazz));
runResult = true;
}
} catch (Exception e) {
logMsg(String.format("Error when rebuilding index for %s in cf %s", id, clazz), true, e);
}
return runResult;
}
Aggregations