Java Code Examples for org.hibernate.Query#setParameterList()
The following examples show how to use
org.hibernate.Query#setParameterList() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageForumsMessageManagerImpl.java From sakai with Educational Community License v2.0 | 6 votes |
/** * FOR SYNOPTIC TOOL: * Returns the count of discussion forum messages grouped by site for sites with * Forum topics that don't have membership items in the db */ public List<Object []> findDiscussionForumMessageCountsForTopicsWithMissingPermsForAllSites(final List<String> siteList) { if (siteList == null) { log.error("findDiscussionForumMessageCountsForTopicsWithMissingPermsForAllSites failed with null site list."); throw new IllegalArgumentException("Null Argument"); } HibernateCallback<List<Object[]>> hcb = session -> { Query q = session.getNamedQuery("findDiscussionForumMessageCountsForTopicsWithMissingPermsForAllSites"); q.setParameterList("siteList", siteList); q.setString("userId", getCurrentUser()); return q.list(); }; return getHibernateTemplate().execute(hcb); }
Example 2
Source File: MessageForumsMessageManagerImpl.java From sakai with Educational Community License v2.0 | 6 votes |
/** * FOR SYNOPTIC TOOL: * Returns the count of discussion forum messages grouped by site */ public List findDiscussionForumMessageCountsForAllSitesByPermissionLevelName(final List siteList, final List roleList) { if (siteList == null) { log.error("findDiscussionForumMessageCountsForAllSitesByPermissionLevelName failed with null site list."); throw new IllegalArgumentException("Null Argument"); } HibernateCallback<List> hcb = session -> { Query q = session.getNamedQuery("findDiscussionForumMessageCountsForAllSitesByPermissionLevelName"); q.setParameterList("siteList", siteList); q.setParameterList("roleList", roleList); q.setString("userId", getCurrentUser()); q.setString("customTypeUuid", typeManager.getCustomLevelType()); return q.list(); }; return getHibernateTemplate().execute(hcb); }
Example 3
Source File: PrivacyManagerImpl.java From sakai with Educational Community License v2.0 | 6 votes |
private List<PrivacyRecord> getPrivacyByContextAndTypeAndUserIds(final String contextId, final String recordType, final List userIds) { if(contextId == null || recordType == null || userIds == null) { throw new IllegalArgumentException("Null Argument in getPrivacyByContextAndTypeAndUserIds"); } HibernateCallback<List<PrivacyRecord>> hcb = session -> { Query q = session.getNamedQuery(QUERY_BY_CONTEXT__TYPE_IDLIST); q.setString(CONTEXT_ID, contextId); q.setString(RECORD_TYPE, recordType); q.setParameterList("userIds", userIds); return q.list(); }; return getHibernateTemplate().execute(hcb); }
Example 4
Source File: SakaiPersonManagerImpl.java From sakai with Educational Community License v2.0 | 6 votes |
private List<SakaiPerson> listSakaiPersons(final Collection<String> userIds, final Type recordType) { final HibernateCallback hcb = new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Query q = session.getNamedQuery(HQL_FIND_SAKAI_PERSONS_BY_AGENTS_AND_TYPE); q.setParameterList(AGENT_UUID_COLLECTION, userIds); q.setParameter(TYPE_UUID, recordType.getUuid(), StringType.INSTANCE); // q.setCacheable(false); return q.list(); } }; List hb = (List) getHibernateTemplate().execute(hcb); if (photoService.overRidesDefault()) { return getDiskPhotosForList(hb); } else { return hb; } }
Example 5
Source File: PrivacyManagerImpl.java From sakai with Educational Community License v2.0 | 6 votes |
private List<PrivacyRecord> getPrivacyByContextAndTypeAndUserIds(final String contextId, final String recordType, final List userIds) { if(contextId == null || recordType == null || userIds == null) { throw new IllegalArgumentException("Null Argument in getPrivacyByContextAndTypeAndUserIds"); } HibernateCallback<List<PrivacyRecord>> hcb = session -> { Query q = session.getNamedQuery(QUERY_BY_CONTEXT__TYPE_IDLIST); q.setString(CONTEXT_ID, contextId); q.setString(RECORD_TYPE, recordType); q.setParameterList("userIds", userIds); return q.list(); }; return getHibernateTemplate().execute(hcb); }
Example 6
Source File: PermissionLevelManagerImpl.java From sakai with Educational Community License v2.0 | 5 votes |
private List queryWithParameterList(Query query, String queryParamName, List fullList) { // sql has a limit for the size of a parameter list, so we may need to cycle // through with sublists List queryResultList = new ArrayList(); if (fullList.size() < MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST) { query.setParameterList(queryParamName, fullList); queryResultList = query.list(); } else { // if there are more than MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST, we need to do multiple queries int begIndex = 0; int endIndex = 0; while (begIndex < fullList.size()) { endIndex = begIndex + MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST; if (endIndex > fullList.size()) { endIndex = fullList.size(); } List tempSubList = new ArrayList(); tempSubList.addAll(fullList.subList(begIndex, endIndex)); query.setParameterList(queryParamName, tempSubList); queryResultList.addAll(query.list()); begIndex = endIndex; } } return queryResultList; }
Example 7
Source File: MessageForumsForumManagerImpl.java From sakai with Educational Community License v2.0 | 5 votes |
public int getNumModTopicCurrentUserHasModPermForWithPermissionLevelName(final List membershipList) { if (membershipList == null) { log.error("getNumModTopicCurrentUserHasModPermForWithPermissionLevelName failed with membershipList: null"); throw new IllegalArgumentException("Null Argument"); } log.debug("getNumModTopicCurrentUserHasModPermForWithPermissionLevelName executing with membershipItems: " + membershipList); // hibernate will not like an empty list so return 0 if (membershipList.isEmpty()) return 0; HibernateCallback<Number> hcb = session -> { Query q = null; if ("mysql".equals(serverConfigurationService.getString("[email protected]"))) { q = session.createSQLQuery("select straight_join count(*) as NBR " + "from MFR_AREA_T area " + "inner join MFR_OPEN_FORUM_T openforum on openforum.surrogateKey=area.ID inner " + "join MFR_TOPIC_T topic on topic.of_surrogateKey=openforum.ID " + "inner join MFR_MEMBERSHIP_ITEM_T membership on topic.ID=membership.t_surrogateKey, " + "MFR_PERMISSION_LEVEL_T permission " + "where area.CONTEXT_ID = :contextId " + "and topic.MODERATED = true " + "and (membership.NAME in ( :membershipList ) " + "and permission.MODERATE_POSTINGS = true " + "and permission.TYPE_UUID <> :customTypeUuid " + "and permission.NAME=membership.PERMISSION_LEVEL_NAME)"); } else { q = session.getNamedQuery(QUERY_GET_NUM_MOD_TOPICS_WITH_MOD_PERM_BY_PERM_LEVEL_NAME); } q.setParameterList("membershipList", membershipList); q.setString("contextId", getContextId()); q.setString("customTypeUuid", typeManager.getCustomLevelType()); return (Number) q.uniqueResult(); }; return getHibernateTemplate().execute(hcb).intValue(); }
Example 8
Source File: RoleDAOHibImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
/** * Gets all the Authorizations for product Types * * @return The authorizations * @throws EMFUserError * the EMF user error */ @Override public List<SbiAuthorizations> loadAllAuthorizationsByProductTypes(List<Integer> productTypesIds) throws EMFUserError { List functs = new ArrayList(); logger.debug("IN"); Session aSession = null; Transaction tx = null; try { aSession = getSession(); tx = aSession.beginTransaction(); String hql = "select f from SbiAuthorizations f where f.productType.productTypeId IN (:PRODUCT_TYPES)"; Query hqlQuery = aSession.createQuery(hql); hqlQuery.setParameterList("PRODUCT_TYPES", productTypesIds); functs = hqlQuery.list(); tx.commit(); } catch (HibernateException he) { logException(he); if (tx != null) tx.rollback(); throw new EMFUserError(EMFErrorSeverity.ERROR, 100); } finally { if (aSession != null) { if (aSession.isOpen()) aSession.close(); } } logger.debug("OUT"); return functs; }
Example 9
Source File: PermissionLevelManagerImpl.java From sakai with Educational Community License v2.0 | 5 votes |
private List queryWithParameterList(Query query, String queryParamName, List fullList) { // sql has a limit for the size of a parameter list, so we may need to cycle // through with sublists List queryResultList = new ArrayList(); if (fullList.size() < MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST) { query.setParameterList(queryParamName, fullList); queryResultList = query.list(); } else { // if there are more than MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST, we need to do multiple queries int begIndex = 0; int endIndex = 0; while (begIndex < fullList.size()) { endIndex = begIndex + MAX_NUMBER_OF_SQL_PARAMETERS_IN_LIST; if (endIndex > fullList.size()) { endIndex = fullList.size(); } List tempSubList = new ArrayList(); tempSubList.addAll(fullList.subList(begIndex, endIndex)); query.setParameterList(queryParamName, tempSubList); queryResultList.addAll(query.list()); begIndex = endIndex; } } return queryResultList; }
Example 10
Source File: ActionFactory.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** * Delete the server actions associated with the given set of parent actions. * @param parentActions Set of parent actions. */ public static void deleteServerActionsByParent(Set parentActions) { Session session = HibernateFactory.getSession(); Query serverActionsToDelete = session.getNamedQuery("ServerAction.deleteByParentActions"); serverActionsToDelete.setParameterList("actions", parentActions); serverActionsToDelete.executeUpdate(); }
Example 11
Source File: MessageForumsMessageManagerImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * FOR SYNOPTIC TOOL: * Returns the count of discussion forum messages grouped by topics within a site * Used by sites that are grouped */ public List findDiscussionForumReadMessageCountsForGroupedSitesByTopic(final List siteList, final List roleList) { HibernateCallback<List> hcb = session -> { Query q = session.getNamedQuery("findDiscussionForumReadMessageCountsForGroupedSitesByTopic"); q.setParameterList("siteList", siteList); q.setParameterList("roleList", roleList); q.setString("userId", getCurrentUser()); q.setString("customTypeUuid", typeManager.getCustomLevelType()); return q.list(); }; return getHibernateTemplate().execute(hcb); }
Example 12
Source File: AssessmentGradingFacadeQueries.java From sakai with Educational Community License v2.0 | 5 votes |
private Map<Long, Set<ItemGradingAttachment>> getItemGradingAttachmentMap(final Set itemGradingIds) { final HibernateCallback<List<ItemGradingAttachment>> hcb = session -> { Query q = session.createQuery( "from ItemGradingAttachment a where a.itemGrading.itemGradingId in (:itemGradingIds)"); q.setParameterList("itemGradingIds", itemGradingIds); return q.list(); }; Set<ItemGradingAttachment> itemGradingAttachmentList = new HashSet<>(getHibernateTemplate().execute(hcb)); return processItemGradingAttachment(itemGradingAttachmentList); }
Example 13
Source File: AnonymousManagerImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Gets a list of AnonymousMapping objects from the database for the specified users in the specified site. */ private List<AnonymousMapping> findMappingsBySiteAndUsers(final String siteId, final List<String> userIds) { if (CollectionUtils.isEmpty(userIds)) { return Collections.emptyList(); } HibernateCallback<List<AnonymousMapping>> hcb = new HibernateCallback<List<AnonymousMapping>>() { public List<AnonymousMapping> doInHibernate(Session session) throws HibernateException { List<AnonymousMapping> mappings = new ArrayList<>(); // be mindful of Oracle's 1000 in clause limit int minUser = 0; int maxUser = Math.min(userIds.size(), MAX_IN_CLAUSE_SIZE); while (minUser < userIds.size()) { Query q = session.getNamedQuery(QUERY_BY_SITE_AND_USERS); q.setParameter("siteId", siteId, StringType.INSTANCE); q.setParameterList("userIds", userIds.subList(minUser, maxUser)); mappings.addAll(q.list()); minUser += MAX_IN_CLAUSE_SIZE; maxUser = Math.min(userIds.size(), minUser + MAX_IN_CLAUSE_SIZE); } return mappings; } }; return getHibernateTemplate().execute(hcb); }
Example 14
Source File: AnonymousManagerImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Gets a list of AnonymousMapping objects from the database for the specified users in the specified site. */ private List<AnonymousMapping> findMappingsBySiteAndUsers(final String siteId, final List<String> userIds) { if (CollectionUtils.isEmpty(userIds)) { return Collections.emptyList(); } HibernateCallback<List<AnonymousMapping>> hcb = new HibernateCallback<List<AnonymousMapping>>() { public List<AnonymousMapping> doInHibernate(Session session) throws HibernateException { List<AnonymousMapping> mappings = new ArrayList<>(); // be mindful of Oracle's 1000 in clause limit int minUser = 0; int maxUser = Math.min(userIds.size(), MAX_IN_CLAUSE_SIZE); while (minUser < userIds.size()) { Query q = session.getNamedQuery(QUERY_BY_SITE_AND_USERS); q.setParameter("siteId", siteId, StringType.INSTANCE); q.setParameterList("userIds", userIds.subList(minUser, maxUser)); mappings.addAll(q.list()); minUser += MAX_IN_CLAUSE_SIZE; maxUser = Math.min(userIds.size(), minUser + MAX_IN_CLAUSE_SIZE); } return mappings; } }; return getHibernateTemplate().execute(hcb); }
Example 15
Source File: GenericDaoImpl.java From olat with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private <K> List<K> getQueryList(String queryName, Map<String, Object> queryParameters) { Query query = getNamedQuery(queryName); for (String key : queryParameters.keySet()) { /** TODO: REVIEW PUBLISH PERFORMANCE (used general solution when parameter is collection): bb/11.03.2012 **/ if (queryParameters.get(key) instanceof Collection) { if (!((Collection<T>) queryParameters.get(key)).isEmpty()) { query.setParameterList(key, ((Collection<T>) queryParameters.get(key))); } } else { query.setParameter(key, queryParameters.get(key)); } } return query.list(); }
Example 16
Source File: StatsManagerImpl.java From sakai with Educational Community License v2.0 | 4 votes |
public int getEventStatsRowCount( final String siteId, final List<String> events, final Date iDate, final Date fDate, final List<String> userIds, final boolean inverseUserSelection, final List<String> totalsBy) { final Set<String> anonymousEvents = eventRegistryService.getAnonymousEventIds(); StatsSqlBuilder sqlBuilder = new StatsSqlBuilder(getDbVendor(), Q_TYPE_EVENT, totalsBy, siteId, events, anonymousEvents, showAnonymousAccessEvents, null, null, iDate, fDate, userIds, inverseUserSelection, null, true); final String hql = sqlBuilder.getHQL(); final Map<Integer,Integer> columnMap = sqlBuilder.getHQLColumnMap(); // DO IT! HibernateCallback<Integer> hcb = session -> { Query q = session.createQuery(hql); if(siteId != null){ q.setString("siteid", siteId); } if(events != null && !events.isEmpty()){ q.setParameterList("events", events); } if(userIds != null && !userIds.isEmpty()) { if(userIds.size() <= 1000) { q.setParameterList("users", userIds); }else{ int nUsers = userIds.size(); int blockId = 0, startIndex = 0; int blocks = (int) (nUsers / 1000); blocks = (blocks*1000 == nUsers) ? blocks : blocks+1; for(int i=0; i<blocks-1; i++) { q.setParameterList("users"+blockId, userIds.subList(startIndex, startIndex+1000)); blockId++; startIndex += 1000; } q.setParameterList("users"+blockId, userIds.subList(startIndex, nUsers)); } } if(iDate != null) q.setDate("idate", iDate); if(fDate != null){ // adjust final date Calendar c = Calendar.getInstance(); c.setTime(fDate); c.add(Calendar.DAY_OF_YEAR, 1); Date fDate2 = c.getTime(); q.setDate("fdate", fDate2); } if(columnMap.containsKey(StatsSqlBuilder.C_USER) && anonymousEvents != null && anonymousEvents.size() > 0){ q.setParameterList("anonymousEvents", anonymousEvents); } log.debug("getEventStatsRowCount(): " + q.getQueryString()); Integer rowCount = q.list().size(); if(!inverseUserSelection){ return rowCount; }else{ return getSiteUsers(siteId).size() - rowCount; } }; return getHibernateTemplate().execute(hcb); }
Example 17
Source File: StatisticsReportingStorage.java From sailfish-core with Apache License 2.0 | 4 votes |
@Override public Map<Long, List<ActionInfoRow>> generateTestCasesFailedActionsInfo(AggregateReportParameters params) { if (params.getTestCaseRunIds() == null || params.getTestCaseRunIds().isEmpty()) { return Collections.emptyMap(); } String queryString = "select " + "TCR.id, " + "AR.rank, " + "AR.description, " + "AR.failReason, " + "A.name, " + "M.name, " + "S.name, " + "AR.tag, " + "AR.status, " + "AR.hash " + "from ActionRun as AR " + "join AR.tcRun as TCR " + "left join AR.action as A " + "left join AR.service as S " + "left join AR.msgType as M " + "where TCR.id in (:tcrIds) and AR.status = 0 " + "order by AR.rank"; Session session = sessionFactory.openSession(); try (AutoCloseable ignore = session::close) { Query query = session.createQuery(queryString); query.setParameterList("ids", params.getTestCaseRunIds()); @SuppressWarnings("unchecked") List<Object[]> resultList = query.list(); Map<Long, List<ActionInfoRow>> testCaseToActionInfo = new HashMap<>(); for (Object[] resultRow : resultList) { Long tcrId = (Long) resultRow[0]; long rank = (long) resultRow[1]; //TODO: Remove escaping after release 3.1, because escaping is executed on save data String description = StringEscapeUtils.escapeEcmaScript((String) resultRow[2]); String failReason = (String) resultRow[3]; String actionName = (String) resultRow[4]; String msgType = (String) resultRow[5]; String service = (String) resultRow[6]; String tag = (String) resultRow[7]; Integer status = (Integer) resultRow[8]; Integer hash = (Integer) resultRow[9]; testCaseToActionInfo.computeIfAbsent(tcrId, id -> new ArrayList<>()) .add(new ActionInfoRow(rank, description, failReason, actionName, msgType, service, tag, status, hash)); } return testCaseToActionInfo; } catch (Exception e) { throw new EPSCommonException(e); } }
Example 18
Source File: RoleDAOHibImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
@Override public Integer insertRoleComplete(Role role) throws EMFUserError { Session aSession = null; Transaction tx = null; Integer roleId = null; try { aSession = getSession(); tx = aSession.beginTransaction(); // if new role is public check there are no other public otherwise unset them if (role.getIsPublic() != null && role.getIsPublic() == true) { unsetOtherPublicRole(aSession); } SbiExtRoles hibRole = new SbiExtRoles(); hibRole.setCode(role.getCode()); hibRole.setDescr(role.getDescription()); hibRole.setName(role.getName()); hibRole.setIsPublic(role.getIsPublic()); SbiDomains roleType = (SbiDomains) aSession.load(SbiDomains.class, role.getRoleTypeID()); hibRole.setRoleType(roleType); hibRole.setRoleTypeCode(role.getRoleTypeCD()); HashSet<SbiAuthorizationsRoles> functs = new HashSet<SbiAuthorizationsRoles>(); updateSbiCommonInfo4Insert(hibRole); roleId = (Integer) aSession.save(hibRole); aSession.flush(); // abilitations // ----------------------------------------- // 1 - get Product Types of this tenant String tenant = this.getTenant(); if (tenant == null) { throw new SpagoBIRuntimeException("Organization not set!!!"); } // Get corresponding Product Type Id for role's tenant Set<Integer> productTypesId = findProductTypesId(aSession, tenant); // ------------------------ // 2 - Get only the authorizations of the product types of the // tenant String hqlall = "from SbiAuthorizations aut where aut.productType.productTypeId IN (:PRODUCT_TYPES)"; Query hqlQueryAll = aSession.createQuery(hqlall); hqlQueryAll.setParameterList("PRODUCT_TYPES", productTypesId); List<SbiAuthorizations> allFunct = hqlQueryAll.list(); Iterator allFunIt = allFunct.iterator(); while (allFunIt.hasNext()) { SbiAuthorizations functI = (SbiAuthorizations) allFunIt.next(); if (isAbleTo(role, functI)) { SbiAuthorizationsRoles fr = new SbiAuthorizationsRoles(); SbiAuthorizationsRolesId id = new SbiAuthorizationsRolesId(functI.getId(), hibRole.getExtRoleId()); fr.setId(id); updateSbiCommonInfo4Insert(fr); aSession.save(fr); functs.add(fr); } } aSession.flush(); hibRole.setSbiAuthorizationsRoleses(functs); aSession.save(hibRole); tx.commit(); } catch (HibernateException he) { logException(he); if (tx != null) tx.rollback(); throw new EMFUserError(EMFErrorSeverity.ERROR, 100); } finally { if (aSession != null) { if (aSession.isOpen()) { aSession.close(); logger.debug("OUT"); this.clearCache(); } } } return roleId; }
Example 19
Source File: DataSetDAOImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
/** * @param scope Sent from DatasetResource <br> * Can be: "all", "owned", "enterprise" and "shared", depends on Tab from Workspace/Datasets (MyDataset, Shared, Enterprise, All) */ @Override public List<IDataSet> loadDatasetsByTags(UserProfile user, List<Integer> tagIds, String scope) { logger.debug("IN"); List<IDataSet> toReturn = new ArrayList<>(); Session session = null; Set<Domain> categoryList = null; String owner = null; String domain = null; String[] domains = null; try { Assert.assertNotNull(user, "UserProfile object cannot be null"); StringBuffer statement = new StringBuffer("select distinct(dst.dataSet) from SbiDatasetTag dst where dst.dataSet.active = ? "); if (scope.equalsIgnoreCase("owned") || scope.equalsIgnoreCase("shared")) { owner = user.getUserId().toString(); if (owner != null) { if (scope.equalsIgnoreCase("owned")) statement.append("and dst.dataSet.owner = :owner "); else statement.append("and dst.dataSet.owner != :owner "); } } if (scope.equalsIgnoreCase("enterprise") || scope.equalsIgnoreCase("shared") || scope.equalsIgnoreCase("all")) { statement.append("and dst.dataSet.scope.valueCd = :domain "); if (scope.equalsIgnoreCase("enterprise")) domain = scope.toUpperCase(); else if (scope.equalsIgnoreCase("shared")) domain = "USER"; else { domains = new String[2]; domains[0] = "USER"; domains[1] = "ENTERPRISE"; statement.append("and (dst.dataSet.scope.valueCd = :user or dst.dataSet.scope.valueCd = :enterprise) "); } categoryList = UserUtilities.getDataSetCategoriesByUser(user); if (categoryList != null && !categoryList.isEmpty()) { statement.append("and dst.dataSet.category.valueCd in (:categories) "); } } if (!tagIds.isEmpty()) { statement.append("and dst.dsTagId.tagId in (:tagIds)"); } session = getSession(); Query query = session.createQuery(statement.toString()); // Always get active versions query.setBoolean(0, true); if (owner != null) { query.setString("owner", owner); } if (domain != null) query.setString("domain", domain); if (domains != null && domains.length > 0) { query.setString("user", domains[0]); query.setString("enterprise", domains[1]); } if (categoryList != null && !categoryList.isEmpty()) { Iterator<Domain> it = categoryList.iterator(); List<String> categoryValues = new ArrayList<>(); while (it.hasNext()) { categoryValues.add(it.next().getValueName()); } query.setParameterList("categories", categoryValues); } if (!tagIds.isEmpty()) { query.setParameterList("tagIds", tagIds); } toReturn = executeQuery(query, session); } catch (Exception e) { logger.error("An error has occured while filtering Enterprise Datasets by Tags", e); throw new SpagoBIDAOException("An unexpected error has occured while filtering Datasets by Tags", e); } finally { if (session != null && session.isOpen()) session.close(); } logger.debug("OUT"); return toReturn; }
Example 20
Source File: StatsManagerImpl.java From sakai with Educational Community License v2.0 | 4 votes |
public int getResourceStatsRowCount( final String siteId, final String resourceAction, final List<String> resourceIds, final Date iDate, final Date fDate, final List<String> userIds, final boolean inverseUserSelection, final List<String> totalsBy) { StatsSqlBuilder sqlBuilder = new StatsSqlBuilder(getDbVendor(), Q_TYPE_RESOURCE, totalsBy, siteId, (Set<String>)null, null, showAnonymousAccessEvents, resourceAction, resourceIds, iDate, fDate, userIds, inverseUserSelection, null, true); final String hql = sqlBuilder.getHQL(); HibernateCallback<Integer> hcb = session -> { Query q = session.createQuery(hql); if(siteId != null){ q.setString("siteid", siteId); } if(userIds != null && !userIds.isEmpty()) { if(userIds.size() <= 1000) { q.setParameterList("users", userIds); }else{ int nUsers = userIds.size(); int blockId = 0, startIndex = 0; int blocks = (int) (nUsers / 1000); blocks = (blocks*1000 == nUsers) ? blocks : blocks+1; for(int i=0; i<blocks-1; i++) { q.setParameterList("users"+blockId, userIds.subList(startIndex, startIndex+1000)); blockId++; startIndex += 1000; } q.setParameterList("users"+blockId, userIds.subList(startIndex, nUsers)); } } if(resourceAction != null) q.setString("action", resourceAction); if(resourceIds != null && !resourceIds.isEmpty()) q.setParameterList("resources", resourceIds); if(iDate != null) q.setDate("idate", iDate); if(fDate != null){ // adjust final date Calendar c = Calendar.getInstance(); c.setTime(fDate); c.add(Calendar.DAY_OF_YEAR, 1); Date fDate2 = c.getTime(); q.setDate("fdate", fDate2); } log.debug("getEventStatsRowCount(): " + q.getQueryString()); Integer rowCount = q.list().size(); if(!inverseUserSelection){ return rowCount; }else{ return getSiteUsers(siteId).size() - rowCount; } }; return getHibernateTemplate().execute(hcb); }