List of usage examples for org.hibernate Session clear
void clear();
From source file:com.elearing.impl.SubjectDaoImpl.java
@Override public Subject getObjectById(int id) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction();//from w w w . j a v a 2 s .co m Subject subj = (Subject) session.get(Subject.class, id); session.clear(); session.close(); return subj; }
From source file:com.elearing.impl.UserDaoImpl.java
@Override public boolean insert(User obj) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction();/* w w w . ja v a 2 s. c o m*/ session.save(obj); session.getTransaction().commit(); session.clear(); session.close(); return true; }
From source file:com.elearing.impl.UserDaoImpl.java
@Override public boolean update(User obj) { Session ses = HibernateUtil.getSessionFactory().openSession(); ses.beginTransaction();// w w w . j ava2 s. c o m String hql = "Update User set firstName= :fn , lastName= :ln , userEmail= :email , userPhone= :ph where userName= :un"; Query qr = ses.createQuery(hql); qr.setString("fn", obj.getFirstName()); qr.setString("ln", obj.getLastName()); qr.setString("email", obj.getUserEmail()); qr.setString("ph", obj.getUserPhone()); qr.setString("un", obj.getUserName()); qr.executeUpdate(); ses.getTransaction().commit(); ses.clear(); ses.close(); return true; //To change body of generated methods, choose Tools | Templates. }
From source file:com.elearing.impl.UserRoleDaoImpl.java
@Override public boolean insert(UserRole obj) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction();//w w w .j av a 2 s . co m session.save(obj); session.getTransaction().commit(); session.clear(); session.close(); return true; }
From source file:com.elearing.impl.UserRoleDaoImpl.java
public UserRole getRole(String s) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction();/*w w w.j ava2s. co m*/ Query query = session.createQuery("from UserRole where roleName =:name"); query.setString("name", s); UserRole userRole = (UserRole) query.list().get(0); session.clear(); session.close(); return userRole; }
From source file:com.evolveum.midpoint.repo.sql.helpers.OrgClosureManager.java
License:Apache License
/** * Main method called from SQL repository service to update the closure table during an operation. * @param originalObject Original state of the object - before applying modification in the repository. * It is used only in case of MODIFY (note that "overwriting ADD" is present here as MODIFY!) * @param modifications Collection of modifications to be applied to the object. * @param session Database session to use. * @param oid OID of the object./*from w ww .j a va 2 s . c o m*/ * @param type Type of the object. * @param operation Operation that is carried out. * @param closureContext */ public <T extends ObjectType> void updateOrgClosure(PrismObject<? extends ObjectType> originalObject, Collection<? extends ItemDelta> modifications, Session session, String oid, Class<T> type, Operation operation, Context closureContext) { if (!isEnabled()) { return; } if (!OrgType.class.isAssignableFrom(type)) { return; } session.flush(); session.clear(); long time = System.currentTimeMillis(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("################# Starting {} for org. closure for {} oid={}.", new Object[] { operation, type.getSimpleName(), oid }); } List<ReferenceDelta> deltas = filterParentRefDeltas(modifications); switch (operation) { case ADD: handleAdd(oid, deltas, closureContext, session); break; case DELETE: handleDelete(oid, closureContext, session); break; case MODIFY: handleModify(oid, deltas, originalObject, closureContext, session); } long duration = System.currentTimeMillis() - time; LOGGER.debug("################# Org. closure update finished in {} ms.", duration); lastOperationDuration = duration; }
From source file:com.evolveum.midpoint.repo.sql.helpers.OrgClosureManager.java
License:Apache License
private void handleAdd(String oid, Set<String> parents, Context context, Session session) { // adding self-record session.save(new ROrgClosure(oid, oid, 1)); session.flush();/*w ww. jav a2s .co m*/ session.clear(); List<String> livingChildren = getChildren(oid, session); // no need to check existence of these oids, as owner is a FK pointing to RObject in RParentRef LOGGER.trace("Living children = {}", livingChildren); addChildrenEdges(oid, livingChildren, context, session); // all parents are "new", so we should just select which do really exist at this moment Collection<String> livingParents = retainExistingOids(parents, session); LOGGER.trace("Living parents = {} (parents = {})", livingParents, parents); if (livingParents.size() <= 1 && (livingChildren == null || livingChildren.isEmpty())) { String parent; if (livingParents.isEmpty()) { parent = null; } else { parent = livingParents.iterator().next(); } addEdgeSimple(oid, parent, session); } else { addParentEdges(oid, livingParents, context, session); } }
From source file:com.evolveum.midpoint.repo.sql.helpers.OrgClosureManager.java
License:Apache License
private void addEdgeSimple(String oid, String parent, Session session) { if (parent != null) { long start = System.currentTimeMillis(); Query addToClosureQuery = session .createSQLQuery("insert into " + CLOSURE_TABLE_NAME + " (descendant_oid, ancestor_oid, val) " + "select :oid as descendant_oid, CL.ancestor_oid as ancestor_oid, CL.val as val " + "from " + CLOSURE_TABLE_NAME + " CL " + "where CL.descendant_oid = :parent"); addToClosureQuery.setString("oid", oid); addToClosureQuery.setParameter("parent", parent); int count = addToClosureQuery.executeUpdate(); if (LOGGER.isTraceEnabled()) LOGGER.trace("addEdges simplified: Added {} records to closure table ({} ms).", count, System.currentTimeMillis() - start); }//from w ww .j a va 2s. c o m session.flush(); session.clear(); }
From source file:com.evolveum.midpoint.repo.sql.helpers.OrgClosureManager.java
License:Apache License
private void addIndependentEdges(List<Edge> edges, Context context, Session session) { long start = System.currentTimeMillis(); LOGGER.trace("===================== ADD INDEPENDENT EDGES: {} ================", edges); if (!edges.isEmpty()) { // for unknown reason, queries in the form of // select t1.descendant_oid as descendant_oid, t2.ancestor_oid as ancestor_oid, sum(t1.val*t2.val) as val // from m_org_closure t1, m_org_closure t2 where // (t1.ancestor_oid = 'o21101..-....-....-....-............' and t2.descendant_oid = 'o1101...-....-....-....-............') // or (t1.ancestor_oid = 'o21101..-....-....-....-............' and t2.descendant_oid = 'o2130...-....-....-....-............') // group by t1.descendant_oid, t2.ancestor_oid ////w w w . j a v a2s .c om // take radically longer in H2 than queries without the disjunction (i.e. having only one "ancestor=X and descendant=Y" item) // So, in H2, we insert the edges one-by-one if (isH2()) { for (Edge edge : edges) { addIndependentEdgesInternal(Arrays.asList(edge), context, session); } } else { addIndependentEdgesInternal(edges, context, session); } } session.flush(); session.clear(); LOGGER.trace("--------------------- DONE ADD EDGES: {} ({} ms) ----------------", edges, System.currentTimeMillis() - start); }
From source file:com.evolveum.midpoint.repo.sql.helpers.OrgClosureManager.java
License:Apache License
private void removeIndependentEdges(List<Edge> edges, Context context, Session session) { long start = System.currentTimeMillis(); LOGGER.trace("===================== REMOVE INDEPENDENT EDGES: {} ================", edges); if (!edges.isEmpty()) { // for the reason for this decomposition, see addIndependentEdges if (isH2()) { for (Edge edge : edges) { removeIndependentEdgesInternal(Arrays.asList(edge), context, session); }/* ww w .j av a 2 s . c o m*/ } else { removeIndependentEdgesInternal(edges, context, session); } } session.flush(); session.clear(); LOGGER.trace("--------------------- DONE REMOVE EDGES: {} ({} ms) ----------------", edges, System.currentTimeMillis() - start); }