List of usage examples for org.hibernate Criteria addOrder
public Criteria addOrder(Order order);
From source file:co.com.codesoftware.logica.inventario.ProductoLogica.java
/** * Funcion con la cual obtengo todos los productos del sistema que tengan * precio dentro de una sede/*from w ww .ja v a 2s.c om*/ * * @param idSede Integer Sede la cual se tendra como referencia * @return */ public List<PrecioProductoEntity> obtieneProductosConPrecioXSede(Integer idSede) { List<PrecioProductoEntity> rta = null; try { this.initOperation(); Criteria crit = sesion.createCriteria(PrecioProductoEntity.class); crit.createAlias("idSede", "sede").add(Restrictions.eq("sede.id", idSede)); crit.add(Restrictions.eq("estado", "A")); crit.setFetchMode("producto", FetchMode.JOIN); crit.setFetchMode("producto.referencia", FetchMode.JOIN); crit.setFetchMode("producto.marca", FetchMode.JOIN); crit.setFetchMode("producto.categoria", FetchMode.JOIN); crit.setFetchMode("producto.subcuenta", FetchMode.JOIN); crit.addOrder(Order.asc("producto.id")); rta = crit.list(); } catch (Exception e) { e.printStackTrace(); } return rta; }
From source file:co.com.codesoftware.logica.inventario.ProductoLogica.java
/** * Funcion con la cual obtengo todos los productos del sistema que tengan * precio dentro de una sede/*w w w. j a v a2s .c o m*/ * * @param idSede Integer Sede la cual se tendra como referencia * @param criterio * @return */ public List<PrecioProductoEntity> obtieneProductosConPrecioXSedeYCrit(Integer idSede, String criterio) { List<PrecioProductoEntity> rta = null; try { this.initOperation(); Criteria crit = sesion.createCriteria(PrecioProductoEntity.class); crit.createAlias("idSede", "sede").add(Restrictions.eq("sede.id", idSede)); crit.createAlias("producto", "prod") .add(Restrictions.like("prod.descripcion", criterio, MatchMode.ANYWHERE).ignoreCase()); crit.add(Restrictions.eq("estado", "A")); crit.setFetchMode("producto", FetchMode.JOIN); crit.setFetchMode("producto.referencia", FetchMode.JOIN); crit.setFetchMode("producto.marca", FetchMode.JOIN); crit.setFetchMode("producto.categoria", FetchMode.JOIN); crit.setFetchMode("producto.subcuenta", FetchMode.JOIN); crit.addOrder(Order.asc("producto.id")); rta = crit.list(); } catch (Exception e) { e.printStackTrace(); } return rta; }
From source file:co.com.codesoftware.logica.inventario.SolicitudLogica.java
/** * metodo que consulta las solicitudes por los filtros seleccionados * * @param fechaInicial//from ww w .j a v a 2 s . c o m * @param fechaFinal * @param estado * @param usuario * @param sede * @return */ public List<SolicitudEntity> consultaSolicitudesXFiltro(Date fechaInicial, Date fechaFinal, String estado, Integer usuario, Integer sede) { System.out.println(fechaInicial); System.out.println(fechaFinal); System.out.println(estado); System.out.println(sede); System.out.println(usuario); List<SolicitudEntity> respuesta = null; try { initOperation(); Criteria crit = sesion.createCriteria(SolicitudEntity.class); if (fechaInicial != null && fechaFinal != null) { crit.add(Restrictions.ge("fecha", fechaInicial)); fechaFinal.setHours(23); fechaFinal.setMinutes(59); fechaFinal.setSeconds(59); crit.add(Restrictions.lt("fecha", fechaFinal)); } if (estado != null && !"".equalsIgnoreCase(estado)) { crit.add(Restrictions.eq("estado", estado)); } if (usuario != null && usuario != 0) { crit.createAlias("usuario", "usu").add(Restrictions.eq("usu.id", usuario)); } if (sede != null && sede != 0) { crit.createAlias("sede", "sede").add(Restrictions.eq("sede.id", sede)); } crit.addOrder(Order.desc("id")); respuesta = crit.setFetchMode("sede", FetchMode.JOIN).setFetchMode("usuario", FetchMode.JOIN).list(); } catch (Exception e) { e.printStackTrace(); } return respuesta; }
From source file:co.id.pegadaian.pasg2.util.SusunTree.java
public void susunTree(Session session, BigInteger parentId, String jarak, Set<BigDecimal> menuIdSet) { /*menu by user */ String j = jarak;/*from w w w.jav a2s . c o m*/ jarak = j + " "; Criteria criteria = session.createCriteria(TblMenu.class); criteria.add(Restrictions.eq("parentId", new BigDecimal(parentId))); criteria.add(Restrictions.in("menuId", l)); criteria.addOrder(Order.asc("noUrut")); List<TblMenu> list = criteria.list(); PriviledgeCek pv = new PriviledgeCek(); for (TblMenu tblmenu : list) { //juka punya child if (tblmenu.getHaveChild() == '0') { //tambahkan parameter menu_id // prililedge pv.cekPriveldge(user, (tblmenu.getMenuId() + ""));//, isAdd, isEdit, isDelete, isView); String priv = "&isAdd=" + pv.getIsAdd() + "&isEdit=" + pv.getIsEdit() + "&isDelete=" + pv.getIsDelete() + "&isView=" + pv.getIsView(); sb.append( jarak + "<li " + "onclick=" + '"' + "window.open(" + "'" + tblmenu.getMenuPage() + "?param=" + tblmenu.getMenuId() + priv + "'" + "," + "'" + "MAIN" + "'" + ")" + '"' + ">"); sb.append(tblmenu.getMenuName()); SusunTree susunTree = new SusunTree(); susunTree(session, BigInteger.valueOf(tblmenu.getMenuId().longValue()), jarak, l); } else { sb.append(jarak + "<li>"); sb.append(tblmenu.getMenuName()); sb.append("\r\n" + jarak + "<ul>\r\n"); SusunTree susunTree = new SusunTree(); susunTree(session, BigInteger.valueOf(tblmenu.getMenuId().longValue()), jarak, l); sb.append(jarak + "</ul>\r\n"); } sb.append("</li>\r\n"); } }
From source file:co.id.pegadaian.pasg2.util.SusunTreeJeasyUI.java
public void susunTree(Session session, BigInteger parentId, String jarak, Set<BigDecimal> menuIdSet) { /*menu by user */ String j = jarak;// w ww .j av a 2 s . c om jarak = j + " "; Criteria criteria = session.createCriteria(TblMenu.class); criteria.add(Restrictions.eq("parentId", new BigDecimal(parentId))); criteria.add(Restrictions.in("menuId", l)); criteria.addOrder(Order.asc("noUrut")); List<TblMenu> list = criteria.list(); for (TblMenu tblmenu : list) { //juka punya child PriviledgeCek pv = new PriviledgeCek(); pv.cekPriveldge(user, (tblmenu.getMenuId() + ""));//, isAdd, isEdit, isDelete, isView); String Enc = crypto.encrypt(tblmenu.getMenuId() + ""); //String x ="isAdd="+crypto.encrypt(pv.getIsAdd())+"isEdit="+crypto.encrypt(pv.getIsEdit())+"isDelete="+crypto.encrypt(pv.getIsDelete())+"isView="+crypto.encrypt(pv.getIsView()); String x = "&isAdd=" + (pv.getIsAdd()) + "&isEdit=" + (pv.getIsEdit()) + "&isDelete=" + (pv.getIsDelete()) + "&isView=" + (pv.getIsView()); String priv = crypto.encrypt(x); String dec = "";// crypto.decrypt(priv); String usrEnc = crypto.encrypt(this.user); if (tblmenu.getHaveChild() == '0') { //tambahkan parameter menu_id// prililedge sb.append(jarak + "<li" + " id='" + tblmenu.getMenuPage() + "?param=" + priv + "&" + "param2=" + this.sKey + "&UID=" + /*this.user*/usrEnc + "'" + ">"); x = null; sb.append(tblmenu.getMenuName() + " (" + tblmenu.getMenuId() + ")");//===TAMBAHHIN MENU ID SusunTreeJeasyUI susunTree = new SusunTreeJeasyUI(); susunTree(session, BigInteger.valueOf(tblmenu.getMenuId().longValue()), jarak, l); } else { sb.append(jarak + "<li " + " id='" + "utamaMain.htm" + "?param=" + priv + "&" + "param2=" + this.sKey + "&UID=" + /*this.user*/usrEnc + "'" + "><span>"); sb.append(tblmenu.getMenuName() + " (" + tblmenu.getMenuId() + ")" + "</span>");//===TAMBAHHIN MENU ID sb.append("\r\n" + jarak + "<ul" + " id='" + "utamaMain.htm" + "?param=" + priv + "&" + "param2=" + this.sKey + "&UID=" + /*this.user*/usrEnc + "'" + ">\r\n"); SusunTreeJeasyUI susunTree = new SusunTreeJeasyUI(); susunTree(session, BigInteger.valueOf(tblmenu.getMenuId().longValue()), jarak, l); sb.append(jarak + "</ul>\r\n"); } sb.append("</li>\r\n"); } }
From source file:com.abiquo.abiserver.commands.UserCommand.java
License:Mozilla Public License
/** * Returns a list of users stored in the Data Base * /* w w w. ja va2 s. co m*/ * @param userSession * @param userListOptions an UserListOptions object containing the options to retrieve the list * of users * @return A DataResult object containing an UserListResult object with an ArrayList of User and * the number of total users */ @SuppressWarnings("unchecked") protected DataResult<UserListResult> getUsers(UserSession userSession, UserListOptions userListOptions) { DataResult<UserListResult> dataResult = new DataResult<UserListResult>(); UserListResult userListResult = new UserListResult(); Session session = null; Transaction transaction = null; try { session = HibernateUtil.getSession(); transaction = session.beginTransaction(); // Getting the user that called this method UserHB userHB = (UserHB) session.createCriteria(UserHB.class) .add(Restrictions.eq("user", userSession.getUser())).uniqueResult(); // getUsers has two different authorization resources // If the user who called this method, does not match the security level for the // authorization resource // USER_GET_ALL_USERS, this method will only return those users who belongs to the same // enterprise than // the user that called this method // Getting the authorization resource USER_GET_ALL_USERS AuthResourceHB authResourceHB = (AuthResourceHB) session.createCriteria(AuthResourceHB.class) .add(Restrictions.eq("name", "USER_GET_ALL_USERS")).uniqueResult(); // Checking if the user has not the necessary security level to see the whole list of // Users. If so, we force // the userListOptions object to filter by the enterprise assigned to the user if (authResourceHB.getRoleHB().getSecurityLevel() .compareTo(userHB.getRoleHB().getSecurityLevel()) == -1) { // NOT GRANTED! userListOptions.setByEnterprise((Enterprise) userHB.getEnterpriseHB().toPojo()); } // Creating users criteria Criteria usersListCriteria = session.createCriteria(UserHB.class); Criteria usersCountCriteria = session.createCriteria(UserHB.class); // Removing the users that are deleted usersListCriteria.add(Restrictions.eq("deleted", 0)); usersCountCriteria.add(Restrictions.eq("deleted", 0)); // Adding filter by name, surname or email Disjunction filterDisjunction = Restrictions.disjunction(); if (userListOptions.getFilter().length() > 0) { filterDisjunction.add(Restrictions.like("name", '%' + userListOptions.getFilter() + '%')); filterDisjunction.add(Restrictions.like("surname", '%' + userListOptions.getFilter() + '%')); filterDisjunction.add(Restrictions.like("email", '%' + userListOptions.getFilter() + '%')); } usersListCriteria.add(filterDisjunction); usersCountCriteria.add(filterDisjunction); // Adding filter by Enterprise if (userListOptions.getByEnterprise() != null) { usersListCriteria.add(Restrictions.eq("enterpriseHB", (EnterpriseHB) userListOptions.getByEnterprise().toPojoHB())); usersCountCriteria.add(Restrictions.eq("enterpriseHB", (EnterpriseHB) userListOptions.getByEnterprise().toPojoHB())); } // Adding order // Little fix to match the object used in Hibernate if (userListOptions.getOrderBy().compareTo("role") == 0) userListOptions.setOrderBy("roleHB"); Order order; if (userListOptions.getAsc()) order = Order.asc(userListOptions.getOrderBy()); else order = Order.desc(userListOptions.getOrderBy()); usersListCriteria.addOrder(order); usersCountCriteria.addOrder(order); // Adding filter to get only the users that currently have an active session if (userListOptions.getLoggedOnly()) { ArrayList<String> currentLoggedUsers = (ArrayList<String>) session .createSQLQuery("SELECT user FROM session WHERE expireDate > CURRENT_TIMESTAMP()").list(); usersListCriteria.add(Restrictions.in("user", currentLoggedUsers)); usersCountCriteria.add(Restrictions.in("user", currentLoggedUsers)); } // Once we have the criteria... // 1. Getting the total number of users that match userListOptions Integer totalUsers = (Integer) usersCountCriteria.setProjection(Projections.rowCount()).uniqueResult(); // 2. Getting the list of users, applying an offset and a max of results ArrayList<UserHB> usersHB = (ArrayList<UserHB>) usersListCriteria .setFirstResult(userListOptions.getOffset()).setMaxResults(userListOptions.getLength()).list(); // Building result ArrayList<User> usersList = new ArrayList<User>(); for (UserHB userToReturnHB : usersHB) { usersList.add((User) userToReturnHB.toPojo()); } userListResult.setTotalUsers(totalUsers); userListResult.setUsersList(usersList); transaction.commit(); } catch (Exception e) { if (transaction != null && transaction.isActive()) transaction.rollback(); this.errorManager.reportError(resourceManager, dataResult, "getUsers", e); return dataResult; } dataResult.setData(userListResult); dataResult.setSuccess(true); dataResult.setMessage(UserCommand.resourceManager.getMessage("getUsers.success")); return dataResult; }
From source file:com.abiquo.abiserver.commands.UserCommand.java
License:Mozilla Public License
/** * Gets the List of enterprises from the Data Base. Enterprises marked as deleted will not be * returned/*from ww w . j a v a2s. co m*/ * * @param userSession A UserSession object containing the information of the user that called * this method * @param enterpriseListOptions an UserListOptions object containing the options to retrieve the * list of users * @return A DataResult object containing an EnterpriseListResult object */ @SuppressWarnings("unchecked") protected DataResult<EnterpriseListResult> getEnterprises(UserSession userSession, EnterpriseListOptions enterpriseListOptions) { DataResult<EnterpriseListResult> dataResult = new DataResult<EnterpriseListResult>(); Session session = null; Transaction transaction = null; try { session = HibernateUtil.getSession(); transaction = session.beginTransaction(); ArrayList<Enterprise> enterpriseList = new ArrayList<Enterprise>(); Integer totalEnterprises = 0; // Getting the user that called this method UserHB userHB = (UserHB) session.createCriteria(UserHB.class) .add(Restrictions.eq("user", userSession.getUser())).uniqueResult(); // getEnterprises has two different authorization resources // If the user who called this method, does not match the security level for the // authorization resource // ENTERPRISE_GET_ALL_ENTERPRISES, this method will only return the enterprise to which // the user belongs // Getting the authorization resources ENTERPRISE_GET_ALL_ENTERPRISES AuthResourceHB authResourceHB = (AuthResourceHB) session.createCriteria(AuthResourceHB.class) .add(Restrictions.eq("name", "ENTERPRISE_GET_ALL_ENTERPRISES")).uniqueResult(); // Checking if the user has a security level equal or higher than the necessary for // retrieve the whole list of // enterprises. Tip: in securityLevel scale, 1 is the greater level of security, and 99 // the lowest if (authResourceHB.getRoleHB().getSecurityLevel() .compareTo(userHB.getRoleHB().getSecurityLevel()) > -1) { // GRANTED! This User can view other Enterprises than the one to he belongs // Creating enterprises criteria Criteria enterprisesListCriteria = session.createCriteria(EnterpriseHB.class); Criteria enterprisesCountCriteria = session.createCriteria(EnterpriseHB.class); // Removing the enterprises that are deleted enterprisesListCriteria.add(Restrictions.eq("deleted", 0)); enterprisesCountCriteria.add(Restrictions.eq("deleted", 0)); // Adding filter text enterprisesListCriteria .add(Restrictions.like("name", '%' + enterpriseListOptions.getFilter() + '%')); enterprisesCountCriteria .add(Restrictions.like("name", '%' + enterpriseListOptions.getFilter() + '%')); // Adding order enterprisesListCriteria.addOrder(Order.asc("name")); // Once we have the criteria... // 1. Getting the total number of enterprises that match enterpriseListOptions totalEnterprises = (Integer) enterprisesCountCriteria.setProjection(Projections.rowCount()) .uniqueResult(); // 2. Getting the list of enterprises, applying an offset and a max of results ArrayList<EnterpriseHB> enterpriseHBList = (ArrayList<EnterpriseHB>) enterprisesListCriteria .setFirstResult(enterpriseListOptions.getOffset()) .setMaxResults(enterpriseListOptions.getLength()).list(); // Building result for (EnterpriseHB enterpriseHB : enterpriseHBList) { enterpriseList.add((Enterprise) enterpriseHB.toPojo()); } } else { // NOT GRANTED! This User can only view the Enterprise to which he belongs enterpriseList.add((Enterprise) userHB.getEnterpriseHB().toPojo()); totalEnterprises = 1; } transaction.commit(); EnterpriseListResult enterpriseListResult = new EnterpriseListResult(); enterpriseListResult.setEnterprisesList(enterpriseList); enterpriseListResult.setTotalEnterprises(totalEnterprises); dataResult.setSuccess(true); dataResult.setData(enterpriseListResult); dataResult.setMessage(UserCommand.resourceManager.getMessage("getEnterprises.success")); } catch (Exception e) { if (transaction != null && transaction.isActive()) transaction.rollback(); this.errorManager.reportError(resourceManager, dataResult, "getEnterprises", e); } return dataResult; }
From source file:com.abiquo.server.core.appslibrary.AppsLibraryDAO.java
License:Open Source License
public AppsLibrary findByEnterprise(final Enterprise enterprise) { Criteria criteria = createCriteria(sameEnterprise(enterprise)); criteria.addOrder(Order.asc(AppsLibrary.ENTERPRISE_PROPERTY)); return (AppsLibrary) criteria.uniqueResult(); }
From source file:com.abiquo.server.core.appslibrary.TemplateDefinitionDAO.java
License:Open Source License
public List<TemplateDefinition> findByAppsLibrary(final AppsLibrary appsLibrary) { Criteria criteria = createCriteria(sameAppsLibrary(appsLibrary)); criteria.addOrder(Order.asc(TemplateDefinition.NAME_PROPERTY)); return getResultList(criteria); }
From source file:com.abiquo.server.core.appslibrary.TemplateDefinitionListDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public TemplateDefinitionList findByName(final String name) { Criteria criteria = createCriteria(sameName(name)); criteria.addOrder(Order.asc(TemplateDefinitionList.NAME_PROPERTY)); return (TemplateDefinitionList) criteria.uniqueResult(); }