Search in sources :

Example 1 with CalendarConverter

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;
}
Also used : DateConverter(org.apache.commons.beanutils.converters.DateConverter) PropertyDescriptor(java.beans.PropertyDescriptor) AbstractChangeTrackingSetMap(com.emc.storageos.db.client.model.AbstractChangeTrackingSetMap) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) IOException(java.io.IOException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CalendarConverter(org.apache.commons.beanutils.converters.CalendarConverter) BeanUtilsBean(org.apache.commons.beanutils.BeanUtilsBean) DataObject(com.emc.storageos.db.client.model.DataObject) AbstractChangeTrackingMap(com.emc.storageos.db.client.model.AbstractChangeTrackingMap) DataObject(com.emc.storageos.db.client.model.DataObject) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet)

Aggregations

AbstractChangeTrackingMap (com.emc.storageos.db.client.model.AbstractChangeTrackingMap)1 AbstractChangeTrackingSet (com.emc.storageos.db.client.model.AbstractChangeTrackingSet)1 AbstractChangeTrackingSetMap (com.emc.storageos.db.client.model.AbstractChangeTrackingSetMap)1 DataObject (com.emc.storageos.db.client.model.DataObject)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)1 BeanInfo (java.beans.BeanInfo)1 IntrospectionException (java.beans.IntrospectionException)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 BeanUtilsBean (org.apache.commons.beanutils.BeanUtilsBean)1 CalendarConverter (org.apache.commons.beanutils.converters.CalendarConverter)1 DateConverter (org.apache.commons.beanutils.converters.DateConverter)1