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


Java EntityGraph.addAttributeNodes方法代码示例

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


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

示例1: 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

示例2: findAllWithAttributes

import javax.persistence.EntityGraph; //导入方法依赖的package包/类
@Override
public List<E> findAllWithAttributes(String... attributes) {
    //        String sql = "SELECT o FROM " + getTableName() + " o";

    EntityGraph<E> graph = entityManager.createEntityGraph(getEntityClass());
    graph.addAttributeNodes(attributes);

    //        TypedQuery<E> query = entityManager.createQuery(sql, getEntityClass());
    //        query.setHint("javax.persistence.loadgraph", graph);

    //        TypedQuery<E> query = entityManager.createQuery(sql, getEntityClass());
    //        LoadGroup lg = new LoadGroup();
    //        lg.addAttributes(Arrays.asList(attributes));
    //        query.setHint(QueryHints.LOAD_GROUP, lg);
    //        for (String att : attributes) {
    //            query.setHint(QueryHints.BATCH, "o." + att);
    //        }

    //        List<E> result = query.getResultList();
    List<E> result = findAllWithGraph(graph);
    return result;
}
 
开发者ID:viydaag,项目名称:dungeonstory-java,代码行数:23,代码来源:AbstractRepository.java

示例3: selectWithEntityGraph

import javax.persistence.EntityGraph; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void selectWithEntityGraph() {
	log.info("... selectWithEntityGraph ...");

	EntityManager em = emf.createEntityManager();
	em.getTransaction().begin();

	EntityGraph<Author> graph = em.createEntityGraph(Author.class);
	graph.addAttributeNodes(Author_.books);
	
	TypedQuery<Author> q = em.createQuery("SELECT a FROM Author a WHERE a.id = 1", Author.class);
	q.setHint("javax.persistence.fetchgraph", graph);
	Author a = q.getSingleResult();
	
	em.getTransaction().commit();
	em.close();
	
	log.info(a.getFirstName()+" "+a.getLastName()+" wrote "+a.getBooks().size()+" books.");
}
 
开发者ID:thjanssen,项目名称:HibernateTips,代码行数:21,代码来源:TestEntityGraph.java

示例4: testInitDynamicEntityGraph

import javax.persistence.EntityGraph; //导入方法依赖的package包/类
@Test
public void testInitDynamicEntityGraph() {
	EntityGraph<User> graph = entityManager.createEntityGraph(User.class);
	graph.addAttributeNodes("cars");
	User user = entityManager.find(User.class, 1L, Collections.singletonMap("javax.persistence.fetchgraph", graph));
	user.getCars().stream().forEach(System.out::println);
}
 
开发者ID:Javatar81,项目名称:code-examples,代码行数:8,代码来源:DynamicFetchTest.java

示例5: shouldLazyInitializationSolution5

import javax.persistence.EntityGraph; //导入方法依赖的package包/类
@Test
public void shouldLazyInitializationSolution5() { //encji
    Map<String, Object> hints = newHashMap();
    EntityGraph<Item> itemGraph = em.createEntityGraph(Item.class); //<13>
    itemGraph.addAttributeNodes("offers"); //<14>
    hints.put("javax.persistence.loadgraph", itemGraph); //<15>
    em.getEntityGraphs(Item.class).forEach(eg->log.info("{}",eg));
    Item one = em.find(Item.class, 1l,hints);
    assertThat(Persistence.getPersistenceUtil().isLoaded(one)).isTrue();
    assertThat(Persistence.getPersistenceUtil().isLoaded(one.getOffers())).isTrue();
}
 
开发者ID:przodownikR1,项目名称:springJpaKata,代码行数:12,代码来源:JpaLazyTest.java

示例6: shouldEntityGraphWork

import javax.persistence.EntityGraph; //导入方法依赖的package包/类
@Test

    public void shouldEntityGraphWork() {

        Map<String, Object> props = newHashMap();
        EntityGraph<Skill> skillGraph = em.createEntityGraph(Skill.class);
        skillGraph.addAttributeNodes("candidate");
        props.put("javax.persistence.loadgraph", skillGraph);

        Skill one = em.find(Skill.class, 1l, props);
        assertThat(Persistence.getPersistenceUtil().isLoaded(one)).isTrue();
        assertThat(Persistence.getPersistenceUtil().isLoaded(one.getCandidate())).isTrue();

    }
 
开发者ID:przodownikR1,项目名称:springJpaKata,代码行数:15,代码来源:N1Test.java

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