List of usage examples for org.hibernate Session getSessionFactory
SessionFactory getSessionFactory();
From source file:gov.nih.nci.security.upt.util.HibernateHelper.java
License:BSD License
private static String modifySQLForGroup(FilterClause filterClause, String generatedSQL, Session session, String peiTableOrViewName) { String targetClassName = null; if (StringUtils.isBlank(filterClause.getTargetClassAlias())) targetClassName = filterClause.getTargetClassName().substring(0, filterClause.getTargetClassName().indexOf(" - ")); else/*from w w w . ja va2s.co m*/ targetClassName = filterClause.getTargetClassAlias(); String targetClassAttributeName = null; if (StringUtils.isBlank(filterClause.getTargetClassAttributeAlias())) targetClassAttributeName = filterClause.getTargetClassAttributeName(); else targetClassAttributeName = filterClause.getTargetClassAttributeAlias(); String CSM_QUERY = "SELECT Distinct pe.attribute_value " + "FROM CSM_PROTECTION_GROUP pg, " + " CSM_PROTECTION_ELEMENT pe, " + " CSM_PG_PE pgpe," + " CSM_USER_GROUP_ROLE_PG ugrpg, " + " CSM_GROUP g, " + " CSM_ROLE_PRIVILEGE rp, " + " CSM_ROLE r, " + " CSM_PRIVILEGE p " + "WHERE ugrpg.role_id = r.role_id " + "AND ugrpg.group_id = g.group_id " + "AND ugrpg.protection_group_id = ANY " + "( select pg1.protection_group_id from csm_protection_group pg1 " + " where pg1.protection_group_id = pg.protection_group_id OR pg1.protection_group_id = " + " (select pg2.parent_protection_group_id from csm_protection_group pg2 where pg2.protection_group_id = pg.protection_group_id)" + " ) " + "AND pg.protection_group_id = pgpe.protection_group_id " + "AND pgpe.protection_element_id = pe.protection_element_id " + "AND r.role_id = rp.role_id " + "AND rp.privilege_id = p.privilege_id " + "AND pe.object_id= '" + targetClassName + "' " + "AND p.privilege_name='READ' " + "AND g.group_name IN (:GROUP_NAMES ) " + "AND pe.application_id=:APPLICATION_ID"; String CSM_QUERY_2 = "select upei.attribute_value from " + peiTableOrViewName + " upei where " + "upei.group_name IN (:GROUP_NAMES) and upei.application_id =:APPLICATION_ID and upei.privilege_name='READ'"; /*String CSM_QUERY = " select pe.attribute_value from " + "csm_protection_group pg, " + "csm_protection_element pe, " + "csm_pg_pe pgpe, " + "csm_user_group_role_pg ugrpg, " + "csm_user u, " + "csm_role_privilege rp, " + "csm_role r, " + "csm_privilege p " + "where ugrpg.role_id = r.role_id " + "and ugrpg.user_id = u.user_id and " + "ugrpg.protection_group_id = ANY " + "(select pg1.protection_group_id " + "from csm_protection_group pg1 " + "where pg1.protection_group_id = pg.protection_group_id " + "or pg1.protection_group_id = " + "(select pg2.parent_protection_group_id " + "from csm_protection_group pg2 " + "where pg2.protection_group_id = pg.protection_group_id)) " + "and pg.protection_group_id = pgpe.protection_group_id " + "and pgpe.protection_element_id = pe.protection_element_id " + "and r.role_id = rp.role_id " + "and rp.privilege_id = p.privilege_id " + "and pe.object_id= '" + targetClassName + "' " + "and pe.attribute='" + targetClassAttributeName + "' " + "and p.privilege_name='READ' " + "and u.login_name=:USER_NAME " + "and pe.application_id=:APPLICATION_ID" ; */ StringBuffer result = new StringBuffer(); String query = generatedSQL.substring(generatedSQL.indexOf('-') + 1, generatedSQL.length()); query = query.trim(); query = query.substring(0, query.indexOf('?')); String delimiters = "+-*/(),. "; StringTokenizer st = new StringTokenizer(query, delimiters, true); while (st.hasMoreTokens()) { String w = st.nextToken(); if (w.equals("this_")) { result = result.append("table_name_csm_"); } else if (w.equals("y0_")) { result = result.append(""); } else if (w.equals("as")) { result = result.append(""); } else { result = result.append(w); } } SessionFactory sessionFactory = session.getSessionFactory(); ClassMetadata classMetadata = sessionFactory.getClassMetadata(filterClause.getClassName()); String columnName = null; if (classMetadata instanceof AbstractEntityPersister) { AbstractEntityPersister abstractEntityPersister = (AbstractEntityPersister) classMetadata; String Id = abstractEntityPersister.getIdentifierPropertyName(); String[] columns = abstractEntityPersister.getPropertyColumnNames(Id); columnName = columns[0]; } if (!StringUtils.isBlank(peiTableOrViewName)) { query = columnName + " in (" + result.toString() + CSM_QUERY_2 + "))"; } else { query = columnName + " in (" + result.toString() + CSM_QUERY + "))"; } return query.toString(); }
From source file:gr.interamerican.bo2.impl.open.hibernate.TestHibernateBo2Utils.java
License:Open Source License
/** * tests isManaged()//from ww w . j a v a 2 s. c om * @throws InitializationException */ @Test public void testLogSessionFactoryStatistics() throws InitializationException { Provider prov = Bo2.getDeployment(UtilityForBo2Test.BATCH_NO_TRAN).getProvider(); //Non transactional provider. HibernateSessionProvider hib = prov.getResource("LOCALDB", HibernateSessionProvider.class); //$NON-NLS-1$ Session session = hib.getHibernateSession(); SessionFactory factory = session.getSessionFactory(); logSessionFactoryStatistics(factory); }
From source file:gumga.framework.application.GumgaUntypedRepository.java
private List<Class> getAllIndexedEntities() { List<Class> aRetornar = new ArrayList<>(); Session session = em.unwrap(Session.class); SessionFactory sessionFactory = session.getSessionFactory(); Map<String, ClassMetadata> map = (Map<String, ClassMetadata>) sessionFactory.getAllClassMetadata(); for (String k : map.keySet()) { Class mappedClass = map.get(k).getMappedClass(); if (mappedClass.isAnnotationPresent(Entity.class) && mappedClass.isAnnotationPresent(Indexed.class)) { aRetornar.add(mappedClass);/*from w ww. jav a 2 s .c o m*/ } } return aRetornar; }
From source file:helper.AgamaHelper.java
public List getListAgama() { List<Agama> listAgama;//from w w w. j ava 2 s. c o m Session session; session = HibernateUtil.getSessionFactory().getCurrentSession(); session.getSessionFactory().openSession(); try { Transaction tx = session.beginTransaction(); Query q; q = session.createQuery("from Agama"); listAgama = (List<Agama>) q.list(); tx.commit(); } catch (HibernateException ex) { errorTrackingApp(ex); session.beginTransaction().rollback(); throw ex; } return listAgama; }
From source file:helper.AgamaHelper.java
public List getListAgamaByID(int id) { List<Agama> listAgama;//from w w w .jav a 2s . c om Session session; session = HibernateUtil.getSessionFactory().getCurrentSession(); session.getSessionFactory().openSession(); try { Transaction tx = session.beginTransaction(); Query q; q = session.createQuery("from Agama as agama where agama.id = :id"); q.setParameter("id", id); listAgama = (List<Agama>) q.list(); tx.commit(); } catch (HibernateException ex) { errorTrackingApp(ex); session.beginTransaction().rollback(); throw ex; } return listAgama; }
From source file:helper.AgamaHelper.java
public void insertAgama(String name) { Session session; session = HibernateUtil.getSessionFactory().getCurrentSession(); session.getSessionFactory().openSession(); try {/*from w ww . j a v a 2s . com*/ Transaction tx = session.beginTransaction(); Agama agama = new Agama(); agama.setName(name); session.save(agama); tx.commit(); } catch (Exception ex) { errorTrackingApp(ex); session.beginTransaction().rollback(); throw ex; } }
From source file:helper.AgamaHelper.java
public void hapusAgama(int ID) { Session session; session = HibernateUtil.getSessionFactory().getCurrentSession(); session.getSessionFactory().openSession(); try {//from w w w.j ava2s . c o m Transaction tx = session.beginTransaction(); Agama agama = (Agama) session.load(Agama.class, (Serializable) ID); session.delete(agama); tx.commit(); } catch (Exception ex) { errorTrackingApp(ex); session.beginTransaction().rollback(); throw ex; } }
From source file:helper.AgamaHelper.java
public void editAgama(Agama agama) { Session session; session = HibernateUtil.getSessionFactory().getCurrentSession(); session.getSessionFactory().openSession(); try {//from w w w. j ava2 s. c om Transaction tx = session.beginTransaction(); session.update(agama); tx.commit(); } catch (Exception ex) { errorTrackingApp(ex); session.beginTransaction().rollback(); throw ex; } }
From source file:helpers.SiteHelper.java
public List geListSite() { List<Sites> listSite;/*from w w w .ja v a2s . c o m*/ Session session; session = HibernateUtil.getSessionFactory().getCurrentSession(); session.getSessionFactory().openSession(); try { Transaction tx = session.beginTransaction(); Query q; q = session.createQuery("from Sites"); listSite = (List<Sites>) q.list(); tx.commit(); } catch (HibernateException ex) { errorTrackingApp(ex); session.beginTransaction().rollback(); throw ex; } return listSite; }
From source file:io.gumga.application.GumgaUntypedRepository.java
/** * Pegar as entidades que esto anotadas com {@link Indexed} * @return dados da pesquisa/*from w w w . j a v a 2 s . com*/ */ private List<Class> getAllIndexedEntities() { List<Class> aRetornar = new ArrayList<>(); Session session = em.unwrap(Session.class); SessionFactory sessionFactory = session.getSessionFactory(); Map<String, ClassMetadata> map = (Map<String, ClassMetadata>) sessionFactory.getAllClassMetadata(); for (String k : map.keySet()) { Class mappedClass = map.get(k).getMappedClass(); if (mappedClass.isAnnotationPresent(Entity.class) && mappedClass.isAnnotationPresent(Indexed.class)) { aRetornar.add(mappedClass); } } return aRetornar; }