public String toString() { ToStringBuilder builder = new ToStringBuilder(this); builder.append("source", getSourceName()); builder.append("target", getTargetName()); return builder.toString(); } }
private boolean isFK(DbAttribute dbAttribute, Collection<DbRelationship> collection, boolean source) { for (DbRelationship rel : collection) { for (DbJoin join : rel.getJoins()) { DbAttribute joinAttribute = source ? join.getSource() : join.getTarget(); if (joinAttribute == dbAttribute) { return true; } } } return false; }
/** * Returns a "reverse" join. Join source relationship is not set and must be * initialized by the caller. */ public DbJoin createReverseJoin() { DbJoin reverse = new DbJoin(); reverse.setTargetName(sourceName); reverse.setSourceName(targetName); return reverse; }
while (joins.hasNext()) { DbJoin protoJoin = (DbJoin) joins.next(); DbJoin join = new DbJoin(rel); join.setSourceName(protoJoin.getSourceName()); join.setTargetName(protoJoin.getTargetName()); rel.addJoin(join);
Object val = srcSnapshot.get(join.getSourceName()); if (val == null) { foundNulls++; idMap = Collections.emptyMap(); } else { idMap = Collections.singletonMap(join.getTargetName(), val); idMap = new HashMap<>(numJoins * 2); for (DbJoin join : joins) { DbAttribute source = join.getSource(); Object val = srcSnapshot.get(join.getSourceName()); idMap.put(join.getTargetName(), val);
private void build() { TreeSet<String> joins = new TreeSet<>(); for(DbJoin join : relationship.getJoins()) { joins.add( (join.getSource() == null ? "~" : join.getSource().getName()) + "." + join.getSourceName() + ">" + (join.getTarget() == null ? "~" : join.getTarget().getName()) + "." + join.getTargetName() ); } joinSignature = joins.toArray(new String[0]); } }
while (joins.hasNext()) { DbJoin join = (DbJoin) joins.next(); if (join.getSource() == dbAttr) { join.setSourceName(newName); if (join.getTarget() == dbAttr) { join.setTargetName(newName);
while (joins.hasNext()) { DbJoin join = (DbJoin) joins.next(); Object value = targetKeyMap.get(join.getTargetName()); if (value == null) { if (supportsGeneratedKeys && join.getTarget().isGenerated()) { .getTargetName()); map.put(join.getSourceName(), value);
private void addJoin(DbRelationship relationship, String sourceName, String targetName){ for (DbJoin join : relationship.getJoins()) { if (join.getSourceName().equals(sourceName) && join.getTargetName().equals(targetName)) { return; } } relationship.addJoin(new DbJoin(relationship, sourceName, targetName)); } }
/** * Returns <code>true</code> if the DB column represented by this attribute is a * foreign key, referencing another table. * * @since 1.1 */ public boolean isForeignKey() { String name = getName(); if (name == null) { // won't be able to match joins... return false; } Iterator relationships = getEntity().getRelationships().iterator(); while (relationships.hasNext()) { DbRelationship relationship = (DbRelationship) relationships.next(); Iterator joins = relationship.getJoins().iterator(); while (joins.hasNext()) { DbJoin join = (DbJoin) joins.next(); if (name.equals(join.getSourceName())) { DbAttribute target = join.getTarget(); if (target != null && target.isPrimaryKey()) { return true; } } } } return false; }
public Object transform(Object input) { return (input instanceof DbJoin) ? ((DbJoin) input).getSource() : input; } };
static boolean hasFK(DbRelationship relationship, Map snapshot) { Iterator joins = relationship.getJoins().iterator(); while(joins.hasNext()) { DbJoin join = (DbJoin) joins.next(); if(!snapshot.containsKey(join.getSourceName())) { return false; } } return true; }
@Override public String quotedSourceName(DbJoin join) { DataMap dataMap = join.getSource().getEntity().getDataMap(); return quotedIdentifier(dataMap, join.getSourceName()); }
/** * 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()); } } }
public Object transform(Object input) { return (input instanceof DbJoin) ? ((DbJoin) input).getTarget() : input; } };
DbEntity ent = join.getRelationship().getTargetEntity(); Collection<DbAttribute> pk = ent.getPrimaryKeys(); if (pk.size() != 1) { attribute = forceJoinForRelations ? join.getTarget() : join.getSource();
public void linkToParent(DataRow row, Persistent object) { if (partitionByChild == null) { indexParents(); } Object key; if (joins.length > 1) { List<Object> values = new ArrayList<>(joins.length); for (int j = 0; j < joins.length; j++) { values.add(row.get(joins[j].getTargetName())); } key = values; } else { key = row.get(joins[0].getTargetName()); } List<Persistent> parents = (List<Persistent>) partitionByChild.get(key); if (parents != null) { for (Persistent parent : parents) { node.linkToParent(object, parent); } } }
@Override public String quotedTargetName(DbJoin join) { DataMap dataMap = join.getTarget().getEntity().getDataMap(); return quotedIdentifier(dataMap, join.getTargetName()); }
public void setUpdatedValueAt(Object aValue, int row, int column) { DbJoin join = getJoin(row); if (join == null) { return; } String value = (String) aValue; if (column == SOURCE) { if (source == null || source.getAttribute(value) == null) { value = null; } join.setSourceName(value); } else if (column == TARGET) { if (target == null || target.getAttribute(value) == null) { value = null; } join.setTargetName(value); } fireTableRowsUpdated(row, row); }
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"); } }