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;
}
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;
}
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;
}
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());
}
}
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();
}
Aggregations