Example usage for org.hibernate Criteria createAlias

List of usage examples for org.hibernate Criteria createAlias

Introduction

In this page you can find the example usage for org.hibernate Criteria createAlias.

Prototype

public Criteria createAlias(String associationPath, String alias) throws HibernateException;

Source Link

Document

Join an association, assigning an alias to the joined association.

Usage

From source file:com.fich.wafproject.dao.ConfigurationFileAttributeDaoImpl.java

public List<ConfigurationFilesAttributes> findByFileConfiguration(Long id) {
    Criteria crit = this.createEntityCriteria();
    crit.createAlias("configurationFileAttributeGroups", "cfag")
            .add(Restrictions.eq("cfag.configurationFiles.id", id));
    return (List<ConfigurationFilesAttributes>) crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
}

From source file:com.fich.wafproject.dao.UserDaoImpl.java

public List<Users> findAll(int pageNumber, String[] targets, String[] names, String[] values,
        boolean pagination) {
    int pageSize = 4;
    Criteria crit = this.createEntityCriteria();
    crit.setProjection(Projections.distinct(Projections.property("id")));
    String dateFrom = "", dateTo = "", targetDate = "";
    if (names != null) {
        for (String alias : names) {
            crit.createAlias(alias, alias);
        }//from ww w  . j a v  a2  s .c  o  m
    }
    int count = 0;
    if (values != null) {
        for (String value : values) {
            if (!value.equals("") && value != null) {
                if (targets[count].contains("date")) {
                    if (dateFrom != "") {
                        dateTo = value;
                    } else {
                        dateFrom = value;
                        targetDate = targets[count];
                    }
                } else {
                    crit.add(Restrictions.like(targets[count], "%" + value + "%"));
                }
            }
            count++;
        }
        if (targetDate != "") {
            if (dateFrom != "" && dateTo == "") {
                dateTo = dateFrom;
            }
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
            try {
                Date dateF = format.parse(dateFrom);
                Date dateT = format.parse(dateTo);
                crit.add(Restrictions.between(targetDate, dateF, dateT));
            } catch (ParseException ex) {
                Logger.getLogger(UserDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    if (pagination) {
        crit.setFirstResult((pageNumber - 1) * pageSize);
        crit.setMaxResults(pageSize);
    }
    List<Users> users = new ArrayList<Users>();
    for (Object idEvent : crit.list()) {
        //            System.out.println(idEvent);
        users.add(this.findById((Long) idEvent));
    }
    return (List<Users>) users;
}

From source file:com.fich.wafproject.dao.UserHistoryDaoImpl.java

public List<UsersHistory> filter(String[] values, String[] names, String[] targets, int pageNumber,
        String role) {//w w w .j av  a 2 s. com
    int pageSize = 6;
    int count = 0;
    boolean filterByUserProperty = false, filterByUserName = false;
    Criteria crit = this.createEntityCriteria();//.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    crit.setProjection(Projections.distinct(Projections.property("id")));
    String dateFrom = "", dateTo = "", targetDate = "";
    if (names != null) {
        for (String alias : names) {
            crit.createAlias(alias, alias);
            if (alias.equals("user"))
                filterByUserProperty = true;
        }
    }
    if (!filterByUserProperty && !role.equals(""))
        crit.createAlias("user", "user");
    if (values != null) {
        for (String value : values) {
            if (!value.equals("") && value != null) {
                if (targets[count].contains("date")) {
                    if (dateFrom != "") {
                        dateTo = value;
                    } else {
                        dateFrom = value;
                        targetDate = targets[count];
                    }
                } else {
                    if (targets[count].contains("userName"))
                        filterByUserName = true;
                    crit.add(Restrictions.like(targets[count], "%" + value + "%"));
                }
            }
            count++;
        }
        if (targetDate != "") {
            if (dateFrom != "" && dateTo == "") {
                dateTo = dateFrom;
            }
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
            try {
                Date dateF = format.parse(dateFrom);
                Date dateT = format.parse(dateTo);
                crit.add(Restrictions.between(targetDate, dateF, dateT));
            } catch (ParseException ex) {
                Logger.getLogger(UserHistoryDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    if (!filterByUserName && !role.equals(""))
        crit.add(Restrictions.like("user.userName", role));
    crit.setFirstResult((pageNumber - 1) * pageSize);
    crit.setMaxResults(pageSize);
    List<UsersHistory> events = new ArrayList<UsersHistory>();
    for (Object idEvent : crit.list()) {
        events.add(this.findById((Long) idEvent));
    }
    return (List<UsersHistory>) events;
}

From source file:com.floreantpos.model.dao.AttendenceHistoryDAO.java

License:Open Source License

public List<User> findNumberOfClockedInUserAtHour(Date fromDay, Date toDay, int hour, UserType userType,
        Terminal terminal) {// ww  w  .  j  av  a 2s  . c  om
    Session session = null;

    ArrayList<User> users = new ArrayList<User>();

    try {
        session = getSession();
        Criteria criteria = session.createCriteria(getReferenceClass());
        criteria.add(Restrictions.ge(AttendenceHistory.PROP_CLOCK_IN_TIME, fromDay));
        criteria.add(Restrictions.le(AttendenceHistory.PROP_CLOCK_IN_TIME, toDay));
        criteria.add(Restrictions.le(AttendenceHistory.PROP_CLOCK_IN_HOUR, new Short((short) hour)));

        if (userType != null) {
            criteria.createAlias(AttendenceHistory.PROP_USER, "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));
        }

        List list = criteria.list();
        for (Object object : list) {
            AttendenceHistory history = (AttendenceHistory) object;

            if (!history.isClockedOut()) {
                users.add(history.getUser());
            } else if (history.getClockOutHour() >= hour) {
                users.add(history.getUser());
            }
        }
        return users;
    } catch (Exception e) {
        throw new PosException(Messages.getString("AttendenceHistoryDAO.2"), e); //$NON-NLS-1$
    } finally {
        if (session != null) {
            closeSession(session);
        }
    }
}

From source file:com.floreantpos.model.dao.AttendenceHistoryDAO.java

License:Open Source License

public List<User> findNumberOfClockedInUserAtShift(Date fromDay, Date toDay, Shift shift, UserType userType,
        Terminal terminal) {/*from  w  w  w .j av a2 s.  c  o  m*/
    Session session = null;

    ArrayList<User> users = new ArrayList<User>();

    try {
        session = getSession();
        Criteria criteria = session.createCriteria(getReferenceClass());
        criteria.add(Restrictions.ge(AttendenceHistory.PROP_CLOCK_IN_TIME, fromDay));
        criteria.add(Restrictions.le(AttendenceHistory.PROP_CLOCK_IN_TIME, toDay));
        criteria.add(Restrictions.le(AttendenceHistory.PROP_SHIFT, shift));

        if (userType != null) {
            criteria.createAlias(AttendenceHistory.PROP_USER, "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));
        }

        List list = criteria.list();
        for (Object object : list) {
            AttendenceHistory history = (AttendenceHistory) object;

            //            if (!history.isClockedOut()) {
            //               users.add(history.getUser());
            //            }
            //            else if (history.getClockOutHour() >= hour) {
            //               users.add(history.getUser());
            //            }
            users.add(history.getUser());
        }
        return users;
    } catch (Exception e) {
        throw new PosException(Messages.getString("AttendenceHistoryDAO.5"), e); //$NON-NLS-1$
    } finally {
        if (session != null) {
            closeSession(session);
        }
    }
}

From source file:com.floreantpos.model.dao.MenuItemDAO.java

License:Open Source License

public List<MenuItem> getMenuItems(String itemName, Object menuGroup, Object selectedType) {
    Session session = null;//from w ww  .  j  a  v  a 2 s.  c om
    Criteria criteria = null;
    try {
        session = getSession();
        criteria = session.createCriteria(MenuItem.class);

        if (menuGroup != null && menuGroup instanceof MenuGroup) {
            criteria.add(Restrictions.eq(MenuItem.PROP_PARENT, (MenuGroup) menuGroup));
        } else if (menuGroup != null && menuGroup instanceof String) {
            criteria.add(Restrictions.isNull(MenuItem.PROP_PARENT));
        }
        if (StringUtils.isNotEmpty(itemName)) {
            criteria.add(Restrictions.ilike(MenuItem.PROP_NAME, itemName.trim(), MatchMode.ANYWHERE));
        }

        //List<MenuItem> similarItems = criteria.list();

        if (selectedType != null && selectedType instanceof OrderType) {
            OrderType orderType = (OrderType) selectedType;

            criteria.createAlias("orderTypeList", "type");
            criteria.add(Restrictions.eq("type.id", orderType.getId()));

            /*List<MenuItem> selectedMenuItems = new ArrayList();
                    
            List<MenuItem> items = findAll();
                    
            for (MenuItem item : items) {
                    
               List<OrderType> types = item.getOrderTypeList();
               OrderType type = (OrderType) selectedType;
                    
               if (types.contains(type.getName()) || types.isEmpty()) {
                  selectedMenuItems.add(item);
               }
            }
            similarItems.retainAll(selectedMenuItems);*/
        } else if (selectedType != null && selectedType instanceof String) {
            criteria.add(Restrictions.isEmpty("orderTypeList"));
        }
        return criteria.list();

    } catch (Exception e) {
    }
    return criteria.list();
}

From source file:com.floreantpos.model.dao.MenuItemDAO.java

License:Open Source License

public List<MenuItem> getPizzaItems(String itemName, MenuGroup menuGroup, Object selectedType) {
    Session session = null;/*from  www. ja  va2 s  .c o m*/
    Criteria criteria = null;
    try {
        session = getSession();
        criteria = session.createCriteria(MenuItem.class);
        criteria.add(Restrictions.eq(MenuItem.PROP_PIZZA_TYPE, true));

        if (menuGroup != null) {
            criteria.add(Restrictions.eq(MenuItem.PROP_PARENT, menuGroup));
        }

        if (StringUtils.isNotEmpty(itemName)) {
            criteria.add(Restrictions.ilike(MenuItem.PROP_NAME, itemName.trim(), MatchMode.ANYWHERE));
        }

        //List<MenuItem> similarItems = criteria.list();

        if (selectedType instanceof OrderType) {
            OrderType orderType = (OrderType) selectedType;

            criteria.createAlias("orderTypeList", "type");
            criteria.add(Restrictions.eq("type.id", orderType.getId()));

            /*List<MenuItem> selectedMenuItems = new ArrayList();
                    
            List<MenuItem> items = findAll();
                    
            for (MenuItem item : items) {
                    
               List<OrderType> types = item.getOrderTypeList();
               OrderType type = (OrderType) selectedType;
               if (types.contains(type.getName()) || types.isEmpty()) {
                  selectedMenuItems.add(item);
               }
            }
            similarItems.retainAll(selectedMenuItems);*/
        }

        return criteria.list();

    } catch (Exception e) {
    }
    return criteria.list();
}

From source file:com.floreantpos.model.dao.ShopTableDAO.java

License:Open Source License

public List<ShopTableType> getTableByTypes(List<ShopTableType> types) {
    List<Integer> typeIds = new ArrayList<Integer>();
    for (ShopTableType shopTableType : types) {
        typeIds.add(shopTableType.getId());
    }/*w  w  w. j a v  a  2s .  c o  m*/

    Session session = getSession();
    Criteria criteria = session.createCriteria(ShopTable.class);
    criteria.createAlias("types", "t"); //$NON-NLS-1$ //$NON-NLS-2$
    criteria.add(Restrictions.in("t.id", typeIds)); //$NON-NLS-1$
    //criteria.add(Restrictions("t.id", typeIds)); //$NON-NLS-1$
    criteria.addOrder(Order.asc(ShopTable.PROP_ID));
    return criteria.list();
}

From source file:com.floreantpos.model.dao.TicketDAO.java

License:Open Source License

public List<Gratuity> getServerGratuities(Terminal terminal, String transactionType) {
    Session session = null;/*  ww w.j a v  a2s .c  om*/
    ArrayList<Gratuity> gratuities = new ArrayList<Gratuity>();

    try {
        session = getSession();
        Criteria criteria = session.createCriteria(getReferenceClass());
        criteria.add(Restrictions.eq(Ticket.PROP_DRAWER_RESETTED, Boolean.FALSE));
        criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal));
        criteria.createAlias(Ticket.PROP_GRATUITY, "gratuity"); //$NON-NLS-1$
        criteria.add(Restrictions.eq("gratuity.paid", Boolean.FALSE)); //$NON-NLS-1$

        List list = criteria.list();
        for (Iterator iter = list.iterator(); iter.hasNext();) {
            Ticket ticket = (Ticket) iter.next();
            gratuities.add(ticket.getGratuity());
        }
        return gratuities;
    } finally {
        closeSession(session);
    }
}

From source file:com.floreantpos.model.dao.TicketDAO.java

License:Open Source License

public double getPaidGratuityAmount(Terminal terminal) {
    Session session = null;/*w w  w  .j  a v  a2s  .c o m*/

    try {
        session = getSession();
        Criteria criteria = session.createCriteria(getReferenceClass(), "t"); //$NON-NLS-1$
        criteria = criteria.createAlias(Ticket.PROP_GRATUITY, "gratuity"); //$NON-NLS-1$
        criteria.add(Restrictions.eq(Ticket.PROP_DRAWER_RESETTED, Boolean.FALSE));
        criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal));
        criteria.add(Restrictions.eq("gratuity.paid", Boolean.TRUE)); //$NON-NLS-1$

        criteria.setProjection(Projections.sum("gratuity.amount")); //$NON-NLS-1$

        List list = criteria.list();
        if (list.size() > 0 && list.get(0) instanceof Number) {
            return ((Number) list.get(0)).doubleValue();
        }
        return 0;
    } finally {
        closeSession(session);
    }
}