/** * Returns true if the underlying DbRelationships point to a at least one of the * columns of the target entity. * * @since 1.1 */ public boolean isToPK() { return ((DbRelationship) getDbRelationships().get(0)).isToPK(); }
/** * Returns true if the underlying DbRelationships point to a at least one of * the columns of the target entity. * * @since 1.1 */ public boolean isToPK() { return (getDbRelationships().get(0)).isToPK(); }
/** * Returns a boolean indicating whether modifying a target of such * relationship in any way will not change the underlying table row of the * source. * * @since 4.0 */ public boolean isSourceIndependentFromTargetChange() { // note - call "isToPK" at the end of the chain, since // if it is to a dependent PK, we still should return true... return isToMany() || isToDependentPK() || !isToPK(); }
/** * Initializes itself to do translation of the match ending * with a DbRelationship. */ public void setRelationship(DbRelationship rel) { this.relationship = rel; attributes = new HashMap(rel.getJoins().size() * 2); if (rel.isToMany() || !rel.isToPK()) { // match on target PK DbEntity ent = (DbEntity) rel.getTargetEntity(); Iterator pk = ent.getPrimaryKey().iterator(); // index by name while (pk.hasNext()) { DbAttribute pkAttr = (DbAttribute) pk.next(); attributes.put(pkAttr.getName(), pkAttr); } } else { // match on this FK Iterator joins = rel.getJoins().iterator(); while (joins.hasNext()) { DbJoin join = (DbJoin) joins.next(); // index by target name attributes.put(join.getTargetName(), join.getSource()); } } }
DbRelationship relationship = (DbRelationship) relationships.next(); if (relationship.getJoins().size() > 0 && relationship.isToPK() && !relationship.isToDependentPK()) {
@Override public List<String> createSql(DbAdapter adapter) { if (!rel.isToMany() && rel.isToPK() && !rel.isToDependentPK()) {
/** * Initializes itself to do translation of the match ending with a * DbRelationship. * * @since 3.0 */ public void setRelationship(DbRelationship rel, String joinSplitAlias) { this.relationship = rel; this.joinSplitAlias = joinSplitAlias; attributes = new HashMap<>(rel.getJoins().size() * 2); if (rel.isToMany() || !rel.isToPK()) { // match on target PK DbEntity ent = rel.getTargetEntity(); // index by name for (DbAttribute pkAttr : ent.getPrimaryKeys()) { attributes.put(pkAttr.getName(), pkAttr); } } else { // match on this FK for (DbJoin join : rel.getJoins()) { // index by target name attributes.put(join.getTargetName(), join.getSource()); } } }
private Optional<ForeignKey> createFk(DbJoin join) { // for now only relationships to a single master PK and those that have explicit ObjEntity mapping should // be treated as FK DbRelationship relationship = join.getRelationship(); // TODO: 1..1 relationships? if (!relationship.isToPK() || relationship.isToMany()) { return Optional.empty(); } DbEntity targetDbEntity = relationship.getTargetEntity(); if (targetDbEntity.getPrimaryKeys().size() > 1) { throw new LmRuntimeException("Unsupported FK: DbEntity " + targetDbEntity.getName() + " has multiple PK columns."); } Collection<ObjEntity> targetEntities = targetDbEntity.getDataMap().getMappedEntities(targetDbEntity); switch (targetEntities.size()) { case 0: return Optional.empty(); case 1: return Optional.of(new ForeignKey(entityMap, targetEntities.iterator().next(), ASTDbPath.DB_PREFIX + join.getTargetName())); default: throw new LmRuntimeException("Unsupported FK: DbEntity " + targetDbEntity.getName() + " maps to more than one ObjEntity"); } }
DbRelationship relationship = objectMatchTranslator.getRelationship(); if(!relationship.isToMany() && !relationship.isToPK()) { queryAssembler.dbRelationshipAdded(relationship);
protected void appendObjectMatch() throws IOException { if (!matchingObject || objectMatchTranslator == null) { throw new IllegalStateException("An invalid attempt to append object match."); } // turn off special handling, so that all the methods behave as a // superclass's // impl. matchingObject = false; boolean first = true; DbRelationship relationship = objectMatchTranslator.getRelationship(); if (!relationship.isToMany() && !relationship.isToPK()) { queryAssembler.dbRelationshipAdded(relationship, JoinType.INNER, objectMatchTranslator.getJoinSplitAlias()); } Iterator<String> it = objectMatchTranslator.keys(); while (it.hasNext()) { if (first) { first = false; } else { out.append(" AND "); } String key = it.next(); DbAttribute attr = objectMatchTranslator.getAttribute(key); Object val = objectMatchTranslator.getValue(key); processColumn(attr); out.append(objectMatchTranslator.getOperation()); appendLiteral(val, attr, objectMatchTranslator.getExpression()); } objectMatchTranslator.reset(); }
if (dbRelationship.isToPK()) { if (!dbRelationship.isFromPK()) { return false;