/** * @return the next copy * @author Jens Peters */ private synchronized Copy fetchCopy(int localNodeId) { Session session = null; try { session = HibernateUtil.openSession(); session.beginTransaction(); @SuppressWarnings("rawtypes") List l = null; l = session .createSQLQuery( "select id from copies c where c.node_id = ?1 " + "order by c.checksumdate asc NULLS FIRST") .setParameter("1", localNodeId) .setReadOnly(true) .list(); @SuppressWarnings("rawtypes") List k = null; k = session .createQuery("from Copy c where c.id = ?1 ") .setParameter("1", l.get(0)) .setReadOnly(true) .list(); Copy copy = (Copy) k.get(0); session.close(); return copy; } catch (Exception e) { if (session != null) session.close(); return null; } }
/** * Updates the Copy with found checksum * * @param copy * @param checksum */ private synchronized void updateCopy(Copy copy, String checksum) { Session session = HibernateUtil.openSession(); session.beginTransaction(); copy.setChecksumDate(new Date()); copy.setChecksum(checksum); session.update(copy); session.getTransaction().commit(); session.close(); }
public void init() { node = new Node(); node.setId(localNodeId); setpSystem(new PreservationSystem()); getPSystem().setId(1); Session session = HibernateUtil.openSession(); session.beginTransaction(); session.refresh(getPSystem()); session.refresh(node); session.getTransaction().commit(); session.close(); }
/** * @return the number of copyjobs * @author Polina Gubaidullina */ private int getNumCopyjobs(int localNodeId) { int numCopyJobs = 0; Session session = null; try { session = HibernateUtil.openSession(); session.beginTransaction(); @SuppressWarnings("rawtypes") List l = null; l = session .createSQLQuery("select count(id) as count from copyjob;") .addScalar("count", IntegerType.INSTANCE) .list(); numCopyJobs = (Integer) l.get(0); session.close(); } catch (Exception e) { if (session != null) session.close(); } return numCopyJobs; }