List of usage examples for org.hibernate Query list
List<R> list();
From source file:au.com.nicta.ct.solution.graphics.canvas.tools.annotations.CtAnnotationsController.java
License:Open Source License
final List<CtAnnotationsTypes> loadTypes() { Session s = CtSession.Current(); CtManualFlush mf = new CtManualFlush(s); s.beginTransaction();//from w ww . j a v a 2s. c om Query q = s.createQuery(" SELECT at" + " FROM CtAnnotationsTypes at"); List<CtAnnotationsTypes> l = (List<CtAnnotationsTypes>) q.list(); s.getTransaction().commit(); mf.restore(); return l; }
From source file:au.com.nicta.ct.solution.graphics.canvas.tools.annotations.CtAnnotationsModel.java
License:Open Source License
public void setSolution(CtSolutions s) { if (s == null) { clear();//from w w w. j a v a 2s. com return; } Session session = CtSession.Current(); session.beginTransaction(); Query q = session .createQuery(" SELECT ctA" + " FROM CtAnnotations as ctA" + " WHERE ctA.ctSolutions = :solutionPk"); q.setInteger("solutionPk", s.getPkSolution()); for (CtAnnotations a : (List<CtAnnotations>) q.list()) { addToMaps(a); } session.getTransaction().commit(); }
From source file:au.com.nicta.ct.solution.tracking.CtSolutionManager.java
License:Open Source License
protected void deleteFromTables(int solutionPk) { // delete from CtTracksDetections Query q = session.createQuery(" SELECT ctTD" + " FROM CtTracksDetections as ctTD" + " JOIN ctTD.ctTracks as ctT" + " WHERE ctT.ctSolutions = :solutionPk"); q.setInteger("solutionPk", solutionPk); deleteRows(q.list()); // delete from CtTracks q = session.createQuery(" SELECT ctT" + " FROM CtTracks as ctT" + " WHERE ctT.ctSolutions = :solutionPk"); q.setInteger("solutionPk", solutionPk); deleteRows(q.list());//from ww w .jav a2 s. co m // delete from CtDetections q = session .createQuery(" SELECT ctD" + " FROM CtDetections as ctD" + " WHERE ctD.ctSolutions = :solutionPk"); q.setInteger("solutionPk", solutionPk); deleteRows(q.list()); // delete from CtSolutions session.delete(session.load(CtSolutions.class, solutionPk)); }
From source file:au.com.nicta.ct.solution.tracking.CtSolutionManager.java
License:Open Source License
/** * TODO: rewrite so that any property without a valid fk in other tables are * removed./*from w w w . ja v a 2s.c o m*/ * @param solutionPk */ protected void deleteProperties(int solutionPk) { // delete properties of CtDetections Query q = session.createQuery( " SELECT ctD.pkDetection" + " FROM CtDetections as ctD" + " WHERE ctD.ctSolutions = :solutionPk"); q.setInteger("solutionPk", solutionPk); deleteProperties(CtDetections.class, q.list()); // delete properties of CtTracks q = session.createQuery( " SELECT ctT.pkTrack" + " FROM CtTracks as ctT" + " WHERE ctT.ctSolutions = :solutionPk"); q.setInteger("solutionPk", solutionPk); deleteProperties(CtTracks.class, q.list()); // delete properties of CtTracksDetections q = session.createQuery(" SELECT ctTD.pkTrackDetection" + " FROM CtTracksDetections as ctTD" + " JOIN ctTD.ctTracks as ctT" + " WHERE ctT.ctSolutions = :solutionPk"); q.setInteger("solutionPk", solutionPk); deleteProperties(CtTracksDetections.class, q.list()); // delete entity properties q = session.createQuery( " DELETE " + " FROM CtEntityProperties as ctEP" + " WHERE ctEP.ctSolutions = :solutionPk"); q.setInteger("solutionPk", solutionPk); q.executeUpdate(); }
From source file:au.com.nicta.ct.solution.tracking.CtSolutionManager.java
License:Open Source License
/** * Delete all properties associated with the rows of the * * @param tableCls// w ww . ja v a 2s . co m * @param rows */ protected void deleteProperties(Class tableCls, List<Integer> pkList) { // get all properties Query q = session.createQuery("FROM CtProperties ctProperties"); List<CtProperties> allProperties = (List<CtProperties>) q.list(); for (int pk : pkList) { String keySuffix = CtKeyValueProperties.getSuffixOfClass(tableCls, pk); // findProperties(allProperties, keySuffix); // Query q = CtKeyValueProperties.queryLike( "%" + keySuffix, session ); for (CtProperties p : findProperties(allProperties, keySuffix)) { // System.out.println( "Name: " + p.getName() + " Value: " + p.getValue() ); // delete it session.delete(p); } } }
From source file:au.com.nicta.ct.solution.tracking.CtSolutionManager.java
License:Open Source License
protected void copyTracksDetections(Map<Integer, CtTracks> tracksMap, Map<Integer, CtDetections> detectionsMap, Map<Integer, CtTracksDetections> tracksDetectionsMap) { Query q = session.createQuery(" SELECT ctTD" + " FROM CtTracksDetections as ctTD" + " JOIN ctTD.ctTracks as ctT" + " WHERE ctT.ctSolutions = :solutionPk"); q.setInteger("solutionPk", oldSolution.getPkSolution()); for (CtTracksDetections td : (List<CtTracksDetections>) q.list()) { CtTracksDetections td2 = new CtTracksDetections(); CtTracks newT = tracksMap.get(td.getCtTracks().getPkTrack()); CtDetections newD = detectionsMap.get(td.getCtDetections().getPkDetection()); td2.setCtTracks(newT);//from www .j a v a2s . c o m td2.setCtDetections(newD); session.save(td2); int oldPk = td.getPkTrackDetection(); int newPk = td2.getPkTrackDetection(); tracksDetectionsMap.put(oldPk, td2); assert oldPk != newPk; // session.evict(t); // session.evict(d); // session.get(CtTracks .class, newPkT); // session.get(CtDetections.class, newPkD); } }
From source file:au.com.nicta.ct.solution.tracking.CtSolutionManager.java
License:Open Source License
protected void copyAnnotations() { Query q = session .createQuery(" SELECT ctA" + " FROM CtAnnotations as ctA" + " WHERE ctA.ctSolutions = :solutionPk"); q.setInteger("solutionPk", oldSolution.getPkSolution()); for (CtAnnotations a : (List<CtAnnotations>) q.list()) { CtAnnotations a2 = new CtAnnotations(0, a.getCtAnnotationsTypes(), a.getCtImages(), newSolution, a.getValue(), a.getX(), a.getY()); session.saveOrUpdate(a2);/* w w w.ja v a2s. com*/ } }
From source file:au.com.nicta.ct.solution.tracking.CtSolutionManager.java
License:Open Source License
protected void deleteAnnotations(int solutionPk) { Query q = session .createQuery(" SELECT ctA" + " FROM CtAnnotations as ctA" + " WHERE ctA.ctSolutions = :solutionPk"); q.setInteger("solutionPk", solutionPk); for (CtAnnotations a : (List<CtAnnotations>) q.list()) { session.delete(a);/* w w w. j a v a 2s . c o m*/ } }
From source file:au.com.nicta.ct.solution.tracking.CtSolutionManager.java
License:Open Source License
protected void copyProperties(Map<Integer, ?> oldToNewMap, Class tableCls, Map<Integer, Integer> propertiesMap) { // get all properties Query q = session.createQuery("FROM CtProperties ctProperties"); List<CtProperties> allProperties = (List<CtProperties>) q.list(); for (Map.Entry<Integer, ?> e : oldToNewMap.entrySet()) { Integer oldObjPk = e.getKey(); Integer newObjPk = getPk(e.getValue()); // System.out.println( "A: " + oldObjPk ); String keySuffix = CtKeyValueProperties.getSuffixOfClass(tableCls, oldObjPk); // Query q = CtKeyValueProperties.queryLike( "%" + keySuffix, session ); // List<CtProperties> l = (List<CtProperties>) q.list(); for (CtProperties p : findProperties(allProperties, keySuffix)) { // System.out.println( "Name: " + p.getName() + " Value: " + p.getValue() ); // replace the PK part of the property name String name = CtKeyValueProperties.getNameToken(p.getName()) + "-" + CtKeyValueProperties.getClassToken(p.getName()) + "-" + newObjPk; // System.out.println( "New name: " + name ); CtProperties p2 = new CtProperties(); p2.setCtPropertiesTypes(p.getCtPropertiesTypes()); p2.setName(name);// www. j av a2 s. c o m p2.setValue(p.getValue()); session.save(p2); int oldPk = p.getPkProperty(); int newPk = p2.getPkProperty(); propertiesMap.put(oldPk, newPk); assert oldPk != newPk; // session.evict( p2 ); } } }
From source file:au.com.nicta.ct.solution.tracking.CtSolutionManager.java
License:Open Source License
protected void copyEntityProperties(Map<Integer, ?> oldToNewMap, Class tableCls, Map<Integer, Integer> entityPropertiesMap) { // get all properties Query q = session.createQuery( "FROM CtEntityProperties ctEntityProperties" + " WHERE ctEntityProperties.ctSolutions = :pkSolution" + " AND ctEntityProperties.entityName = :entityName"); q.setInteger("pkSolution", oldSolution.getPkSolution()); q.setString("entityName", CtEntityPropertiesUtil.getClassName(tableCls)); List<CtEntityProperties> allEntityProperties = (List<CtEntityProperties>) q.list(); for (Map.Entry<Integer, ?> e : oldToNewMap.entrySet()) { Integer oldObjPk = e.getKey(); Integer newObjPk = getPk(e.getValue()); // System.out.println("oldPk: " + (oldObjPk) ); // List<CtEntityProperties> l = CtEntityPropertiesUtil.find(session, oldSolution, tableCls, oldObjPk, null); for (CtEntityProperties ep : findEntityProperties(allEntityProperties, oldObjPk)) { // System.out.println( "Name: " + ep.getName() + " Value: " + ep.getValue() ); CtEntityProperties ep2 = new CtEntityProperties(); ep2.setCtSolutions(newSolution); ep2.setEntityName(ep.getEntityName()); ep2.setEntityPk(newObjPk);//from ww w . j a va 2 s .co m ep2.setName(ep.getName()); ep2.setValue(ep.getValue()); session.save(ep2); int oldPk = ep.getPkEntityProperty(); int newPk = ep2.getPkEntityProperty(); entityPropertiesMap.put(oldPk, newPk); assert oldPk != newPk; // session.evict( ep2 ); } } }