List of usage examples for org.hibernate SessionFactory getAllClassMetadata
@Deprecated Map<String, ClassMetadata> getAllClassMetadata();
From source file:org.seasar.hibernate.jpa.PersistenceUnitConfigurationTest.java
License:Apache License
public void testPersistenceClassAutoDetection() throws Exception { final Session session = Session.class.cast(em.getDelegate()); final SessionFactory sf = session.getSessionFactory(); assertEquals(4, sf.getAllClassMetadata().size()); assertNotNull(sf.getClassMetadata(Employee.class)); assertNotNull(sf.getClassMetadata(Department.class)); assertNotNull(sf.getClassMetadata(Customer.class)); assertNotNull(sf.getClassMetadata(Department2.class)); }
From source file:org.seasar.hibernate.jpa.PersistenceUnitConfigurationTest.java
License:Apache License
public void testPersistenceClassAutoDetectionSubPackage() throws Exception { final PersistenceUnitManager pum = PersistenceUnitManager.class .cast(getComponent(PersistenceUnitManager.class)); final EntityManagerFactory emf = pum.getEntityManagerFactory("aaaPersistenceUnit"); final EntityManager em = emf.createEntityManager(); final Session session = Session.class.cast(em.getDelegate()); final SessionFactory sf = session.getSessionFactory(); assertEquals(3, sf.getAllClassMetadata().size()); assertNotNull(sf.getClassMetadata(Dummy.class)); }
From source file:org.springframework.flex.core.io.HibernateConfigProcessor.java
License:Apache License
/** * Extracts all {@link ClassMetadata} and {@link CollectionMetadata} from a given {@link SessionFactory} to be * used in determining the types that need a {@link SpringPropertyProxy} registered in {@link #findTypesToRegister()} * @param sessionFactory the session factory from which to read metadata *//*from w w w . j a va 2s. c o m*/ @SuppressWarnings("unchecked") protected void extractHibernateMetadata(SessionFactory sessionFactory) { this.classMetadata.addAll(sessionFactory.getAllClassMetadata().values()); this.collectionMetadata.addAll(sessionFactory.getAllCollectionMetadata().values()); this.hibernateConfigured = true; }
From source file:org.thelq.stackexchange.dbimport.Controller.java
License:Apache License
public void initMetadataMap(SessionFactory sessionFactory) { ImmutableSortedMap.Builder<String, ImmutableMap<String, Type>> metadataMapBuilder = ImmutableSortedMap .orderedBy(String.CASE_INSENSITIVE_ORDER); for (Map.Entry<String, ClassMetadata> curEntry : sessionFactory.getAllClassMetadata().entrySet()) { ClassMetadata tableDataRaw = curEntry.getValue(); ImmutableMap.Builder<String, Type> propertiesBuilder = ImmutableMap.builder(); propertiesBuilder.put(tableDataRaw.getIdentifierPropertyName(), tableDataRaw.getIdentifierType()); for (String curPropertyName : tableDataRaw.getPropertyNames()) propertiesBuilder.put(curPropertyName, tableDataRaw.getPropertyType(curPropertyName)); metadataMapBuilder.put(curEntry.getKey(), propertiesBuilder.build()); }// ww w. j a va2 s .co m metadataMap = metadataMapBuilder.build(); }
From source file:org.unitime.commons.hibernate.util.HibernateUtil.java
License:Open Source License
public static void clearCache(Class persistentClass, boolean evictQueries) { _RootDAO dao = new _RootDAO(); org.hibernate.Session hibSession = dao.getSession(); SessionFactory hibSessionFactory = hibSession.getSessionFactory(); if (persistentClass == null) { for (Iterator i = hibSessionFactory.getAllClassMetadata().entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Map.Entry) i.next(); String className = (String) entry.getKey(); ClassMetadata classMetadata = (ClassMetadata) entry.getValue(); try { hibSessionFactory.getCache().evictEntityRegion(Class.forName(className)); for (int j = 0; j < classMetadata.getPropertyNames().length; j++) { if (classMetadata.getPropertyTypes()[j].isCollectionType()) { try { hibSessionFactory.getCache().evictCollectionRegion( className + "." + classMetadata.getPropertyNames()[j]); } catch (MappingException e) { }/*from w w w.ja v a 2s . c o m*/ } } } catch (ClassNotFoundException e) { } } hibSessionFactory.getCache().evictEntityRegions(); hibSessionFactory.getCache().evictCollectionRegions(); } else { ClassMetadata classMetadata = hibSessionFactory.getClassMetadata(persistentClass); hibSessionFactory.getCache().evictEntityRegion(persistentClass); if (classMetadata != null) { for (int j = 0; j < classMetadata.getPropertyNames().length; j++) { if (classMetadata.getPropertyTypes()[j].isCollectionType()) { try { hibSessionFactory.getCache().evictCollectionRegion(persistentClass.getClass().getName() + "." + classMetadata.getPropertyNames()[j]); } catch (MappingException e) { } } } } } if (evictQueries) { hibSessionFactory.getCache().evictQueryRegions(); hibSessionFactory.getCache().evictDefaultQueryRegion(); } }
From source file:org.yestech.maven.HibernateSearchBuildIndexesMojo.java
License:Apache License
@SuppressWarnings({ "unchecked" }) private FullTextSession processObjects(FullTextSession fullTextSession, Connection con, Configuration configuration) { SessionFactory sessionFactory = configuration.buildSessionFactory(); Session session = sessionFactory.openSession(con); fullTextSession = Search.getFullTextSession(session); Map<String, ClassMetadata> metadata = sessionFactory.getAllClassMetadata(); for (Map.Entry<String, ClassMetadata> entry : metadata.entrySet()) { Class clazz = entry.getValue().getMappedClass(EntityMode.POJO); if (clazz.isAnnotationPresent(Indexed.class)) { getLog().info("Indexing " + entry); Transaction tx = fullTextSession.beginTransaction(); Criteria criteria = fullTextSession.createCriteria(clazz); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); DirectoryProvider[] providers = fullTextSession.getSearchFactory().getDirectoryProviders(clazz); for (DirectoryProvider provider : providers) { getLog().info("Index directory: " + provider.getDirectory()); }//from ww w . j a v a 2s. co m List<?> list = criteria.list(); for (Object o : list) { fullTextSession.index(o); } fullTextSession.flushToIndexes(); tx.commit(); } } return fullTextSession; }
From source file:test.eurocarbdb.dataaccess.HibernateEntityManagerTest.java
License:Open Source License
@Test(groups = { "ecdb.db.populated" }, dependsOnGroups = { "ecdb.db.connection" }) public void isDatabasePopulated() { super.setup(); long total = 0; HibernateEntityManager hem = (HibernateEntityManager) getEntityManager(); SessionFactory sf = hem.getSessionFactory(); Map<String, ClassMetadata> hash = (Map<String, ClassMetadata>) sf.getAllClassMetadata(); List<String> list = new ArrayList(hash.keySet()); Collections.sort(list);/*from w ww .j a v a2s. co m*/ out.println("Class : database count"); for (Class<?> c : classes) { try { long count = getEntityManager().countAll(c); out.println(c + ": " + count); total += count; } catch (HibernateException ex) { out.println(c + ": " + join(" -> ", ex.getMessages())); } } super.teardown(); out.println(); out.println("Total count of entities in data store: " + total); assert total > 0; }
From source file:test.eurocarbdb.dataaccess.HibernateEntityManagerTest.java
License:Open Source License
public void isDatabasePopulated___shows_all_entities() { super.setup(); long total = 0; HibernateEntityManager hem = (HibernateEntityManager) getEntityManager(); SessionFactory sf = hem.getSessionFactory(); Map<String, ClassMetadata> hash = (Map<String, ClassMetadata>) sf.getAllClassMetadata(); List<String> list = new ArrayList(hash.keySet()); Collections.sort(list);/* ww w.j a va2s.c om*/ out.println("Class : database count"); for (String entity_name : list) { ClassMetadata class_metadata = null; Class<?> c = null; try { class_metadata = hash.get(entity_name); c = class_metadata.getMappedClass(EntityMode.POJO); long count = getEntityManager().countAll(c); out.println(c + ": " + count); total += count; } catch (HibernateException ex) { out.println(c + ": " + join(" -> ", ex.getMessages())); } } super.teardown(); out.println(); out.println("Total count of entities in data store: " + total); assert total > 0; }