Search in sources :

Example 11 with QueryDescriptor

use of org.apache.cayenne.map.QueryDescriptor in project cayenne by apache.

the class FindAction method jumpToResult.

/**
 * Navigate to search result
 * Used also in {@link org.apache.cayenne.modeler.graph.action.EntityDisplayAction}
 */
public static void jumpToResult(FindAction.SearchResultEntry searchResultEntry) {
    EditorView editor = ((CayenneModelerFrame) Application.getInstance().getFrameController().getView()).getView();
    DataChannelDescriptor domain = (DataChannelDescriptor) Application.getInstance().getProject().getRootNode();
    if (searchResultEntry.getObject() instanceof Entity) {
        jumpToEntityResult((Entity) searchResultEntry.getObject(), editor, domain);
    } else if (searchResultEntry.getObject() instanceof QueryDescriptor) {
        jumpToQueryResult((QueryDescriptor) searchResultEntry.getObject(), editor, domain);
    } else if (searchResultEntry.getObject() instanceof Embeddable) {
        jumpToEmbeddableResult((Embeddable) searchResultEntry.getObject(), editor, domain);
    } else if (searchResultEntry.getObject() instanceof EmbeddableAttribute) {
        jumpToEmbeddableAttributeResult((EmbeddableAttribute) searchResultEntry.getObject(), editor, domain);
    } else if (searchResultEntry.getObject() instanceof Attribute || searchResultEntry.getObject() instanceof Relationship) {
        jumpToAttributeResult(searchResultEntry, editor, domain);
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DetectedDbEntity(org.apache.cayenne.map.DetectedDbEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity) EJBQLQueryDescriptor(org.apache.cayenne.map.EJBQLQueryDescriptor) SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor) QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ProcedureQueryDescriptor(org.apache.cayenne.map.ProcedureQueryDescriptor) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DbAttribute(org.apache.cayenne.map.DbAttribute) ObjAttribute(org.apache.cayenne.map.ObjAttribute) Attribute(org.apache.cayenne.map.Attribute) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) Relationship(org.apache.cayenne.map.Relationship) DbRelationship(org.apache.cayenne.map.DbRelationship) ObjRelationship(org.apache.cayenne.map.ObjRelationship) EditorView(org.apache.cayenne.modeler.editor.EditorView) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) CayenneModelerFrame(org.apache.cayenne.modeler.CayenneModelerFrame) Embeddable(org.apache.cayenne.map.Embeddable)

Example 12 with QueryDescriptor

use of org.apache.cayenne.map.QueryDescriptor in project cayenne by apache.

the class RemoveAction method removeLastPathComponent.

/**
 * Removes an object, depending on its type
 */
private UndoableEdit removeLastPathComponent(ConfigurationNode object, ConfigurationNode parentObject) {
    UndoableEdit undo = null;
    if (object instanceof DataMap) {
        if (parentObject != null && parentObject instanceof DataNodeDescriptor) {
            undo = new RemoveUndoableEdit(application, (DataNodeDescriptor) parentObject, (DataMap) object);
            removeDataMapFromDataNode((DataNodeDescriptor) parentObject, (DataMap) object);
        } else {
            // Not under Data Node, remove completely
            undo = new RemoveUndoableEdit(application, (DataMap) object);
            removeDataMap((DataMap) object);
        }
    } else if (object instanceof DataNodeDescriptor) {
        undo = new RemoveUndoableEdit(application, (DataNodeDescriptor) object);
        removeDataNode((DataNodeDescriptor) object);
    } else if (object instanceof DbEntity) {
        undo = new RemoveUndoableEdit(((DbEntity) object).getDataMap(), (DbEntity) object);
        removeDbEntity(((DbEntity) object).getDataMap(), (DbEntity) object);
    } else if (object instanceof ObjEntity) {
        undo = new RemoveUndoableEdit(((ObjEntity) object).getDataMap(), (ObjEntity) object);
        removeObjEntity(((ObjEntity) object).getDataMap(), (ObjEntity) object);
    } else if (object instanceof QueryDescriptor) {
        undo = new RemoveUndoableEdit(((QueryDescriptor) object).getDataMap(), (QueryDescriptor) object);
        removeQuery(((QueryDescriptor) object).getDataMap(), (QueryDescriptor) object);
    } else if (object instanceof Procedure) {
        undo = new RemoveUndoableEdit(((Procedure) object).getDataMap(), (Procedure) object);
        removeProcedure(((Procedure) object).getDataMap(), (Procedure) object);
    } else if (object instanceof Embeddable) {
        undo = new RemoveUndoableEdit(((Embeddable) object).getDataMap(), (Embeddable) object);
        removeEmbeddable(((Embeddable) object).getDataMap(), (Embeddable) object);
    }
    return undo;
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) RemoveAttributeUndoableEdit(org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit) RemoveCallbackMethodUndoableEdit(org.apache.cayenne.modeler.undo.RemoveCallbackMethodUndoableEdit) UndoableEdit(javax.swing.undo.UndoableEdit) RemoveRelationshipUndoableEdit(org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit) RemoveUndoableEdit(org.apache.cayenne.modeler.undo.RemoveUndoableEdit) RemoveCompoundUndoableEdit(org.apache.cayenne.modeler.undo.RemoveCompoundUndoableEdit) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) Procedure(org.apache.cayenne.map.Procedure) RemoveUndoableEdit(org.apache.cayenne.modeler.undo.RemoveUndoableEdit) DataMap(org.apache.cayenne.map.DataMap) Embeddable(org.apache.cayenne.map.Embeddable)

Example 13 with QueryDescriptor

use of org.apache.cayenne.map.QueryDescriptor in project cayenne by apache.

the class RemoveAction method removeObjEntity.

/**
 * Removes current object entity from its DataMap.
 */
public void removeObjEntity(DataMap map, ObjEntity entity) {
    ProjectController mediator = getProjectController();
    EntityEvent e = new EntityEvent(Application.getFrame(), entity, MapEvent.REMOVE);
    e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
    map.removeObjEntity(entity.getName(), true);
    mediator.fireObjEntityEvent(e);
    // clone to be able to remove within iterator...
    for (QueryDescriptor query : new ArrayList<>(map.getQueryDescriptors())) {
        if (!QueryDescriptor.EJBQL_QUERY.equals(query.getType())) {
            Object root = query.getRoot();
            if (root == entity || (root instanceof String && root.toString().equals(entity.getName()))) {
                removeQuery(map, query);
            }
        }
    }
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) EntityEvent(org.apache.cayenne.map.event.EntityEvent) ArrayList(java.util.ArrayList) ProjectController(org.apache.cayenne.modeler.ProjectController)

Example 14 with QueryDescriptor

use of org.apache.cayenne.map.QueryDescriptor in project cayenne by apache.

the class MappedSelect method createReplacementQuery.

@Override
protected Query createReplacementQuery(EntityResolver resolver) {
    QueryDescriptor descriptor = resolver.getQueryDescriptor(queryName);
    Query query = super.createReplacementQuery(resolver);
    QueryCacheStrategy cacheStrategyOverride = null;
    if (forceNoCache) {
        QueryCacheStrategy cacheStrategy = query.getMetaData(resolver).getCacheStrategy();
        if (QueryCacheStrategy.LOCAL_CACHE == cacheStrategy) {
            cacheStrategyOverride = QueryCacheStrategy.LOCAL_CACHE_REFRESH;
        } else if (QueryCacheStrategy.SHARED_CACHE == cacheStrategy) {
            cacheStrategyOverride = QueryCacheStrategy.SHARED_CACHE_REFRESH;
        }
    }
    switch(descriptor.getType()) {
        case QueryDescriptor.SELECT_QUERY:
            SelectQuery selectQuery = (SelectQuery) query;
            if (fetchLimit != null) {
                selectQuery.setFetchLimit(fetchLimit);
            }
            if (fetchOffset != null) {
                selectQuery.setFetchOffset(fetchOffset);
            }
            if (statementFetchSize != null) {
                selectQuery.setStatementFetchSize(statementFetchSize);
            }
            if (pageSize != null) {
                selectQuery.setPageSize(pageSize);
            }
            if (cacheStrategyOverride != null) {
                selectQuery.setCacheStrategy(cacheStrategyOverride);
            }
            break;
        case QueryDescriptor.SQL_TEMPLATE:
            SQLTemplate sqlTemplate = (SQLTemplate) query;
            if (fetchLimit != null) {
                sqlTemplate.setFetchLimit(fetchLimit);
            }
            if (fetchOffset != null) {
                sqlTemplate.setFetchOffset(fetchOffset);
            }
            if (statementFetchSize != null) {
                sqlTemplate.setStatementFetchSize(statementFetchSize);
            }
            if (pageSize != null) {
                sqlTemplate.setPageSize(pageSize);
            }
            if (cacheStrategyOverride != null) {
                sqlTemplate.setCacheStrategy(cacheStrategyOverride);
            }
            break;
        case QueryDescriptor.EJBQL_QUERY:
            EJBQLQuery ejbqlQuery = (EJBQLQuery) query;
            if (fetchLimit != null) {
                ejbqlQuery.setFetchLimit(fetchLimit);
            }
            if (fetchOffset != null) {
                ejbqlQuery.setFetchOffset(fetchOffset);
            }
            if (statementFetchSize != null) {
                ejbqlQuery.setStatementFetchSize(statementFetchSize);
            }
            if (pageSize != null) {
                ejbqlQuery.setPageSize(pageSize);
            }
            if (cacheStrategyOverride != null) {
                ejbqlQuery.setCacheStrategy(cacheStrategyOverride);
            }
            break;
        case QueryDescriptor.PROCEDURE_QUERY:
            ProcedureQuery procedureQuery = (ProcedureQuery) query;
            if (fetchLimit != null) {
                procedureQuery.setFetchLimit(fetchLimit);
            }
            if (fetchOffset != null) {
                procedureQuery.setFetchOffset(fetchOffset);
            }
            if (statementFetchSize != null) {
                procedureQuery.setStatementFetchSize(statementFetchSize);
            }
            if (pageSize != null) {
                procedureQuery.setPageSize(pageSize);
            }
            if (cacheStrategyOverride != null) {
                procedureQuery.setCacheStrategy(cacheStrategyOverride);
            }
            break;
        default:
            throw new CayenneRuntimeException("Unknown query type: %s", descriptor.getType());
    }
    return query;
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Example 15 with QueryDescriptor

use of org.apache.cayenne.map.QueryDescriptor in project cayenne by apache.

the class QueryDisplayEventType method fireLastDisplayEvent.

@Override
public void fireLastDisplayEvent() {
    DataChannelDescriptor dataChannel = (DataChannelDescriptor) controller.getProject().getRootNode();
    if (!dataChannel.getName().equals(preferences.getDomain())) {
        return;
    }
    DataMap dataMap = dataChannel.getDataMap(preferences.getDataMap());
    if (dataMap == null) {
        return;
    }
    QueryDescriptor query = dataMap.getQueryDescriptor(preferences.getQuery());
    if (query == null) {
        return;
    }
    QueryDisplayEvent queryDisplayEvent = new QueryDisplayEvent(this, query, dataMap, dataChannel);
    controller.fireQueryDisplayEvent(queryDisplayEvent);
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) QueryDisplayEvent(org.apache.cayenne.modeler.event.QueryDisplayEvent) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)37 DataMap (org.apache.cayenne.map.DataMap)16 QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)12 ObjEntity (org.apache.cayenne.map.ObjEntity)9 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)8 DbEntity (org.apache.cayenne.map.DbEntity)7 Embeddable (org.apache.cayenne.map.Embeddable)6 Procedure (org.apache.cayenne.map.Procedure)6 ProcedureQueryDescriptor (org.apache.cayenne.map.ProcedureQueryDescriptor)6 SelectQueryDescriptor (org.apache.cayenne.map.SelectQueryDescriptor)6 Entity (org.apache.cayenne.map.Entity)5 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)4 QueryDisplayEvent (org.apache.cayenne.modeler.event.QueryDisplayEvent)4 ValidationException (org.apache.cayenne.validation.ValidationException)4 DbAttribute (org.apache.cayenne.map.DbAttribute)3 DbRelationship (org.apache.cayenne.map.DbRelationship)3 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)3 ObjAttribute (org.apache.cayenne.map.ObjAttribute)3 ObjRelationship (org.apache.cayenne.map.ObjRelationship)3 ProjectController (org.apache.cayenne.modeler.ProjectController)3