Search in sources :

Example 11 with ColumnField

use of com.emc.storageos.db.client.impl.ColumnField in project coprhd-controller by CoprHD.

the class DataObjectScanner method addToTypeMap.

private void addToTypeMap(Class clazz, Map<String, ColumnFamily> useCfMap) {
    DependencyInterceptor dependencyInterceptor = new DependencyInterceptor(this.modelClasses);
    Map<String, List<String>> indexCfTypeMap = new HashMap<String, List<String>>();
    DataObjectType doType = TypeMap.getDoType(clazz);
    useCfMap.put(doType.getCF().getName(), doType.getCF());
    boolean include = (clazz.getAnnotation(ExcludeFromGarbageCollection.class) == null);
    Iterator<ColumnField> it = doType.getColumnFields().iterator();
    while (it.hasNext()) {
        ColumnField field = it.next();
        if (field.getIndex() == null) {
            continue;
        }
        useCfMap.put(field.getIndexCF().getName(), field.getIndexCF());
        // for dependency processing
        if (field.getIndexRefType() != null) {
            _log.info(" index: " + field.getIndex().getClass().getSimpleName() + " class: " + clazz.getSimpleName() + " field: " + field.getName() + " indexCF: " + field.getIndexCF().getName() + " reference: " + field.getIndexRefType());
            if (isDuplicateIndexCf(field, indexCfTypeMap)) {
                _log.error("Class: {} has muliple indexed columns of the same type configured to use the same index column family: {}", clazz.getName(), field.getIndexCF().getName());
                throw new IllegalStateException("Class: " + clazz.getName() + " has muliple indexed columns of the same type configured to use the same index column family: " + field.getIndexCF().getName());
            }
            // check first before adding the dependency
            if (!isDependencyValidated(field.getIndexRefType(), clazz)) {
                _log.error("Class: {} is a global object but it has illegal reference to a non-global dependency: {}", clazz.getName(), field.getIndexRefType());
                throw new IllegalStateException("Class: " + clazz.getName() + " is a global object but it has illegal reference to a non-global dependency: " + field.getIndexRefType());
            }
            if (dependencyInterceptor.isConcretModelClass(field.getIndexRefType())) {
                _dependencyTracker.addDependency(field.getIndexRefType(), clazz, field);
            } else {
                _log.info("reference type is abstract class, need special process");
                dependencyInterceptor.handleDependency(_dependencyTracker, clazz, field);
            }
        }
    }
    if (include) {
        _dependencyTracker.includeClass(clazz);
    } else {
        _dependencyTracker.excludeClass(clazz);
    }
}
Also used : HashMap(java.util.HashMap) ColumnField(com.emc.storageos.db.client.impl.ColumnField) ArrayList(java.util.ArrayList) List(java.util.List) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType)

Example 12 with ColumnField

use of com.emc.storageos.db.client.impl.ColumnField in project coprhd-controller by CoprHD.

the class BourneDbClient method findBy.

public <T extends DataObject> List<NamedElement> findBy(Class<T> clazz, String columnField, URI id) throws DataAccessException {
    LOG.debug("findBy({}, {}, {})", new Object[] { clazz, columnField, id });
    DataObjectType doType = TypeMap.getDoType(clazz);
    ColumnField field = doType.getColumnField(columnField);
    ContainmentConstraint constraint = new ContainmentConstraintImpl(id, clazz, field);
    return queryNamedElementsByConstraint(constraint);
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ColumnField(com.emc.storageos.db.client.impl.ColumnField) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType)

Example 13 with ColumnField

use of com.emc.storageos.db.client.impl.ColumnField in project coprhd-controller by CoprHD.

the class ConstraintDescriptor method toConstraint.

public Constraint toConstraint() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
    log.info("ConstraintDescriptor {}", this);
    Class type = Class.forName(dataObjectClassName);
    DataObjectType doType = TypeMap.getDoType(type);
    ColumnField field = doType.getColumnField(columnFieldName);
    Class constraintClass = Class.forName(constraintClassName);
    List<Class> parameterTypes = new ArrayList(arguments.size() + 1);
    List<Object> args = new ArrayList(arguments.size() + 1);
    int i = 1;
    for (Object arg : arguments) {
        if (i == columnFieldPosition) {
            parameterTypes.add(ColumnField.class);
            args.add(field);
        }
        i++;
        parameterTypes.add(arg.getClass());
        args.add(arg);
    }
    if (i == columnFieldPosition) {
        parameterTypes.add(ColumnField.class);
        args.add(field);
    }
    Constructor constructor = constraintClass.getConstructor(parameterTypes.toArray(new Class[0]));
    Constraint constraint = (Constraint) constructor.newInstance(args.toArray());
    return constraint;
}
Also used : Constructor(java.lang.reflect.Constructor) ColumnField(com.emc.storageos.db.client.impl.ColumnField) ArrayList(java.util.ArrayList) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType)

Aggregations

ColumnField (com.emc.storageos.db.client.impl.ColumnField)13 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)3 ArrayList (java.util.ArrayList)3 DbIndex (com.emc.storageos.db.client.impl.DbIndex)2 IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)2 DataObject (com.emc.storageos.db.client.model.DataObject)2 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)2 JsonObject (com.google.gson.JsonObject)2 Rows (com.netflix.astyanax.model.Rows)2 HashMap (java.util.HashMap)2 com.emc.storageos.db.client.constraint (com.emc.storageos.db.client.constraint)1 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 Constraint (com.emc.storageos.db.client.constraint.Constraint)1 ContainmentPermissionsConstraint (com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint)1 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)1 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 ContainmentConstraintImpl (com.emc.storageos.db.client.constraint.impl.ContainmentConstraintImpl)1