@Override public boolean isNameInUse(String name) { DbEntity entity = (DbEntity) parent; // check if either attribute or relationship name matches... return entity.getAttribute(name) != null || entity.getRelationship(name) != null; } });
private void processLastPathComponent() { DbAttribute attribute = currentEntity.getAttribute(lastPathComponent); if (attribute != null) { processTerminatingAttribute(attribute); return; } DbRelationship relationship = currentEntity.getRelationship(lastPathComponent); if (relationship != null) { processTerminatingRelationship(relationship); return; } throw new IllegalStateException("Invalid path component: " + lastPathComponent); }
/** * check if path is correct. path is correct when he consist from <code>DbRelationship</code> * objects, each <code>DbRelationship</code> object have following <code>DbRelationship</code> * object as a target, last component is <code>DbAttribute</code> * * @param currentEnt current db entity * @param dbAttributePath path to check * @return if path is correct return true */ public static boolean isDbAttributePathCorrect(DbEntity currentEnt, String dbAttributePath) { if (currentEnt == null) { return true; } String[] pathSplit = dbAttributePath.split("\\."); int size = pathSplit.length - 1; for (int j = 0; j < size; j++) { DbRelationship relationship = currentEnt.getRelationship(pathSplit[j]); if (relationship == null) { return false; } currentEnt = relationship.getTargetEntity(); } return currentEnt.getAttribute(pathSplit[(size)]) != null; }
public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) { String arcIdString = arcId.toString(); ObjRelationship relationship = objEntity.getRelationship(arcIdString); if (relationship == null) { // phantom FK if (arcIdString.startsWith(ASTDbPath.DB_PREFIX)) { DbRelationship dbRelationship = dbEntity.getRelationship(arcIdString.substring(ASTDbPath.DB_PREFIX .length())); if (!dbRelationship.isSourceIndependentFromTargetChange()) { doArcCreated(targetNodeId, arcId); } } else { throw new IllegalArgumentException("Bad arcId: " + arcId); } } else if (!relationship.isSourceIndependentFromTargetChange()) { doArcCreated(targetNodeId, arcId); } }
public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) { String arcIdString = arcId.toString(); ObjRelationship relationship = objEntity.getRelationship(arcIdString); if (relationship == null) { // phantom FK if (arcIdString.startsWith(ASTDbPath.DB_PREFIX)) { DbRelationship dbRelationship = dbEntity.getRelationship(arcIdString.substring(ASTDbPath.DB_PREFIX .length())); if (!dbRelationship.isSourceIndependentFromTargetChange()) { doArcDeleted(targetNodeId, arcId); } } else { throw new IllegalArgumentException("Bad arcId: " + arcId); } } else if (!relationship.isSourceIndependentFromTargetChange()) { doArcDeleted(targetNodeId, arcId); } }
private void processIntermediatePathComponent() { DbRelationship relationship = currentEntity.getRelationship(lastPathComponent); if (relationship == null) { throw new EJBQLException("Unknown relationship '" + lastPathComponent + "' for entity '" + currentEntity.getName() + "'"); } this.currentEntity = (DbEntity) relationship.getTargetEntity(); }
private void appendForeignKeys(Map<String, Object> dbDiff) { // populate changed FKs if (currentArcDiff != null) { for (Entry<Object, Object> entry : currentArcDiff.entrySet()) { DbRelationship dbRelation; String arcIdString = entry.getKey().toString(); ObjRelationship relation = objEntity.getRelationship(arcIdString); if (relation == null) { dbRelation = dbEntity.getRelationship(arcIdString.substring(ASTDbPath.DB_PREFIX.length())); } else { dbRelation = relation.getDbRelationships().get(0); } // In case of a vertical inheritance, ensure that it belongs to this bucket... if (dbRelation.getSourceEntity() == dbEntity) { ObjectId targetId = (ObjectId) entry.getValue(); for (DbJoin join : dbRelation.getJoins()) { Object value = (targetId != null) ? new PropagatedValueFactory(targetId, join.getTargetName()) : null; dbDiff.put(join.getSourceName(), value); } } } } }
private void addPhantomFkDiff(ArcOperation arcDiff) { String arcId = arcDiff.getArcId().toString(); DbEntity dbEntity = classDescriptor.getEntity().getDbEntity(); DbRelationship dbRelationship = (DbRelationship) dbEntity.getRelationship(arcId.substring(ASTDbPath.DB_PREFIX .length())); if (dbRelationship.isToMany()) { return; } if (currentArcSnapshot == null) { currentArcSnapshot = new HashMap<>(); } currentArcSnapshot.put(arcId, arcDiff.getTargetNodeId()); if (phantomFks == null) { phantomFks = new HashMap<>(); } ArcOperation oldOp = phantomFks.put(arcDiff, arcDiff); // "delete" cancels "create" and vice versa... if (oldOp != null && oldOp.isDelete() != arcDiff.isDelete()) { phantomFks.remove(arcDiff); if (otherDiffs != null) { otherDiffs.remove(oldOp); } } }
dbRel = (DbRelationship) dbSrc.getRelationship(relName); if (dbRel == null) {
dbRel = dbSrc.getRelationship(relName); if (dbRel == null) {
DbRelationship lastRelationship = currentEntity.getRelationship(lastPathComponent); if (lastRelationship != null) { DbEntity targetEntity = lastRelationship.getTargetEntity(); DbRelationship lastRelationship = currentEntity.getRelationship(lastPathComponent);
private void resolveJoin(boolean inner) { EJBQLJoinAppender joinAppender = context.getTranslatorFactory().getJoinAppender(context); // TODO: andrus 1/6/2007 - conflict with object path naming... maybe // 'registerReusableJoin' should normalize everything to a db path? String newPath = idPath + '.' + lastPathComponent; String oldPath = joinAppender.registerReusableJoin(idPath, lastPathComponent, newPath); this.fullPath = fullPath + '.' + lastPathComponent; if (oldPath != null) { this.idPath = oldPath; this.lastAlias = context.getTableAlias(oldPath, context.getQuotingStrategy().quotedFullyQualifiedName(currentEntity)); } else { // register join if (inner) { joinAppender.appendInnerJoin(joinMarker, new EJBQLTableId(idPath), new EJBQLTableId(fullPath)); this.lastAlias = context.getTableAlias(fullPath, context.getQuotingStrategy().quotedFullyQualifiedName(currentEntity)); } else { joinAppender.appendOuterJoin(joinMarker, new EJBQLTableId(idPath), new EJBQLTableId(fullPath)); Relationship lastRelationship = currentEntity.getRelationship(lastPathComponent); DbEntity targetEntity = (DbEntity) lastRelationship.getTargetEntity(); this.lastAlias = context.getTableAlias(fullPath, context.getQuotingStrategy().quotedFullyQualifiedName(targetEntity)); } this.idPath = newPath; } }