当前位置: 首页>>代码示例>>Java>>正文


Java DbRelationship类代码示例

本文整理汇总了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);
}
 
开发者ID:bootique,项目名称:bootique-cayenne,代码行数:21,代码来源:CayenneModelUtils.java

示例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());
}
 
开发者ID:bootique,项目名称:bootique-cayenne,代码行数:32,代码来源:CayenneTableManager.java

示例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;
    }
 
开发者ID:nhl,项目名称:link-move,代码行数:30,代码来源:TargetPropertyWriterFactory.java

示例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());
		}
	}
 
开发者ID:nhl,项目名称:link-rest,代码行数:32,代码来源:EntityParent.java

示例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;
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:11,代码来源:CayenneLrRelationship.java

示例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());
    }
}
 
开发者ID:bootique,项目名称:bootique-cayenne,代码行数:6,代码来源:ModelDependencyResolver.java

示例7: getDbRelationship

import org.apache.cayenne.map.DbRelationship; //导入依赖的package包/类
private DbRelationship getDbRelationship() {
    return objRelationship.getDbRelationships().get(0);
}
 
开发者ID:nhl,项目名称:link-rest,代码行数:4,代码来源:CayenneLrRelationship.java


注:本文中的org.apache.cayenne.map.DbRelationship类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。