本文整理汇总了Java中org.apache.cayenne.map.DbRelationship类的典型用法代码示例。如果您正苦于以下问题:Java DbRelationship类的具体用法?Java DbRelationship怎么用?Java DbRelationship使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DbRelationship类属于org.apache.cayenne.map包,在下文中一共展示了DbRelationship类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRelatedDbEntities
import org.apache.cayenne.map.DbRelationship; //导入依赖的package包/类
static Stream<DbEntity> getRelatedDbEntities(EntityResolver resolver, Class<?> entityType, Property<?> relationship) {
ObjEntity entity = resolver.getObjEntity(entityType);
if (entity == null) {
throw new IllegalArgumentException("Not a Cayenne entity class: " + entityType.getName());
}
ObjRelationship objRelationship = entity.getRelationship(relationship.getName());
if (objRelationship == null) {
throw new IllegalArgumentException("No relationship '" + relationship.getName() + "' in entity " + entityType.getName());
}
List<DbRelationship> path = objRelationship.getDbRelationships();
if (path.size() < 2) {
return Stream.empty();
}
return path.subList(1, path.size()).stream().map(DbRelationship::getSourceEntity);
}
示例2: getRelatedTable
import org.apache.cayenne.map.DbRelationship; //导入依赖的package包/类
/**
* Returns a Table related to a given entity via the specified relationship. Useful for navigation to join tables
* that are not directly mapped to Java classes.
*
* @param entityType a root entity used to resolve a join table.
* @param relationship a Property indicating an ObjRelationship.
* @param tableIndex An index in a list of tables spanned by 'relationship'. Index of 0 corresponds to the target
* DbEntity of the first object in a chain of DbRelationships for a given ObjRelationship.
* @return a Table related to a given entity via the specified relationship.
* @since 0.24
*/
public Table getRelatedTable(Class<?> entityType, Property<?> relationship, int tableIndex) {
ObjEntity entity = resolver.getObjEntity(entityType);
if (entity == null) {
throw new IllegalArgumentException("Not a Cayenne entity class: " + entityType.getName());
}
ObjRelationship flattened = entity.getRelationship(relationship.getName());
if (flattened == null) {
throw new IllegalArgumentException("No relationship '" + relationship.getName() + "' in entity " + entityType.getName());
}
List<DbRelationship> path = flattened.getDbRelationships();
if (path.size() < tableIndex + 1) {
throw new IllegalArgumentException("Index " + tableIndex + " is out of bounds for relationship '" + relationship.getName());
}
return getTable(path.get(tableIndex).getTargetEntityName());
}
示例3: getOrCreateWriter
import org.apache.cayenne.map.DbRelationship; //导入依赖的package包/类
public TargetPropertyWriter getOrCreateWriter(ToOneProperty property) {
if (!entity.equals(property.getRelationship().getSourceEntity())) {
throw new LmRuntimeException("Property belongs to different entity: " + property.getName());
}
List<DbRelationship> dbRelationships = property.getRelationship().getDbRelationships();
if (dbRelationships.size() > 1) {
// TODO: support for flattened to-one relationships
LOGGER.info("TODO: not mapping db: path for a flattened relationship: " + property.getName());
} else {
DbRelationship dbRelationship = dbRelationships.get(0);
List<DbJoin> joins = dbRelationship.getJoins();
if (joins.size() > 1) {
// TODO: support for multi-key to-one relationships
LOGGER.info("TODO: not mapping db: path for a multi-key relationship: " + property.getName());
} else {
return getOrCreateWriter(
property.getName(),
ASTDbPath.DB_PREFIX + joins.get(0).getSourceName(),
new TargetToOnePropertyWriter(property)
);
}
}
return null;
}
示例4: qualifier
import org.apache.cayenne.map.DbRelationship; //导入依赖的package包/类
public Expression qualifier(EntityResolver resolver) {
ObjEntity parentEntity = resolver.getObjEntity(type);
ObjRelationship objRelationship = parentEntity.getRelationship(relationship);
if (objRelationship == null) {
throw new LinkRestException(Status.BAD_REQUEST, "Invalid relationship: '" + relationship + "'");
}
// navigate through DbRelationships ... there may be no reverse
// ObjRel.. Reverse DB should always be there
if (id.size() > 1) {
List<Expression> expressions = new ArrayList<>();
for (DbRelationship dbRelationship : objRelationship.getDbRelationships()) {
DbRelationship reverseRelationship = dbRelationship.getReverseRelationship();
for (DbJoin join : reverseRelationship.getJoins()) {
Object joinValue = id.get(join.getTargetName());
if (joinValue == null) {
throw new LinkRestException(Status.BAD_REQUEST,
"Failed to build a Cayenne qualifier for a by-parent relationship '" + relationship +
"'; one of the parent's ID parts is missing in it's ID: " + join.getTargetName());
}
expressions.add(ExpressionFactory.matchDbExp(join.getSourceName(), joinValue));
}
}
return ExpressionFactory.and(expressions);
} else {
return ExpressionFactory.matchDbExp(objRelationship.getReverseDbRelationshipPath(), id.get());
}
}
示例5: extractId
import org.apache.cayenne.map.DbRelationship; //导入依赖的package包/类
private Map<String, Object> extractId(Function<String, Object> idPartSupplier) {
Map<String, Object> parentIdMap = new HashMap<>();
for (DbRelationship dbRelationship : objRelationship.getDbRelationships()) {
DbRelationship reverseRelationship = dbRelationship.getReverseRelationship();
for (DbJoin join : reverseRelationship.getJoins()) {
parentIdMap.put(join.getSourceName(), idPartSupplier.apply(join.getTargetName()));
}
}
return parentIdMap;
}
示例6: resolveDependent
import org.apache.cayenne.map.DbRelationship; //导入依赖的package包/类
static private void resolveDependent(Set<DbEntity> resolved, DbRelationship relationship) {
if (relationship.isFromPK() && !relationship.isToMasterPK()) {
resolve(resolved, relationship.getTargetEntity());
}
}
示例7: getDbRelationship
import org.apache.cayenne.map.DbRelationship; //导入依赖的package包/类
private DbRelationship getDbRelationship() {
return objRelationship.getDbRelationships().get(0);
}