Search in sources :

Example 1 with Cf

use of com.emc.storageos.db.client.model.Cf in project coprhd-controller by CoprHD.

the class DataObjectType method init.

/**
 * Initializes cf & all column metadata for this data type
 */
private void init() {
    String cfName = _clazz.getAnnotation(Cf.class).value();
    _cf = new ColumnFamily<String, CompositeColumnName>(cfName, StringSerializer.get(), CompositeColumnNameSerializer.get());
    BeanInfo bInfo;
    try {
        bInfo = Introspector.getBeanInfo(_clazz);
    } catch (IntrospectionException ex) {
        throw DatabaseException.fatals.serializationFailedInitializingBeanInfo(_clazz, ex);
    }
    PropertyDescriptor[] pds = bInfo.getPropertyDescriptors();
    for (int i = 0; i < pds.length; i++) {
        PropertyDescriptor pd = pds[i];
        // skip class property
        if (!isColumnField(bInfo.getBeanDescriptor().getBeanClass().getName(), pd)) {
            _log.info("Not column field, skip {}.{}", bInfo.getBeanDescriptor().getBeanClass().getName(), pd.getName());
            continue;
        }
        ColumnField col = new ColumnField(this, pd);
        if (col.getType() == ColumnField.ColumnType.Id) {
            _idField = col;
            continue;
        }
        _columnFieldMap.put(col.getName(), col);
        if (col.isLazyLoaded()) {
            _lazyLoadedFields.add(col);
        }
    }
    // Need to resolve field cross references here....
    Collection<ColumnField> fields = _columnFieldMap.values();
    for (ColumnField field : fields) {
        DbIndex index = field.getIndex();
        if (index instanceof AggregateDbIndex) {
            String[] groupByArr = ((AggregateDbIndex) index).getGroupBy();
            for (String groupByName : groupByArr) {
                ColumnField groupField = _columnFieldMap.get(groupByName);
                // The index for this field will be cleared together with the index of the referenced field
                if (groupField == null || groupField.getIndex() == null) {
                    DatabaseException.fatals.invalidAnnotation("AggregateIndex", "property " + groupByName + " does not have a valid value or referenced another indexed field");
                }
                ((AggregateDbIndex) index).addGroupByField(_columnFieldMap.get(groupByName));
                if (groupField != null && groupField.getDependentFields() != null) {
                    groupField.getDependentFields().add(field);
                }
                field.getRefFields().add(groupField);
            }
            if (!field.getRefFields().isEmpty()) {
                _preprocessedFields.add(field);
            }
        }
    }
    // initialization for lazy loading
    lazyLoadInit();
}
Also used : Cf(com.emc.storageos.db.client.model.Cf) PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException)

Aggregations

Cf (com.emc.storageos.db.client.model.Cf)1 BeanInfo (java.beans.BeanInfo)1 IntrospectionException (java.beans.IntrospectionException)1 PropertyDescriptor (java.beans.PropertyDescriptor)1