Search in sources :

Example 6 with Joiner

use of com.emc.storageos.db.joiner.Joiner in project coprhd-controller by CoprHD.

the class ApiSystemTestUtil method getURIFromLabel.

public <T extends DataObject> URI getURIFromLabel(Class<T> clazz, String label) {
    Joiner j = new Joiner(dbClient);
    Set<URI> uris = j.join(clazz, "a").match("label", label).go().uris("a");
    if (uris.isEmpty()) {
        return null;
    } else {
        return uris.iterator().next();
    }
}
Also used : Joiner(com.emc.storageos.db.joiner.Joiner) URI(java.net.URI)

Example 7 with Joiner

use of com.emc.storageos.db.joiner.Joiner in project coprhd-controller by CoprHD.

the class ApiSystemTestUtil method findVolumesByNativeGuid.

public List<Volume> findVolumesByNativeGuid(URI storageSystemURI, List<String> nativeGuids) {
    Joiner joiner = new Joiner(dbClient);
    List<Volume> volumes = joiner.join(Volume.class, "vol").match("storageDevice", storageSystemURI).match("nativeGuid", nativeGuids).go().list("vol");
    return volumes;
}
Also used : Joiner(com.emc.storageos.db.joiner.Joiner) Volume(com.emc.storageos.db.client.model.Volume)

Example 8 with Joiner

use of com.emc.storageos.db.joiner.Joiner in project coprhd-controller by CoprHD.

the class WorkflowTest method readWorkflowFromDb.

/**
 * Reads a workflow from the database. Called recursively for sub-workflows.
 *
 * @param orchTaskId
 *            -- the Orchestration task id.
 * @return A map from step description to WorkflowStep entry
 */
private Map<String, WorkflowStep> readWorkflowFromDb(String orchTaskId) {
    Map<String, WorkflowStep> msgToStep = new HashMap<String, WorkflowStep>();
    Joiner j = new Joiner(dbClient);
    List<WorkflowStep> steps = j.join(com.emc.storageos.db.client.model.Workflow.class, "wf").match("orchTaskId", orchTaskId).join("wf", WorkflowStep.class, "step", "workflow").go().list("step");
    for (WorkflowStep step : steps) {
        msgToStep.put(step.getDescription(), step);
        System.out.println(String.format("Step %s: status: %s message: %s", step.getDescription(), step.getState(), step.getMessage()));
        // Check for sub-workflow.
        Map<String, WorkflowStep> subWorkflowMap = readWorkflowFromDb(step.getStepId());
        msgToStep.putAll(subWorkflowMap);
    }
    return msgToStep;
}
Also used : Joiner(com.emc.storageos.db.joiner.Joiner) WorkflowStep(com.emc.storageos.db.client.model.WorkflowStep) HashMap(java.util.HashMap)

Example 9 with Joiner

use of com.emc.storageos.db.joiner.Joiner in project coprhd-controller by CoprHD.

the class LazyLoader method load.

/**
 * @param clazz class type of the return list
 * @param parentId id of the owning object
 * @param col field to be lazy loaded
 * @param retList return list
 */
public <T extends DataObject> Iterator<T> load(String lazyLoadedFieldName, T obj, Collection<T> collection, DbClientCallbackEvent cb) {
    DataObjectType doType = TypeMap.getDoType(obj.getClass());
    ColumnField lazyLoadedField = doType.getColumnField(lazyLoadedFieldName);
    if (lazyLoadedField == null) {
        throw new IllegalStateException(String.format("lazy loaded field %s in class %s not found; make sure the argument passed into refreshMappedByField matches the @Name annotation on the getter method", lazyLoadedFieldName, obj.getClass()));
    }
    ColumnField mappedByField = getMappedByField(lazyLoadedField, doType);
    if (mappedByField == null) {
        throw new IllegalStateException(String.format("lazy loaded field %s in class %s could not be found;" + " make sure the mappedBy argument in the @Relation annotation matches the @Name annotation on the mapped by field", lazyLoadedFieldName, obj.getClass()));
    }
    Joiner j = queryObjects(obj, cb, lazyLoadedField, mappedByField, JOINER_ALIAS_TWO);
    if (collection != null) {
        collection.addAll((Collection<? extends T>) j.list(JOINER_ALIAS_TWO));
    }
    return j.iterator(JOINER_ALIAS_TWO);
}
Also used : Joiner(com.emc.storageos.db.joiner.Joiner)

Example 10 with Joiner

use of com.emc.storageos.db.joiner.Joiner in project coprhd-controller by CoprHD.

the class LazyLoader method load.

/**
 * @param lazyLoadedFieldName
 * @param _id
 * @param fieldValue
 */
public <T extends DataObject> void load(String lazyLoadedFieldName, DataObject obj) {
    DataObjectType doType = TypeMap.getDoType(obj.getClass());
    ColumnField lazyLoadedField = doType.getColumnField(lazyLoadedFieldName);
    if (lazyLoadedField == null) {
        throw new IllegalStateException(String.format("lazy loaded field %s in class %s not found; make sure the argument passed into refreshMappedByField matches the @Name annotation on the getter method", lazyLoadedFieldName, obj.getClass()));
    }
    if (!lazyLoadedField.isLazyLoaded()) {
        log.debug("skipping; field %s in class %s is not a lazy loadable field", lazyLoadedFieldName, obj.getClass());
        return;
    }
    if (!DataObject.class.isAssignableFrom(lazyLoadedField.getPropertyDescriptor().getPropertyType())) {
        log.debug("skipping; field %s in class %s is a collection; lazy loading is handled by LazyLoadedCollection", lazyLoadedFieldName, obj.getClass());
        return;
    }
    // make sure the lazy loaded field has a setter method
    Method lazyLoadedFieldWriteMethod = lazyLoadedField.getPropertyDescriptor().getWriteMethod();
    if (lazyLoadedFieldWriteMethod == null) {
        throw new IllegalStateException(String.format("lazy loaded field %s in class %s must have a write method", lazyLoadedFieldName, obj.getClass()));
    }
    try {
        T retObj = null;
        ColumnField mappedByField = doType.getColumnField(lazyLoadedField.getMappedByField());
        if (mappedByField == null) {
            // mapped by field is a collection in the related class; use joiner to get the lazy loaded object
            mappedByField = TypeMap.getDoType(lazyLoadedField.getMappedByType()).getColumnField(lazyLoadedField.getMappedByField());
            if (mappedByField == null) {
                throw new IllegalStateException(String.format("lazy loaded field %s in class %s could not be found;" + " make sure the mappedBy argument in the @Relation annotation matches the @Name annotation on the mapped by field", lazyLoadedFieldName, obj.getClass()));
            }
            Joiner j = new Joiner(dbClient);
            j.join(obj.getClass(), JOINER_ALIAS_ONE, obj.getId()).join(JOINER_ALIAS_ONE, lazyLoadedField.getMappedByType(), JOINER_ALIAS_TWO, mappedByField.getName()).go();
            if (j.iterator(JOINER_ALIAS_TWO).hasNext()) {
                retObj = (T) j.iterator(JOINER_ALIAS_TWO).next();
            }
        } else {
            // the mapped by field is a URI field in the same class as the lazy loaded field
            Method mappedByFieldReadMethod = mappedByField.getPropertyDescriptor().getReadMethod();
            if (mappedByFieldReadMethod == null) {
                throw new IllegalStateException(String.format("mapped by field %s mapped to lazy loaded field %s in class %s must have a read method", mappedByField.getName(), lazyLoadedFieldName, obj.getClass()));
            }
            // check the mapped by type is URI (supported type)
            Class mappedByObjType = mappedByFieldReadMethod.getReturnType();
            if (!URI.class.isAssignableFrom(mappedByObjType)) {
                throw new IllegalStateException(String.format("lazy loaded field %s in class %s has mapped by field %s with an unsupported type: %s;" + " the mapped by field for a DataObject must be a URI", lazyLoadedFieldName, obj.getClass(), mappedByField.getName(), mappedByObjType.getName()));
            }
            URI id = (URI) mappedByFieldReadMethod.invoke(obj);
            // id could be null if the mapped by field is not set to anything in persistence
            if (id != null) {
                retObj = (T) dbClient.queryObject(lazyLoadedField.getMappedByType(), id);
            }
        }
        lazyLoadedFieldWriteMethod.invoke(obj, retObj);
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        log.error(e.getMessage(), e);
    }
}
Also used : Joiner(com.emc.storageos.db.joiner.Joiner) Method(java.lang.reflect.Method) URI(java.net.URI) InvocationTargetException(java.lang.reflect.InvocationTargetException) DataObject(com.emc.storageos.db.client.model.DataObject)

Aggregations

Joiner (com.emc.storageos.db.joiner.Joiner)11 URI (java.net.URI)5 HashMap (java.util.HashMap)4 ExportMask (com.emc.storageos.db.client.model.ExportMask)3 Initiator (com.emc.storageos.db.client.model.Initiator)3 ArrayList (java.util.ArrayList)3 FCZoneReference (com.emc.storageos.db.client.model.FCZoneReference)2 StoragePort (com.emc.storageos.db.client.model.StoragePort)2 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)2 UnManagedExportMask (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedExportMask)2 Volume (com.emc.storageos.db.client.model.Volume)2 List (java.util.List)2 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 Bucket (com.emc.storageos.db.client.model.Bucket)1 DataObject (com.emc.storageos.db.client.model.DataObject)1 FileShare (com.emc.storageos.db.client.model.FileShare)1 StoragePool (com.emc.storageos.db.client.model.StoragePool)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)1