use of org.apache.cayenne.map.DbJoin in project cayenne by apache.
the class EJBQLPathAnaliserTranslator method processFlattenedRelationShip.
private String processFlattenedRelationShip(String subqueryRootAlias, ObjRelationship relationship) {
QuotingStrategy quoter = context.getQuotingStrategy();
List<DbRelationship> dbRelationships = relationship.getDbRelationships();
// relation
for (int i = dbRelationships.size() - 1; i > 0; i--) {
DbRelationship dbRelationship = dbRelationships.get(i);
String subqueryTargetTableName = quoter.quotedFullyQualifiedName((DbEntity) dbRelationship.getTargetEntity());
String subqueryTargetAlias;
if (i == dbRelationships.size() - 1) {
subqueryTargetAlias = subqueryRootAlias;
context.append(subqueryTargetTableName).append(' ').append(subqueryTargetAlias);
} else {
subqueryTargetAlias = context.getTableAlias(subqueryTargetTableName, subqueryTargetTableName);
}
context.append(" JOIN ");
String subquerySourceTableName = quoter.quotedFullyQualifiedName((DbEntity) dbRelationship.getSourceEntity());
String subquerySourceAlias = context.getTableAlias(subquerySourceTableName, subquerySourceTableName);
context.append(subquerySourceTableName).append(' ').append(subquerySourceAlias);
context.append(" ON (");
List<DbJoin> joins = dbRelationship.getJoins();
Iterator<DbJoin> it = joins.iterator();
while (it.hasNext()) {
DbJoin join = it.next();
context.append(' ').append(subqueryTargetAlias).append('.').append(join.getTargetName()).append(" = ");
context.append(subquerySourceAlias).append('.').append(join.getSourceName());
if (it.hasNext()) {
context.append(" AND");
}
}
context.append(" )");
subqueryRootAlias = subquerySourceAlias;
}
return subqueryRootAlias;
}
use of org.apache.cayenne.map.DbJoin in project cayenne by apache.
the class EJBQLJoinAppender method generateJoiningExpression.
private void generateJoiningExpression(DbRelationship incomingDB, String sourceAlias, String targetAlias) {
context.append(" ON (");
QuotingStrategy quoter = context.getQuotingStrategy();
Iterator<DbJoin> it = incomingDB.getJoins().iterator();
if (it.hasNext()) {
DbJoin dbJoin = it.next();
context.append(sourceAlias).append('.').append(quoter.quotedSourceName(dbJoin)).append(" = ").append(targetAlias).append('.').append(quoter.quotedTargetName(dbJoin));
}
while (it.hasNext()) {
context.append(" AND ");
DbJoin dbJoin = it.next();
context.append(sourceAlias).append('.').append(quoter.quotedSourceName(dbJoin)).append(" = ").append(targetAlias).append('.').append(quoter.quotedTargetName(dbJoin));
}
context.append(")");
}
use of org.apache.cayenne.map.DbJoin in project cayenne by apache.
the class DataObjectMatchTranslator method setRelationship.
/**
* 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());
}
}
}
use of org.apache.cayenne.map.DbJoin in project cayenne by apache.
the class InferRelationshipsControllerBase method createNames.
protected void createNames() {
for (InferredRelationship myir : inferredRelationships) {
DbRelationship localRelationship = new DbRelationship();
localRelationship.setToMany(myir.isToMany());
if (myir.getJoinSource().isPrimaryKey()) {
localRelationship.addJoin(new DbJoin(localRelationship, myir.getJoinSource().getName(), myir.getJoinTarget().getName()));
localRelationship.setSourceEntity(myir.getSource());
localRelationship.setTargetEntityName(myir.getTarget().getName());
} else {
localRelationship.addJoin(new DbJoin(localRelationship, myir.getJoinTarget().getName(), myir.getJoinSource().getName()));
localRelationship.setSourceEntity(myir.getTarget());
localRelationship.setTargetEntityName(myir.getSource().getName());
}
myir.setName(strategy.relationshipName(localRelationship));
}
}
use of org.apache.cayenne.map.DbJoin in project cayenne by apache.
the class DbJoinTableModel method setUpdatedValueAt.
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);
}
Aggregations