List of usage examples for org.hibernate EntityMode POJO
EntityMode POJO
To view the source code for org.hibernate EntityMode POJO.
Click Source Link
From source file:org.babyfish.hibernate.cfg.Configuration.java
License:Open Source License
private void registerXPojoEntityTuplizer() { this.getEntityTuplizerFactory().registerDefaultTuplizerClass(EntityMode.POJO, XPojoEntityTuplizer.class); }
From source file:org.beanfuse.entity.context.HibernateEntityContext.java
License:Open Source License
/** * ???.<br>//from w ww . j a v a 2 s . co m * ?entityTypes. * * @param entityName * @return */ private EntityType buildEntityType(SessionFactory sessionFactory, String entityName) { EntityType entityType = (EntityType) entityTypes.get(entityName); if (null == entityType) { ClassMetadata cm = sessionFactory.getClassMetadata(entityName); if (null == cm) { logger.error("Cannot find ClassMetadata for {}", entityName); return null; } entityType = new EntityType(); entityType.setEntityName(cm.getEntityName()); entityType.setIdPropertyName(cm.getIdentifierPropertyName()); entityType.setEntityClass(cm.getMappedClass(EntityMode.POJO)); entityTypes.put(cm.getEntityName(), entityType); Map propertyTypes = entityType.getPropertyTypes(); String[] ps = cm.getPropertyNames(); for (int i = 0; i < ps.length; i++) { org.hibernate.type.Type type = cm.getPropertyType(ps[i]); if (type.isEntityType()) { propertyTypes.put(ps[i], buildEntityType(sessionFactory, type.getName())); } else if (type.isComponentType()) { propertyTypes.put(ps[i], buildComponentType(sessionFactory, entityName, ps[i])); } else if (type.isCollectionType()) { propertyTypes.put(ps[i], buildCollectionType(sessionFactory, defaultCollectionClass(type), entityName + "." + ps[i])); } } } return entityType; }
From source file:org.beangle.commons.orm.hibernate.internal.HibernateEntityContext.java
License:Open Source License
/** * ???.<br>//from ww w.j a v a2 s . c om * ?entityTypes. * * @param entityName * @return */ private EntityType buildEntityType(SessionFactory sessionFactory, String entityName) { EntityType entityType = (EntityType) entityTypes.get(entityName); if (null == entityType) { ClassMetadata cm = sessionFactory.getClassMetadata(entityName); if (null == cm) { logger.error("Cannot find ClassMetadata for {}", entityName); return null; } entityType = new EntityType(cm.getEntityName(), cm.getMappedClass(EntityMode.POJO), cm.getIdentifierPropertyName()); entityTypes.put(cm.getEntityName(), entityType); Map<String, Type> propertyTypes = entityType.getPropertyTypes(); String[] ps = cm.getPropertyNames(); for (int i = 0; i < ps.length; i++) { org.hibernate.type.Type type = cm.getPropertyType(ps[i]); if (type.isEntityType()) { propertyTypes.put(ps[i], buildEntityType(sessionFactory, type.getName())); } else if (type.isComponentType()) { propertyTypes.put(ps[i], buildComponentType(sessionFactory, entityName, ps[i])); } else if (type.isCollectionType()) { propertyTypes.put(ps[i], buildCollectionType(sessionFactory, defaultCollectionClass(type), entityName + "." + ps[i])); } } } return entityType; }
From source file:org.beangle.model.persist.hibernate.HibernateEntityContext.java
License:Open Source License
/** * ???.<br>//from w ww .ja v a2s .co m * ?entityTypes. * * @param entityName * @return */ private EntityType buildEntityType(SessionFactory sessionFactory, String entityName) { EntityType entityType = (EntityType) entityTypes.get(entityName); if (null == entityType) { ClassMetadata cm = sessionFactory.getClassMetadata(entityName); if (null == cm) { logger.error("Cannot find ClassMetadata for {}", entityName); return null; } entityType = new EntityType(); entityType.setEntityName(cm.getEntityName()); entityType.setIdPropertyName(cm.getIdentifierPropertyName()); entityType.setEntityClass(cm.getMappedClass(EntityMode.POJO)); entityTypes.put(cm.getEntityName(), entityType); Map<String, Type> propertyTypes = entityType.getPropertyTypes(); String[] ps = cm.getPropertyNames(); for (int i = 0; i < ps.length; i++) { org.hibernate.type.Type type = cm.getPropertyType(ps[i]); if (type.isEntityType()) { propertyTypes.put(ps[i], buildEntityType(sessionFactory, type.getName())); } else if (type.isComponentType()) { propertyTypes.put(ps[i], buildComponentType(sessionFactory, entityName, ps[i])); } else if (type.isCollectionType()) { propertyTypes.put(ps[i], buildCollectionType(sessionFactory, defaultCollectionClass(type), entityName + "." + ps[i])); } } } return entityType; }
From source file:org.broadleafcommerce.openadmin.server.dao.DynamicEntityDaoImpl.java
License:Apache License
public Class<?>[] getAllPolymorphicEntitiesFromCeiling(Class<?> ceilingClass) { Class<?>[] cache;//from w w w. jav a 2 s . c om synchronized (LOCK_OBJECT) { cache = (Class<?>[]) POLYMORPHIC_ENTITY_CACHE.get(ceilingClass); if (cache == null) { List<Class<?>> entities = new ArrayList<Class<?>>(); for (Object item : getSessionFactory().getAllClassMetadata().values()) { ClassMetadata metadata = (ClassMetadata) item; Class<?> mappedClass = metadata.getMappedClass(EntityMode.POJO); if (mappedClass != null && ceilingClass.isAssignableFrom(mappedClass)) { entities.add(mappedClass); } } /* * Sort entities with the most derived appearing first */ Class<?>[] sortedEntities = new Class<?>[entities.size()]; List<Class<?>> stageItems = new ArrayList<Class<?>>(); stageItems.add(ceilingClass); int j = 0; while (j < sortedEntities.length) { List<Class<?>> newStageItems = new ArrayList<Class<?>>(); boolean topLevelClassFound = false; for (Class<?> stageItem : stageItems) { Iterator<Class<?>> itr = entities.iterator(); while (itr.hasNext()) { Class<?> entity = itr.next(); checkitem: { if (ArrayUtils.contains(entity.getInterfaces(), stageItem) || entity.equals(stageItem)) { topLevelClassFound = true; break checkitem; } if (topLevelClassFound) { continue; } if (entity.getSuperclass().equals(stageItem)) { break checkitem; } continue; } sortedEntities[j] = entity; itr.remove(); j++; newStageItems.add(entity); } } if (newStageItems.isEmpty()) { throw new RuntimeException("There was a gap in the inheritance hierarchy for (" + ceilingClass.getName() + ")"); } stageItems = newStageItems; } ArrayUtils.reverse(sortedEntities); cache = sortedEntities; POLYMORPHIC_ENTITY_CACHE.put(ceilingClass, sortedEntities); } } return cache; }
From source file:org.brushingbits.jnap.persistence.factory.DaoFactoryPostProcessor.java
License:Apache License
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { Assert.isAssignable(DefaultListableBeanFactory.class, registry.getClass(), "The DaoFactoryPostProcessor only works within a DefaultListableBeanFactory capable" + "BeanFactory, your BeanDefinitionRegistry is " + registry.getClass()); final DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) registry; // get already defined beans of type Dao final Set<Class<? extends PersistentModel>> alreadyDefinedDaos = new HashSet<Class<? extends PersistentModel>>(); for (String beanName : beanFactory.getBeanNamesForType(Dao.class, true, false)) { Dao<? extends PersistentModel> dao = beanFactory.getBean(beanName, Dao.class); alreadyDefinedDaos.add(dao.getEntityClass()); }/* w w w. j a v a 2 s. c o m*/ for (String sessionFactoryName : beanFactory.getBeanNamesForType(SessionFactory.class)) { final SessionFactory sessionFactory = beanFactory.getBean(sessionFactoryName, SessionFactory.class); Map<String, ClassMetadata> entitiesMetadata = sessionFactory.getAllClassMetadata(); for (ClassMetadata entityMetadata : entitiesMetadata.values()) { Class<? extends PersistentModel> entityClass = entityMetadata.getMappedClass(EntityMode.POJO); if (entityClass != null && !alreadyDefinedDaos.contains(entityClass)) { String daoName = entityClass.getSimpleName() + "Dao"; daoName = Character.toLowerCase(daoName.charAt(0)) + daoName.substring(1); beanFactory.registerBeanDefinition(daoName, createDaoDefinition(entityClass, sessionFactory)); } } } }
From source file:org.castafiore.designer.designable.table.JSONTableModel.java
License:Open Source License
public Object getValueAt(int col, int row, int page) { try {/*from www .ja va 2 s.com*/ String property = null; String entity = null; ClassMetadata metadata = null; int index = (getRowsPerPage() * page) + row; if (model != null) { property = this.model.getJSONArray("properties").getString(col); entity = model.getString("entity"); SessionFactory factory = BaseSpringUtil.getBeanOfType(SessionFactory.class); metadata = factory.getClassMetadata(entity); Object value = metadata.getPropertyValue(data.get(index), property, EntityMode.POJO); return value; } else { return data.get(index); } } catch (Exception e) { //e.printStackTrace(); logger.error(e); return "??"; } }
From source file:org.cgiar.ccafs.marlo.data.AuditLogInterceptor.java
License:Open Source License
public Set<HashMap<String, Object>> loadList(IAuditLog entity) { Set<HashMap<String, Object>> setRelations = new HashSet<>(); ClassMetadata classMetadata = session.getSessionFactory().getClassMetadata(entity.getClass()); String[] propertyNames = classMetadata.getPropertyNames(); for (String name : propertyNames) { Object propertyValue = classMetadata.getPropertyValue(entity, name, EntityMode.POJO); Type propertyType = classMetadata.getPropertyType(name); if (propertyValue != null && (propertyType instanceof OrderedSetType || propertyType instanceof SetType)) { HashMap<String, Object> objects = new HashMap<>(); Set<IAuditLog> listRelation = new HashSet<>(); Set<IAuditLog> entityRelation = (Set<IAuditLog>) propertyValue; for (IAuditLog iAuditLog : entityRelation) { if (iAuditLog.isActive()) { listRelation.add(iAuditLog); }// w w w . jav a2 s .c o m } objects.put(ENTITY, listRelation); objects.put(PRINCIPAL, "3"); objects.put(RELATION_NAME, propertyType.getName() + ":" + entity.getId()); setRelations.add(objects); } } return setRelations; }
From source file:org.cgiar.ccafs.marlo.data.AuditLogInterceptor.java
License:Open Source License
public void loadRelations(IAuditLog entity, boolean loadUsers, int level) { ClassMetadata classMetadata = session.getSessionFactory().getClassMetadata(entity.getClass()); String[] propertyNames = classMetadata.getPropertyNames(); for (String name : propertyNames) { Object propertyValue = classMetadata.getPropertyValue(entity, name, EntityMode.POJO); if (propertyValue != null && propertyValue instanceof IAuditLog) { Type propertyType = classMetadata.getPropertyType(name); if (propertyValue != null && propertyType instanceof ManyToOneType) { if (loadUsers) { IAuditLog entityRelation = (IAuditLog) propertyValue; Object obj = dao.find(propertyType.getReturnedClass(), (Serializable) entityRelation.getId()); this.loadRelations((IAuditLog) obj, false, 2); classMetadata.setPropertyValue(entity, name, obj, EntityMode.POJO); } else { if (!(name.equals("createdBy") || name.equals("modifiedBy"))) { IAuditLog entityRelation = (IAuditLog) propertyValue; Object obj = dao.find(propertyType.getReturnedClass(), (Serializable) entityRelation.getId()); if (level == 2) { this.loadRelations((IAuditLog) obj, false, 3); }// w ww. j a v a2 s.c o m // this.loadRelations((IAuditLog) obj, false); classMetadata.setPropertyValue(entity, name, obj, EntityMode.POJO); } } } } } }
From source file:org.cgiar.ccafs.marlo.data.dao.impl.AuditLogDao.java
License:Open Source License
public void loadRelationsForIAuditLog(IAuditLog iAuditLog, String transactionID) { try {//from w ww . j a v a 2 s. c o m Session session = dao.openSession(); ClassMetadata classMetadata = session.getSessionFactory().getClassMetadata(iAuditLog.getClass()); String[] propertyNames = classMetadata.getPropertyNames(); for (String name : propertyNames) { Type propertyType = classMetadata.getPropertyType(name); if (propertyType instanceof OrderedSetType || propertyType instanceof SetType) { String classNameRelation = propertyType.getName(); String sql = "from " + Auditlog.class.getName() + " where transaction_id='" + transactionID + "' and main=3 and relation_name='" + classNameRelation + ":" + iAuditLog.getId() + "'order by ABS(ENTITY_ID) asc"; List<Auditlog> auditLogsRelations = dao.findAll(sql); Set<IAuditLog> relation = new HashSet<IAuditLog>(); for (Auditlog auditlog : auditLogsRelations) { IAuditLog relationObject = this.loadFromAuditLog(auditlog); this.loadRelationsForIAuditLog(relationObject, transactionID); relation.add(relationObject); } classMetadata.setPropertyValue(iAuditLog, name, relation, EntityMode.POJO); } } session.close(); } catch (JsonSyntaxException e) { e.printStackTrace(); } }