Search in sources :

Example 6 with CayenneMapEntry

use of org.apache.cayenne.util.CayenneMapEntry in project cayenne by apache.

the class ObjAttribute method getParentDbAttribute.

private DbAttribute getParentDbAttribute(ObjEntity entity) {
    if (entity != null) {
        ObjEntity parent = entity.getSuperEntity();
        if (parent != null) {
            Iterator<CayenneMapEntry> pathIterator = getDbPathIterator(parent);
            CayenneMapEntry o = null;
            while (pathIterator.hasNext()) {
                o = pathIterator.next();
            }
            if (o == null) {
                return getParentDbAttribute(parent);
            }
            return (DbAttribute) o;
        }
    }
    return null;
}
Also used : CayenneMapEntry(org.apache.cayenne.util.CayenneMapEntry)

Example 7 with CayenneMapEntry

use of org.apache.cayenne.util.CayenneMapEntry in project cayenne by apache.

the class DbAttributePathComboBoxEditor method getFirstEntity.

private Entity getFirstEntity(ObjAttribute attribute) {
    Iterator<CayenneMapEntry> it = attribute.getDbPathIterator();
    Entity firstEnt = attribute.getDbAttribute().getEntity();
    boolean setEnt = false;
    while (it.hasNext()) {
        Object ob = it.next();
        if (ob instanceof DbRelationship) {
            if (!setEnt) {
                firstEnt = ((DbRelationship) ob).getSourceEntity();
                setEnt = true;
            }
        } else if (ob instanceof DbAttribute) {
            if (!setEnt) {
                firstEnt = ((DbAttribute) ob).getEntity();
            }
        }
    }
    return firstEnt;
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) CayenneMapEntry(org.apache.cayenne.util.CayenneMapEntry) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 8 with CayenneMapEntry

use of org.apache.cayenne.util.CayenneMapEntry in project cayenne by apache.

the class ObjAttribute method getDbAttribute.

/**
 * Returns a DbAttribute mapped by this ObjAttribute.
 */
public DbAttribute getDbAttribute() {
    Iterator<CayenneMapEntry> pathIterator = getDbPathIterator(getEntity());
    CayenneMapEntry o = null;
    while (pathIterator.hasNext()) {
        o = pathIterator.next();
    }
    if (o == null) {
        return getParentDbAttribute(getEntity());
    }
    return (DbAttribute) o;
}
Also used : CayenneMapEntry(org.apache.cayenne.util.CayenneMapEntry)

Example 9 with CayenneMapEntry

use of org.apache.cayenne.util.CayenneMapEntry in project cayenne by apache.

the class ObjAttribute method updateDbAttributePath.

/**
 * Updates DbAttributePath for this ObjAttribute
 */
public void updateDbAttributePath() {
    if (isFlattened()) {
        StringBuilder newDbAttributePath = new StringBuilder();
        Iterator<CayenneMapEntry> dbPathIterator = getDbPathIterator();
        while (dbPathIterator.hasNext()) {
            CayenneMapEntry next = dbPathIterator.next();
            newDbAttributePath.append(next.getName());
            if (next instanceof DbRelationship) {
                newDbAttributePath.append('.');
            }
        }
        setDbAttributePath(newDbAttributePath.toString());
    }
}
Also used : CayenneMapEntry(org.apache.cayenne.util.CayenneMapEntry)

Example 10 with CayenneMapEntry

use of org.apache.cayenne.util.CayenneMapEntry in project cayenne by apache.

the class ObjRelationship method refreshFromPath.

/**
 * Rebuild a list of relationships if String relationshipPath has changed.
 */
final void refreshFromPath(String dbRelationshipPath, boolean stripInvalid) {
    // remove existing relationships
    dbRelationships.clear();
    if (dbRelationshipPath != null) {
        ObjEntity entity = (ObjEntity) getSourceEntity();
        if (entity == null) {
            throw new CayenneRuntimeException("Can't resolve DbRelationships, null source ObjEntity");
        }
        try {
            // add new relationships from path
            Iterator<CayenneMapEntry> it = entity.resolvePathComponents(new ASTDbPath(dbRelationshipPath));
            while (it.hasNext()) {
                DbRelationship relationship = (DbRelationship) it.next();
                dbRelationships.add(relationship);
            }
        } catch (ExpressionException ex) {
            if (!stripInvalid) {
                throw ex;
            }
        }
    }
    recalculateToManyValue();
    recalculateReadOnlyValue();
}
Also used : CayenneMapEntry(org.apache.cayenne.util.CayenneMapEntry) ASTDbPath(org.apache.cayenne.exp.parser.ASTDbPath) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) ExpressionException(org.apache.cayenne.exp.ExpressionException)

Aggregations

CayenneMapEntry (org.apache.cayenne.util.CayenneMapEntry)19 DbEntity (org.apache.cayenne.map.DbEntity)6 DbRelationship (org.apache.cayenne.map.DbRelationship)6 ObjEntity (org.apache.cayenne.map.ObjEntity)6 Expression (org.apache.cayenne.exp.Expression)5 DbAttribute (org.apache.cayenne.map.DbAttribute)5 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)4 ASTDbPath (org.apache.cayenne.exp.parser.ASTDbPath)3 Entity (org.apache.cayenne.map.Entity)3 ObjAttribute (org.apache.cayenne.map.ObjAttribute)3 ObjRelationship (org.apache.cayenne.map.ObjRelationship)3 HashSet (java.util.HashSet)2 ExpressionException (org.apache.cayenne.exp.ExpressionException)2 DbJoin (org.apache.cayenne.map.DbJoin)2 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)2 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)2 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)2 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)2 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)2 Test (org.junit.Test)2