use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class EOModelProcessorTest method assertOneWayRelationships.
protected void assertOneWayRelationships(DataMap map) throws Exception {
// assert that one way relationships are loaded properly
// - Db loaded as two-way, obj - as one-way
ObjEntity exhibitEntity = map.getObjEntity("Exhibit");
ObjRelationship toTypeObject = exhibitEntity.getRelationship("toExhibitType");
DbRelationship toTypeDB = exhibitEntity.getDbEntity().getRelationship("toExhibitType");
assertNotNull(toTypeObject);
assertNotNull(toTypeDB);
assertNull(toTypeObject.getReverseRelationship());
assertNotNull(toTypeDB.getReverseRelationship());
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class DbArcIdTest method testHashCode.
@Test
public void testHashCode() {
DbArcId id1 = new DbArcId(new ObjectId("x", "k", "v"), new DbRelationship("r1"));
int h1 = id1.hashCode();
assertEquals(h1, id1.hashCode());
assertEquals(h1, id1.hashCode());
DbArcId id1_eq = new DbArcId(new ObjectId("x", "k", "v"), new DbRelationship("r1"));
assertEquals(h1, id1_eq.hashCode());
DbArcId id2 = new DbArcId(new ObjectId("x", "k", "v"), new DbRelationship("r2"));
assertFalse(h1 == id2.hashCode());
DbArcId id3 = new DbArcId(new ObjectId("y", "k", "v"), new DbRelationship("r1"));
assertFalse(h1 == id3.hashCode());
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class OpenBaseJoinStack method appendJoinSubtree.
@Override
protected void appendJoinSubtree(StringBuilder out, JoinTreeNode node) {
DbRelationship relationship = node.getRelationship();
if (relationship == null) {
return;
}
DbEntity targetEntity = relationship.getTargetEntity();
String targetAlias = node.getTargetTableAlias();
out.append(", ").append(targetEntity.getFullyQualifiedName()).append(' ').append(targetAlias);
for (JoinTreeNode child : node.getChildren()) {
appendJoinSubtree(out, child);
}
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class Oracle8JoinStack method appendQualifierSubtree.
protected void appendQualifierSubtree(StringBuilder out, JoinTreeNode node) {
DbRelationship relationship = node.getRelationship();
String srcAlias = node.getSourceTableAlias();
String targetAlias = node.getTargetTableAlias();
List<DbJoin> joins = relationship.getJoins();
int len = joins.size();
for (int i = 0; i < len; i++) {
DbJoin join = joins.get(i);
if (i > 0) {
out.append(" AND ");
}
out.append(srcAlias).append('.').append(join.getSourceName());
switch(node.getJoinType()) {
case INNER:
out.append(" = ");
break;
case LEFT_OUTER:
out.append(" * ");
break;
default:
throw new IllegalArgumentException("Unsupported join type: " + node.getJoinType());
}
out.append(targetAlias).append('.').append(join.getTargetName());
}
for (JoinTreeNode child : node.getChildren()) {
out.append(" AND ");
appendQualifierSubtree(out, child);
}
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class Compiler method compileEntityResultWithPrefetch.
private EntityResult compileEntityResultWithPrefetch(EntityResult compiledResult, EJBQLExpression prefetchExpression) {
final EntityResult result = compiledResult;
String id = prefetchExpression.getText().toLowerCase();
ClassDescriptor descriptor = descriptorsById.get(id);
if (descriptor == null) {
descriptor = descriptorsById.get(prefetchExpression.getText());
}
final String prefix = prefetchExpression.getText().substring(prefetchExpression.getText().indexOf(".") + 1);
final Set<String> visited = new HashSet<String>();
PropertyVisitor visitor = new PropertyVisitor() {
public boolean visitAttribute(AttributeProperty property) {
ObjAttribute oa = property.getAttribute();
if (visited.add(oa.getDbAttributePath())) {
result.addObjectField(oa.getEntity().getName(), "fetch." + prefix + "." + oa.getName(), prefix + "." + oa.getDbAttributeName());
}
return true;
}
public boolean visitToMany(ToManyProperty property) {
return true;
}
public boolean visitToOne(ToOneProperty property) {
ObjRelationship rel = property.getRelationship();
DbRelationship dbRel = rel.getDbRelationships().get(0);
for (DbJoin join : dbRel.getJoins()) {
DbAttribute src = join.getSource();
if (src.isForeignKey() && visited.add(src.getName())) {
result.addDbField("fetch." + prefix + "." + src.getName(), prefix + "." + src.getName());
}
}
return true;
}
};
descriptor.visitAllProperties(visitor);
// append id columns ... (some may have been appended already via relationships)
for (String pkName : descriptor.getEntity().getPrimaryKeyNames()) {
if (visited.add(pkName)) {
result.addDbField("fetch." + prefix + "." + pkName, prefix + "." + pkName);
}
}
// append inheritance discriminator columns...
for (ObjAttribute column : descriptor.getDiscriminatorColumns()) {
if (visited.add(column.getName())) {
result.addDbField("fetch." + prefix + "." + column.getDbAttributePath(), prefix + "." + column.getDbAttributePath());
}
}
return result;
}
Aggregations