Example usage for org.hibernate.metadata ClassMetadata getMappedClass

List of usage examples for org.hibernate.metadata ClassMetadata getMappedClass

Introduction

In this page you can find the example usage for org.hibernate.metadata ClassMetadata getMappedClass.

Prototype

Class getMappedClass();

Source Link

Document

The persistent class, or null

Usage

From source file:at.molindo.esi4j.module.hibernate.HibernateEntityResolver.java

License:Apache License

/**
 * must be called within originating session
 *//*from  w  w w  .  j av  a2 s . com*/
@Override
public ObjectKey toObjectKey(Object entity) {
    SessionFactory factory = getSessionFactory();

    Session session = getCurrentSession(factory);

    String entityName = _entityNames.find(entity.getClass());

    ClassMetadata meta = factory.getClassMetadata(entityName);

    Class<?> type = meta.getMappedClass();

    Serializable id = meta.getIdentifier(entity, (SessionImpl) session);
    Long version = toLongVersion(meta.getVersion(entity));

    return new ObjectKey(type, id, version);
}

From source file:at.molindo.esi4j.module.hibernate.HibernateModule.java

License:Apache License

public HibernateModule(SessionFactory sessionFactory) {
    if (sessionFactory == null) {
        throw new NullPointerException("sessionFactory");
    }//  w w w  . ja  v  a 2 s .com
    _sessionFactory = sessionFactory;

    // calculate types
    List<Class<?>> list = Lists.newArrayList();
    for (ClassMetadata classMetadata : sessionFactory.getAllClassMetadata().values()) {
        Class<?> type = classMetadata.getMappedClass();
        if (type != null) {
            list.add(type);
        }
    }
    _types = Collections.unmodifiableList(list);
}

From source file:com.supermy.base.service.WebMetaService.java

License:Apache License

/**
 *
 *
 * @param domainName/*from   ww  w.j a  v a2 s . co  m*/
 * @return
  */
public Map getHibernateMetaJson(String domainName) {
    System.out.println("getHibernateMetaJson:" + domainName);

    ClassMetadata meta = sessionfactory.getClassMetadata(domainName);

    //Object[] propertyValues = catMeta.getPropertyValues(fritz);
    String[] propertyNames = meta.getPropertyNames();
    Type[] propertyTypes = meta.getPropertyTypes();

    // get a Map of all properties which are not collections or associations
    Map namedValues = new HashMap();
    for (int i = 0; i < propertyNames.length; i++) {
        namedValues.put(propertyNames[i], propertyTypes[i].getName());
        //         if ( !propertyTypes[i].isEntityType() && !propertyTypes[i].isCollectionType() ) {
        //            namedValues.put( propertyNames[i], propertyValues[i] );
        //         }
    }
    //configuration.getClassMapping([entity class name]).getTable().getColumn([column number]).getComment()

    Map result = new HashMap();
    result.put("domainName", meta.getEntityName());
    result.put("entityName", meta.getMappedClass().getSimpleName());
    result.put("id", meta.getIdentifierPropertyName());
    result.put("idType", meta.getIdentifierType().getName());

    result.put("data", namedValues);

    System.out.println(result);

    return result;
}

From source file:com.yahoo.elide.datastores.hibernate5.HibernateStore.java

License:Apache License

@Override
public void populateEntityDictionary(EntityDictionary dictionary) {
    /* bind all entities */
    for (ClassMetadata meta : sessionFactory.getAllClassMetadata().values()) {
        dictionary.bindEntity(meta.getMappedClass());
    }/*from ww w.  ja v  a 2s.c o m*/
}

From source file:cz.jirutka.rsql.visitor.hibernate.HibernateCriterionVisitor.java

License:Apache License

private Type getPropertyType(ClassMetadata classMetadata, String property) {
    property = propertyResolver.getPropertyName(classMetadata.getMappedClass(), property);
    return classMetadata.getPropertyType(property);
}

From source file:cz.jirutka.rsql.visitor.hibernate.HibernateCriterionVisitor.java

License:Apache License

private Type getPropertyType(EntityType entityType, String property) {
    String associatedEntityName = entityType.getAssociatedEntityName(getSessionFactory());
    ClassMetadata classMetadata = getSessionFactory().getClassMetadata(associatedEntityName);
    property = propertyResolver.getPropertyName(classMetadata.getMappedClass(), property);
    return getPropertyType(classMetadata, property);
}

From source file:es.logongas.ix3.dao.metadata.impl.MetaDataFactoryImplHibernate.java

License:Apache License

@Override
public MetaData getMetaData(Class entityClass) {
    ClassMetadata classMetadata = getClassMetadata(entityClass);
    if (classMetadata == null) {
        return null;
    } else {//from  ww  w  .  j a va 2s  .  com
        return new MetaDataImplHibernate(classMetadata.getMappedClass(), sessionFactory, null, null,
                classMetadata.getMappedClass().getSimpleName());
    }
}

From source file:es.logongas.ix3.dao.metadata.impl.MetaDataFactoryImplHibernate.java

License:Apache License

@Override
public MetaData getMetaData(String entityName) {
    ClassMetadata classMetadata = getClassMetadata(entityName);
    if (classMetadata == null) {
        return null;
    } else {/*from  ww  w.  j a  v  a 2 s.c  o  m*/
        return new MetaDataImplHibernate(classMetadata.getMappedClass(), sessionFactory, null, null,
                entityName);
    }
}

From source file:kr.debop4j.search.tools.SearchTool.java

License:Apache License

/**
 * ??? ? ? .//from  w  ww. j a  v  a2  s. c  o  m
 *
 * @param sessionFactory the session factory
 * @return ??? ? 
 */
public static Set<Class> getIndexedClasses(SessionFactory sessionFactory) {
    if (log.isDebugEnabled())
        log.debug("? ? ???  ? .");

    final Set<Class> classes = Sets.newHashSet();
    Collection<ClassMetadata> metadatas = sessionFactory.getAllClassMetadata().values();

    for (ClassMetadata meta : metadatas) {
        Class clazz = meta.getMappedClass();
        if (clazz.getAnnotation(Indexed.class) != null) {
            classes.add(clazz);

            log.trace("??? =[{}]", clazz);
        }
    }
    return classes;
}

From source file:org.apache.tapestry5.hibernate.modules.HibernateModule.java

License:Apache License

/**
 * Contributes {@link ValueEncoderFactory}s for all registered Hibernate entity classes. Encoding and decoding are
 * based on the id property value of the entity using type coercion. Hence, if the id can be coerced to a String and
 * back then the entity can be coerced./* ww  w  .jav a2  s.  co  m*/
 */
@SuppressWarnings("unchecked")
public static void contributeValueEncoderSource(MappedConfiguration<Class, ValueEncoderFactory> configuration,
        @Symbol(HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS) boolean provideEncoders,
        final HibernateSessionSource sessionSource, final Session session, final TypeCoercer typeCoercer,
        final PropertyAccess propertyAccess, final LoggerSource loggerSource) {
    if (!provideEncoders)
        return;

    for (ClassMetadata classMetadata : sessionSource.getSessionFactory().getAllClassMetadata().values()) {
        final Class entityClass = classMetadata.getMappedClass();
        final String idenfierPropertyName = classMetadata.getIdentifierPropertyName();

        if (entityClass != null) {
            ValueEncoderFactory factory = new ValueEncoderFactory() {
                @Override
                public ValueEncoder create(Class type) {
                    return new HibernateEntityValueEncoder(entityClass, idenfierPropertyName, session,
                            propertyAccess, typeCoercer, loggerSource.getLogger(entityClass));
                }
            };

            configuration.add(entityClass, factory);

        }
    }
}