List of usage examples for org.hibernate SessionFactory getClassMetadata
@Deprecated ClassMetadata getClassMetadata(String entityName);
From source file:org.castafiore.designer.designable.table.JSONTableModel.java
License:Open Source License
public Object getValueAt(int col, int row, int page) { try {/* w w w .j a v a 2 s . c o m*/ 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.codehaus.groovy.grails.orm.hibernate.GrailsHibernateDomainClass.java
License:Apache License
/** * Contructor to be used by all child classes to create a new instance * and get the name right.//w ww.ja v a 2 s . c om * * @param clazz the Grails class * @param sessionFactory The Hibernate SessionFactory instance * @param metaData The ClassMetaData for this class retrieved from the SF */ public GrailsHibernateDomainClass(Class<?> clazz, SessionFactory sessionFactory, GrailsApplication application, ClassMetadata metaData) { super(clazz, ""); this.application = application; new StandardAnnotationMetadata(clazz); String ident = metaData.getIdentifierPropertyName(); if (ident != null) { Class<?> identType = getPropertyType(ident); identifier = new GrailsHibernateDomainClassProperty(this, ident); identifier.setIdentity(true); identifier.setType(identType); propertyMap.put(ident, identifier); } // configure the version property final int versionIndex = metaData.getVersionProperty(); String versionPropertyName = null; if (versionIndex > -1) { versionPropertyName = metaData.getPropertyNames()[versionIndex]; version = new GrailsHibernateDomainClassProperty(this, versionPropertyName); version.setType(getPropertyType(versionPropertyName)); } // configure remaining properties String[] propertyNames = metaData.getPropertyNames(); for (String propertyName : propertyNames) { if (!propertyName.equals(ident) && !(versionPropertyName != null && propertyName.equals(versionPropertyName))) { GrailsHibernateDomainClassProperty prop = new GrailsHibernateDomainClassProperty(this, propertyName); prop.setType(getPropertyType(propertyName)); Type hibernateType = metaData.getPropertyType(propertyName); // if its an association type if (hibernateType.isAssociationType()) { prop.setAssociation(true); // get the associated type from the session factory and set it on the property AssociationType assType = (AssociationType) hibernateType; if (assType instanceof AnyType) { continue; } try { String associatedEntity = assType .getAssociatedEntityName((SessionFactoryImplementor) sessionFactory); ClassMetadata associatedMetaData = sessionFactory.getClassMetadata(associatedEntity); prop.setRelatedClassType(associatedMetaData.getMappedClass(EntityMode.POJO)); } catch (MappingException me) { // other side must be a value object if (hibernateType.isCollectionType()) { prop.setRelatedClassType(Collection.class); } } // configure type of relationship if (hibernateType.isCollectionType()) { prop.setOneToMany(true); } else if (hibernateType.isEntityType()) { prop.setManyToOne(true); // might not really be true, but for our purposes this is ok prop.setOneToOne(true); } } propertyMap.put(propertyName, prop); } } properties = propertyMap.values().toArray(new GrailsDomainClassProperty[propertyMap.size()]); // process the constraints evaluateConstraints(); }
From source file:org.geomajas.layer.hibernate.HibernateLayerUtil.java
License:Open Source License
/** * Set session factory./*w w w . j a v a 2s. com*/ * * @param sessionFactory session factory * @throws HibernateLayerException could not get class metadata for data source */ public void setSessionFactory(SessionFactory sessionFactory) throws HibernateLayerException { try { this.sessionFactory = sessionFactory; if (null != layerInfo) { entityMetadata = sessionFactory.getClassMetadata(layerInfo.getFeatureInfo().getDataSourceName()); } } catch (Exception e) { // NOSONAR throw new HibernateLayerException(e, ExceptionCode.HIBERNATE_NO_SESSION_FACTORY); } }
From source file:org.hsqldb.hibernate.geomajas.layer.hibernate.HibernateLayerUtil.java
License:Open Source License
/** * Set session factory./*from w ww . ja v a 2 s .c o m*/ * * @param sessionFactory session factory * @throws HibernateLayerException could not get class metadata for data source */ public void setSessionFactory(SessionFactory sessionFactory) throws HibernateLayerException { try { this.sessionFactory = sessionFactory; if (null != layerInfo) { entityMetadata = sessionFactory.getClassMetadata(layerInfo.getFeatureInfo().getDataSourceName()); } } catch (Exception e) { throw new HibernateLayerException(e, ExceptionCode.HIBERNATE_NO_SESSION_FACTORY); } }
From source file:org.jadira.usertype.spi.repository.JpaBaseRepository.java
License:Apache License
/** * Determines the ID for the entity// w w w. jav a 2s . c om * * @param entity The entity to retrieve the ID for * @return The ID */ protected ID extractId(T entity) { final Class<?> entityClass = TypeHelper.getTypeArguments(JpaBaseRepository.class, this.getClass()).get(0); final SessionFactory sf = ((HibernateEntityManagerFactory) getEntityManager().getEntityManagerFactory()) .getSessionFactory(); final ClassMetadata cmd = sf.getClassMetadata(entityClass); final SessionImplementor si = (SessionImplementor) (getEntityManager().getDelegate()); @SuppressWarnings("unchecked") final ID result = (ID) cmd.getIdentifier(entity, si); return result; }
From source file:org.jbpm.context.exe.matcher.HibernateLongIdMatcher.java
License:Open Source License
public boolean matches(Object value) { boolean matches = false; JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext(); if (jbpmContext != null) { Class valueClass = value.getClass(); if (value instanceof HibernateProxy) { valueClass = valueClass.getSuperclass(); }//from w w w. jav a2 s. co m SessionFactory sessionFactory = jbpmContext.getSessionFactory(); if (sessionFactory != null) { ClassMetadata classMetadata = sessionFactory.getClassMetadata(valueClass); matches = ((classMetadata != null) && (classMetadata.getIdentifierType().getClass() == LongType.class)); } } else { log.debug("no current context so valueClass cannot be stored as a long-id-ref to a hibernate object"); matches = false; } return matches; }
From source file:org.jbpm.context.exe.matcher.HibernateStringIdMatcher.java
License:Open Source License
public boolean matches(Object value) { boolean matches = false; JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext(); if (jbpmContext != null) { Class valueClass = value.getClass(); if (value instanceof HibernateProxy) { valueClass = valueClass.getSuperclass(); }//from www . j a v a2s . com SessionFactory sessionFactory = jbpmContext.getSessionFactory(); if (sessionFactory != null) { ClassMetadata classMetadata = sessionFactory.getClassMetadata(valueClass); matches = ((classMetadata != null) && (classMetadata.getIdentifierType().getClass() == StringType.class)); } } else { log.debug("no current context so valueClass cannot be stored as a string-id-ref to a hibernate object"); matches = false; } return matches; }
From source file:org.jbpm.pvm.internal.type.matcher.HibernateIdMatcher.java
License:Open Source License
public boolean matches(String name, Object value) { boolean matches = false; Environment environment = Environment.getCurrent(); if (environment != null) { SessionFactory sessionFactory = null; if (hibernateSessionFactoryName != null) { sessionFactory = (SessionFactory) environment.get(hibernateSessionFactoryName); } else {/* w ww . j av a 2 s.c o m*/ sessionFactory = environment.get(SessionFactory.class); } if (sessionFactory != null) { ClassMetadata classMetadata = sessionFactory.getClassMetadata(value.getClass()); matches = ((classMetadata != null) && (classMetadata.getIdentifierType().getClass() == getIdType())); } } else { log.trace("no current environment so valueClass cannot be stored as an id-ref to a hibernate object"); matches = false; } return matches; }
From source file:org.jdal.hibernate.HibernateUtils.java
License:Apache License
/** * Get ClassMetadata for persistent object * /*from w w w.jav a2 s . c o m*/ * @param sessionFactory the hibernate SessionFactory * @param obj Object to initilize * @return ClassMetadata the class metadata */ private static ClassMetadata getClassMetadata(SessionFactory sessionFactory, Object obj) { return sessionFactory.getClassMetadata(Hibernate.getClass(obj)); }
From source file:org.nextframework.persistence.PersistenceUtils.java
License:Apache License
private static ClassMetadata getClassMetadata(Class<? extends Object> class1, SessionFactory sessionFactory) { if (class1.getSimpleName().contains("$$")) { //this is a generated class.. get the user class class1 = class1.getSuperclass(); }/* w ww .j av a 2 s . c om*/ return sessionFactory.getClassMetadata(class1); }