List of usage examples for org.hibernate SessionFactory getAllClassMetadata
@Deprecated Map<String, ClassMetadata> getAllClassMetadata();
From source file:app.core.Db.java
License:Open Source License
public static Set<Class> getEntityClassList() { SortedSet<Class> classes = new TreeSet<Class>(new ORMUtils.DependencyComparator()); SessionFactory sessionFactory = getSessionFactory(); try {//w w w . ja va2 s . c o m for (String className : sessionFactory.getAllClassMetadata().keySet()) { classes.add(Class.forName(className)); } } catch (ClassNotFoundException e) { //log(); } return classes; }
From source file:at.molindo.esi4j.module.hibernate.HibernateEntityResolver.java
License:Apache License
public HibernateEntityResolver(SessionFactory sessionFactory) { if (sessionFactory == null) { throw new NullPointerException("sessionFactory"); }/*ww w . ja v a2s . c o m*/ for (Entry<String, ClassMetadata> e : sessionFactory.getAllClassMetadata().entrySet()) { Class<?> mappedClass = e.getValue().getMappedClass(); if (mappedClass != null) { _entityNames.put(mappedClass, e.getKey()); } } _sessionFactory = sessionFactory; }
From source file:at.molindo.esi4j.module.hibernate.HibernateModule.java
License:Apache License
public HibernateModule(SessionFactory sessionFactory) { if (sessionFactory == null) { throw new NullPointerException("sessionFactory"); }/* www . j a v a 2 s . co m*/ _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.abixen.platform.businessintelligence.chart.service.impl.DatabaseH2ServiceImpl.java
License:Open Source License
private void loadSystemTableList(SessionFactory sessionFactory) { Map<String, ClassMetadata> allClassMetadata = sessionFactory.getAllClassMetadata(); allClassMetadata.forEach((key, value) -> { AbstractEntityPersister abstractEntityPersister = (AbstractEntityPersister) value; SYSTEM_TABLE_LIST.add(abstractEntityPersister.getTableName()); });/*from w w w .j a v a 2 s. c om*/ }
From source file:com.autobizlogic.abl.mgmt.ClassMetadataService.java
License:Open Source License
public static Map<String, Object> getAllPersistentBeans(Map<String, String> args) { String sessionFactoryId = args.get("sessionFactoryId"); HashMap<String, Object> result = new HashMap<String, Object>(); SessionFactory sessionFactory = HibernateConfiguration.getSessionFactoryById(sessionFactoryId); if (sessionFactory == null) return null; // Sort the result List<String> sorted = new Vector<String>(sessionFactory.getAllClassMetadata().keySet()); Collections.sort(sorted);// ww w . ja v a2 s . c o m result.put("data", sorted); return result; }
From source file:com.fiveamsolutions.nci.commons.test.AbstractHibernateTestCase.java
License:Open Source License
/** * In JUnit3x you would normally override the setUp() and add your own functionality locally however, in JUnit4 to * override simply define your method and give it the <code>@Before annotation</code>. Doing so will cause that * method to be invoked after the parent class's setUp(). *//*from ww w. j av a 2 s . c o m*/ @SuppressWarnings("unchecked") @Before public final void setUp() { Transaction tx = HibernateUtil.getHibernateHelper().beginTransaction(); SchemaExport se = new SchemaExport(HibernateUtil.getHibernateHelper().getConfiguration()); se.drop(false, true); se.create(false, true); tx.commit(); // clean up the hibernate second level cache between runs SessionFactory sf = getCurrentSession().getSessionFactory(); Map<?, EntityPersister> classMetadata = sf.getAllClassMetadata(); for (EntityPersister ep : classMetadata.values()) { if (ep.hasCache()) { sf.evictEntity(ep.getCacheAccessStrategy().getRegion().getName()); } } Map<?, AbstractCollectionPersister> collMetadata = sf.getAllCollectionMetadata(); for (AbstractCollectionPersister acp : collMetadata.values()) { if (acp.hasCache()) { sf.evictCollection(acp.getCacheAccessStrategy().getRegion().getName()); } } transaction = HibernateUtil.getHibernateHelper().beginTransaction(); }
From source file:de.iteratec.iteraplan.presentation.problemreports.DatabaseProblemReportPart.java
License:Open Source License
static ProblemReportPart generateDatabaseReport(String filename, HttpServletRequest request) { DatabaseProblemReportPart reportPart = new DatabaseProblemReportPart(filename); PrintWriter dbWriter = reportPart.getWriter(); ApplicationContext context = DefaultSpringApplicationContext.getSpringApplicationContext(); Object sessionFactoryObject = context.getBean("sessionFactory"); if (sessionFactoryObject instanceof SessionFactory) { SessionFactory sessionFactory = (SessionFactory) sessionFactoryObject; Session currentSession = sessionFactory.getCurrentSession(); Map<String, ClassMetadata> allClassMetadata = sessionFactory.getAllClassMetadata(); final Set<String> tableNames = Sets.newHashSet(); for (ClassMetadata cm : allClassMetadata.values()) { if (cm instanceof AbstractEntityPersister) { AbstractEntityPersister aep = (AbstractEntityPersister) cm; tableNames.add(aep.getTableName()); }/*ww w . j a v a 2 s .c o m*/ } ByteArrayOutputStream dbInfoBuffer = new ByteArrayOutputStream(); final PrintWriter dbInfoWriter = new PrintWriter(dbInfoBuffer); Work work = new Work() { @Override public void execute(Connection connection) throws SQLException { try { DatabaseMetaData metaData = connection.getMetaData(); dbInfoWriter.println("Database Name: " + metaData.getDatabaseProductName() + " " + metaData.getDatabaseMajorVersion() + "." + metaData.getDatabaseMinorVersion()); dbInfoWriter.println("Database Product Version: " + metaData.getDatabaseProductVersion()); dbInfoWriter.println("JDBC URL: " + metaData.getURL()); dbInfoWriter.println("JDBC API: " + metaData.getJDBCMajorVersion() + "." + metaData.getJDBCMinorVersion()); dbInfoWriter.println("JDBC-Driver Name: " + metaData.getDriverName() + " " + metaData.getDriverMajorVersion() + "." + metaData.getDriverMinorVersion()); dbInfoWriter.println("JDBC-Driver Version: " + metaData.getDriverVersion()); } catch (Exception e) { e.printStackTrace(); } } }; try { TimeLimiter timeLimiter = new SimpleTimeLimiter(); Session sessionProxy = timeLimiter.newProxy(currentSession, Session.class, TIMEOUT_IN_SECONDS, TimeUnit.SECONDS); sessionProxy.doWork(work); } catch (UncheckedTimeoutException e) { dbInfoWriter.println("Couldn't gather database information from conncetion within " + TIMEOUT_IN_SECONDS + " seconds."); } catch (Exception e) { dbInfoWriter.println("Couldn't gather database information from connection."); } dbInfoWriter.close(); dbWriter.print(dbInfoBuffer); } dbWriter.close(); return reportPart; }
From source file:edu.byu.mpn.test.MpnDomainTest.java
License:Apache License
@Test public void testDomainObjects() { assertNotNull("need application context", ctx); final SessionFactory sf = (SessionFactory) ctx.getBean("mpnSessionFactory"); assertNotNull("need session factory", sf); final List<String> ents = new LinkedList<String>(sf.getAllClassMetadata().keySet()); Collections.sort(ents);/*from w w w . j a v a2s .co m*/ final Session session = sf.openSession(); boolean queryPass = true; for (final String en : ents) { if (!IS_MPN_DOMAIN.matcher(en).matches()) { continue; } LOG.info("executing test for " + en); queryPass = queryPass && testEntityValidity(en, session); } //for entities Assert.assertTrue("not all queries passed", queryPass); }
From source file:edu.utah.further.core.data.util.HibernateUtil.java
License:Apache License
/** * @param sessionFactory/*from w w w . j a v a2s. c o m*/ * @return */ @SuppressWarnings("unchecked") public static Set<Class<? extends PersistentEntity<?>>> getEntityClasses(final SessionFactory sessionFactory) { final Set<Class<? extends PersistentEntity<?>>> entityClasses = CollectionUtil.newSet(); for (final Object persister : sessionFactory.getAllClassMetadata().values()) { final Class<?> entityClass = ((EntityPersister) persister).getClassMetadata() .getMappedClass(EntityMode.POJO); // Must perform an unchecked cast because a) Hibernate's API uses raw types // and b) Hibernate is not aware of our PersistentEntity<?> at compile-time, // although effectively enforces it on all mapped classes at runtime. entityClasses.add((Class<? extends PersistentEntity<?>>) entityClass); } return entityClasses; }
From source file:gov.nih.nci.firebird.test.AbstractHibernateTestCase.java
License:Open Source License
/** * Method that runs before the test to clean up the db and start the transaction. *///w w w.j a va 2 s. c o m @SuppressWarnings("unchecked") @Before public void setUp() throws Exception { // clean up the hibernate second level cache between runs SessionFactory sf = getCurrentSession().getSessionFactory(); Map<String, EntityPersister> classMetadata = sf.getAllClassMetadata(); for (EntityPersister ep : classMetadata.values()) { if (ep.hasCache()) { sf.evictEntity(ep.getCacheAccessStrategy().getRegion().getName()); } } Map<?, AbstractCollectionPersister> collMetadata = sf.getAllCollectionMetadata(); for (AbstractCollectionPersister acp : collMetadata.values()) { if (acp.hasCache()) { sf.evictCollection(acp.getCacheAccessStrategy().getRegion().getName()); } } transaction = helper.beginTransaction(); }