List of usage examples for org.hibernate Session createQuery
@Override org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery);
From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.UpdateLocalRigStatusTester.java
License:Open Source License
@Test public void testUpdateStatusInActiveNotContactURL() { Session ses = DataAccessActivator.getNewSession(); RigType type = new RigType("ulrsTypr", 180, false); new RigTypeDao(ses).persist(type); RigCapabilities caps = new RigCapabilities("ulrsA,urlsB"); new RigCapabilitiesDao(ses).persist(caps); Rig rig = new Rig(type, caps, "urls", null, new Date(System.currentTimeMillis() - 86400001), // A day ago true, null, false, false, true); /* Bad. *//*from ww w . j a v a 2s. co m*/ rig.setOnline(false); rig.setOfflineReason("Broken"); rig.setActive(false); new RigDao(ses).persist(rig); assertFalse(this.update.updateStatus("urls", true, null)); assertNotNull(this.update.getFailedReason()); ses.refresh(rig); assertFalse(rig.isActive()); assertFalse(rig.isOnline()); assertNotNull(rig.getOfflineReason()); ses.beginTransaction(); ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate(); ses.getTransaction().commit(); ses.beginTransaction(); ses.delete(rig); ses.delete(type); ses.delete(caps); ses.getTransaction().commit(); }
From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.RigProviderActivator.java
License:Open Source License
@Override public void stop(final BundleContext context) throws Exception { this.logger.info("Stopping " + context.getBundle().getSymbolicName() + " bundle."); this.serverReg.unregister(); /* Clean up identity tokens. */ this.idenTokReg.unregister(); IdentityTokenRegister.getInstance().expunge(); this.runnableReg.unregister(); /* Take all rigs offline. */ Session ses = DataAccessActivator.getNewSession(); if (ses != null) { Query qu = ses.createQuery("UPDATE Rig SET active=:false, in_session=:false, online=:false, " + "session_id=:null, offline_reason=:offline"); qu.setBoolean("false", false); qu.setParameter("null", null, Hibernate.BIG_INTEGER); qu.setString("offline", "Scheduling Server shutting down."); ses.beginTransaction();/* w ww .j a v a 2s . c om*/ int num = qu.executeUpdate(); ses.getTransaction().commit(); this.logger.info("Took " + num + " rigs offline for shutdown."); ses.close(); } /* Cleanup the configuration service tracker. */ RigProviderActivator.configTracker.close(); RigProviderActivator.configTracker = null; }
From source file:au.edu.uts.eng.remotelabs.schedserver.session.SessionActivator.java
License:Open Source License
@Override public void stop(BundleContext context) throws Exception { this.logger.info("Stopping the Session bundle..."); this.soapReg.unregister(); this.terminatorService.unregister(); this.sessionCheckerReg.unregister(); SessionActivator.bookingsTracker.close(); /* Terminate all in progress sessions. */ Session ses = DataAccessActivator.getNewSession(); if (ses != null) { Query qu = ses .createQuery("UPDATE Session SET active=:false, removal_reason=:reason, removal_time=:time " + " WHERE active=:true"); qu.setBoolean("false", false); qu.setBoolean("true", true); qu.setString("reason", "Scheduling Server shutting down."); qu.setTimestamp("time", new Date()); ses.beginTransaction();/*from w w w.java 2 s . com*/ int num = qu.executeUpdate(); ses.getTransaction().commit(); this.logger.info("Terminated " + num + " sessions for shutdown."); ses.close(); } }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
/** * //w ww. j a v a2s . c o m */ public List<List<String>> getPhenoDataAsMatrix(Study study, List<String> subjectUids, List<PhenoDataSetField> phenoDataSetFields, List<PhenoDataSetGroup> phenoDataSetGroups, PhenoDataSetCategory phenoDataSetCategory) { List<List<String>> dataSet = new ArrayList<List<String>>(); StringBuffer dataHQLquery = new StringBuffer(); StringBuffer noDataHQLquery = new StringBuffer(); StringBuffer phenoFieldColumnSQL = new StringBuffer(); List<String> header = new ArrayList<String>(0); //stringBuffer.append("SELECT data.* FROM (\n"); //ARK-799 // dataHQLquery.append("SELECT lss.subjectUID, pc.recordDate, pc.description, \n"); dataHQLquery.append("SELECT lss.subjectUID, pdsc.recordDate, \n"); noDataHQLquery .append("SELECT lss.subjectUID, cast(null as char) AS recordDate, cast(null as char) AS name, \n"); header.add("SUBJECTUID"); header.add("RECORD_DATE"); //ARK-799 // header.add("COLLECTION"); // Loop for all custom goups for (PhenoDataSetGroup pdsg : phenoDataSetGroups) { // Get all custom fields for the group and create pivot SQL to create column //for(PhenoDataSetFieldDisplay pdsfd : getPhenoDataSetFieldDisplayForPhenoDataSetFieldGroup(pdsg)) { for (PhenoDataSetField pdsfd : getPhenoDataSetFieldsLinkedToPhenoDataSetFieldGroupAndPhenoDataSetCategory( pdsg, phenoDataSetCategory)) { //MAX(IF(custom_field_display_id = 14, pd.number_data_value, NULL)) AS cfd14, phenoFieldColumnSQL.append("(MAX(CASE WHEN pdsd.phenoDataSetFieldDisplay.id = "); phenoFieldColumnSQL .append(getPhenoDataSetFieldDisplayByPhenoDataSetFieldAndGroup(pdsfd, pdsg).getId()); // Determine field type and append SQL accordingly if (pdsfd.getFieldType().getName().equalsIgnoreCase(Constants.FIELD_TYPE_DATE)) { phenoFieldColumnSQL.append(" THEN pdsd.dateDataValue ELSE NULL END) "); } if (pdsfd.getFieldType().getName().equalsIgnoreCase(Constants.FIELD_TYPE_NUMBER)) { phenoFieldColumnSQL.append(" THEN pdsd.numberDataValue ELSE NULL END) "); } if (pdsfd.getFieldType().getName().equalsIgnoreCase(Constants.FIELD_TYPE_CHARACTER)) { phenoFieldColumnSQL.append(" THEN pdsd.textDataValue ELSE NULL END) "); } phenoFieldColumnSQL.append(") "); phenoFieldColumnSQL.append(","); noDataHQLquery.append("cast(null as char) "); noDataHQLquery.append(","); header.add(pdsfd.getName().toUpperCase()); } } // Remove erroneous ',' char from end of strings if (phenoFieldColumnSQL.length() > 0) { phenoFieldColumnSQL.setLength(phenoFieldColumnSQL.length() - 1); noDataHQLquery.setLength(noDataHQLquery.length() - 1); dataHQLquery.append(phenoFieldColumnSQL); dataHQLquery.append("\nFROM \n"); dataHQLquery.append(" PhenoDataSetData pdsd, "); dataHQLquery.append(" PhenoDataSetCollection pdsc, "); dataHQLquery.append(" LinkSubjectStudy lss, "); dataHQLquery.append(" PhenoDataSetFieldDisplay pdsfd \n"); dataHQLquery.append(" WHERE pdsd.phenoDataSetCollection.id = pdsc.id \n"); dataHQLquery.append(" AND pdsc.linkSubjectStudy.id = lss.id \n"); dataHQLquery.append(" AND lss.study = :study \n"); dataHQLquery.append(" AND lss.subjectUID IN (:subjectUids) \n"); dataHQLquery.append(" AND pdsfd.phenoDataSetGroup in (:phenoDataSetGroups) \n"); dataHQLquery.append(" AND pdsd.phenoDataSetFieldDisplay.id = pdsfd.id \n"); dataHQLquery.append("GROUP BY lss.subjectUID, pdsd.phenoDataSetCollection"); noDataHQLquery.append("\nFROM LinkSubjectStudy lss\n"); noDataHQLquery.append("WHERE lss.study = :study \n"); noDataHQLquery.append( "AND lss.id NOT IN (SELECT pdsc.linkSubjectStudy.id FROM PhenoDataSetCollection pdsc WHERE pdsc.questionnaire IN (:phenoDataSetGroups))\n"); String hqlQuery = dataHQLquery.toString(); Session session = getSession(); Query dataQuery = session.createQuery(hqlQuery); dataQuery.setParameter("study", study); dataQuery.setParameterList("subjectUids", subjectUids); dataQuery.setParameterList("phenoDataSetGroups", phenoDataSetGroups); // Add header as first list item dataSet.add(header); // Add data //ArrayList<List<String>> dataList = new ArrayList<List<String>>(); //dataList = (ArrayList<List<String>>) dataQuery.list(); //This result set contains a List of Object arrayseach array represents one set of properties Iterator it = dataQuery.iterate(); while (it.hasNext()) { Object[] val = (Object[]) it.next(); List<String> stringList = new ArrayList<String>(); for (Object o : val) { stringList.add(o != null ? o.toString() : new String()); } dataSet.add(stringList); } hqlQuery = noDataHQLquery.toString(); Query noDataQuery = session.createQuery(hqlQuery); noDataQuery.setParameter("study", study); noDataQuery.setParameterList("phenoDataSetGroups", phenoDataSetGroups); //noDataQuery.list(); //dataSet.addAll(noDataQuery.list()); } return dataSet; }
From source file:autoancillarieslimited.hiberate.dao.AbstractDao.java
@Override public boolean deleteByID(int id, Class clazz) { Session session = null; Transaction beginTransaction = null; int executeUpdate = 0; try {//from w w w. j a v a2s . co m session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); Query setInteger = session.createQuery("delete from " + clazz.getName() + " where id like ?") .setInteger(0, id); executeUpdate = setInteger.executeUpdate(); beginTransaction.commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return executeUpdate == 0 ? false : true; }
From source file:autoancillarieslimited.hiberate.dao.AbstractDao.java
public List<T> getList(String tableName) { List<T> set = null;// www . j av a2s . c o m Session session = null; Transaction beginTransaction = null; try { session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); set = session.createQuery("from " + tableName + "").list(); session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }
From source file:autoancillarieslimited.hiberate.dao.CustomerDAO.java
public Customer checkLogin(String email, String password) { Customer item = null;//from ww w . java 2 s.c o m Session session = null; Transaction beginTransaction = null; try { session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); item = (Customer) session .createQuery( "from Customer where Email like '" + email + "' AND PassWord like '" + password + "'") .uniqueResult(); session.flush(); session.clear(); beginTransaction.commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return item; }
From source file:autoancillarieslimited.hiberate.dao.CustomerDAO.java
public boolean checkEmail(String email) { Customer item = null;/*from w w w . ja v a2s. c o m*/ Session session = null; Transaction beginTransaction = null; try { session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); item = (Customer) session.createQuery("from Customer where Email like '" + email + "'").uniqueResult(); session.flush(); session.clear(); beginTransaction.commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } if (item != null) { return false; } return true; }
From source file:autoancillarieslimited.hiberate.dao.EmployeeDAO.java
public List<Employee> getEmployees(Employee filter) { List<Employee> set = null; Session session = null; Transaction beginTransaction = null; try {/* w ww . j a v a 2 s. c o m*/ session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); if (filter.getWareHouses_ID() != 0) { set = session.createQuery("from Employee where Name like '%" + filter.getName() + "%' AND WareHouses_ID ='" + filter.getWareHouses_ID() + "' ").list(); } else { set = session.createQuery("from Employee where Name like '%" + filter.getName() + "%'").list(); } session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }
From source file:autoancillarieslimited.hiberate.dao.EmployeeDAO.java
public List<Employee> getEmployees() { List<Employee> set = null; Session session = null; Transaction beginTransaction = null; try {//from w w w .java 2 s . c o m session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); set = session.createQuery("from Employee").list(); session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }