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


Java EntityGraph.addSubgraph方法代码示例

本文整理汇总了Java中javax.persistence.EntityGraph.addSubgraph方法的典型用法代码示例。如果您正苦于以下问题:Java EntityGraph.addSubgraph方法的具体用法?Java EntityGraph.addSubgraph怎么用?Java EntityGraph.addSubgraph使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.persistence.EntityGraph的用法示例。


在下文中一共展示了EntityGraph.addSubgraph方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadFully

import javax.persistence.EntityGraph; //导入方法依赖的package包/类
/**
 * Fetches an instance of given PhoneBookEntry with all lazy 
 * loaded properties loaded.
 * @param entry
 * @return the fully loaded instance
 */
public PhoneBookEntry loadFully(PhoneBookEntry entry) {
    // To get lazy loaded fields initialized, you have couple of options,
    // all with pros and cons, 3 of them presented here.

    // 1) use an explicit join query (with EntityManager or @Query annotation
    //    in repository method.
    //    em.createQuery("select e from PhoneBookEntry e LEFT JOIN FETCH e.groups where e.id = :id", PhoneBookEntry.class);
    //    ...
    // 2) use EntityGraph's introduced in JPA 2.1, here constructed dynamically
    //    and passed via QueryResult object from DeltaSpike Data. You can 
    //    also use entity graphs with @Query annotation in repositories or
    //    with raw EntityManager API.
    EntityGraph<PhoneBookEntry> graph = this.em.createEntityGraph(
            PhoneBookEntry.class);
    graph.addSubgraph("groups");
    entry = entryRepo.findById(entry.getId())
            .hint("javax.persistence.loadgraph", graph)
            .getSingleResult();

    // 3) ..or use the infamous size() hack that all of us actually do :-)
    entry.getAddresses().size();

    return entry;
}
 
开发者ID:mstahv,项目名称:jpa-addressbook,代码行数:31,代码来源:PhoneBookService.java

示例2: addAttributeNodes

import javax.persistence.EntityGraph; //导入方法依赖的package包/类
private static void addAttributeNodes(String fieldName, EntityGraph<?> graph) {
    int pos = fieldName.indexOf(GRAPH_DELIMETER);
    if (pos < 0) {
        graph.addAttributeNodes(fieldName);
        return;
    }

    String subgraphName = fieldName.substring(0, pos);
    Subgraph<?> subGraph = graph.addSubgraph(subgraphName);
    String nextFieldName = fieldName.substring(pos + 1);
    pos = nextFieldName.indexOf(GRAPH_DELIMETER);

    while (pos > 0) {
        subgraphName = nextFieldName.substring(0, pos);
        subGraph = graph.addSubgraph(subgraphName);
        nextFieldName = nextFieldName.substring(pos + 1);
        pos = nextFieldName.indexOf(GRAPH_DELIMETER);
    }

    subGraph.addAttributeNodes(nextFieldName);
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:22,代码来源:EntityGraphRepositoryImpl.java

示例3: applyFetchPaths

import javax.persistence.EntityGraph; //导入方法依赖的package包/类
private <T> Subgraph<Object> applyFetchPaths(EntityGraph<T> graph, MetaAttributePath fetchPath) {
	if (fetchPath.length() >= 2) {
		// ensure parent is fetched
		MetaAttributePath parentPath = fetchPath.subPath(0, fetchPath.length() - 1);
		Subgraph<Object> parentGraph = applyFetchPaths(graph, parentPath);
		return parentGraph.addSubgraph(fetchPath.toString());
	} else {
		return graph.addSubgraph(fetchPath.toString());
	}
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:11,代码来源:EntityGraphBuilderImpl.java

示例4: applyFetchPaths

import javax.persistence.EntityGraph; //导入方法依赖的package包/类
private Subgraph<Object> applyFetchPaths(EntityGraph<T> graph, MetaAttributePath fetchPath) {
	if (fetchPath.length() >= 2) {
		// ensure parent is fetched
		MetaAttributePath parentPath = fetchPath.subPath(0, fetchPath.length() - 1);
		Subgraph<Object> parentGraph = applyFetchPaths(graph, parentPath);
		return parentGraph.addSubgraph(fetchPath.toString());
	}
	else {
		return graph.addSubgraph(fetchPath.toString());
	}
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:12,代码来源:AbstractQueryExecutorImpl.java

示例5: generateEntityGraphXPath

import javax.persistence.EntityGraph; //导入方法依赖的package包/类
/**
 * Builds an entity graph from a XML file.
 * 
 * @param graphName
 *            name of the entity graph
 * @param classType
 *            entity graph with rootElement of classType
 * @return result generated entity graph with rootElement of classType - can
 *         be null if an error occurs during entity graph initialization
 */
@Override
public <T> EntityGraph<?> generateEntityGraphXPath(final EntityManager em, final String graphName,
		final Class<T> classType) {
	EntityGraph<?> graph = null;

	try {
		URL centralMappingFilePath = JEntityGraphDataMapper.class.getResource(FilePaths.CENTRAL_XML_NAME.path());
		File centralRules;

		centralRules = new File(centralMappingFilePath.toURI());

		final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
		final Document doc = dBuilder.parse(centralRules);
		doc.getDocumentElement().normalize();

		xPath = XPathFactory.newInstance().newXPath();

		// list of attribute-nodes from the root class of the selected
		// entity graph
		final String attributeRootNodeListString = "//named-entity-graph[@name='" + graphName
				+ "']/named-attribute-node";
		final NodeList attributeRootNodeList = (NodeList) xPath.compile(attributeRootNodeListString).evaluate(doc,
				XPathConstants.NODESET);

		// list of all subgraphs
		final String subgraphListString = "//named-entity-graph[@name='" + graphName + "']/subgraph";
		final NodeList subgraphList = (NodeList) xPath.compile(subgraphListString).evaluate(doc,
				XPathConstants.NODESET);

		// create EntityGraph
		graph = em.createEntityGraph(classType);

		// reads all named-attribute-nodes below the named-entity-graph
		for (int i = 0; i < attributeRootNodeList.getLength(); ++i) {
			final Element nodeElem = (Element) attributeRootNodeList.item(i);

			// adds the attributes to the graph
			if ("".equals(nodeElem.getAttribute("subgraph"))) {
				graph.addAttributeNodes(nodeElem.getAttribute("name"));
			}
			// reference to a subgraph
			else {
				// create subgraph with a reference to the upper class
				final Subgraph<?> subgraph = graph.addSubgraph(nodeElem.getAttribute("name"));
				buildSubgraph(subgraph, graphName, nodeElem, subgraphList, doc);
			}
		}
	} catch (XPathExpressionException | ParserConfigurationException | SAXException | IOException
			| URISyntaxException e) {
		LOGGER.warn("Exception in BuildEntityGraph::generateEntityGraphXPath, full stack trace follows: ", e);
	}
	return graph;
}
 
开发者ID:doubleSlashde,项目名称:jEDM,代码行数:65,代码来源:BuildEntityGraph.java


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