List of usage examples for org.hibernate Session refresh
void refresh(Object object);
From source file:de.uzk.hki.da.at.ATIntegrityCheck.java
License:Open Source License
private boolean checkCopies(Object object) { Session session = HibernateUtil.openSession(); session.beginTransaction();/*from www. j av a 2 s. co m*/ session.refresh(object); for (Copy rec : object.getLatestPackage().getCopies()) rec.getId(); Copy copy = object.getLatestPackage().getCopies().iterator().next(); if (copy.getChecksum().equals(object.getLatestPackage().getChecksum())) return true; return false; }
From source file:de.uzk.hki.da.at.ATInvalidTiffTagsInBigTiff.java
License:Open Source License
/** * In real world scenario, this is being done with Da-Web * @author Jens Peters/* ww w. j a va 2 s. c o m*/ * @param job */ private void modifyPackageDataFromOutside(Job job) { Session session = HibernateUtil.openSession(); session.beginTransaction(); session.refresh(job); System.out.println(" set " + C.QUESTION_STORE_ALLOWED_IPTC_ERROR + " " + C.ANSWER_YO); job.setQuestion(C.QUESTION_STORE_ALLOWED_IPTC_ERROR); job.setStatus(PROCESS_MOCK_USER_DECISION); job.setAnswer(C.ANSWER_YO); session.update(job); session.getTransaction().commit(); session.close(); }
From source file:de.uzk.hki.da.at._ATIntegrityCheck.java
License:Open Source License
private void setChecksumSecondaryCopy(String checksum, int minusHoursInPast) { Session session = HibernateUtil.openSession(); session.beginTransaction();//from ww w. j a va2s . co m // replace proxies by real objects session.refresh(object); for (Copy rec : object.getLatestPackage().getCopies()) { } assertTrue(object.getLatestPackage().getCopies().size() > 0); // Simulate checksumming done by foreign nodes Copy copy = object.getLatestPackage().getCopies().iterator().next(); copy.setChecksum(checksum); // set object to older creationdate than one day Calendar now = Calendar.getInstance(); now.add(Calendar.HOUR_OF_DAY, minusHoursInPast); copy.setChecksumDate(now.getTime()); session.update(copy); session.getTransaction().commit(); session.close(); }
From source file:de.uzk.hki.da.core.ChecksumWorker.java
License:Open Source License
public void init() { node = new Node(); node.setId(localNodeId);// ww w.ja v a 2s. co m setpSystem(new PreservationSystem()); getPSystem().setId(1); Session session = HibernateUtil.openSession(); session.beginTransaction(); session.refresh(getPSystem()); session.refresh(node); session.getTransaction().commit(); session.close(); }
From source file:de.uzk.hki.da.core.IntegrityScannerWorker.java
License:Open Source License
public void init() { node = new Node(); node.setId(Integer.parseInt(localNodeId)); setpSystem(new PreservationSystem()); getPSystem().setId(1);// w ww .j a v a2 s.co m Session session = HibernateUtil.openSession(); session.beginTransaction(); session.refresh(getPSystem()); session.refresh(node); session.getTransaction().commit(); session.close(); }
From source file:de.uzk.hki.da.core.IntegrityWorker.java
License:Open Source License
public void init() { node = new Node(); node.setId(Integer.parseInt(localNodeId)); setpSystem(new PreservationSystem()); getPSystem().setId(1);/*from ww w . j av a2s . c o m*/ Session session = HibernateUtil.openSession(); session.beginTransaction(); session.refresh(getPSystem()); session.refresh(node); session.getTransaction().commit(); session.close(); is = new IntegrityService(); is.setGridFacade(gridFacade); }
From source file:de.uzk.hki.da.core.RepairWorker.java
License:Open Source License
public void init() { Node node = new Node(); PreservationSystem pSystem;//ww w.ja v a 2s . c om node.setId(Integer.parseInt(localNodeId)); pSystem = new PreservationSystem(); pSystem.setId(1); Session session = HibernateUtil.openSession(); session.refresh(pSystem); session.refresh(node); session.close(); this.repairService = new RepairService(pSystem, node, this.zoneName, this.replDestinations); }
From source file:edu.harvard.i2b2.crc.dao.setfinder.QueryInstanceDao.java
License:Open Source License
/** * Update query instance/*from w w w . j a v a 2 s. c o m*/ * @param queryInstance * @return QtQueryInstance */ public QtQueryInstance update(QtQueryInstance queryInstance) { Session session = getSession(); session.update(queryInstance); session.flush(); session.refresh(queryInstance); return queryInstance; }
From source file:edu.ku.brc.specify.treeutils.HibernateTreeDataServiceImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public synchronized boolean deleteTreeNode(final T nodeToDelete) { //Session session = getNewSession(node); Session session = HibernateUtil.getSessionFactory().openSession(); try {// w w w. j a v a 2 s .c o m T node = (T) mergeIntoSession(session, nodeToDelete); // refresh the node data so we have correct information for the following calculation session.refresh(node); T parent = node.getParent(); if (parent != null) { parent = (T) mergeIntoSession(session, parent); session.refresh(parent); } Transaction tx = session.beginTransaction(); // detach from the parent node if (parent != null) { parent.removeChild(node); node.setParent(null); } // let Hibernate delete the subtree DataProviderSessionIFace sessionWrapper = new HibernateDataProviderSession(session); BusinessRulesIFace busRulesObj = DBTableIdMgr.getInstance().getBusinessRule(node); if (busRulesObj != null) { node = (T) busRulesObj.beforeDelete(node, sessionWrapper); } session.delete(node); if (busRulesObj != null) { try { if (!busRulesObj.beforeDeleteCommit(node, sessionWrapper)) { tx.rollback(); return false; } } catch (Exception e) { tx.rollback(); return false; } } boolean retVal = commitTransaction(session, tx); // NOTE: this closes an open session if (busRulesObj != null && retVal) { busRulesObj.afterDeleteCommit(node); } return retVal; } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(HibernateTreeDataServiceImpl.class, ex); log.error(ex); } finally { if (session.isOpen()) { session.close(); } } return false; }
From source file:edu.ku.brc.specify.treeutils.HibernateTreeDataServiceImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public synchronized int moveTreeNode(final T node, final T newParent) { //log.debug("Moving ["+nodeDebugInfo(node)+"] to ["+nodeDebugInfo(newParent)+"]"); if (node == null || newParent == null) { throw new NullPointerException("'node' and 'newParent' must both be non-null"); }//from w w w .ja va2 s . c om if (node.getParent() == newParent) { return ERROR; } T oldParent = node.getParent(); if (oldParent == null) { throw new NullPointerException("'node' must already have a parent"); } BusinessRulesIFace busRules = DBTableIdMgr.getInstance().getBusinessRule(node); STATUS status = ((BaseTreeBusRules) busRules).checkForSiblingWithSameName(newParent, node, true); if (status != STATUS.OK) { return CANCELLED; } Session session = getNewSession(); try { T mergedNode = (T) mergeIntoSession(session, node); T mergedNewParent = (T) mergeIntoSession(session, newParent); T mergedOldParent = (T) mergeIntoSession(session, oldParent); Transaction tx = session.beginTransaction(); //log.debug("refreshing " + nodeDebugInfo(mergedNode)); session.refresh(mergedNode); //log.debug("refreshing " + nodeDebugInfo(mergedNewParent)); session.refresh(mergedNewParent); // fix up the parent/child pointers for the effected nodes // oldParent cannot be null at this point mergedOldParent.removeChild(mergedNode); mergedNewParent.addChild(mergedNode); mergedNode.setParent(mergedNewParent); //BusinessRulesIFace busRules = DBTableIdMgr.getInstance().getBusinessRule(mergedNode); HibernateDataProviderSession sessionWrapper = new HibernateDataProviderSession(session); if (busRules != null) { busRules.beforeSave(mergedNode, sessionWrapper); } session.saveOrUpdate(mergedNode); // fix all the node numbers for effected nodes // X will represent moving subtree's root node // Y will represent new parent of moving subtree // get the root node T rootNode = mergedNewParent; while (rootNode.getParent() != null) { rootNode = rootNode.getParent(); } int rootHC = rootNode.getHighestChildNodeNumber(); int xNN = mergedNode.getNodeNumber(); int xHC = mergedNode.getHighestChildNodeNumber(); int yNN = mergedNewParent.getNodeNumber(); D def = mergedNode.getDefinition(); String className = mergedNode.getClass().getName(); int numMoving = xHC - xNN + 1; // the HQL update statements that need to happen now are dependant on the 'direction' of the move boolean downwardMove = true; if (xNN > yNN) { downwardMove = false; } if (downwardMove) { // change node numbers for the moving nodes to high values in order to temporarily 'move them out of the tree' String step1QueryStr = "UPDATE " + className + " SET nodeNumber=nodeNumber+:rootHC, highestChildNodeNumber=highestChildNodeNumber+:rootHC WHERE nodeNumber>=:xNN AND nodeNumber<=:xHC AND definition=:def"; Query step1Query = session.createQuery(step1QueryStr); step1Query.setParameter("def", def); step1Query.setParameter("xNN", xNN); step1Query.setParameter("xHC", xHC); step1Query.setParameter("rootHC", rootHC); step1Query.executeUpdate(); String step2QueryStr = "UPDATE " + className + " SET nodeNumber=nodeNumber-:numMoving WHERE nodeNumber>:xHC AND nodeNumber<=:yNN AND definition=:def"; Query step2Query = session.createQuery(step2QueryStr); step2Query.setParameter("def", def); step2Query.setParameter("xHC", xHC); step2Query.setParameter("yNN", yNN); step2Query.setParameter("numMoving", numMoving); step2Query.executeUpdate(); String step3QueryStr = "UPDATE " + className + " SET highestChildNodeNumber=highestChildNodeNumber-:numMoving WHERE highestChildNodeNumber>=:xHC AND highestChildNodeNumber<:yNN AND definition=:def"; Query step3Query = session.createQuery(step3QueryStr); step3Query.setParameter("def", def); step3Query.setParameter("xHC", xHC); step3Query.setParameter("yNN", yNN); step3Query.setParameter("numMoving", numMoving); step3Query.executeUpdate(); String step4QueryStr = "UPDATE " + className + " SET highestChildNodeNumber=highestChildNodeNumber-nodeNumber WHERE nodeNumber>:rootHC AND definition=:def"; Query step4Query = session.createQuery(step4QueryStr); step4Query.setParameter("def", def); step4Query.setParameter("rootHC", rootHC); step4Query.executeUpdate(); String step5QueryStr = "UPDATE " + className + " SET nodeNumber=nodeNumber + :yNN - :xHC - :rootHC WHERE nodeNumber>:rootHC AND definition=:def"; Query step5Query = session.createQuery(step5QueryStr); step5Query.setParameter("def", def); step5Query.setParameter("xHC", xHC); step5Query.setParameter("yNN", yNN); step5Query.setParameter("rootHC", rootHC); step5Query.executeUpdate(); String step6QueryStr = "UPDATE " + className + " SET highestChildNodeNumber=nodeNumber+highestChildNodeNumber WHERE nodeNumber >:lowerBound AND nodeNumber<=:yNN AND definition=:def"; Query step6Query = session.createQuery(step6QueryStr); step6Query.setParameter("def", def); step6Query.setParameter("yNN", yNN); //step6Query.setParameter("numMoving", numMoving); step6Query.setParameter("lowerBound", yNN - numMoving); step6Query.executeUpdate(); } else { // change node numbers for the moving nodes to high values in order to temporarily 'move them out of the tree' String step1QueryStr = "UPDATE " + className + " SET nodeNumber=nodeNumber+:rootHC, highestChildNodeNumber=highestChildNodeNumber+:rootHC WHERE nodeNumber>=:xNN AND nodeNumber<=:xHC AND definition=:def"; Query step1Query = session.createQuery(step1QueryStr); step1Query.setParameter("def", def); step1Query.setParameter("xNN", xNN); step1Query.setParameter("xHC", xHC); step1Query.setParameter("rootHC", rootHC); step1Query.executeUpdate(); String step2QueryStr = "UPDATE " + className + " SET nodeNumber=nodeNumber+:numMoving WHERE nodeNumber>:yNN AND nodeNumber<:xNN AND definition=:def"; Query step2Query = session.createQuery(step2QueryStr); step2Query.setParameter("def", def); step2Query.setParameter("xNN", xNN); step2Query.setParameter("yNN", yNN); step2Query.setParameter("numMoving", numMoving); step2Query.executeUpdate(); String step3QueryStr = "UPDATE " + className + " SET highestChildNodeNumber=highestChildNodeNumber+:numMoving WHERE highestChildNodeNumber>=:yNN AND highestChildNodeNumber<:xHC AND definition=:def"; Query step3Query = session.createQuery(step3QueryStr); step3Query.setParameter("def", def); step3Query.setParameter("yNN", yNN); step3Query.setParameter("xHC", xHC); step3Query.setParameter("numMoving", numMoving); step3Query.executeUpdate(); String step4QueryStr = "UPDATE " + className + " SET highestChildNodeNumber=highestChildNodeNumber-nodeNumber WHERE nodeNumber>:rootHC AND definition=:def"; Query step4Query = session.createQuery(step4QueryStr); step4Query.setParameter("def", def); step4Query.setParameter("rootHC", rootHC); step4Query.executeUpdate(); String step5QueryStr = "UPDATE " + className + " SET nodeNumber=nodeNumber+1+:yNN-:xNN-:rootHC WHERE nodeNumber>:rootHC AND definition=:def"; Query step5Query = session.createQuery(step5QueryStr); step5Query.setParameter("def", def); step5Query.setParameter("xNN", xNN); step5Query.setParameter("yNN", yNN); step5Query.setParameter("rootHC", rootHC); step5Query.executeUpdate(); String step6QueryStr = "UPDATE " + className + " SET highestChildNodeNumber=highestChildNodeNumber+nodeNumber WHERE nodeNumber>:yNN AND nodeNumber<=:upperBound AND definition=:def"; Query step6Query = session.createQuery(step6QueryStr); step6Query.setParameter("def", def); step6Query.setParameter("yNN", yNN); //step6Query.setParameter("numMoving", numMoving); step6Query.setParameter("upperBound", yNN + numMoving); step6Query.executeUpdate(); } if (busRules != null) { try { boolean retVal = busRules.beforeSaveCommit(mergedNode, sessionWrapper); if (retVal == false) { tx.rollback(); return ERROR; } } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(HibernateTreeDataServiceImpl.class, e); tx.rollback(); return ERROR; } } boolean success = commitTransaction(session, tx); // NOTE: Closes open session if (busRules != null) { success &= busRules.afterSaveCommit(mergedNode, null); } if (success) { return SUCCESS; } else { return ERROR; } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(HibernateTreeDataServiceImpl.class, ex); log.error(ex); } finally { if (session.isOpen()) { session.close(); } } return ERROR; }