org.hibernate.SessionFactory.getAllClassMetadata()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(144)

本文整理了Java中org.hibernate.SessionFactory.getAllClassMetadata()方法的一些代码示例,展示了SessionFactory.getAllClassMetadata()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SessionFactory.getAllClassMetadata()方法的具体详情如下:
包路径:org.hibernate.SessionFactory
类名称:SessionFactory
方法名:getAllClassMetadata

SessionFactory.getAllClassMetadata介绍

[英]Retrieve the ClassMetadata for all mapped entities.
[中]检索所有映射实体的类元数据。

代码示例

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

for (Object item : sessionFactory.getAllClassMetadata().values()) {
  ClassMetadata metadata = (ClassMetadata) item;
  Class<?> mappedClass = metadata.getMappedClass();

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

protected void populateCaches(String targetMode, Map<String, Object> managerMap) {
  final EntityManager em = getEntityManager(managerMap);
  final PlatformTransactionManager txManager = getTransactionManager(managerMap);
  final EJB3ConfigurationDao ejb3ConfigurationDao = getEJB3ConfigurationDao(managerMap);
  SessionFactory sessionFactory = em.unwrap(Session.class).getSessionFactory();
  for (Object item : sessionFactory.getAllClassMetadata().values()) {
    ClassMetadata metadata = (ClassMetadata) item;
    Class<?> mappedClass = metadata.getMappedClass();
    String managerCacheKey = buildManagerCacheKey(targetMode, mappedClass);
    ENTITY_MANAGER_CACHE.put(managerCacheKey, em);
    TRANSACTION_MANAGER_CACHE.put(managerCacheKey, txManager);
    String ejb3ConfigDaoCacheKey = buildEJB3ConfigDaoCacheKey(mappedClass);
    if (!EJB3_CONFIG_DAO_CACHE.containsKey(ejb3ConfigDaoCacheKey)) {
      EJB3_CONFIG_DAO_CACHE.put(ejb3ConfigDaoCacheKey, ejb3ConfigurationDao);
    }
  }
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

protected void patchSequenceGeneratorInconsistencies(EntityManager em, Session session) {
  SessionFactory sessionFactory = session.getSessionFactory();
  for (Object item : sessionFactory.getAllClassMetadata().values()) {
    ClassMetadata metadata = (ClassMetadata) item;
    String idProperty = metadata.getIdentifierPropertyName();

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
protected TransactionStatus startTransaction(int propagationBehavior, int isolationLevel, boolean readOnly, PlatformTransactionManager transactionManager) {
  BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
  if (context.getAdditionalProperties().containsKey(FAILURE_MODE_KEY)) {
    String failureModePU = (String) context.getAdditionalProperties().get(FAILURE_MODE_PU);
    String checkClassName = failureModePU.equals("blPU")?blPUCheckClassName:blEventPUCheckClassName;
    if (((HibernateEntityManagerFactory) ((JpaTransactionManager) transactionManager).getEntityManagerFactory())
                .getSessionFactory().getAllClassMetadata().containsKey(checkClassName)){
      throw (RuntimeException) context.getAdditionalProperties().get(FAILURE_MODE_EXCEPTION);
    }
  }
  return super.startTransaction(propagationBehavior, isolationLevel, readOnly, transactionManager);
}

代码示例来源:origin: my2iu/Jinq

public MetamodelUtilFromSessionFactory(SessionFactory factory)
{
 // Go through all the entities 
 for (String entityClassName: factory.getAllClassMetadata().keySet())
 {
   ClassMetadata entityData = factory.getClassMetadata(entityClassName);
   classToEntityName.put(entityData.getMappedClass(), entityData.getEntityName());
   classNameToEntityName.put(entityClassName, entityData.getEntityName());
   //System.out.println(entityClassName + " " + entityData.getMappedClass().getCanonicalName() + " " + entityData.getEntityName());
   // TODO: It turns out all three values are the same, but I think it's ok for now.
      scanClassMetadata(entityData);
 }
}

代码示例来源:origin: openmrs/openmrs-core

public boolean isOrderFrequencyInUse(OrderFrequency orderFrequency) {
  Map<String, ClassMetadata> metadata = sessionFactory.getAllClassMetadata();
  for (ClassMetadata classMetadata : metadata.values()) {
    Class<?> entityClass = classMetadata.getMappedClass();

代码示例来源:origin: picocontainer/picocontainer

/** {@inheritDoc} **/
@SuppressWarnings("unchecked")
public Map getAllClassMetadata() {
  return delegate.getAllClassMetadata();
}

代码示例来源:origin: org.codehaus.griffon.plugins/griffon-hibernate5-core

@Deprecated
@Override
public Map<String, ClassMetadata> getAllClassMetadata() {
  return delegate.getAllClassMetadata();
}

代码示例来源:origin: org.apache.tapestry/tapestry-hibernate

@SuppressWarnings("unchecked")
public Collection<ClassMetadata> getAllClassMetadata()
{
  return session.getSessionFactory().getAllClassMetadata().values();
}

代码示例来源:origin: stackoverflow.com

public Set<String> getTablesName() {
  Set<String> names = new HashSet<>();
  SessionFactory sessionFactory = emf.unwrap(SessionFactory.class);

  Map<String, ClassMetadata> classMetadataMap = sessionFactory.getAllClassMetadata();
  for (ClassMetadata classMetadata : classMetadataMap.values()) {
    AbstractEntityPersister aep = (AbstractEntityPersister) classMetadata;
    String tableName = aep.getTableName();
    if (StringUtils.isBlank(tableName) || StringUtils.containsWhitespace(tableName)) {
      continue;
    }
    names.add(tableName);
  }
  return names;
}

代码示例来源:origin: org.jboss.ejb3/jboss-ejb3-jpa-int

@SuppressWarnings("unchecked")
public Map getAllClassMetadata() throws HibernateException
{
 return getSessionFactory().getAllClassMetadata();
}

代码示例来源:origin: apache/tapestry-5

@SuppressWarnings("unchecked")
public Collection<ClassMetadata> getAllClassMetadata()
{
  return session.getSessionFactory().getAllClassMetadata().values();
}

代码示例来源:origin: apache/tapestry-5

public HibernateSessionSourceImpl(Logger logger, List<HibernateConfigurer> hibernateConfigurers)
{
  long startTime = System.currentTimeMillis();
  configuration = new Configuration();
  for (HibernateConfigurer configurer : hibernateConfigurers)
    configurer.configure(configuration);
  long configurationComplete = System.currentTimeMillis();
  sessionFactory = configuration.buildSessionFactory();
  long factoryCreated = System.currentTimeMillis();
  logger.info(String.format("Hibernate startup: %,d ms to configure, %,d ms overall.", configurationComplete - startTime, factoryCreated - startTime));
  logger.info(String.format("Configured Hibernate entities: %s", InternalUtils.joinSorted(sessionFactory.getAllClassMetadata().keySet())));
}

代码示例来源:origin: stackoverflow.com

private List<String> getAllTables() {
  List<String> tableNames = new ArrayList<>();
  Session session = entityManager.unwrap(Session.class);
  SessionFactory sessionFactory = session.getSessionFactory();
  Map<String, ClassMetadata>  map = (Map<String, ClassMetadata>) sessionFactory.getAllClassMetadata();
  for(String entityName : map.keySet()){
    SessionFactoryImpl sfImpl = (SessionFactoryImpl) sessionFactory;
    String tableName = ((AbstractEntityPersister)sfImpl.getEntityPersister(entityName)).getTableName();
    tableNames.add(tableName);
  }
  return tableNames;
}

代码示例来源:origin: yahoo/elide

@Override
public void populateEntityDictionary(EntityDictionary dictionary) {
  /* bind all entities */
  for (ClassMetadata meta : sessionFactory.getAllClassMetadata().values()) {
    dictionary.bindEntity(meta.getMappedClass(EntityMode.POJO));
  }
}

代码示例来源:origin: org.apache.tapestry/tapestry-hibernate-core

public HibernateSessionSourceImpl(Logger logger, List<HibernateConfigurer> hibernateConfigurers)
{
  long startTime = System.currentTimeMillis();
  configuration = new Configuration();
  for (HibernateConfigurer configurer : hibernateConfigurers)
    configurer.configure(configuration);
  long configurationComplete = System.currentTimeMillis();
  sessionFactory = configuration.buildSessionFactory();
  long factoryCreated = System.currentTimeMillis();
  logger.info(String.format("Hibernate startup: %,d ms to configure, %,d ms overall.", configurationComplete - startTime, factoryCreated - startTime));
  logger.info(String.format("Configured Hibernate entities: %s", InternalUtils.joinSorted(sessionFactory.getAllClassMetadata().keySet())));
}

代码示例来源:origin: omero/server

public SessionFactory(org.hibernate.SessionFactory factory, SqlAction isolatedSqlAction) {
  this.factory = factory;
  for (Object k : this.factory.getAllClassMetadata().keySet()) {
    IdentifierGenerator ig =
      ((SessionFactoryImpl) factory).getIdentifierGenerator((String)k);
    if (ig instanceof TableIdGenerator) {
      ((TableIdGenerator) ig).setSqlAction(isolatedSqlAction);
    }
  }
}

代码示例来源:origin: com.github.albfernandez/jbpm-jpdl

public Set<String> getJbpmTables() {
 configure();
 Set<String> jbpmTables = new HashSet<>();
 Map<String, ClassMetadata>  map = sessionFactory.getAllClassMetadata();
 for(String entityName : map.keySet()){
   SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) sessionFactory;
   String tableName = ((AbstractEntityPersister)sessionFactoryImpl.getEntityPersister(entityName)).getTableName();
   jbpmTables.add(tableName);
 }
 return jbpmTables;
}

代码示例来源:origin: org.grails/grails-hibernate

public static void configureHibernateDomainClasses(SessionFactory sessionFactory,
    String sessionFactoryName, GrailsApplication application) {
  Map<String, GrailsDomainClass> hibernateDomainClassMap = new HashMap<String, GrailsDomainClass>();
  for (Object o : sessionFactory.getAllClassMetadata().values()) {
    ClassMetadata classMetadata = (ClassMetadata) o;
    configureDomainClass(sessionFactory, sessionFactoryName, application, classMetadata,
        classMetadata.getMappedClass(EntityMode.POJO),
        hibernateDomainClassMap);
  }
  configureInheritanceMappings(hibernateDomainClassMap);
}

代码示例来源:origin: omero/server

public static void indexFullDb() {
  init();
  final AllEntitiesPseudoLogLoader loader = new AllEntitiesPseudoLogLoader();
  loader.setQueryService(rawQuery);
  loader.setExcludes(excludes);
  loader.setClasses(factory.getAllClassMetadata().keySet());
  final FullTextThread ftt = createFullTextThread(loader);
  while (loader.more() > 0) {
    ftt.run();
  }
}

相关文章