Package org.hibernate.metadata

Examples of org.hibernate.metadata.ClassMetadata


    if (null != sessionFactory && entityTypes.isEmpty()) {
      StopWatch watch = new StopWatch();
      watch.start();
      Map<String, ClassMetadata> classMetadatas = sessionFactory.getAllClassMetadata();
      for (Iterator<ClassMetadata> iter = classMetadatas.values().iterator(); iter.hasNext();) {
        ClassMetadata cm = (ClassMetadata) iter.next();
        buildEntityType(sessionFactory, cm.getEntityName());
      }
      logger.info("Find {} entities,{} collections from hibernate in {} ms",
          new Object[] { entityTypes.size(), collectionTypes.size(), watch.getTime() });
      if (logger.isDebugEnabled()) {
        loggerTypeInfo();
View Full Code Here


   * @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()) {
View Full Code Here

    if (null != entityType) {
      Type propertyType = (Type) entityType.getPropertyTypes().get(propertyName);
      if (null != propertyType) { return (ComponentType) propertyType; }
    }

    ClassMetadata cm = sessionFactory.getClassMetadata(entityName);
    org.hibernate.type.ComponentType hcType = (org.hibernate.type.ComponentType) cm
        .getPropertyType(propertyName);
    String[] propertyNames = hcType.getPropertyNames();

    ComponentType cType = new ComponentType(hcType.getReturnedClass());
    Map<String, Type> propertyTypes = cType.getPropertyTypes();
    for (int j = 0; j < propertyNames.length; j++) {
      org.hibernate.type.Type type = cm.getPropertyType(propertyName + "." + propertyNames[j]);
      if (type.isEntityType()) {
        propertyTypes.put(propertyNames[j], buildEntityType(sessionFactory, type.getName()));
      } else if (type.isComponentType()) {
        propertyTypes
            .put(propertyNames[j],
View Full Code Here

    feature2.setGeometry(geometryFactory.createPoint(new Coordinate(0, 0)));
  }

  @Test
  public void testGetAttribute() throws LayerException {
    ClassMetadata metadata = factory.getClassMetadata(AbstractHibernateTestFeature.class);
    Attribute<?> attribute = featureModel.getAttribute(feature1, PARAM_INT_ATTR);
    Assert.assertNotNull(attribute);
    Assert.assertTrue(attribute instanceof IntegerAttribute);
    Assert.assertEquals(feature1.getIntAttr(), attribute.getValue());
View Full Code Here

          // normally should not happen, hibernate instantiates it automatically
          coll = (Collection) ct.instantiate(0);
          metadata.setPropertyValue(object, name, coll, EntityMode.POJO);
        }
        String entityName = ct.getAssociatedEntityName((SessionFactoryImplementor) sessionFactory);
        ClassMetadata childMetadata = sessionFactory.getClassMetadata(entityName);
        return new HibernateEntityCollection(metadata, childMetadata, object, coll);
      } else {
        throw new LayerException(ExceptionCode.FEATURE_MODEL_PROBLEM);
      }
    }
View Full Code Here

        Type prop = meta.getPropertyType(directProperty);
        if (prop.isCollectionType()) {
          CollectionType coll = (CollectionType) prop;
          prop = coll.getElementType((SessionFactoryImplementor) sessionFactory);
        }
        ClassMetadata propMeta = sessionFactory.getClassMetadata(prop.getReturnedClass());
        return getPropertyClass(propMeta, propertyName.substring(propertyName.indexOf(SEPARATOR) + 1));
      } catch (HibernateException e) {
        throw new HibernateLayerException(e, ExceptionCode.HIBERNATE_COULD_NOT_RESOLVE, propertyName,
            meta.getEntityName());
      }
View Full Code Here

    }
  }

  public Metadata get(Class<?> entityClass) {
    entityClass = getUnproxiedClass(entityClass);
    ClassMetadata cm = sessionFactory.getClassMetadata(entityClass);
    if (cm == null) {
      throw new IllegalArgumentException("Unable to introspect " + entityClass.toString()
          + ". The class is not a registered Hibernate entity.");
    } else {
      return new HibernateEntityMetadata(sessionFactory, cm, null);
View Full Code Here

      }
   }
  
   public static void checkVersion(Object value, Session session, Object oldVersion, Object version)
   {
      ClassMetadata classMetadata = getClassMetadata(value, session);
      VersionType versionType = (VersionType) classMetadata.getPropertyTypes()[ classMetadata.getVersionProperty() ];
      if ( !versionType.isEqual(oldVersion, version) )
      {
         throw new StaleStateException("current database version number does not match passivated version number");
      }
   }
View Full Code Here

      }
   }
  
   public static Object getVersion(Object value, Session session)
   {
      ClassMetadata classMetadata = getClassMetadata(value, session);
      return classMetadata!=null && classMetadata.isVersioned() ?
               classMetadata.getVersion(value, EntityMode.POJO) : null;
   }
View Full Code Here

   }
  
   private static ClassMetadata getClassMetadata(Object value, Session session)
   {
      Class entityClass = getEntityClass(value);
      ClassMetadata classMetadata = null;
      if (entityClass!=null)
      {
         classMetadata = session.getSessionFactory().getClassMetadata(entityClass);
         if (classMetadata==null)
         {
View Full Code Here

TOP

Related Classes of org.hibernate.metadata.ClassMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.