List of usage examples for org.hibernate Query setParameterList
Query<R> setParameterList(int position, Object[] values);
From source file:com.ephesoft.dcma.performance.reporting.service.ReportDataServiceImpl.java
License:Open Source License
/** * Method to get Reports Per page for a User for a specified time. * //from ww w .java2 s .co m * @param batchClassIds List<{@link String}>, Batch Class Ids for which the report data needs to be fetched * @param userName {@link String}, User name for which the report are to be fetched * @param endTime {@link Date}, Date upto which the reporting data needs to be fetched * @param startTime {@link Date}, Starting Date from which the reporting data needs to be fetched * @param StartIndex int, Start Index for pagination * @param range int, Number of records per page * @param order {@link Order}, By field * @return List<{@link ReportDisplayData}>, List of RepoertDisplayData DTOs * @throws DCMAException if error occurs in database creation */ @SuppressWarnings("unchecked") public List<ReportDisplayData> getReportByUser(List<String> batchClassIds, String userName, Date endTime, Date startTime, int StartIndex, int range, Order order) throws DCMAException { Connection connection = null; Query qry = null; List<ReportDisplayData> resultList = null; try { connection = dynamicHibernateDao.getConnectionProvider().getConnection(); StatelessSession session = dynamicHibernateDao.getStatelessSession(connection); if (userName.equalsIgnoreCase(ReportingConstants.ALL)) { qry = session.getNamedQuery(ReportingConstants.GET_REPORT_FOR_ALL_USERS); } else { qry = session.getNamedQuery(ReportingConstants.GET_REPORT_BY_USER_NAME); qry.setParameter(ReportingConstants.USER_NAME, userName); } qry.setResultTransformer(Transformers.aliasToBean(ReportDisplayData.class)); qry.setParameterList(ReportingConstants.BATCH_CLASS_ID_LIST, batchClassIds); // Adding 1 Day in the End Time to show all the records for that Day Calendar calendar = Calendar.getInstance(); calendar.setTime(endTime); calendar.add(Calendar.DATE, 1); qry.setParameter(ReportingConstants.END_TIME, new java.sql.Date(calendar.getTimeInMillis())); qry.setParameter(ReportingConstants.START_TIME, new java.sql.Date(startTime.getTime())); qry.setParameter(ReportingConstants.START_INDEX, StartIndex); qry.setParameter(ReportingConstants.RANGE, range); resultList = qry.list(); } catch (SQLException e) { LOGGER.error(ERROR_CREATING_DATABASE_CONNECTION + e.getMessage(), e); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { LOGGER.error(ERROR_CLOSING_DATABASE_CONNECTION + e.getMessage(), e); } } } return resultList; }
From source file:com.ephesoft.dcma.performance.reporting.service.ReportDataServiceImpl.java
License:Open Source License
/** * Method to get total records for a WorkflowType for a specified time. * /*from ww w .ja v a 2s . c o m*/ * @param batchClassIds List<{@link String}>, Batch Class Ids for which the report data needs to be fetched * @param workflowType {@link WorkflowType}, One of Module , Plugin or Workflow specifying the type of filter * @param endTime {@link Date}, Date upto which the reporting data needs to be fetched * @param startTime {@link Date}, Starting Date from which the reporting data needs to be fetched * @return Total {@link Integer}, Record count for the crtieria parameters * @throws DCMAException if error occurs in database creation */ public Integer getReportTotalRowCountByWorkflow(List<String> batchClassIds, WorkflowType workflowType, Date endTime, Date startTime) throws DCMAException { Connection connection = null; Integer finalResult = 0; try { connection = dynamicHibernateDao.getConnectionProvider().getConnection(); StatelessSession session = dynamicHibernateDao.getStatelessSession(connection); Query qry = session.getNamedQuery(ReportingConstants.GET_TOTAL_ROW_COUNT_BY_WORKFLOW); qry.setParameterList(ReportingConstants.BATCH_CLASS_ID_LIST, batchClassIds); // Adding 1 Day in the End Time to show all the records for that Day Calendar calendar = Calendar.getInstance(); calendar.setTime(endTime); calendar.add(Calendar.DATE, 1); qry.setParameter(ReportingConstants.END_TIME, new java.sql.Date(calendar.getTimeInMillis())); qry.setParameter(ReportingConstants.START_TIME, new java.sql.Date(startTime.getTime())); qry.setParameter(ReportingConstants.WORK_FLOW_TYPE, workflowType.name()); List<?> results = qry.list(); if (results != null) { finalResult = (Integer) results.get(0); } } catch (SQLException e) { LOGGER.error(ERROR_CREATING_DATABASE_CONNECTION + e.getMessage(), e); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { LOGGER.error(ERROR_CLOSING_DATABASE_CONNECTION + e.getMessage(), e); } } } return finalResult; }
From source file:com.ephesoft.dcma.performance.reporting.service.ReportDataServiceImpl.java
License:Open Source License
/** * Method to get total records for a User for a specified time. * /*w w w.j a v a 2 s . c om*/ * @param batchClassIds List<{@link String}>, Batch Class Ids for which the report data needs to be fetched * @param userName {@link String}, User name for which the report are to be fetched * @param endTime {@link Date}, Date upto which the reporting data needs to be fetched * @param startTime {@link Date}, Starting Date from which the reporting data needs to be fetched * @return Total {@link Integer}, Record count for the crtieria parameters * @throws DCMAException if error occurs in database creation */ public Integer getReportTotalRowCountByUser(List<String> batchClassIds, String userName, Date endTime, Date startTime) throws DCMAException { Connection connection = null; Integer finalResult = 0; try { connection = dynamicHibernateDao.getConnectionProvider().getConnection(); StatelessSession session = dynamicHibernateDao.getStatelessSession(connection); Query qry; if (userName.equalsIgnoreCase(ReportingConstants.ALL)) { qry = session.getNamedQuery(ReportingConstants.GET_TOTAL_ROW_COUNT_BY_ALL_USERS); } else { qry = session.getNamedQuery(ReportingConstants.GET_TOTAL_ROW_COUNT_BY_USER_NAME); qry.setParameter(ReportingConstants.USER_NAME, userName); } qry.setParameterList(ReportingConstants.BATCH_CLASS_ID_LIST, batchClassIds); // Adding 1 Day in the End Time to show all the records for that Day Calendar calendar = Calendar.getInstance(); calendar.setTime(endTime); calendar.add(Calendar.DATE, 1); qry.setParameter(ReportingConstants.END_TIME, new java.sql.Date(calendar.getTimeInMillis())); qry.setParameter(ReportingConstants.START_TIME, new java.sql.Date(startTime.getTime())); List<?> results = qry.list(); finalResult = 0; if (results != null && (!results.isEmpty())) { finalResult = (Integer) results.get(0); } } catch (SQLException e) { LOGGER.error(ERROR_CREATING_DATABASE_CONNECTION + e.getMessage(), e); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { LOGGER.error(ERROR_CLOSING_DATABASE_CONNECTION + e.getMessage(), e); } } } return finalResult; }
From source file:com.evolveum.midpoint.repo.sql.helpers.NameResolutionHelper.java
License:Apache License
public <C extends Containerable> void resolveNamesIfRequested(Session session, PrismContainerValue<C> containerValue, Collection<SelectorOptions<GetOperationOptions>> options) { GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options); if (GetOperationOptions.isResolveNames(rootOptions)) { final List<String> oidsToResolve = new ArrayList<>(); Visitor oidExtractor = new Visitor() { @Override// www . j av a2 s . co m public void visit(Visitable visitable) { if (visitable instanceof PrismReferenceValue) { PrismReferenceValue value = (PrismReferenceValue) visitable; if (value.getTargetName() != null) { // just for sure return; } if (value.getObject() != null) { // improbable but possible value.setTargetName(value.getObject().getName()); return; } if (value.getOid() == null) { // shouldn't occur as well return; } oidsToResolve.add(value.getOid()); } } }; containerValue.accept(oidExtractor); if (!oidsToResolve.isEmpty()) { Query query = session.getNamedQuery("resolveReferences"); query.setParameterList("oid", oidsToResolve); query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); List<Map<String, Object>> results = query.list(); final Map<String, PolyString> oidNameMap = consolidateResults(results); Visitor nameSetter = new Visitor() { @Override public void visit(Visitable visitable) { if (visitable instanceof PrismReferenceValue) { PrismReferenceValue value = (PrismReferenceValue) visitable; if (value.getTargetName() == null && value.getOid() != null) { value.setTargetName(oidNameMap.get(value.getOid())); } } } }; containerValue.accept(nameSetter); } } }
From source file:com.evolveum.midpoint.repo.sql.helpers.ObjectRetriever.java
License:Apache License
public boolean isAnySubordinateAttempt(String upperOrgOid, Collection<String> lowerObjectOids) { Session session = null;/*from w w w . j av a2s . c o m*/ try { session = baseHelper.beginReadOnlyTransaction(); Query query; if (lowerObjectOids.size() == 1) { query = session.getNamedQuery("isAnySubordinateAttempt.oneLowerOid"); query.setString("dOid", lowerObjectOids.iterator().next()); } else { query = session.getNamedQuery("isAnySubordinateAttempt.moreLowerOids"); query.setParameterList("dOids", lowerObjectOids); } query.setString("aOid", upperOrgOid); Number number = (Number) query.uniqueResult(); session.getTransaction().commit(); return number != null && number.longValue() != 0L; } catch (RuntimeException ex) { baseHelper.handleGeneralException(ex, session, null); } finally { baseHelper.cleanupSessionAndResult(session, null); } throw new SystemException("isAnySubordinateAttempt failed somehow, this really should not happen."); }
From source file:com.evolveum.midpoint.repo.sql.helpers.OrgClosureManager.java
License:Apache License
private List<String> retainExistingOids(Collection<String> oids, Session session) { if (!oids.isEmpty()) { Query query = session.createQuery("select o.oid from RObject o where o.oid in (:oids)"); query.setParameterList("oids", oids); return query.list(); } else {/* ww w .ja v a 2 s. c o m*/ return new ArrayList<String>(); } }
From source file:com.example.app.model.company.LocationDAO.java
License:Open Source License
/** * Set the status of the specified locations. * * @param locations the locations to update * @param status the new status/* ww w. j a v a2s . com*/ */ public void setLocationStatus(final Collection<? extends Location> locations, final LocationStatus status) { doInTransaction(session -> { final String hql = "update " + Location.class.getName() + " location" + " set location." + Location.STATUS_PROP + " = :status" + " where location in :locations"; final Query query = session.createQuery(hql); query.setParameter("status", status); query.setParameterList("locations", locations.stream().map(Location::getId).toArray(Integer[]::new)); query.executeUpdate(); }); }
From source file:com.example.app.model.profile.ProfileDAO.java
License:Open Source License
/** * Test if the specified user can perform all the operations on any of the specified profiles. * * @param user the User.//from w w w. ja v a 2 s .co m * @param profiles the Profiles. * @param timeZone the timezone. * @param operations the MembershipOperations to check * * @return true or false. */ @Contract("null,_,_->false") public boolean canOperate(@Nullable User user, @Nonnull Collection<Profile> profiles, TimeZone timeZone, @Nonnull MembershipOperation... operations) { if (user == null || profiles.isEmpty()) return false; final Date now = convertForPersistence(getZonedDateTimeForComparison(timeZone)); Preconditions.checkArgument(operations.length > 0); final Query query = getSession().createQuery("SELECT COUNT(m) FROM Membership m INNER JOIN m.profile p\n" + " INNER JOIN m.operations op\n" + " WHERE m.user = :user\n" + " AND p IN (:profiles)\n" + " AND op IN (:operations)\n" + " AND (m.startDate IS NULL OR m.startDate <= :today)\n" + " AND (m.endDate IS NULL OR m.endDate >= :today)\n" + " GROUP BY m\n" + " HAVING COUNT(op) = :operationCount"); query.setCacheable(true).setCacheRegion(ProjectCacheRegions.PROFILE_QUERY); query.setParameter("user", user); query.setParameterList("profiles", profiles); query.setParameterList("operations", operations); query.setParameter("today", now); query.setInteger("operationCount", operations.length); return Optional.ofNullable(((Number) query.uniqueResult())).map(Number::intValue).map(i -> i > 0) .orElse(false); }
From source file:com.example.app.model.profile.ProfileDAO.java
License:Open Source License
/** * Returns a boolean flag on whether or not the given User can perform the given MembershipOperation on the given Profile * * @param user the User, may be null/*from w w w . ja v a 2 s . c o m*/ * @param profileType the ProfileType. * @param operations the MembershipOperations to check * @param timeZone the timezone. * * @return a boolean flag. If true, the given user can perform the given operation on the given profile */ public boolean canOperate(@Nullable User user, @Nullable ProfileType profileType, TimeZone timeZone, MembershipOperation... operations) { if (user == null || profileType == null) return false; Preconditions.checkArgument(operations.length > 0); final Date now = convertForPersistence(getZonedDateTimeForComparison(timeZone)); final Query query = getSession().createQuery( "SELECT COUNT(m) FROM Membership m INNER JOIN m.profile p INNER JOIN p.profileType pt\n" + " INNER JOIN m.operations op\n" + " WHERE m.user = :user\n" + " AND pt.id = :profileTypeId\n" + " AND op IN (:operations)\n" + " AND (m.startDate IS NULL OR m.startDate <= :today)\n" + " AND (m.endDate IS NULL OR m.endDate >= :today)\n" + " GROUP BY m\n" + " HAVING COUNT(op) = :operationCount"); query.setCacheable(true).setCacheRegion(ProjectCacheRegions.PROFILE_QUERY); query.setParameter("user", user); query.setParameter("profileTypeId", profileType.getId()); query.setParameterList("operations", operations); query.setParameter("today", now); query.setInteger("operationCount", operations.length); return Optional.ofNullable(((Number) query.uniqueResult())).map(Number::intValue).map(i -> i > 0) .orElse(false); }
From source file:com.example.app.model.repository.RepositoryDAO.java
License:Open Source License
/** * Get a list of RepositoryItems from the given list of Repositories, filtered by the given RepositoryItem subclass * * @param <RI> the RepositoryItem subclass * @param repos the repositories to retrieve the items from * @param clazz the RepositoryItem subclass to filter by * @param statuses optional statuses.// www.j a v a 2 s . c om * * @return a list of all RepositoryItemRelations for the given repos, subclass combination */ public <RI extends RepositoryItem> List<RI> getRepositoryItems(@Nonnull List<Repository> repos, @Nonnull Class<RI> clazz, @Nullable RepositoryItemStatus... statuses) { boolean hasStatuses = statuses != null && statuses.length > 0; String hql = "SELECT DISTINCT ri\n" + "FROM RepositoryItemRelation repositoryItemRelation,\n" + " " + clazz.getName() + " ri\n" + "WHERE repositoryItemRelation.repository.id IN (:repoIds)\n" + "AND repositoryItemRelation.repositoryItem.id = ri.id\n" + (hasStatuses ? "AND ri.status IN (:statuses)" : "") + " ORDER BY ri.createTime ASC \n"; Query query = getSession().createQuery(hql) .setParameterList("repoIds", repos.stream().map(Repository::getId).collect(Collectors.toList())) .setCacheable(true).setCacheRegion(ProjectCacheRegions.ENTITY_QUERY); if (hasStatuses) query.setParameterList("statuses", statuses); @SuppressWarnings("unchecked") List<RI> list = query.list(); return list; }