/** * Returns a DbAttribute mapped by this ObjAttribute. */ public DbAttribute getDbAttribute() { Iterator pathIterator = getDbPathIterator(); Object o = null; while (pathIterator.hasNext()) { o = pathIterator.next(); } return (DbAttribute) o; }
public Iterator<CayenneMapEntry> getDbPathIterator() { return getDbPathIterator(getEntity()); }
private void setEnabledSaveButton() { if (!attribute.getDbPathIterator().hasNext()) { view.getSaveButton().setEnabled(true); } else { boolean isAttributeLast = false; Iterator<CayenneMapEntry> it = attribute.getDbPathIterator(); while (it.hasNext()) { Object obj = it.next(); if (obj instanceof DbAttribute && !it.hasNext()) { isAttributeLast = true; } } view.getSaveButton().setEnabled(isAttributeLast); } }
/** * @deprecated Since 1.2 unused. */ public boolean mapsToDependentDbEntity() { Iterator i = getDbPathIterator(); if (!i.hasNext()) { return false; } Object o = i.next(); if (!i.hasNext()) { return false; } Object o1 = i.next(); if (!(o1 instanceof DbAttribute)) { return false; } DbRelationship toDependent = (DbRelationship) o; return toDependent.isToDependentPK(); }
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; }
/** * 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()); } }
/** * 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; }
/** * Selects path in browser */ public void setSelectionPath() { List list = new ArrayList(); boolean isAttributeLast = false; Iterator<CayenneMapEntry> it = attribute.getDbPathIterator(); while (it.hasNext()) { Object obj = it.next(); list.add(obj); if (obj instanceof DbAttribute && !it.hasNext()) { isAttributeLast = true; } } if (isAttributeLast) { Object[] path = new Object[list.size() + 1]; path[0] = getFirstEntity(); System.arraycopy(list.toArray(), 0, path, 1, list.size()); view.getPathBrowser().setSelectionPath(new TreePath(path)); view.getSaveButton().setEnabled(true); } }
String toDbPath(Iterator objectPathComponents) { StringBuffer buf = new StringBuffer(); while (objectPathComponents.hasNext()) { Object component = objectPathComponents.next(); Iterator dbSubpath; if (component instanceof ObjRelationship) { dbSubpath = ((ObjRelationship) component) .getDbRelationships() .iterator(); } else if (component instanceof ObjAttribute) { dbSubpath = ((ObjAttribute) component).getDbPathIterator(); } else { throw new CayenneRuntimeException("Unknown path component: " + component); } while (dbSubpath.hasNext()) { CayenneMapEntry subComponent = (CayenneMapEntry) dbSubpath.next(); if (buf.length() > 0) { buf.append(Entity.PATH_SEPARATOR); } buf.append(subComponent.getName()); } } return buf.toString(); }
public boolean visitAttribute(AttributeProperty property) { ObjAttribute oa = property.getAttribute(); Iterator<CayenneMapEntry> dbPathIterator = oa.getDbPathIterator(); while (dbPathIterator.hasNext()) { CayenneMapEntry pathPart = dbPathIterator.next(); if (pathPart instanceof DbAttribute) { result.addDbField(pathPart.getName(), pathPart.getName()); } } return true; }
DbEntityClassDescriptor(ClassDescriptor classDescriptor, ObjAttribute masterAttribute) { this.classDescriptor = classDescriptor; Iterator<?> it = masterAttribute.getDbPathIterator(); if (masterAttribute.isFlattened()) { while (it.hasNext()) { Object object = it.next(); if (object instanceof DbRelationship) { if (pathFromMaster == null) { pathFromMaster = new ArrayList<>(2); } pathFromMaster.add((DbRelationship) object); } else if (object instanceof DbAttribute) { this.dbEntity = ((DbAttribute) object).getEntity(); } } } if (dbEntity == null) { dbEntity = classDescriptor.getEntity().getDbEntity(); } }
private Entity getFirstEntity() { 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; }
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; } }
String toDbPath(PathComponentIterator objectPathComponents) { StringBuilder buf = new StringBuilder(); while (objectPathComponents.hasNext()) { PathComponent<Attribute, Relationship> component = objectPathComponents.next(); Iterator<?> dbSubpath; if (component.getAttribute() != null) { dbSubpath = ((ObjAttribute) component.getAttribute()).getDbPathIterator(); } else if (component.getRelationship() != null) { dbSubpath = ((ObjRelationship) component.getRelationship()).getDbRelationships().iterator(); } else { throw new CayenneRuntimeException("Unknown path component: %s", component); } while (dbSubpath.hasNext()) { CayenneMapEntry subComponent = (CayenneMapEntry) dbSubpath.next(); if (buf.length() > 0) { buf.append(Entity.PATH_SEPARATOR); } buf.append(subComponent.getName()); // use OUTER join for all components of the path is Obj path is OUTER if (component.getJoinType() == JoinType.LEFT_OUTER) { buf.append(OUTER_JOIN_INDICATOR); } } } return buf.toString(); }
public boolean visitAttribute(AttributeProperty property) { ObjAttribute oa = property.getAttribute(); Iterator<CayenneMapEntry> dbPathIterator = oa.getDbPathIterator(); while (dbPathIterator.hasNext()) { Object pathPart = dbPathIterator.next(); if (pathPart == null) { throw new CayenneRuntimeException("ObjAttribute has no component: %s", oa.getName()); } else if (pathPart instanceof DbRelationship) { DbRelationship rel = (DbRelationship) pathPart; dbRelationshipAdded(rel, JoinType.INNER, null); } else if (pathPart instanceof DbAttribute) { DbAttribute dbAttr = (DbAttribute) pathPart; appendColumn(columns, oa, dbAttr, attributes, labelPrefix + '.' + dbAttr.getName()); } } return true; }
public boolean visitAttribute(AttributeProperty property) { ObjAttribute oa = property.getAttribute(); resetJoinStack(); Iterator<CayenneMapEntry> dbPathIterator = oa.getDbPathIterator(); while (dbPathIterator.hasNext()) { Object pathPart = dbPathIterator.next(); if (pathPart == null) { throw new CayenneRuntimeException("ObjAttribute has no component: %s", oa.getName()); } else if (pathPart instanceof DbRelationship) { DbRelationship rel = (DbRelationship) pathPart; dbRelationshipAdded(rel, JoinType.LEFT_OUTER, null); } else if (pathPart instanceof DbAttribute) { DbAttribute dbAttr = (DbAttribute) pathPart; appendColumn(columns, oa, dbAttr, attributes, null, tableAlias); } } return true; }
public boolean visitAttribute(AttributeProperty property) { ObjAttribute oa = property.getAttribute(); Iterator<?> dbPathIterator = oa.getDbPathIterator(); EJBQLJoinAppender joinAppender = null; String marker = null; EJBQLTableId lhsId = new EJBQLTableId(idVar); while (dbPathIterator.hasNext()) { Object pathPart = dbPathIterator.next(); if (pathPart == null) { throw new CayenneRuntimeException("ObjAttribute has no component: %s", oa.getName()); } else if (pathPart instanceof DbRelationship) { if (marker == null) { marker = EJBQLJoinAppender.makeJoinTailMarker(idVar); joinAppender = context.getTranslatorFactory().getJoinAppender(context); } DbRelationship dr = (DbRelationship) pathPart; EJBQLTableId rhsId = new EJBQLTableId(lhsId, dr.getName()); joinAppender.appendOuterJoin(marker, lhsId, rhsId); lhsId = rhsId; } else if (pathPart instanceof DbAttribute) { appendColumn(idVar, oa, (DbAttribute) pathPart, fields, oa.getType()); } } return true; }
protected void processTerminatingAttribute(ObjAttribute attribute) { DbEntity table = null; Iterator<?> it = attribute.getDbPathIterator(); while (it.hasNext()) { Object pathComponent = it.next(); if (pathComponent instanceof DbAttribute) { table = (DbEntity) ((DbAttribute) pathComponent).getEntity(); } } if (isUsingAliases()) { String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath, context .getQuotingStrategy().quotedFullyQualifiedName(table)); context.append(' ').append(alias).append('.') .append(context.getQuotingStrategy().quotedName(attribute.getDbAttribute())); } else { context.append(' ').append(context.getQuotingStrategy().quotedName(attribute.getDbAttribute())); } }
getQueryMetadata().getObjEntity().resolvePath(property.getExpression(), getPathAliases())) { if(component.getAttribute() != null) { Iterator<CayenneMapEntry> dbPathIterator = component.getAttribute().getDbPathIterator(); while (dbPathIterator.hasNext()) { Object pathPart = dbPathIterator.next();
@Override protected void processTerminatingAttribute(ObjAttribute attribute) { DbEntity table = currentEntity.getDbEntity(); String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath, context .getQuotingStrategy().quotedFullyQualifiedName(table)); if (attribute.isFlattened()) { Iterator<?> dbPathIterator = attribute.getDbPathIterator(); EJBQLTableId lhsId = new EJBQLTableId(idPath); while (dbPathIterator.hasNext()) { Object pathPart = dbPathIterator.next(); // DbRelationships not processed, because they will be // processed // later when appending table if (pathPart == null) { throw new CayenneRuntimeException("ObjAttribute has no component: %s", attribute.getName()); } else if (pathPart instanceof DbAttribute) { DbAttribute dbAttribute = (DbAttribute) pathPart; appendColumn(attribute.getType(), context.getTableAlias(lhsId.getEntityId(), context.getQuotingStrategy() .quotedFullyQualifiedName((DbEntity) dbAttribute.getEntity())), dbAttribute, context.isAppendingResultColumns() ? context.nextColumnAlias() : ""); } } } else { DbAttribute dbAttribute = attribute.getDbAttribute(); appendColumn(attribute.getType(), alias, dbAttribute, context.isAppendingResultColumns() ? context.nextColumnAlias() : ""); } }