Search in sources :

Example 1 with PrefixIndex

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

the class ColumnField method processProperty.

/**
 * Helper to reflect on PropertyDescriptor and fill out _type and _name
 * information;
 */
private void processProperty() {
    // ignore if no get method
    if (_property.getReadMethod() == null) {
        return;
    }
    Method readMethod = _property.getReadMethod();
    Annotation[] annotations = readMethod.getAnnotations();
    ColumnFamily<String, IndexColumnName> indexCF = null;
    int minPrefixChars;
    boolean isLazyLoadable = false;
    boolean hasRelationIndex = false;
    for (int i = 0; i < annotations.length; i++) {
        Annotation a = annotations[i];
        if (a instanceof Id) {
            _colType = ColumnType.Id;
            _name = "Id";
        } else if (a instanceof Name) {
            _name = ((Name) a).value();
            if (Number.class.isAssignableFrom(_valueType) || _valueType == URI.class || _valueType == String.class || _valueType == Date.class || _valueType == Boolean.class || _valueType == Byte.class || _valueType == Long.class || _valueType == byte[].class || _valueType.isEnum() || _valueType == Calendar.class) {
                _colType = ColumnType.Primitive;
                compositeName = new CompositeColumnName(_name);
            } else if (NamedURI.class == _valueType) {
                _colType = ColumnType.NamedURI;
                compositeName = new CompositeColumnName(_name);
            } else if (AbstractChangeTrackingSet.class.isAssignableFrom(_valueType)) {
                _colType = ColumnType.TrackingSet;
            } else if (AbstractChangeTrackingMap.class.isAssignableFrom(_valueType)) {
                _colType = ColumnType.TrackingMap;
            } else if (AbstractChangeTrackingSetMap.class.isAssignableFrom(_valueType)) {
                _colType = ColumnType.TrackingSetMap;
            } else if (AbstractSerializableNestedObject.class.isAssignableFrom(_valueType)) {
                _colType = ColumnType.NestedObject;
                compositeName = new CompositeColumnName(_name);
            } else if (Collection.class.isAssignableFrom(_valueType) || DataObject.class.isAssignableFrom(_valueType)) {
                isLazyLoadable = true;
            } else {
                throw new IllegalArgumentException(_name + " " + _valueType + " " + _property + " " + _parentType.getDataObjectClass());
            }
        } else if (a instanceof Ttl) {
            _ttl = ((Ttl) a).value();
        } else if (a instanceof RelationIndex) {
            indexCF = new ColumnFamily<String, IndexColumnName>(((RelationIndex) a).cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
            _indexRefType = ((RelationIndex) a).type();
            deactivateIfEmpty = ((RelationIndex) a).deactivateIfEmpty();
            _index = new RelationDbIndex(indexCF);
        } else if (a instanceof AlternateId) {
            indexCF = new ColumnFamily<String, IndexColumnName>(((AlternateId) a).value(), StringSerializer.get(), IndexColumnNameSerializer.get());
            _index = new AltIdDbIndex(indexCF);
        } else if (a instanceof ClassNameTimeSeries) {
            ColumnFamily<String, ClassNameTimeSeriesIndexColumnName> newIndexCF = new ColumnFamily<String, ClassNameTimeSeriesIndexColumnName>(((ClassNameTimeSeries) a).value(), StringSerializer.get(), ClassNameTimeSeriesSerializer.get());
            _index = new ClassNameTimeSeriesDBIndex(newIndexCF);
        } else if (a instanceof TimeSeriesAlternateId) {
            ColumnFamily<String, TimeSeriesIndexColumnName> newIndexCF = new ColumnFamily<String, TimeSeriesIndexColumnName>(((TimeSeriesAlternateId) a).value(), StringSerializer.get(), TimeSeriesColumnNameSerializer.get());
            _index = new TimeSeriesDbIndex(newIndexCF);
        } else if (a instanceof NamedRelationIndex) {
            indexCF = new ColumnFamily<String, IndexColumnName>(((NamedRelationIndex) a).cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
            _indexRefType = ((NamedRelationIndex) a).type();
            _index = new NamedRelationDbIndex(indexCF);
        } else if (a instanceof PrefixIndex) {
            indexCF = new ColumnFamily<String, IndexColumnName>(((PrefixIndex) a).cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
            minPrefixChars = ((PrefixIndex) a).minChars();
            _index = new PrefixDbIndex(indexCF, minPrefixChars);
        } else if (a instanceof PermissionsIndex && AbstractChangeTrackingSetMap.class.isAssignableFrom(_valueType)) {
            indexCF = new ColumnFamily<String, IndexColumnName>(((PermissionsIndex) a).value(), StringSerializer.get(), IndexColumnNameSerializer.get());
            _index = new PermissionsDbIndex(indexCF);
        } else if (a instanceof Encrypt && _valueType == String.class) {
            _encrypt = true;
        } else if (a instanceof ScopedLabelIndex) {
            ScopedLabelIndex scopeLabelIndex = (ScopedLabelIndex) a;
            indexCF = new ColumnFamily<String, IndexColumnName>(scopeLabelIndex.cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
            minPrefixChars = scopeLabelIndex.minChars();
            _index = new ScopedLabelDbIndex(indexCF, minPrefixChars);
        } else if (a instanceof ClockIndependent) {
            clockIndValue = ((ClockIndependent) a).value();
        } else if (a instanceof DecommissionedIndex && Boolean.class.isAssignableFrom(_valueType)) {
            if (!_property.getName().equals(DataObject.INACTIVE_FIELD_NAME) || _parentType.getDataObjectClass().getAnnotation(NoInactiveIndex.class) == null) {
                indexCF = new ColumnFamily<String, IndexColumnName>(((DecommissionedIndex) a).value(), StringSerializer.get(), IndexColumnNameSerializer.get());
                _index = new DecommissionedDbIndex(indexCF);
            }
        } else if (a instanceof IndexByKey && (AbstractChangeTrackingMap.class.isAssignableFrom(_valueType) || AbstractChangeTrackingSet.class.isAssignableFrom(_valueType))) {
            _indexByKey = true;
        } else if (a instanceof Relation) {
            hasRelationIndex = true;
            if (((Relation) a).type().equals(DataObject.class)) {
                _mappedByType = _valueType;
            } else {
                _mappedByType = ((Relation) a).type();
            }
            _mappedByField = ((Relation) a).mappedBy();
        } else if (a instanceof AggregatedIndex) {
            indexCF = new ColumnFamily<String, IndexColumnName>(((AggregatedIndex) a).cf(), StringSerializer.get(), IndexColumnNameSerializer.get());
            String groupBy = ((AggregatedIndex) a).groupBy();
            boolean global = ((AggregatedIndex) a).classGlobal();
            _index = new AggregateDbIndex(indexCF, groupBy, global);
        }
    }
    if (_name == null) {
        String className = _parentType.getDataObjectClass().getName();
        String fieldName = _property.getName();
        throw new IllegalArgumentException(String.format("@Name annotation missing from field '%s' in class '%s'", fieldName, className));
    }
    if (_index != null) {
        _index.setFieldName(_name);
        _index.setIndexByKey(_indexByKey);
    }
    if (isLazyLoadable && hasRelationIndex) {
        lazyLoaded = true;
    }
}
Also used : NamedRelationIndex(com.emc.storageos.db.client.model.NamedRelationIndex) DecommissionedIndex(com.emc.storageos.db.client.model.DecommissionedIndex) Name(com.emc.storageos.db.client.model.Name) PrefixIndex(com.emc.storageos.db.client.model.PrefixIndex) NoInactiveIndex(com.emc.storageos.db.client.model.NoInactiveIndex) AggregatedIndex(com.emc.storageos.db.client.model.AggregatedIndex) Method(java.lang.reflect.Method) Encrypt(com.emc.storageos.db.client.model.Encrypt) PermissionsIndex(com.emc.storageos.db.client.model.PermissionsIndex) DataObject(com.emc.storageos.db.client.model.DataObject) IndexByKey(com.emc.storageos.db.client.model.IndexByKey) AbstractChangeTrackingMap(com.emc.storageos.db.client.model.AbstractChangeTrackingMap) AlternateId(com.emc.storageos.db.client.model.AlternateId) TimeSeriesAlternateId(com.emc.storageos.db.client.model.TimeSeriesAlternateId) Id(com.emc.storageos.db.client.model.Id) AlternateId(com.emc.storageos.db.client.model.AlternateId) TimeSeriesAlternateId(com.emc.storageos.db.client.model.TimeSeriesAlternateId) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet) AbstractChangeTrackingSetMap(com.emc.storageos.db.client.model.AbstractChangeTrackingSetMap) Ttl(com.emc.storageos.db.client.model.Ttl) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) ClockIndependent(com.emc.storageos.db.client.model.ClockIndependent) Relation(com.emc.storageos.db.client.model.Relation) ScopedLabelIndex(com.emc.storageos.db.client.model.ScopedLabelIndex) NamedRelationIndex(com.emc.storageos.db.client.model.NamedRelationIndex) RelationIndex(com.emc.storageos.db.client.model.RelationIndex) Annotation(java.lang.annotation.Annotation) ClassNameTimeSeries(com.emc.storageos.db.client.model.ClassNameTimeSeries) TimeSeriesAlternateId(com.emc.storageos.db.client.model.TimeSeriesAlternateId)

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 AggregatedIndex (com.emc.storageos.db.client.model.AggregatedIndex)1 AlternateId (com.emc.storageos.db.client.model.AlternateId)1 ClassNameTimeSeries (com.emc.storageos.db.client.model.ClassNameTimeSeries)1 ClockIndependent (com.emc.storageos.db.client.model.ClockIndependent)1 DataObject (com.emc.storageos.db.client.model.DataObject)1 DecommissionedIndex (com.emc.storageos.db.client.model.DecommissionedIndex)1 Encrypt (com.emc.storageos.db.client.model.Encrypt)1 Id (com.emc.storageos.db.client.model.Id)1 IndexByKey (com.emc.storageos.db.client.model.IndexByKey)1 Name (com.emc.storageos.db.client.model.Name)1 NamedRelationIndex (com.emc.storageos.db.client.model.NamedRelationIndex)1 NoInactiveIndex (com.emc.storageos.db.client.model.NoInactiveIndex)1 PermissionsIndex (com.emc.storageos.db.client.model.PermissionsIndex)1 PrefixIndex (com.emc.storageos.db.client.model.PrefixIndex)1 Relation (com.emc.storageos.db.client.model.Relation)1 RelationIndex (com.emc.storageos.db.client.model.RelationIndex)1 ScopedLabelIndex (com.emc.storageos.db.client.model.ScopedLabelIndex)1