List of usage examples for org.hibernate Query setDate
@Deprecated @SuppressWarnings("unchecked") default Query<R> setDate(String name, Date val)
From source file:org.egov.wtms.application.service.DailyWTCollectionReportService.java
License:Open Source License
@ReadOnly public List<DailyWTCollectionReport> getCollectionDetails(final Date fromDate, final Date toDate, final String collectionMode, final String collectionOperator, final String status) throws ParseException { final StringBuilder queryStr = new StringBuilder(500); queryStr.append(//ww w .j a v a 2s. c o m "select distinct receiptheader from ReceiptHeader receiptheader inner join fetch receiptheader.receiptInstrument instHeader" + " inner join fetch instHeader.instrumentType instType where receiptheader.service.name =:service and (receiptdate between :fromDate and :toDate) "); if (StringUtils.isNotBlank(collectionMode)) queryStr.append(" and receiptheader.source =:mode "); if (StringUtils.isNotBlank(collectionOperator)) queryStr.append(" and receiptheader.createdBy.id =:operator "); if (StringUtils.isNotBlank(status)) queryStr.append(" and receiptheader.status.id =:status "); queryStr.append(" order by instHeader "); final Query query = getCurrentSession().createQuery(queryStr.toString()); query.setString("service", WaterTaxConstants.EGMODULES_NAME); query.setDate("fromDate", new DateTime(fromDate).withTimeAtStartOfDay().toDate()); query.setDate("toDate", new DateTime(toDate).plusDays(1).toDate()); if (StringUtils.isNotBlank(collectionMode)) query.setString("mode", collectionMode); if (StringUtils.isNotBlank(collectionOperator)) query.setLong("operator", Long.valueOf(collectionOperator)); if (StringUtils.isNotBlank(status)) query.setLong("status", Long.valueOf(status)); final List<ReceiptHeader> receiptHeaderList = query.list(); final List<DailyWTCollectionReport> dailyWTCollectionReportList = new ArrayList<DailyWTCollectionReport>(0); for (final ReceiptHeader receiptHeader : receiptHeaderList) { BigDecimal currCollection = BigDecimal.ZERO; BigDecimal arrCollection = BigDecimal.ZERO; final DailyWTCollectionReport result = new DailyWTCollectionReport(); result.setReceiptNumber(receiptHeader.getReceiptnumber()); result.setReceiptDate(receiptHeader.getReceiptdate()); result.setConsumerCode(receiptHeader.getConsumerCode()); result.setConsumerName(receiptHeader.getPayeeName()); result.setPaidAt(receiptHeader.getSource()); final WaterConnectionDetails waterConnection = waterConnectionDetailsService .findByApplicationNumberOrConsumerCode(receiptHeader.getConsumerCode()); if (null != waterConnection) result.setConnectionType(waterConnection.getConnectionType().toString()); final StringBuilder queryString = new StringBuilder(); queryString.append( "select wardboundary.name as \"wardName\",dcbinfo.houseno as \"houseNo\" from egwtr_mv_dcb_view dcbinfo" + " INNER JOIN eg_boundary wardboundary on dcbinfo.wardid = wardboundary.id where dcbinfo.hscno = '" + receiptHeader.getConsumerCode() + "'"); final SQLQuery finalQuery = getCurrentSession().createSQLQuery(queryString.toString()); finalQuery.setResultTransformer(new AliasToBeanResultTransformer(DefaultersReport.class)); List<DefaultersReport> listforWardAndHsc = new ArrayList<DefaultersReport>(); listforWardAndHsc = finalQuery.list(); if (!listforWardAndHsc.isEmpty()) { result.setDoorNumber(listforWardAndHsc.get(0).getHouseNo()); result.setWardName(listforWardAndHsc.get(0).getWardName()); } result.setTotal(receiptHeader.getTotalAmount()); result.setStatus(receiptHeader.getStatus().getDescription()); if ("CANCELLED".equalsIgnoreCase(receiptHeader.getStatus().getCode())) result.setCancellationDetails(receiptHeader.getReasonForCancellation()); else result.setCancellationDetails("N/A"); final StringBuilder paymentMode = new StringBuilder(30); int count = 0; for (final InstrumentHeader instrument : receiptHeader.getReceiptInstrument()) { final int instrumentSize = receiptHeader.getReceiptInstrument().size(); paymentMode.append(instrument.getInstrumentType().getType()); if (instrumentSize > 1 && count < instrumentSize - 1) { paymentMode.append(","); count++; } } result.setPaidAt(receiptHeader.getSource()); result.setPaymentMode(paymentMode.toString()); final List<ReceiptDetail> receiptDetailsList = new ArrayList<ReceiptDetail>( receiptHeader.getReceiptDetails()); final int lastindex = receiptDetailsList.size() - 2; if (null != receiptDetailsList.get(0).getDescription()) { final int index = receiptDetailsList.get(0).getDescription().indexOf("-"); final int hashIndex = receiptDetailsList.get(0).getDescription().indexOf("#"); final String instDesc = receiptDetailsList.get(0).getDescription().substring(index + 1, hashIndex); result.setFromInstallment(instDesc); } if (null != receiptDetailsList.get(lastindex).getDescription()) { final int index = receiptDetailsList.get(lastindex).getDescription().indexOf("-"); final int hashIndex = receiptDetailsList.get(lastindex).getDescription().indexOf("#"); final String instDesc = receiptDetailsList.get(lastindex).getDescription().substring(index + 1, hashIndex); result.setToInstallment(instDesc); } for (final ReceiptDetail receiptDetail : receiptHeader.getReceiptDetails()) { final String rdesc = receiptDetail.getDescription(); if (null != rdesc) { final String receiptDmdRsnDesc = rdesc.substring(0, receiptDetail.getDescription().indexOf("-")) .trim(); String currentInstallment = null; if (Arrays.asList(WaterTaxConstants.CREATECONNECTIONDMDDESC).contains(receiptDmdRsnDesc)) currentInstallment = connectionDemandService .getCurrentInstallment(WaterTaxConstants.MODULE_NAME, WaterTaxConstants.YEARLY, new Date()) .getDescription(); else if (Arrays.asList(WaterTaxConstants.WATERCHARGESDMDDESC).contains(receiptDmdRsnDesc)) if (ConnectionType.METERED.equals(waterConnection.getConnectionType())) currentInstallment = connectionDemandService .getCurrentInstallment(WaterTaxConstants.MODULE_NAME, WaterTaxConstants.MONTHLY, new Date()) .getDescription(); else if (ConnectionType.NON_METERED.equals(waterConnection.getConnectionType())) currentInstallment = connectionDemandService .getCurrentInstallment(WaterTaxConstants.PROPERTY_MODULE_NAME, null, new Date()) .getDescription(); if (null != rdesc && rdesc.substring(rdesc.indexOf("-") + 1, rdesc.indexOf("#")).trim() .equals(currentInstallment)) currCollection = currCollection.add(receiptDetail.getCramount()); else if (null != rdesc && !rdesc.substring(rdesc.indexOf("-") + 1, rdesc.indexOf("#")).trim() .equals(currentInstallment)) arrCollection = arrCollection.add(receiptDetail.getCramount()); } } result.setArrearTotal(null != arrCollection ? arrCollection : new BigDecimal(0)); result.setCurrentTotal(currCollection); result.setTotal(currCollection.add(arrCollection)); dailyWTCollectionReportList.add(result); } return dailyWTCollectionReportList; }
From source file:org.eu5.ainhoalm.airportAena.dao.hibernate.AirplaneDAOHibernateImpl.java
@SuppressWarnings("unchecked") @Override/*from w w w . j a v a 2s . co m*/ @Transactional public List<Airplane> expirationLicense() { Session session = getSessionFactory().getCurrentSession(); List<Airplane> listOfObj; Query q = session.createQuery(" from Airplane where company.expirationDate < :pdate"); q.setDate("pdate", new Date()); listOfObj = q.list(); return listOfObj; }
From source file:org.fireflow.engine.persistence.hibernate.PersistenceServiceHibernateImpl.java
License:Open Source License
public void abortTaskInstance(final TaskInstance taskInstance) { this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session arg0) throws HibernateException, SQLException { Date now = rtCtx.getCalendarService().getSysDate(); //Cancel TaskInstance taskInstance.setState(ITaskInstance.CANCELED); taskInstance.setEndTime(now); taskInstance.setCanBeWithdrawn(Boolean.FALSE); arg0.update(taskInstance);/* w w w. ja va2s. com*/ String hql = "Update org.fireflow.engine.impl.WorkItem m set m.state=:state ,m.endTime=:endTime Where m.taskInstance.id=:taskInstanceId And (m.state=0 Or m.state=1)"; Query query = arg0.createQuery(hql); query.setInteger("state", IWorkItem.CANCELED); query.setDate("endTime", now); query.setString("taskInstanceId", taskInstance.getId()); query.executeUpdate(); 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 ww.j a va2 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.fourthline.konto.server.dao.EntryDAO.java
License:Open Source License
public List<Entry> getEntries(final Account account, EntriesQueryCriteria criteria) { StringBuilder sb = new StringBuilder(); sb.append("select e, s, ea, sa, eaUnit, saUnit from Entry e, Split s, "); sb.append("Account ea, MonetaryUnit eaUnit, Account sa, MonetaryUnit saUnit"); sb.append(" where e.id = s.entryId"); sb.append(" and ea.id = e.accountId and sa.id = s.accountId"); sb.append(" and ea.monetaryUnitId = eaUnit.id and sa.monetaryUnitId = saUnit.id"); sb.append(" and (e.accountId = :accountId or s.accountId = :accountId)"); if (!criteria.isStringFilterEmpty()) sb.append(" and (lower(e.description) like :desc or lower(s.description) like :desc)"); if (criteria.getEffectiveOn() != null && criteria.getEffectiveOn().getStart() != null) sb.append(" and e.effectiveOn >= :effectiveOnStart"); if (criteria.getEffectiveOn() != null && criteria.getEffectiveOn().getEnd() != null) sb.append(" and e.effectiveOn <= :effectiveOnEnd"); sb.append(" order by "); if (criteria.getOrderBy() == null) { sb.append("e.effectiveOn desc"); } else if (criteria.getOrderBy().equals(Entry.Property.description)) { sb.append("e.description ").append(criteria.isSortAscending() ? "asc" : "desc"); sb.append(", s.description ").append(criteria.isSortAscending() ? "asc" : "desc"); } else if (criteria.getOrderBy().equals(Entry.Property.enteredOn)) { sb.append("e.enteredOn ").append(criteria.isSortAscending() ? "asc" : "desc"); } else {//from w ww.j a v a 2s . c o m sb.append("e.effectiveOn ").append(criteria.isSortAscending() ? "asc" : "desc"); } sb.append(", e.enteredOn desc, s.enteredOn desc"); Query q = getCurrentSession().createQuery(sb.toString()); q.setLong("accountId", account.getId()); if (!criteria.isStringFilterEmpty()) q.setString("desc", criteria.getStringFilterWildcards()); if (criteria.getEffectiveOn() != null && criteria.getEffectiveOn().getStart() != null) q.setDate("effectiveOnStart", criteria.getEffectiveOn().getStart()); if (criteria.getEffectiveOn() != null && criteria.getEffectiveOn().getEnd() != null) q.setDate("effectiveOnEnd", criteria.getEffectiveOn().getEnd()); // TODO: Pagination? final Map<Long, Entry> entries = new LinkedHashMap(); q.setResultTransformer(new ResultTransformer() { @Override public Object transformTuple(Object[] objects, String[] strings) { Entry entry = (Entry) objects[0]; Split split = (Split) objects[1]; entry.setAccount((Account) objects[2]); split.setAccount((Account) objects[3]); split.setEntryMonetaryUnit((MonetaryUnit) objects[4]); split.setMonetaryUnit((MonetaryUnit) objects[5]); Entry existingEntry = entries.get(entry.getId()); if (existingEntry != null) { split.setEntry(existingEntry); existingEntry.getSplits().add(split); } else { // Clear the splits, this entry might have passed through // this transformer before (querying several times with the same PC) entry.getSplits().clear(); entry.getSplits().add(split); split.setEntry(entry); entries.put(entry.getId(), entry); } return null; } @Override public List transformList(List list) { return list; } }); q.list(); return new ArrayList(entries.values()); }
From source file:org.fourthline.konto.server.dao.EntryDAO.java
License:Open Source License
public List<AccountReportLine> getAccountReportLines(List<Account> accounts, DateRange dateRange, boolean useInitialBalance) { List<Long> accountIds = getAccountIds(accounts); Query q = getCurrentSession().getNamedQuery("sumOfAccounts"); q.setParameterList("ids", accountIds); // Default to 01.01.1900 -> Today if there is no start or end in the given date range q.setDate("rangeStart", dateRange.getStart() != null ? dateRange.getStart() : new Date(0, 0, 1)); q.setDate("rangeEnd", dateRange.getEnd() != null ? dateRange.getEnd() : new Date()); List<Object[]> result = q.list(); List<AccountReportLine> lines = new ArrayList(accounts.size()); for (Account account : accounts) { // Start with account's initial balance or zero, then add the query result balance MonetaryAmount amount = useInitialBalance ? account.getInitialBalance() : new MonetaryAmount(account.getMonetaryUnit()); for (Object[] r : result) { if (account.getId().equals(r[0])) { MonetaryAmount m = new MonetaryAmount(account.getMonetaryUnit(), (BigDecimal) r[1]); amount = amount.add(m);/*from www . j a v a 2 s . c om*/ break; } } lines.add(new AccountReportLine(account, amount)); } return lines; }
From source file:org.fourthline.konto.server.dao.EntryDAO.java
License:Open Source License
public Map<Account, List<EntryReportLine>> getEntryReportLines(List<Account> accounts, DateRange dateRange) { List<Long> accountIds = getAccountIds(accounts); Query q = getCurrentSession().getNamedQuery("cashflowOfAccounts"); q.setParameterList("ids", accountIds); // Default to 01.01.1900 -> Today if there is no start or end in the given date range q.setDate("rangeStart", dateRange.getStart() != null ? dateRange.getStart() : new Date(0, 0, 1)); q.setDate("rangeEnd", dateRange.getEnd() != null ? dateRange.getEnd() : new Date()); List<Object[]> result = q.list(); Map<Account, List<EntryReportLine>> accountEntryLines = new LinkedHashMap(accounts.size()); for (Account account : accounts) { boolean haveEntries = false; for (Object[] r : result) { if (account.getId().equals(r[0])) { List<EntryReportLine> lines; if ((lines = accountEntryLines.get(account)) == null) { lines = new ArrayList(); accountEntryLines.put(account, lines); }/*ww w. j ava2 s . co m*/ Long entryId = (Long) r[1]; Long splitId = (Long) r[2]; Date effectiveOn = (Date) r[3]; String description = (String) r[4]; Long fromToAccountId = (Long) r[5]; String fromToAccountGroup = (String) r[6]; String fromToAccount = (String) r[7]; BigDecimal amount = (BigDecimal) r[8]; lines.add( new EntryReportLine(description, new MonetaryAmount(account.getMonetaryUnit(), amount), new LedgerCoordinates(account.getId(), entryId, splitId), effectiveOn, fromToAccountId, fromToAccountGroup, fromToAccount)); haveEntries = true; } } if (!haveEntries) { accountEntryLines.put(account, new ArrayList()); } } return accountEntryLines; }
From source file:org.glite.security.voms.admin.integration.orgdb.tools.OrgDBUtil.java
License:Apache License
protected void updateParticipation(Participation p, Date newEndDate) { Session s = OrgDBSessionFactory.getSessionFactory().getCurrentSession(); s.getTransaction();/*from w ww. jav a2 s. c o m*/ Query q = s.createSQLQuery("update person_participation set end_date = ? where person_id = ?"); q.setDate(0, newEndDate); q.setLong(1, p.getVomsPerson().getId()); q.executeUpdate(); s.getTransaction().commit(); }
From source file:org.glite.security.voms.admin.integration.orgdb.tools.OrgDBUtil.java
License:Apache License
protected void createParticipation(VOMSOrgDBPerson p, Experiment e, Institute i) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.YEAR, -1);//from w w w. j a v a2 s . c o m Session s = OrgDBSessionFactory.getSessionFactory().getCurrentSession(); s.beginTransaction(); Query q = s.createSQLQuery( "insert into person_participation(EXPERIMENT,INSTITUTE,PERSON_ID,START_DATE) values(?,?,?,?)"); q.setString(0, e.getName()); q.setString(1, i.getCode()); q.setLong(2, p.getId()); q.setDate(3, cal.getTime()); q.executeUpdate(); s.getTransaction().commit(); }
From source file:org.glite.security.voms.admin.persistence.dao.VOMSUserDAO.java
License:Apache License
public Long countExpiredUsers() { Date now = new Date(); String queryString = "select count(*) from VOMSUser u where u.endTime < :now"; Query q = HibernateFactory.getSession().createQuery(queryString); q.setDate("now", now); return (Long) q.uniqueResult(); }