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


Java PersistenceUnitUtil.isLoaded方法代码示例

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


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

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

示例2: initialize

import javax.persistence.PersistenceUnitUtil; //导入方法依赖的package包/类
/**
 * Initialize a entity. 
 * @param em entity manager to use
 * @param entity entity to initialize
 * @param depth max depth on recursion
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void initialize(EntityManager em, Object entity, int depth) {
	// return on nulls, depth = 0 or already initialized objects
	if (entity == null || depth == 0) { 
		return; 
	}
	
	PersistenceUnitUtil unitUtil = em.getEntityManagerFactory().getPersistenceUnitUtil();
	EntityType entityType = em.getMetamodel().entity(entity.getClass());
	Set<Attribute>  attributes = entityType.getDeclaredAttributes();
	
	Object id = unitUtil.getIdentifier(entity);
	
	if (id != null) {
		Object attached = em.find(entity.getClass(), unitUtil.getIdentifier(entity));

		for (Attribute a : attributes) {
			if (!unitUtil.isLoaded(entity, a.getName())) {
				if (a.isCollection()) {
					intializeCollection(em, entity, attached,  a, depth);
				}
				else if(a.isAssociation()) {
					intialize(em, entity, attached, a, depth);
				}
			}
		}
	}
}
 
开发者ID:chelu,项目名称:jdal,代码行数:35,代码来源:JpaUtils.java

示例3: isInitialized

import javax.persistence.PersistenceUnitUtil; //导入方法依赖的package包/类
public boolean isInitialized(final Object value) {
    PersistenceUnitUtil persistenceUnitUtil = entityManager.getEntityManagerFactory().getPersistenceUnitUtil();
    return persistenceUnitUtil.isLoaded(value);
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:5,代码来源:FetchDAOImpl.java


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