List of usage examples for org.hibernate Query setParameterList
Query<R> setParameterList(int position, Object[] values);
From source file:com.thoughtworks.go.server.dao.UserSqlMapDao.java
License:Apache License
@Override public boolean deleteUsers(List<String> userNames, String byWhom) { return (Boolean) transactionTemplate.execute((TransactionCallback) status -> { String queryString = "delete from User where name in (:userNames)"; Query query = sessionFactory.getCurrentSession().createQuery(queryString); query.setParameterList("userNames", userNames); query.executeUpdate();// w w w . j a va 2 s .c o m accessTokenDao.revokeTokensBecauseOfUserDelete(userNames, byWhom); return Boolean.TRUE; }); }
From source file:com.thoughtworks.go.server.dao.UserSqlMapDao.java
License:Apache License
private void changeEnabledStatus(final List<String> usernames, final boolean enabled) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override/*w w w .j ava 2s .co m*/ protected void doInTransactionWithoutResult(TransactionStatus status) { transactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() { @Override public void afterCommit() { clearEnabledUserCountFromCache(); } }); String queryString = String.format("update %s set enabled = :enabled where name in (:userNames)", User.class.getName()); Query query = sessionFactory.getCurrentSession().createQuery(queryString); query.setParameter("enabled", enabled); query.setParameterList("userNames", usernames); query.executeUpdate(); } }); }
From source file:com.thoughtworks.go.server.persistence.OauthRepository.java
License:Apache License
private <T> void deleteEntitiesByUserIds(Class<? extends OauthDomainEntity<T>> type, Session session, List<String> userIds) { Query query = session .createQuery(String.format("DELETE FROM %s WHERE userId IN (:userIds)", type.getSimpleName())); query.setParameterList("userIds", userIds); query.executeUpdate();/*from w w w. j a va2s. c o m*/ }
From source file:com.thoughtworks.go.server.service.ScheduleTestUtil.java
License:Apache License
private List<Modification> modForRev(final RevisionsForMaterial revision) { return (List<Modification>) materialRepository.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query q = session.createQuery("from Modification where revision in (:in) order by id desc"); q.setParameterList("in", revision.revs); List list = q.list(); if (list.isEmpty()) { throw new RuntimeException( "you are trying to load revision " + revision + " which doesn't exist"); }//ww w .j a va 2s.c om return list; } }); }
From source file:com.tw.hibernate.basics.one2many.unidir.ProductTest.java
private void asas(Session session, long threshold, List<Long> license) { // Query query = session.createQuery( // "select lics, count(*) from UserSession as ses " + // " inner join ses.licenses as lics group by lics.id " + // " having lics.id in (:lid) and count(*) < lics.maxUsersForLicense"); Query query = session.createQuery("from License lic where lic.id in ( " + " select licenses.id from UserSession as session " + " inner join session.licenses as licenses " + " group by licenses.id, licenses.maxUsersForLicense " + " having licenses.id in (:licensesIds)" + " and count(*) < licenses.maxUsersForLicense " + ")"); List list = query.setParameterList("licensesIds", license) // .setParameter("threshold", 4l) .list();//from ww w . j ava 2 s . c o m // Object object = uniqueResult; System.out.println("============================ For Lic: " + license + "=== th:" + threshold); for (Object object : list) { // Object[] object2 = (Object[]) object; // System.out.println("============================>" + object.getClass() + ":" + object2[0] + ":" + object2[1]); System.out.println("============================>" + object.getClass() + ":" + object); } System.out.println("============================"); }
From source file:com.ut.healthelink.dao.impl.transactionInDAOImpl.java
/** * The 'getConfigIdsForBatch' function will return a list of configurations for a batch * * @param batchUploadId The id of batch// ww w.ja va2s . c om * @param getAll - get configs for the entire batch or just the ones not in final status * @transactionInId - just get the configId for the transaction * * @return This function will return a list of configIds (Integer) */ @Override @Transactional @SuppressWarnings("unchecked") public List<Integer> getConfigIdsForBatch(int batchUploadId, boolean getAll, Integer transactionInId) { try { Integer id = batchUploadId; String sql = "select distinct configId from transactionTranslatedIn " + " where "; if (transactionInId == 0) { sql = sql + " transactionInId in (select id from transactionIn where batchId = :id "; } else { sql = sql + "( transactionInId = :id "; id = transactionInId; //we don't care about statusId if only one transaction getAll = true; } if (!getAll) { sql = sql + " and statusId not in (:transRELId)"; } sql = sql + ");"; Query query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.setParameter("id", id); if (!getAll) { query.setParameterList("transRELId", transRELId); } List<Integer> configIds = query.list(); return configIds; } catch (Exception ex) { ex.printStackTrace(); System.err.println("clearMessageTableForBatch " + ex.getCause()); return null; } }
From source file:com.ut.healthelink.dao.impl.transactionInDAOImpl.java
@Override @Transactional//from w w w . ja v a 2s . co m @SuppressWarnings("unchecked") public List<Integer> getBlankTransIds(ConfigForInsert config) { String sql = ("select transactionInId from " + " transactionTranslatedIn where (length(CONCAT_WS(''," + config.getSingleValueFields() + ")) = 0 or length(CONCAT_WS(''," + config.getSingleValueFields() + ")) is null) and transactionInId in (select id from transactionIn where statusId in ( :transRELId) " + " and batchId = :batchUploadId" + " and configId = :configId); "); Query query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.setParameter("configId", config.getConfigId()); query.setParameter("batchUploadId", config.getBatchUploadId()); query.setParameterList("transRELId", transRELId); List<Integer> transId = query.list(); return transId; }
From source file:com.ut.healthelink.dao.impl.transactionInDAOImpl.java
/** * errorId = 1 is required field missing* we do not re-check REL records *///from ww w. j a v a 2 s . c o m @Override @Transactional public Integer insertFailedRequiredFields(configurationFormFields cff, Integer batchUploadId, Integer transactionInId) { try { Integer id = batchUploadId; String sql = "insert into transactionInerrors (batchUploadId, configId, transactionInId, fieldNo, errorid)" + "select " + batchUploadId + ", " + cff.getconfigId() + ", transactionInId, " + cff.getFieldNo() + ", 1 from transactionTranslatedIn where configId = :configId " + " and (F" + cff.getFieldNo() + " is null or length(trim(F" + cff.getFieldNo() + ")) = 0" + " or length(REPLACE(REPLACE(F" + cff.getFieldNo() + ", '\n', ''), '\r', '')) = 0)" + "and transactionInId "; if (transactionInId == 0) { sql = sql + " in (select id from transactionIn where batchId = :id and configId = :configId and statusId not in (:transRELId));"; } else { sql = sql + " = :id"; id = transactionInId; } Query insertData = sessionFactory.getCurrentSession().createSQLQuery(sql).setParameter("id", id); insertData.setParameter("configId", cff.getconfigId()); if (transactionInId == 0) { insertData.setParameterList("transRELId", transRELId); } insertData.executeUpdate(); return 0; } catch (Exception ex) { System.err.println("insertFailedRequiredFields " + ex.getCause()); ex.printStackTrace(); return 1; } }
From source file:com.ut.healthelink.dao.impl.transactionInDAOImpl.java
@Override @Transactional//from w ww . j ava 2 s.co m public Integer clearTransactionInErrors(Integer batchUploadId, boolean leaveFinalStatusIds) { try { String sql = "delete from transactionInErrors where batchUploadId = :batchUploadId"; if (leaveFinalStatusIds) { sql = sql + " and transactionInId not in (select id from " + "transactionIn where statusId in (:transRELId) and " + " batchId = :batchUploadId)"; } Query deleteData = sessionFactory.getCurrentSession().createSQLQuery(sql).setParameter("batchUploadId", batchUploadId); if (leaveFinalStatusIds) { deleteData.setParameterList("transRELId", transRELId); } deleteData.executeUpdate(); return 0; } catch (Exception ex) { System.err.println("clearTransactionInErrors " + ex.getCause()); return 1; } }
From source file:com.ut.healthelink.dao.impl.transactionInDAOImpl.java
@Override @Transactional/* w w w .jav a2s .c o m*/ public void updateStatusForErrorTrans(Integer batchId, Integer statusId, boolean foroutboundProcessing, Integer transactionId) { try { String sql; Integer id = batchId; if (foroutboundProcessing == false) { sql = "update transactionIn set statusId = :statusId where" + " id in (select distinct transactionInId from transactionInErrors where "; if (transactionId == 0) { sql = sql + " batchUploadId = :id) and statusId not in (:transRELId); "; } else { sql = sql + " transactionInId = :id);"; } } else { sql = "update transactionTarget set statusId = :statusId where" + " id in (select distinct transactionTargetId from transactionOutErrors where "; if (transactionId == 0) { sql = sql + " batchDownLoadId = :id) and statusId not in (:transRELId); "; } else { sql = sql + " transactionInId = :id);"; } } Query updateData = sessionFactory.getCurrentSession().createSQLQuery(sql).setParameter("id", id) .setParameter("statusId", statusId); if (transactionId == 0) { updateData.setParameterList("transRELId", transRELId); } updateData.executeUpdate(); } catch (Exception ex) { System.err.println("updateStatusForErrorTrans " + ex.getCause()); ex.printStackTrace(); } }