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


Java PersistenceUnitUtil类代码示例

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


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

示例1: primaryKeyAsObject

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
/**
 * returns the objects ID as a Object value. Native data types like int and long are casted to Integer and Long.
 * 
 * @param entity
 * @return
 * @throws AnnotationNotFoundException
 */
public static Object primaryKeyAsObject(Object entity) throws AnnotationNotFoundException {
   if (entity == null) return null;
   try {
      Object id = getValueOfAnnotatedFieldOrMethod(entity, Id.class);
      if (id == null) {
         // OpenJPA returns proprietary object type
         EntityManager em = Context.internalRequestScope().getApplicationEntityManager();
         if (em.getEntityManagerFactory() == null || em.getEntityManagerFactory().getPersistenceUnitUtil() == null) {
            throw new CibetException("CibetContext.getApplicationEntityManager().getEntityManagerFactory() is null");
         }
         PersistenceUnitUtil puu = em.getEntityManagerFactory().getPersistenceUnitUtil();
         id = puu.getIdentifier(entity);
         log.debug("found primary key from PersistenceUnitUtil: " + id);
      } else {
         log.debug("found primary key from annotation: " + id);
      }
      return id;
   } catch (IllegalArgumentException e) {
      throw new AnnotationNotFoundException(e.getMessage());
   }
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:29,代码来源:AnnotationUtil.java

示例2: init

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
public void init() {
        log.info("call init, id @" + id);
        if (id != null) {
            //this.post = em.find(Post.class, this.id);
            EntityGraph postEntityGraph=em.getEntityGraph("post");
//            EntityGraph postEntityGraph=em.createEntityGraph(Post.class);
//            postEntityGraph.addAttributeNodes("title");
//            postEntityGraph.addSubgraph("comments").addAttributeNodes("content");
            
            this.post=em
                    .createQuery("select p from Post p where p.id=:id", Post.class)
                    .setHint("javax.persistence.loadgraph", postEntityGraph)
                    .setParameter("id", this.id)
                    .getResultList()
                    .get(0);
            
            PersistenceUnitUtil util=em.getEntityManagerFactory().getPersistenceUnitUtil();
            
            log.info("title is [email protected]"+util.isLoaded(this.post, "title"));
            log.info("body is [email protected]"+util.isLoaded(this.post, "body"));
            log.info("comments is [email protected]"+util.isLoaded(this.post, "comments"));
        } else {
            throw new RuntimeException("id is required");
        }
    }
 
开发者ID:hantsy,项目名称:ee7-sandbox,代码行数:26,代码来源:ViewPostBean.java

示例3: testFindProductWithJoinFetch

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
@Test
@Transactional
public void testFindProductWithJoinFetch() throws Exception {
	JPAQuery query = new JPAQuery(em);
	QProduct path = QProduct.product;
	Product results = query.from(path)
			.join(path.stockKeepingUnits)
			.fetch() // Eager fetch the last join
			.where(path.productId.eq(1))
			.uniqueResult(path);

	// Get the PersistenceUnitUtil
	PersistenceUnitUtil util = em.getEntityManagerFactory().getPersistenceUnitUtil();

	// Check that the eager fetching occurred!
	Assert.assertTrue(util.isLoaded(results, "stockKeepingUnits"));

}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:19,代码来源:JpaQueryTest.java

示例4: testFindSkuWithFetchAll

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
@Test
@Transactional
public void testFindSkuWithFetchAll() throws Exception {
	JPAQuery query = new JPAQuery(em);
	QStockKeepingUnit path = QStockKeepingUnit.stockKeepingUnit;

	StockKeepingUnit results = query.from(path)
			.fetchAll() // Get all non-association fields eagerly
			.singleResult(path);

	// Get the PersistenceUnitUtil
	PersistenceUnitUtil util = em.getEntityManagerFactory().getPersistenceUnitUtil();

	// Check that the eager fetching occurred!
	Assert.assertTrue(util.isLoaded(results));

}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:18,代码来源:JpaQueryTest.java

示例5: testFindSkuWithJoinFetch

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
@Test
@Transactional
public void testFindSkuWithJoinFetch() throws Exception {
	JPAQuery query = new JPAQuery(em);
	QStockKeepingUnit path = QStockKeepingUnit.stockKeepingUnit;

	StockKeepingUnit results = query.from(path)
			.join(path.product())
			.fetch() // Get the product eagerly
			.singleResult(path);

	// Get the PersistenceUnitUtil
	PersistenceUnitUtil util = em.getEntityManagerFactory().getPersistenceUnitUtil();

	// Check that the eager fetching occurred!
	Assert.assertTrue(util.isLoaded(results, "product"));

}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:19,代码来源:JpaQueryTest.java

示例6: shouldLoadArtistWithLiveConcertsAndNoContracts

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
@Test
@InSequence(4)
public void shouldLoadArtistWithLiveConcertsAndNoContracts()
    throws Exception {
    Artist artist = getArtistWithEntityGraph(
        "Artist.WithConcertsAndNoContracts");
    PersistenceUnitUtil util =
        em.getEntityManagerFactory().getPersistenceUnitUtil();
    System.out.printf("++++ artist=%s\n", artist);
    assertTrue(util.isLoaded(artist, "id"));
    assertTrue(util.isLoaded(artist, "name"));
    assertTrue(util.isLoaded(artist, "events"));
    ConcertEvent event = artist.getEvents().values().iterator().next();
    System.out.printf("++++ concert event=%s\n", event );
    assertTrue(util.isLoaded(event, "id"));
    assertTrue(util.isLoaded(event, "name"));
    assertTrue(util.isLoaded(event, "eventType"));
    assertFalse(util.isLoaded(event, "contracts"));
}
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:20,代码来源:ArtistEntityGraphRetrievalTest.java

示例7: shouldLoadArtistWithLiveConcertsAndContracts

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
@Test
@InSequence(5)
public void shouldLoadArtistWithLiveConcertsAndContracts()
    throws Exception{
    EntityGraph artistGraph = em.getEntityGraph("Artist.WithConcertsAndContracts");
    PersistenceUnitUtil util =
        em.getEntityManagerFactory().getPersistenceUnitUtil();
    Artist artist = getArtistWithEntityGraph(
        "Artist.WithConcertsAndContracts");
    System.out.printf("++++ artist=%s\n", artist);
    assertTrue(util.isLoaded(artist, "id"));
    assertTrue(util.isLoaded(artist, "name"));
    assertTrue(util.isLoaded(artist, "events"));
    ConcertEvent event = artist.getEvents().values().iterator().next();
    System.out.printf("++++ concert event=%s\n", event );
    assertTrue(util.isLoaded(event, "id"));
    assertTrue(util.isLoaded(event, "name"));
    assertTrue(util.isLoaded(event, "eventType"));
    assertTrue(util.isLoaded(event, "contracts"));
}
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:21,代码来源:ArtistEntityGraphRetrievalTest.java

示例8: shouldLoadArtistWithoutConcerts

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
@Test
@InSequence(2)
public void shouldLoadArtistWithoutConcerts() throws Exception{
    PersistenceUnitUtil util =
        em.getEntityManagerFactory().getPersistenceUnitUtil();
    EntityGraph artistGraph = em.getEntityGraph("Artist.NoConcerts");
    Artist artist = (Artist) em.createQuery("Select a from Artist a")
        .setHint("javax.persistence.fetchgraph", artistGraph)
        .getResultList()
        .get(0);
    System.out.printf("++++ artist=%s\n", artist);
    System.out.printf(">> loaded  artist.id = %s\n", util.isLoaded(artist, "id"));
    System.out.printf(">> loaded  artist.name = %s\n", util.isLoaded(artist, "name"));
    System.out.printf(">> loaded  artist.events = %s\n", util.isLoaded(artist, "events"));
    assertTrue(util.isLoaded(artist, "id"));
    assertTrue(util.isLoaded(artist, "name"));
    assertFalse(util.isLoaded(artist, "events"));
}
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:19,代码来源:ArtistEntityGraphRetrievalTest.java

示例9: shouldLoadArtistWithConcerts

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
@Test
@InSequence(3)
public void shouldLoadArtistWithConcerts() throws Exception{
    PersistenceUnitUtil util =
        em.getEntityManagerFactory().getPersistenceUnitUtil();
    EntityGraph artistGraph = em.getEntityGraph("Artist.WithConcerts");
    Artist artist = (Artist)
        em.createQuery("Select a from Artist a")
        .setHint("javax.persistence.fetchgraph", artistGraph)
        .getResultList()
        .get(0);
    System.out.printf("++++ artist=%s\n", artist);
    System.out.printf("artist=%s\n", artist);
    assertTrue(util.isLoaded(artist, "id"));
    assertTrue(util.isLoaded(artist, "name"));
    assertTrue(util.isLoaded(artist, "events"));
}
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:18,代码来源:ArtistEntityGraphRetrievalTest.java

示例10: shouldLoadArtistWithLiveConcertsAndNoContracts

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
@Test
@InSequence(4)
public void shouldLoadArtistWithLiveConcertsAndNoContracts()
    throws Exception {
    PersistenceUnitUtil util =
            em.getEntityManagerFactory().getPersistenceUnitUtil();
    em.clear();
    EntityGraph artistGraph = em.getEntityGraph(
        "Artist.WithConcertsAndNoContracts");
    Artist artist = (Artist)
        em.createQuery("Select a from Artist a")
        .setHint("javax.persistence.fetchgraph", artistGraph)
        .getResultList()
        .get(0);
    System.out.printf("++++ artist=%s\n", artist);
    assertTrue(util.isLoaded(artist, "id"));
    assertTrue(util.isLoaded(artist, "name"));
    assertTrue(util.isLoaded(artist, "events"));
    ConcertEvent event = artist.getEvents().values().iterator().next();
    System.out.printf("++++ concert event=%s\n", event );
    assertTrue(util.isLoaded(event, "id"));
    assertTrue(util.isLoaded(event, "name"));
    assertTrue(util.isLoaded(event, "eventType"));
    assertFalse(util.isLoaded(event, "contracts"));
}
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:26,代码来源:ArtistEntityGraphRetrievalTest.java

示例11: shouldLoadArtistWithLiveConcertsAndContracts

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
@Test
@InSequence(5)
public void shouldLoadArtistWithLiveConcertsAndContracts()
    throws Exception{
    PersistenceUnitUtil util =
            em.getEntityManagerFactory().getPersistenceUnitUtil();
    em.clear();
    EntityGraph artistGraph = em.getEntityGraph("Artist.WithConcertsAndContracts");
    Artist artist = (Artist)
        em.createQuery("Select a from Artist a")
        .setHint("javax.persistence.fetchgraph", artistGraph)
        .getResultList()
        .get(0);
    System.out.printf("++++ artist=%s\n", artist);
    assertTrue(util.isLoaded(artist, "id"));
    assertTrue(util.isLoaded(artist, "name"));
    assertTrue(util.isLoaded(artist, "events"));
    ConcertEvent event = artist.getEvents().values().iterator().next();
    System.out.printf("++++ concert event=%s\n", event );
    assertTrue(util.isLoaded(event, "id"));
    assertTrue(util.isLoaded(event, "name"));
    assertTrue(util.isLoaded(event, "eventType"));
    assertTrue(util.isLoaded(event, "contracts"));
}
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:25,代码来源:ArtistEntityGraphRetrievalTest.java

示例12: isLoaded

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
/**
 * checks if the entity and all its properties are completely loaded from the database and all lazy properties are
 * initialised.
 * 
 * @param em
 *           EntityManager for loading the entity
 * @param entity
 * @return
 */
public static boolean isLoaded(EntityManager em, Object entity) {
   if (entity == null) {
      return true;
   }

   log.debug("check load state!");
   if (!em.contains(entity)) {
      log.debug("Entity is not in persistence context. Cannot check load state");
      // return true;
   }

   PersistenceUnitUtil util = em.getEntityManagerFactory().getPersistenceUnitUtil();
   if (util == null) {
      log.debug("no PersistenceUnitUtil");
      return true;
   }

   boolean loadstate = true;
   Class<?> clazz = entity.getClass();
   while (clazz != null) {
      Field[] fields = clazz.getDeclaredFields();
      for (Field f : fields) {
         if (Modifier.isStatic(f.getModifiers())) continue;
         if (Modifier.isTransient(f.getModifiers())) continue;
         if (AnnotationUtil.isFieldOrGetterOrSetterAnnotationPresent(clazz, f, Transient.class)) continue;
         boolean loaded = util.isLoaded(entity, f.getName());
         log.debug(f.getName() + " [" + f.getType() + "] loaded: " + loaded);
         if (!loaded) loadstate = false;
      }
      clazz = clazz.getSuperclass();
   }

   return loadstate;
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:44,代码来源:CibetUtil.java

示例13: EclipseLinkEntityEventListener

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
public EclipseLinkEntityEventListener(PersistenceUnitUtil persistenceUnitUtil, InternalEntityListener internalEntityListener)
{
    this.persistenceUnitUtil = persistenceUnitUtil;
	this.listener = internalEntityListener;
    this.entityUtil = new EntityUtil();
    
    this.entityFilter = internalEntityListener.entityFilter();
    this.fieldFilter = internalEntityListener.fieldFilter();
}
 
开发者ID:ethlo,项目名称:dachs,代码行数:10,代码来源:EclipseLinkEntityEventListener.java

示例14: ObjectHandlerTask

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
public ObjectHandlerTask(
		BatchBackend batchBackend, Class<?> entityClass, EntityIndexBinding entityIndexBinding,
		Supplier<EntityProvider> emProvider, BiConsumer<ObjectHandlerTask, EntityProvider> entityManagerDisposer,
		PersistenceUnitUtil peristenceUnitUtil) {
	this(
			batchBackend,
			entityClass,
			entityIndexBinding,
			emProvider,
			entityManagerDisposer,
			peristenceUnitUtil,
			null,
			null
	);
}
 
开发者ID:Hotware,项目名称:Hibernate-Search-GenericJPA,代码行数:16,代码来源:ObjectHandlerTask.java

示例15: shouldLoadArtistWithoutConcerts

import javax.persistence.PersistenceUnitUtil; //导入依赖的package包/类
@Test
@InSequence(2)
public void shouldLoadArtistWithoutConcerts() throws Exception{
    Artist artist = getArtistWithEntityGraph("Artist.NoConcerts");
    PersistenceUnitUtil util =
        em.getEntityManagerFactory().getPersistenceUnitUtil();
    System.out.printf("++++ artist=%s\n", artist);
    System.out.printf(">> loaded  artist.id = %s\n", util.isLoaded(artist, "id"));
    System.out.printf(">> loaded  artist.name = %s\n", util.isLoaded(artist, "name"));
    System.out.printf(">> loaded  artist.events = %s\n", util.isLoaded(artist, "events"));
    assertTrue(util.isLoaded(artist, "id"));
    assertTrue(util.isLoaded(artist, "name"));
    assertFalse(util.isLoaded(artist, "events"));
}
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:15,代码来源:ArtistEntityGraphRetrievalTest.java


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