Search in sources :

Example 1 with Entity

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

the class DataMapUtils method getParameterNames.

private Map<String, String> getParameterNames(Expression expression, Object root) {
    if (expression != null) {
        Map<String, String> types = new HashMap<>();
        String typeName = "";
        List<String> names = new LinkedList<>();
        for (int i = 0; i < expression.getOperandCount(); i++) {
            Object operand = expression.getOperand(i);
            if (operand instanceof Expression) {
                types.putAll(getParameterNames((Expression) operand, root));
            }
            if (operand instanceof ASTObjPath) {
                PathComponent<ObjAttribute, ObjRelationship> component = ((Entity) root).lastPathComponent((ASTObjPath) operand, null);
                ObjAttribute attribute = component.getAttribute();
                if (attribute != null) {
                    typeName = attribute.getType();
                } else {
                    ObjRelationship relationship = component.getRelationship();
                    if (relationship != null) {
                        typeName = relationship.getTargetEntity().getClassName();
                    } else {
                        typeName = "Object";
                    }
                }
            }
            if (operand instanceof ASTList) {
                Object[] values = (Object[]) ((ASTList) operand).getOperand(0);
                for (Object value : values) {
                    if (value instanceof ExpressionParameter) {
                        names.add(((ExpressionParameter) value).getName());
                    }
                }
            }
            if (operand instanceof ExpressionParameter) {
                names.add(((ExpressionParameter) operand).getName());
            }
        }
        for (String name : names) {
            types.put(Util.underscoredToJava(name, false), typeName);
        }
        return types;
    }
    return Collections.emptyMap();
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjAttribute(org.apache.cayenne.map.ObjAttribute) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) Expression(org.apache.cayenne.exp.Expression) ExpressionParameter(org.apache.cayenne.exp.ExpressionParameter) ASTList(org.apache.cayenne.exp.parser.ASTList)

Example 2 with Entity

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

the class SelectQueryValidator method validate.

void validate(SelectQueryDescriptor query, ValidationResult validationResult) {
    validateName(query, validationResult);
    validateCacheGroup(query, validationResult);
    // Resolve root to Entity for further validation
    Entity root = validateRoot(query, validationResult);
    // validate path-based parts
    if (root != null) {
        validateQualifier(root, query.getQualifier(), validationResult);
        for (final Ordering ordering : query.getOrderings()) {
            validateOrdering(query, root, ordering, validationResult);
        }
        if (query.getPrefetchesMap() != null) {
            for (String prefetchPath : query.getPrefetchesMap().keySet()) {
                validatePrefetch(root, prefetchPath, validationResult);
            }
        }
    }
}
Also used : Entity(org.apache.cayenne.map.Entity) Ordering(org.apache.cayenne.query.Ordering)

Example 3 with Entity

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

the class EntityMergeSupport method addMissingRelationship.

private void addMissingRelationship(ObjEntity entity, DbRelationship dbRelationship) {
    // getting DataMap from DbRelationship's source entity. This is the only object in our arguments that
    // is guaranteed to be a part of the map....
    DataMap dataMap = dbRelationship.getSourceEntity().getDataMap();
    DbEntity targetEntity = dbRelationship.getTargetEntity();
    Collection<ObjEntity> mappedObjEntities = dataMap.getMappedEntities(targetEntity);
    if (mappedObjEntities.isEmpty()) {
        if (targetEntity == null) {
            targetEntity = new DbEntity(dbRelationship.getTargetEntityName());
        }
        if (dbRelationship.getTargetEntityName() != null) {
            boolean needGeneratedEntity = createObjRelationship(entity, dbRelationship, nameGenerator.objEntityName(targetEntity));
            if (needGeneratedEntity) {
                LOGGER.warn("Can't find ObjEntity for " + dbRelationship.getTargetEntityName());
                LOGGER.warn("Db Relationship (" + dbRelationship + ") will have GUESSED Obj Relationship reflection. ");
            }
        }
    } else {
        for (Entity mappedTarget : mappedObjEntities) {
            createObjRelationship(entity, dbRelationship, mappedTarget.getName());
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) DataMap(org.apache.cayenne.map.DataMap)

Example 4 with Entity

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

the class ObjEntityTabbedView method currentObjEntityChanged.

public void currentObjEntityChanged(EntityDisplayEvent e) {
    Entity entity = e.getEntity();
    if (e.isMainTabFocus() && entity instanceof ObjEntity) {
        if (getSelectedComponent() != entityPanel) {
            setSelectedComponent(entityPanel);
            entityPanel.setVisible(true);
        }
    }
    resetRemoveButtons();
    setVisible(e.getEntity() != null);
    if (getRootPane() != null) {
        if (projectController.getEntityTabSelection() < getTabCount()) {
            setSelectedIndex(projectController.getEntityTabSelection());
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) ObjEntity(org.apache.cayenne.map.ObjEntity)

Example 5 with Entity

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

the class SelectQueryOrderingTab method initFromModel.

protected void initFromModel() {
    QueryDescriptor query = mediator.getCurrentQuery();
    if (query == null || !QueryDescriptor.SELECT_QUERY.equals(query.getType())) {
        processInvalidModel("Unknown query.");
        return;
    }
    if (!(query.getRoot() instanceof Entity)) {
        processInvalidModel("SelectQuery has no root set.");
        return;
    }
    this.selectQuery = (SelectQueryDescriptor) query;
    browser.setModel(createBrowserModel((Entity) selectQuery.getRoot()));
    table.setModel(createTableModel());
    // init column sizes
    table.getColumnModel().getColumn(0).setPreferredWidth(250);
    cardLayout.show(this, REAL_PANEL);
}
Also used : SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor) QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) Entity(org.apache.cayenne.map.Entity)

Aggregations

Entity (org.apache.cayenne.map.Entity)38 DbEntity (org.apache.cayenne.map.DbEntity)24 ObjEntity (org.apache.cayenne.map.ObjEntity)23 DataMap (org.apache.cayenne.map.DataMap)10 DbRelationship (org.apache.cayenne.map.DbRelationship)9 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)6 DbAttribute (org.apache.cayenne.map.DbAttribute)6 Attribute (org.apache.cayenne.map.Attribute)5 ObjAttribute (org.apache.cayenne.map.ObjAttribute)5 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)5 Relationship (org.apache.cayenne.map.Relationship)5 EntityEvent (org.apache.cayenne.map.event.EntityEvent)5 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)4 ObjRelationship (org.apache.cayenne.map.ObjRelationship)4 SelectQueryDescriptor (org.apache.cayenne.map.SelectQueryDescriptor)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2