List of usage examples for org.hibernate Query setBoolean
@Deprecated @SuppressWarnings("unchecked") default Query<R> setBoolean(String name, boolean val)
From source file:org.fireflow.engine.modules.persistence.hibernate.ProcessPersisterHibernateImpl.java
License:Open Source License
public int findTheLatestPublishedVersion(final String processId, final String processType) { Object result = this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query q = session.createQuery( "select max(c.version) from ProcessDescriptorImpl c where c.processId=:processId and c.processType=:processType and c.publishState=:publishState"); q.setString("processId", processId); q.setString("processType", processType); q.setBoolean("publishState", Boolean.TRUE); return q.uniqueResult(); }/*ww w . j av a 2 s . co m*/ }); if (result == null) { return 0; } else { if (result instanceof Integer) { return (Integer) result; } else if (result instanceof Long) { return ((Long) result).intValue(); } else { return 0; } } }
From source file:org.fireflow.engine.persistence.hibernate.PersistenceServiceHibernateImpl.java
License:Open Source License
public Integer findTheLatestVersionNumber(final String processId) { //????version Integer result = (Integer) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session arg0) throws HibernateException, SQLException { Query q = arg0.createQuery( "select max(m.version) from WorkflowDefinition m where m.processId=:processId and m.state=:state"); q.setString("processId", processId); q.setBoolean("state", Boolean.TRUE); Object obj = q.uniqueResult(); if (obj != null) { Integer latestVersion = (Integer) obj; return latestVersion; } else { return null; }/*from w w w .j ava 2s . com*/ } }); return result; }
From source file:org.fireflow.engine.persistence.hibernate.PersistenceServiceHibernateImpl.java
License:Open Source License
public void suspendProcessInstance(final ProcessInstance processInstance) { this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session arg0) throws HibernateException, SQLException { processInstance.setSuspended(Boolean.TRUE); arg0.update(processInstance); String hql1 = "Update org.fireflow.engine.impl.TaskInstance m Set m.suspended=:suspended Where m.processInstanceId=:processInstanceId And (m.state=0 Or m.state=1)"; Query query1 = arg0.createQuery(hql1); query1.setBoolean("suspended", Boolean.TRUE); query1.setString("processInstanceId", processInstance.getId()); query1.executeUpdate();/*from w w w .j a v a2s . co m*/ return null; } }); }
From source file:org.fireflow.engine.persistence.hibernate.PersistenceServiceHibernateImpl.java
License:Open Source License
public void restoreProcessInstance(final ProcessInstance processInstance) { this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session arg0) throws HibernateException, SQLException { processInstance.setSuspended(Boolean.FALSE); arg0.update(processInstance); String hql1 = "Update org.fireflow.engine.impl.TaskInstance m Set m.suspended=:suspended Where m.processInstanceId=:processInstanceId And (m.state=0 Or m.state=1)"; Query query1 = arg0.createQuery(hql1); query1.setBoolean("suspended", Boolean.FALSE); query1.setString("processInstanceId", processInstance.getId()); query1.executeUpdate();// w w w .ja va 2 s .c om return null; } }); }
From source file:org.fireflow.engine.persistence.hibernate.PersistenceServiceHibernateImpl.java
License:Open Source License
public void abortProcessInstance(final ProcessInstance processInstance) { this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session arg0) throws HibernateException, SQLException { Date now = rtCtx.getCalendarService().getSysDate(); processInstance.setState(IProcessInstance.CANCELED); processInstance.setEndTime(now); arg0.update(processInstance); //?canceled String hql1 = "Update org.fireflow.engine.impl.TaskInstance as m set m.state=:state,m.endTime=:endTime,m.canBeWithdrawn=:canBewithdrawn Where m.processInstanceId=:processInstanceId And (m.state=0 Or m.state=1)"; Query query1 = arg0.createQuery(hql1); query1.setInteger("state", ITaskInstance.CANCELED); query1.setDate("endTime", now); query1.setBoolean("canBewithdrawn", Boolean.FALSE); query1.setString("processInstanceId", processInstance.getId()); query1.executeUpdate();//from w w w . j a v a2 s . c o m //?canceled String hql2 = "Update org.fireflow.engine.impl.WorkItem as m set m.state=:state,m.endTime=:endTime Where m.taskInstance in (From org.fireflow.engine.impl.TaskInstance n Where n.processInstanceId=:processInstanceId) And (m.state=0 Or m.state=1)"; Query query2 = arg0.createQuery(hql2); query2.setInteger("state", IWorkItem.CANCELED); query2.setDate("endTime", now); query2.setString("processInstanceId", processInstance.getId()); query2.executeUpdate(); //token String hql3 = "Delete org.fireflow.kernel.impl.Token where processInstanceId=:processInstanceId"; Query query3 = arg0.createQuery(hql3); query3.setString("processInstanceId", processInstance.getId()); query3.executeUpdate(); return null; } }); }
From source file:org.hyperic.hq.measurement.server.session.MeasurementDAO.java
License:Open Source License
/** * @param tids - {@link Integer[]} of templateIds * @param iids - {@link Integer[]} of AppdefEntityIds * @param onlyEnabled - only selects enabled measurements *///from w w w . j a v a 2 s.co m @SuppressWarnings("unchecked") List<Measurement> findMeasurements(Integer[] tids, Integer[] iids, boolean onlyEnabled) { final IntegerType iType = new IntegerType(); // sort to take advantage of query cache final List<Integer> iidList = new ArrayList<Integer>(Arrays.asList(iids)); final List<Integer> tidList = new ArrayList<Integer>(Arrays.asList(tids)); Collections.sort(tidList); Collections.sort(iidList); final StringBuilder buf = new StringBuilder(32).append("select m from Measurement m ") .append("join m.template t ").append("where m.instanceId in (:iids) AND t.id in (:tids)"); if (onlyEnabled) { buf.append(" and enabled = :enabled"); } final String sql = buf.toString(); final List<Measurement> rtn = new ArrayList<Measurement>(iidList.size()); final int batch = BATCH_SIZE / 2; for (int xx = 0; xx < iidList.size(); xx += batch) { final int iidEnd = Math.min(xx + batch, iidList.size()); for (int yy = 0; yy < tidList.size(); yy += batch) { final int tidEnd = Math.min(yy + batch, tidList.size()); Query query = getSession().createQuery(sql) .setParameterList("iids", iidList.subList(xx, iidEnd), iType) .setParameterList("tids", tidList.subList(yy, tidEnd), iType); if (onlyEnabled) { query.setBoolean("enabled", onlyEnabled); } rtn.addAll(query.setCacheable(true).setCacheRegion("Measurement.findMeasurements").list()); } } return rtn; }
From source file:org.i4change.app.data.user.daos.UserDaoImpl.java
public List<Users> getPendingUsersForSendingMail() { try {//w w w. j av a2 s . c om String hql = "select c from Users as c " + "where c.isPending = :isPending " + "AND deleted != :deleted"; Query query = getSession().createQuery(hql); query.setBoolean("isPending", true); query.setString("deleted", "true"); List<Users> orgList = query.list(); return orgList; } catch (HibernateException ex) { log.error("[getPendingOrganisationsForSendingMail]", ex); } catch (Exception ex2) { log.error("[getPendingOrganisationsForSendingMail]", ex2); } return null; }
From source file:org.jblupus.merger.dao.CrawlerTargetDAOImpl.java
@Transactional @Override/*www. j a va2 s.co m*/ public List<CrawlerTarget> listBySetNumberAndIsCompleted(int setNumber, boolean isCompleted) { Session session = null; List<CrawlerTarget> response = null; try { session = sessionFactory.openSession(); String queryString = "SELECT c FROM CrawlerTarget c" + " WHERE c.setNumber = :setNumber" + " AND c.isCompleted = :isCompleted"; Query query = session.createQuery(queryString); query.setInteger("setNumber", setNumber); query.setBoolean("isCompleted", isCompleted); query.setMaxResults(4000); response = query.list(); } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); } finally { if (session != null) { session.close(); } } return response != null && !response.isEmpty() ? response : null; }
From source file:org.jblupus.merger.dao.CrawlerTargetDAOImpl.java
@SuppressWarnings("unchecked") @Override/*from w w w.j a v a 2s.c om*/ public List<CrawlerTarget> listBySetNumberAndIsCompleted(int setNumber, boolean isCompleted, int serverId) { Session session = null; List<CrawlerTarget> response = null; try { session = sessionFactory.openSession(); String queryString = "SELECT c FROM CrawlerTarget c" + " WHERE c.setNumber = :setNumber" + " AND c.isCompleted = :isCompleted" + " AND c.serverId = :serverId"; Query query = session.createQuery(queryString); System.out.println(queryString); query.setInteger("setNumber", setNumber); query.setBoolean("isCompleted", isCompleted); query.setInteger("serverId", serverId); query.setMaxResults(4000); response = query.list(); } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); } finally { if (session != null) { session.close(); } } return response != null && !response.isEmpty() ? response : null; }
From source file:org.jboss.dashboard.security.PermissionManager.java
License:Apache License
/** * Recover Permissions for the given permission class and resource name, including or excluding the ones marked as readonly *//*from ww w . j ava 2 s . c o m*/ public List<PermissionDescriptor> find(final String permissionClass, final String permissionResource, final Boolean includeReadOnly) { final List<PermissionDescriptor> results = new ArrayList<PermissionDescriptor>(10); HibernateTxFragment txFragment = new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { StringBuffer buf = new StringBuffer( " from " + PermissionDescriptor.class.getName() + " as item where item.dbid is not null "); buf.append( "and item.permissionClass = :permissionClass and item.permissionResource = :permissionResource"); if (!includeReadOnly) buf.append(" and item.readonly = :readonly"); Query query = session.createQuery(buf.toString()); query.setString("permissionClass", permissionClass); query.setString("permissionResource", permissionResource); if (!includeReadOnly) query.setBoolean("readonly", includeReadOnly); query.setCacheable(true); FlushMode oldFlushMode = session.getFlushMode(); session.setFlushMode(FlushMode.NEVER); results.addAll(query.list()); session.setFlushMode(oldFlushMode); } }; try { txFragment.execute(); } catch (Exception e) { log.error("Error retrieving PermissionDescriptors for permission class " + permissionClass + " and resource " + permissionResource, e); } return results; }