List of usage examples for org.hibernate Criteria createAlias
public Criteria createAlias(String associationPath, String alias) throws HibernateException;
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public List<Ticket> findOpenTickets(Terminal terminal, UserType userType) { Session session = null;// w w w. ja v a2s. c om try { session = getSession(); Criteria criteria = session.createCriteria(getReferenceClass()); criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.FALSE)); if (userType != null) { criteria.createAlias(Ticket.PROP_OWNER, "u"); //$NON-NLS-1$ criteria.add(Restrictions.eq("u.type", userType)); //$NON-NLS-1$ } if (terminal != null) { criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal)); } criteria.addOrder(getDefaultOrder()); List list = criteria.list(); return list; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public List<Ticket> findTicketsForLaborHour(Date startDate, Date endDate, int hour, UserType userType, Terminal terminal) {//from ww w .j a v a 2 s . co m Session session = null; try { session = getSession(); Criteria criteria = session.createCriteria(getReferenceClass()); criteria.add(Restrictions.ge(Ticket.PROP_ACTIVE_DATE, startDate)); criteria.add(Restrictions.le(Ticket.PROP_ACTIVE_DATE, endDate)); criteria.add(Restrictions.eq(Ticket.PROP_CREATION_HOUR, Integer.valueOf(hour))); //criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.TRUE)); //criteria.add(Restrictions.eq(Ticket.PROP_VOIDED, Boolean.FALSE)); if (userType != null) { criteria.createAlias(Ticket.PROP_OWNER, "u"); //$NON-NLS-1$ criteria.add(Restrictions.eq("u.type", userType)); //$NON-NLS-1$ } if (terminal != null) { criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal)); } return criteria.list(); } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public List<Ticket> findTicketsForShift(Date startDate, Date endDate, Shift shit, UserType userType, Terminal terminal) {/*from w w w .j av a2 s .co m*/ Session session = null; try { session = getSession(); Criteria criteria = session.createCriteria(getReferenceClass()); criteria.add(Restrictions.ge(Ticket.PROP_CREATE_DATE, startDate)); criteria.add(Restrictions.le(Ticket.PROP_CREATE_DATE, endDate)); criteria.add(Restrictions.eq(Ticket.PROP_SHIFT, shit)); criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.TRUE)); criteria.add(Restrictions.eq(Ticket.PROP_VOIDED, Boolean.FALSE)); criteria.add(Restrictions.eq(Ticket.PROP_REFUNDED, Boolean.FALSE)); if (userType != null) { criteria.createAlias(Ticket.PROP_OWNER, "u"); //$NON-NLS-1$ criteria.add(Restrictions.eq("u.type", userType)); //$NON-NLS-1$ } if (terminal != null) { criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal)); } return criteria.list(); } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public List<Ticket> getTicketsWithSpecificFields(String... fields) { Session session = null;/* w ww . j ava2 s . c o m*/ Criteria criteria = null; User currentUser = Application.getCurrentUser(); boolean filterUser = !currentUser.isAdministrator() || !currentUser.isManager(); try { session = createNewSession(); criteria = session.createCriteria(Ticket.class); ProjectionList projectionList = Projections.projectionList(); for (String field : fields) { projectionList.add(Projections.property(field)); } criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.FALSE)); if (filterUser) { criteria.createAlias(Ticket.PROP_OWNER, "u"); criteria.add(Restrictions.eq("u.userId", currentUser.getUserId())); } ResultTransformer transformer = new ResultTransformer() { public Object transformTuple(Object[] row, String[] arg1) { Ticket ticket = new Ticket(); ticket.setId(Integer.valueOf("" + row[0])); ticket.setDueAmount(Double.valueOf("" + row[1])); return ticket; } public List transformList(List arg0) { return arg0; } }; criteria.setProjection(projectionList).setResultTransformer(transformer); return criteria.list(); } finally { closeSession(session); } }
From source file:com.floreantpos.report.service.ReportService.java
License:Open Source License
private double calculateTipsPaid(Session session, Date fromDate, Date toDate, User user) { Criteria criteria = session.createCriteria(Ticket.class); criteria.createAlias(Ticket.PROP_GRATUITY, "gratuity"); //$NON-NLS-1$ criteria.add(Restrictions.ge(Ticket.PROP_CREATE_DATE, fromDate)); criteria.add(Restrictions.le(Ticket.PROP_CREATE_DATE, toDate)); criteria.add(Restrictions.eq("gratuity." + Gratuity.PROP_PAID, Boolean.TRUE)); //$NON-NLS-1$ if (user != null) { criteria.add(Restrictions.eq(Ticket.PROP_OWNER, user)); }//from w w w . j a va2 s . c om criteria.setProjection(Projections.sum("gratuity." + Gratuity.PROP_AMOUNT)); //$NON-NLS-1$ return getDoubleAmount(criteria.uniqueResult()); }
From source file:com.floreantpos.report.service.ReportService.java
License:Open Source License
private double calculateTips(Session session, Date fromDate, Date toDate, User user) { //tips// w ww.j av a2 s .c om Criteria criteria = session.createCriteria(Ticket.class); criteria.createAlias(Ticket.PROP_GRATUITY, "g"); //$NON-NLS-1$ criteria.add(Restrictions.ge(Ticket.PROP_CREATE_DATE, fromDate)); criteria.add(Restrictions.le(Ticket.PROP_CREATE_DATE, toDate)); if (user != null) { criteria.add(Restrictions.eq(Ticket.PROP_OWNER, user)); } //FIXME: HOW ABOUT TIPS ON VOID OR REFUNDED TICKET? //criteria.add(Restrictions.eq(Ticket.PROP_VOIDED, Boolean.FALSE)); //criteria.add(Restrictions.eq(Ticket.PROP_REFUNDED, Boolean.FALSE)); criteria.setProjection(Projections.sum("g." + Gratuity.PROP_AMOUNT)); //$NON-NLS-1$ return getDoubleAmount(criteria.uniqueResult()); }
From source file:com.floreantpos.report.service.ReportService.java
License:Open Source License
public SalesDetailedReport getSalesDetailedReport(Date fromDate, Date toDate) { GenericDAO dao = new GenericDAO(); SalesDetailedReport report = new SalesDetailedReport(); Session session = null;//from w w w . jav a 2 s. co m report.setFromDate(fromDate); report.setToDate(toDate); report.setReportTime(new Date()); try { session = dao.getSession(); Criteria criteria = session.createCriteria(DrawerPullReport.class); criteria.add(Restrictions.ge(DrawerPullReport.PROP_REPORT_TIME, fromDate)); criteria.add(Restrictions.le(DrawerPullReport.PROP_REPORT_TIME, toDate)); List list = criteria.list(); for (Iterator iter = list.iterator(); iter.hasNext();) { DrawerPullReport drawerPullReport = (DrawerPullReport) iter.next(); DrawerPullData data = new DrawerPullData(); data.setDrawerPullId(drawerPullReport.getId()); data.setTicketCount(drawerPullReport.getTicketCount()); data.setIdealAmount(drawerPullReport.getDrawerAccountable()); data.setActualAmount(drawerPullReport.getCashToDeposit()); data.setVarinceAmount( drawerPullReport.getDrawerAccountable() - drawerPullReport.getCashToDeposit()); report.addDrawerPullData(data); } criteria = session.createCriteria(CreditCardTransaction.class); criteria.add(Restrictions.ge(CreditCardTransaction.PROP_TRANSACTION_TIME, fromDate)); criteria.add(Restrictions.le(CreditCardTransaction.PROP_TRANSACTION_TIME, toDate)); list = criteria.list(); for (Iterator iter = list.iterator(); iter.hasNext();) { CreditCardTransaction t = (CreditCardTransaction) iter.next(); report.addCreditCardData(t); } criteria = session.createCriteria(DebitCardTransaction.class); criteria.add(Restrictions.ge(DebitCardTransaction.PROP_TRANSACTION_TIME, fromDate)); criteria.add(Restrictions.le(DebitCardTransaction.PROP_TRANSACTION_TIME, toDate)); list = criteria.list(); for (Iterator iter = list.iterator(); iter.hasNext();) { DebitCardTransaction t = (DebitCardTransaction) iter.next(); report.addCreditCardData(t); } criteria = session.createCriteria(GiftCertificateTransaction.class); criteria.add(Restrictions.ge(GiftCertificateTransaction.PROP_TRANSACTION_TIME, fromDate)); criteria.add(Restrictions.le(GiftCertificateTransaction.PROP_TRANSACTION_TIME, toDate)); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.rowCount()); projectionList.add(Projections.sum(GiftCertificateTransaction.PROP_AMOUNT)); criteria.setProjection(projectionList); Object[] object = (Object[]) criteria.uniqueResult(); if (object != null && object.length > 0 && object[0] instanceof Number) { report.setGiftCertReturnCount(((Number) object[0]).intValue()); } if (object != null && object.length > 1 && object[1] instanceof Number) { report.setGiftCertReturnAmount(((Number) object[1]).doubleValue()); } criteria = session.createCriteria(GiftCertificateTransaction.class); criteria.add(Restrictions.ge(GiftCertificateTransaction.PROP_TRANSACTION_TIME, fromDate)); criteria.add(Restrictions.le(GiftCertificateTransaction.PROP_TRANSACTION_TIME, toDate)); criteria.add( Restrictions.gt(GiftCertificateTransaction.PROP_GIFT_CERT_CASH_BACK_AMOUNT, Double.valueOf(0))); projectionList = Projections.projectionList(); projectionList.add(Projections.rowCount()); projectionList.add(Projections.sum(GiftCertificateTransaction.PROP_GIFT_CERT_CASH_BACK_AMOUNT)); criteria.setProjection(projectionList); object = (Object[]) criteria.uniqueResult(); if (object != null && object.length > 0 && object[0] instanceof Number) { report.setGiftCertChangeCount(((Number) object[0]).intValue()); } if (object != null && object.length > 1 && object[1] instanceof Number) { report.setGiftCertChangeAmount(((Number) object[1]).doubleValue()); } criteria = session.createCriteria(Ticket.class); criteria.createAlias(Ticket.PROP_GRATUITY, "g"); //$NON-NLS-1$ criteria.add(Restrictions.ge(Ticket.PROP_CREATE_DATE, fromDate)); criteria.add(Restrictions.le(Ticket.PROP_CREATE_DATE, toDate)); criteria.add(Restrictions.gt("g." + Gratuity.PROP_AMOUNT, Double.valueOf(0))); //$NON-NLS-1$ projectionList = Projections.projectionList(); projectionList.add(Projections.rowCount()); projectionList.add(Projections.sum("g." + Gratuity.PROP_AMOUNT)); //$NON-NLS-1$ criteria.setProjection(projectionList); object = (Object[]) criteria.uniqueResult(); if (object != null && object.length > 0 && object[0] instanceof Number) { report.setTipsCount(((Number) object[0]).intValue()); } if (object != null && object.length > 1 && object[1] instanceof Number) { report.setChargedTips(((Number) object[1]).doubleValue()); } criteria = session.createCriteria(Ticket.class); criteria.createAlias(Ticket.PROP_GRATUITY, "g"); //$NON-NLS-1$ criteria.add(Restrictions.ge(Ticket.PROP_CREATE_DATE, fromDate)); criteria.add(Restrictions.le(Ticket.PROP_CREATE_DATE, toDate)); criteria.add(Restrictions.gt("g." + Gratuity.PROP_AMOUNT, Double.valueOf(0))); //$NON-NLS-1$ criteria.add(Restrictions.gt("g." + Gratuity.PROP_PAID, Boolean.TRUE)); //$NON-NLS-1$ projectionList = Projections.projectionList(); projectionList.add(Projections.sum("g." + Gratuity.PROP_AMOUNT)); //$NON-NLS-1$ criteria.setProjection(projectionList); object = (Object[]) criteria.uniqueResult(); if (object != null && object.length > 0 && object[0] instanceof Number) { report.setTipsPaid(((Number) object[0]).doubleValue()); } return report; } finally { if (session != null) { session.close(); } } }
From source file:com.gettec.fsnip.fsn.dao.product.impl.ProductDAOImpl.java
@Override public Product checkProduct(Product product) throws ServiceException { Criteria criteria = getSession().createCriteria(Product.class); BusinessUnit businessUnit = product.getProducer(); if (null != businessUnit && !StringUtil.isBlank(businessUnit.getName())) { criteria.createAlias("producer", "producer"); criteria.add(Restrictions.eq("producer.name", businessUnit.getName())); }//from www .j av a2 s . c o m if (!StringUtil.isBlank(product.getName())) { criteria.add(Restrictions.eq("name", product.getName())); } if (!StringUtil.isBlank(product.getFormat())) { criteria.add(Restrictions.eq("format", product.getFormat())); } criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);// ROOT_ENTITY if (criteria.list().size() > 0) { return (Product) criteria.list().get(0); } return null; }
From source file:com.googlecode.wicketwebbeans.databinder.DataSearchFilter.java
License:Apache License
@Override public void build(Criteria criteria) { super.build(criteria); if (searchPanel.getDefaultModelObject() != null && properties != null) { for (String alias : aliases) { criteria.createAlias(alias, alias); }/*from w w w . j a va 2s. c o m*/ Disjunction disjunction = Restrictions.disjunction(); criteria.add(disjunction); for (String property : properties) { disjunction.add(Restrictions.ilike(property, searchPanel.getDefaultModelObject().toString(), MatchMode.ANYWHERE)); } } }
From source file:com.googlecode.wicketwebbeans.databinder.DataSorter.java
License:Apache License
public void buildOrdered(Criteria criteria) { String property;/*ww w. j a va2 s.c o m*/ SortParam sort = sortState.getSort(); if (sort != null && sort.getProperty() != null) { property = sort.getProperty(); asc = sort.isAscending(); } else { property = defaultProperty; } if (property != null) { if (property.contains(".")) { String[] path = property.split("\\."); for (int ii = 0; ii < path.length - 1; ii++) { criteria.createAlias(path[ii], path[ii]); } } criteria.addOrder(asc ? Order.asc(property) : Order.desc(property)); } }