List of usage examples for org.hibernate.criterion Restrictions ilike
public static Criterion ilike(String propertyName, Object value)
From source file:com.ignou.aadhar.dao.hibernate.BankDaoHibernate.java
License:Open Source License
/** * Gets the records from the Database based on the parameters provided. * @param searchField The field name on which the search is to be made. * @param searchValue Value which needs to be searched. * @param pageNumber Initial offset of the records. * @param recordsPerPage Total number of records which are selected for * resultset./*from w w w . j av a2 s. c o m*/ * @param sortField Name of the field on which the data needs to be sorted. * @param sortOrder Order in which the sortField is sorted. * @return Returns the records as list of map where each map stores the * record data as key-value pairs. */ @Override public List<Map<String, Object>> getBanks(String searchField, String searchValue, Integer pageNumber, Integer recordsPerPage, String sortField, String sortOrder) { List<Bank> banks = null; List<Map<String, Object>> returnBanks = new ArrayList<Map<String, Object>>(); Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Bank.class); /* Add the search parameters to the criteria */ if (searchField != null && !searchField.isEmpty() && searchValue != null && !searchValue.isEmpty()) { /* Prefix and suffix the searchValue with % */ searchValue = "%" + searchValue + "%"; /* Now there are only two fields which we can search here. */ if ("name".equals(searchField)) { criteria.add(Restrictions.ilike("name", searchValue)); } else if ("url".equals(searchField)) { criteria.add(Restrictions.ilike("url", searchValue)); } } /* Let's first get the total number of records that satisfy the provided * parameters. */ String totalCount = (String) criteria.setProjection(Projections.rowCount()).uniqueResult().toString(); /* Reset the Criteria specification to remove the projection details */ criteria.setProjection(null); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); /* Set the default sort field if not provided */ if (sortField != null && !sortField.isEmpty()) { /* Check what order was provided for this field */ if ("asc".equals(sortOrder)) { /* Sort in ascending order */ criteria.addOrder(Order.asc(sortField)); } else if ("desc".equals(sortOrder)) { /* Sort in descending order */ criteria.addOrder(Order.desc(sortField)); } else { /* Default sort behaviour other wise */ criteria.addOrder(Order.asc(sortField)); } } /* Set the record filtering on pageCount and recordsPerPage if they are * available. */ if (pageNumber != null && recordsPerPage != null) { banks = criteria.setFirstResult(pageNumber).setMaxResults(recordsPerPage).list(); } else { banks = criteria.list(); } /* Format this data before sending back for any other further usage */ for (Bank bankRecord : banks) { /* Create new map for current bank and add it to master list */ Map<String, Object> returnMap = new LinkedHashMap<String, Object>(); returnMap.put("id", bankRecord.getId()); returnMap.put("name", bankRecord.getName()); returnMap.put("url", bankRecord.getUrl()); returnMap.put("totalCount", totalCount); returnBanks.add(returnMap); } return returnBanks; }
From source file:com.ignou.aadhar.dao.hibernate.CityDaoHibernate.java
License:Open Source License
/** * Gets the records from the Database based on the parameters provided. * @param searchField The field name on which the search is to be made. * @param searchValue Value which needs to be searched. * @param pageNumber Initial offset of the records. * @param recordsPerPage Total number of records which are selected for * resultset.// w w w. j a v a 2 s.c o m * @param sortField Name of the field on which the data needs to be sorted. * @param sortOrder Order in which the sortField is sorted. * @return Returns the records as list of map where each map stores the * record data as key-value pairs. */ @Override public List<Map<String, Object>> getCities(String searchField, String searchValue, Integer pageNumber, Integer recordsPerPage, String sortField, String sortOrder) { List<City> cities = null; List<Map<String, Object>> returnCities = new ArrayList<Map<String, Object>>(); Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(City.class, "c") .createAlias("state", "s"); /* Add the search parameters to the criteria */ if (searchField != null && !searchField.isEmpty() && searchValue != null && !searchValue.isEmpty()) { /* Prefix and suffix the searchValue with % */ searchValue = "%" + searchValue + "%"; /* Now there are only two fields which we can search here. */ if ("city".equals(searchField)) { criteria.add(Restrictions.ilike("c.city", searchValue)); } else if ("state".equals(searchField)) { criteria.add(Restrictions.ilike("s.state", searchValue)); } } /* Let's first get the total number of records that satisfy the provided * parameters. */ String totalCount = (String) criteria.setProjection(Projections.rowCount()).uniqueResult().toString(); /* Reset the Criteria specification to remove the projection details */ criteria.setProjection(null); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); /* Set the default sort field if not provided */ if (sortField != null && !sortField.isEmpty()) { /* Check what order was provided for this field */ if ("asc".equals(sortOrder)) { /* Sort in ascending order */ criteria.addOrder(Order.asc(sortField)); } else if ("desc".equals(sortOrder)) { /* Sort in descending order */ criteria.addOrder(Order.desc(sortField)); } else { /* Default sort behaviour other wise */ criteria.addOrder(Order.asc(sortField)); } } /* We don't want to load the entire objects. Just the names would * suffice. Setting projections for the same. */ //criteria.setProjection(Projections.property("id").as("id")); //criteria.setProjection(Projections.property("city").as("city")); //criteria.setProjection(Projections.property("state").as("state")); /* Set the record filtering on pageCount and recordsPerPage if they are * available. */ if (pageNumber != null && recordsPerPage != null) { cities = criteria.setFirstResult(pageNumber).setMaxResults(recordsPerPage).list(); } else { cities = criteria.list(); } /* Format this data before sending back for any other further usage */ for (City cityRecord : cities) { /* Create a new map for current city and add it to master list */ Map<String, Object> returnMap = new LinkedHashMap<String, Object>(); returnMap.put("id", cityRecord.getId()); returnMap.put("city", cityRecord.getCity()); returnMap.put("state", cityRecord.getState().getState()); returnMap.put("totalCount", totalCount); returnCities.add(returnMap); } return returnCities; }
From source file:com.ignou.aadhar.dao.hibernate.DistrictDaoHibernate.java
License:Open Source License
/** * Gets the records from the Database based on the parameters provided. * @param searchField The field name on which the search is to be made. * @param searchValue Value which needs to be searched. * @param pageNumber Initial offset of the records. * @param recordsPerPage Total number of records which are selected for * resultset.//w w w. ja v a 2 s.c o m * @param sortField Name of the field on which the data needs to be sorted. * @param sortOrder Order in which the sortField is sorted. * @return Returns the records as list of map where each map stores the * record data as key-value pairs. */ @Override public List<Map<String, Object>> getDistricts(String searchField, String searchValue, Integer pageNumber, Integer recordsPerPage, String sortField, String sortOrder) { List<District> districts = null; List<Map<String, Object>> returnDistricts = new ArrayList<Map<String, Object>>(); Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(District.class, "d") .createAlias("state", "s"); /* Add the search parameters to the criteria */ if (searchField != null && !searchField.isEmpty() && searchValue != null && !searchValue.isEmpty()) { /* Prefix and suffix the searchValue with % */ searchValue = "%" + searchValue + "%"; /* Now there are only two fields which we can search here. */ if ("district".equals(searchField)) { criteria.add(Restrictions.ilike("d.district", searchValue)); } else if ("state".equals(searchField)) { criteria.add(Restrictions.ilike("s.state", searchValue)); } } /* Let's first get the total number of records that satisfy the provided * parameters. */ String totalCount = (String) criteria.setProjection(Projections.rowCount()).uniqueResult().toString(); /* Reset the Criteria specification to remove the projection details */ criteria.setProjection(null); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); /* Set the default sort field if not provided */ if (sortField != null && !sortField.isEmpty()) { /* Check what order was provided for this field */ if ("asc".equals(sortOrder)) { /* Sort in ascending order */ criteria.addOrder(Order.asc(sortField)); } else if ("desc".equals(sortOrder)) { /* Sort in descending order */ criteria.addOrder(Order.desc(sortField)); } else { /* Default sort behaviour other wise */ criteria.addOrder(Order.asc(sortField)); } } /* Set the record filtering on pageCount and recordsPerPage if they are * available. */ if (pageNumber != null && recordsPerPage != null) { districts = criteria.setFirstResult(pageNumber).setMaxResults(recordsPerPage).list(); } else { districts = criteria.list(); } /* Format this data before sending back for any other further usage */ for (District districtRecord : districts) { /* Create new map for current district and add it to master list */ Map<String, Object> returnMap = new LinkedHashMap<String, Object>(); returnMap.put("id", districtRecord.getId()); returnMap.put("district", districtRecord.getDistrict()); returnMap.put("state", districtRecord.getState().getState()); returnMap.put("totalCount", totalCount); returnDistricts.add(returnMap); } return returnDistricts; }
From source file:com.ignou.aadhar.dao.hibernate.ServiceProviderDaoHibernate.java
License:Open Source License
/** * Gets the records from the Database based on the parameters provided. * @param searchField The field name on which the search is to be made. * @param searchValue Value which needs to be searched. * @param pageNumber Initial offset of the records. * @param recordsPerPage Total number of records which are selected for * resultset.//ww w . j ava 2s . c o m * @param sortField Name of the field on which the data needs to be sorted. * @param sortOrder Order in which the sortField is sorted. * @return Returns the records as list of map where each map stores the * record data as key-value pairs. */ @Override public List<Map<String, Object>> getServiceProviders(String searchField, String searchValue, Integer pageNumber, Integer recordsPerPage, String sortField, String sortOrder) { List<ServiceProvider> records = null; List<Map<String, Object>> returnRecords = new ArrayList<Map<String, Object>>(); Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(ServiceProvider.class); /* Add the search parameters to the criteria */ if (searchField != null && !searchField.isEmpty() && searchValue != null && !searchValue.isEmpty()) { /* Prefix and suffix the searchValue with % */ searchValue = "%" + searchValue + "%"; /* Set the matching field accordingly */ if ("name".equals(searchField)) { criteria.add(Restrictions.ilike("name", searchValue)); } else if ("requestUrl".equals(searchField)) { criteria.add(Restrictions.ilike("requestUrl", searchValue)); } else if ("responseUrl".equals(searchField)) { criteria.add(Restrictions.ilike("responseUrl", searchValue)); } else if ("accountNumber".equals(searchField)) { criteria.add(Restrictions.ilike("accountNumber", searchValue)); } else if ("bankIFSCode".equals(searchField)) { criteria.add(Restrictions.ilike("bankIFSCode", searchValue)); } } /* Let's first get the total number of records that satisfy the provided * parameters. */ String totalCount = (String) criteria.setProjection(Projections.rowCount()).uniqueResult().toString(); /* Reset the Criteria specification to remove the projection details */ criteria.setProjection(null); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); /* Set the default sort field if not provided */ if (sortField != null && !sortField.isEmpty()) { /* Check what order was provided for this field */ if ("asc".equals(sortOrder)) { /* Sort in ascending order */ criteria.addOrder(Order.asc(sortField)); } else if ("desc".equals(sortOrder)) { /* Sort in descending order */ criteria.addOrder(Order.desc(sortField)); } else { /* Default sort behaviour other wise */ criteria.addOrder(Order.asc(sortField)); } } /* Set the record filtering on pageCount and recordsPerPage if they are * available. */ if (pageNumber != null && recordsPerPage != null) { records = criteria.setFirstResult(pageNumber).setMaxResults(recordsPerPage).list(); } else { records = criteria.list(); } /* Format this data before sending back for any other further usage */ for (ServiceProvider serviceProvider : records) { /* Create new map for current service provider and add it to * master list */ Map<String, Object> returnMap = new LinkedHashMap<String, Object>(); returnMap.put("id", serviceProvider.getId()); returnMap.put("name", serviceProvider.getName()); returnMap.put("requestUrl", serviceProvider.getRequestUrl()); returnMap.put("responseUrl", serviceProvider.getResponseUrl()); returnMap.put("accountNumber", serviceProvider.getAccountNumber()); returnMap.put("bankIFSCCode", serviceProvider.getBankIFSCCode()); returnMap.put("totalCount", totalCount); returnRecords.add(returnMap); } return returnRecords; }
From source file:com.ignou.aadhar.dao.hibernate.StateDaoHibernate.java
License:Open Source License
/** * Gets the records from the Database based on the parameters provided. * @param searchField The field name on which the search is to be made. * @param searchValue Value which needs to be searched. * @param pageNumber Initial offset of the records. * @param recordsPerPage Total number of records which are selected for * resultset.//from ww w . j a va 2s . c o m * @param sortField Name of the field on which the data needs to be sorted. * @param sortOrder Order in which the sortField is sorted. * @return Returns the records as list of map where each map stores the * record data as key-value pairs. */ @Override public List<Map<String, Object>> getStates(String searchField, String searchValue, Integer pageNumber, Integer recordsPerPage, String sortField, String sortOrder) { List<State> states = null; List<Map<String, Object>> returnStates = new ArrayList<Map<String, Object>>(); Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(State.class, "s"); /* Add the search parameters to the criteria */ if (searchField != null && !searchField.isEmpty() && searchValue != null && !searchValue.isEmpty()) { /* Prefix and suffix the searchValue with % */ searchValue = "%" + searchValue + "%"; criteria.add(Restrictions.ilike("s.state", searchValue)); } /* Let's first get the total number of records that satisfy the provided * parameters. */ String totalCount = (String) criteria.setProjection(Projections.rowCount()).uniqueResult().toString(); /* Reset the Criteria specification to remove the projection details */ criteria.setProjection(null); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); /* Set the default sort field if not provided */ if (sortField != null && !sortField.isEmpty()) { /* Check what order was provided for this field */ if ("asc".equals(sortOrder)) { /* Sort in ascending order */ criteria.addOrder(Order.asc(sortField)); } else if ("desc".equals(sortOrder)) { /* Sort in descending order */ criteria.addOrder(Order.desc(sortField)); } else { /* Default sort behaviour other wise */ criteria.addOrder(Order.asc(sortField)); } } /* Set the record filtering on pageCount and recordsPerPage if they are * available. */ if (pageNumber != null && recordsPerPage != null) { states = criteria.setFirstResult(pageNumber).setMaxResults(recordsPerPage).list(); } else { states = criteria.list(); } /* Format this data before sending back for any other further usage */ for (State stateRecord : states) { /* Create new map for current state and add it to master list */ Map<String, Object> returnMap = new LinkedHashMap<String, Object>(); returnMap.put("id", stateRecord.getId()); returnMap.put("state", stateRecord.getState()); returnMap.put("totalCount", totalCount); returnStates.add(returnMap); } return returnStates; }
From source file:com.ignou.aadhar.dao.hibernate.TransactionDaoHibernate.java
License:Open Source License
/** * Gets the records from the Database based on the parameters provided. * @param searchField The field name on which the search is to be made. * @param searchValue Value which needs to be searched. * @param pageNumber Initial offset of the records. * @param recordsPerPage Total number of records which are selected for * resultset.//from w w w.ja v a 2 s .c om * @param sortField Name of the field on which the data needs to be sorted. * @param sortOrder Order in which the sortField is sorted. * @return Returns the records as list of map where each map stores the * record data as key-value pairs. */ @Override @Transactional public List<Map<String, Object>> getTransactions(String searchField, String searchValue, Integer pageNumber, Integer recordsPerPage, String sortField, String sortOrder) { List<Transaction> records = null; List<Map<String, Object>> returnRecords = new ArrayList<Map<String, Object>>(); Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Transaction.class); /* Add the search parameters to the criteria */ if (searchField != null && !searchField.isEmpty() && searchValue != null && !searchValue.isEmpty()) { /* Prefix and suffix the searchValue with % */ searchValue = "%" + searchValue + "%"; /* Set the matching field accordingly */ if ("uid".equals(searchField)) { criteria.add(Restrictions.ilike("citizen.uid", searchValue)); } else if ("serviceprovider".equals(searchField)) { criteria.add(Restrictions.ilike("serviceProvider.name", searchValue)); } else if ("clientTxnId".equals(searchField)) { criteria.add(Restrictions.ilike("spTransactionId", searchValue)); } else if ("bankTxnId".equals(searchField)) { criteria.add(Restrictions.ilike("bankTransactionId", searchValue)); } else if ("status".equals(searchField)) { criteria.add(Restrictions.ilike("status", searchValue)); } } /* Let's first get the total number of records that satisfy the provided * parameters. */ String totalCount = (String) criteria.setProjection(Projections.rowCount()).uniqueResult().toString(); /* Reset the Criteria specification to remove the projection details */ criteria.setProjection(null); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); /* Set the default sort field if not provided */ if (sortField != null && !sortField.isEmpty()) { /* Check what order was provided for this field */ if ("asc".equals(sortOrder)) { /* Sort in ascending order */ criteria.addOrder(Order.asc(sortField)); } else if ("desc".equals(sortOrder)) { /* Sort in descending order */ criteria.addOrder(Order.desc(sortField)); } else { /* Default sort behaviour other wise */ criteria.addOrder(Order.asc(sortField)); } } /* Set the record filtering on pageCount and recordsPerPage if they are * available. */ if (pageNumber != null && recordsPerPage != null) { records = criteria.setFirstResult(pageNumber).setMaxResults(recordsPerPage).list(); } else { records = criteria.list(); } /* Format the Date */ SimpleDateFormat format = new SimpleDateFormat("dd-MMM-yyyy h:m:s a"); /* Format this data before sending back for any other further usage */ for (Transaction transaction : records) { /* Create new map for current transaction and add it to * master list */ Map<String, Object> returnMap = new LinkedHashMap<String, Object>(); returnMap.put("id", transaction.getId()); returnMap.put("uid", transaction.getCitizen().getUid()); returnMap.put("name", transaction.getCitizen().getName()); returnMap.put("serviceprovider", transaction.getServiceProvider().getName()); returnMap.put("clientTxnId", transaction.getSpTransactionId()); returnMap.put("bankTxnId", transaction.getBankTransactionId()); returnMap.put("status", transaction.getStatus()); returnMap.put("created", format.format(transaction.getCreated())); returnMap.put("amount", transaction.getAmount()); returnMap.put("totalCount", totalCount); returnRecords.add(returnMap); } return returnRecords; }
From source file:com.indicator_engine.dao.GLACategoryDaoImpl.java
License:Open Source License
/** * Searches Category Items based on a Minor Value. * @param searchParameter Minor Value used for Searching. * @param exactSearch Search Type : Exact or Likewise. * @param colName Column Name used for Sorting the Results. * @param sortDirection Sorting Direction : Ascending/Descending. * @param sort Turn Sorting ON/OFF.//from ww w . ja v a 2 s .c om * @return Returns list of Matching GLACategory Items. */ @Override @Transactional(readOnly = true) public List<GLACategory> searchCategoryByMinor(String searchParameter, boolean exactSearch, String colName, String sortDirection, boolean sort) { if (!exactSearch) searchParameter = "%" + searchParameter + "%"; Session session = factory.getCurrentSession(); Criteria criteria = session.createCriteria(GLACategory.class); criteria.setFetchMode("events", FetchMode.JOIN); if (!exactSearch) criteria.add(Restrictions.ilike("minor", searchParameter)); else criteria.add(Restrictions.eq("minor", searchParameter)); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); if (sort) { if (sortDirection.equals("asc")) criteria.addOrder(Order.asc(colName)); else criteria.addOrder(Order.desc(colName)); } return criteria.list(); }
From source file:com.indicator_engine.dao.GLAEntityDaoImpl.java
License:Open Source License
/** * Search GLA Entity Objects based on Entity Key * @param searchParameter Entity Key used for searching * @param exactSearch Search Pattern : Exact or Likewise * @param colName Sort Results based on this Column Name * @param sortDirection Specify Sort Direction ASC/DESC * @param sort Turn Sorting ON/OFF.//ww w.j av a 2s . co m * @return Returns all GLA Entity Objects present in Database and matching the Search Criteria. **/ @Override @Transactional(readOnly = true) public List<GLAEntity> searchEntitiesByKey(String searchParameter, boolean exactSearch, String colName, String sortDirection, boolean sort) { if (!exactSearch) searchParameter = "%" + searchParameter + "%"; Session session = factory.getCurrentSession(); Criteria criteria = session.createCriteria(GLAEntity.class); criteria.createAlias("glaEvent", "events"); criteria.setFetchMode("events", FetchMode.JOIN); criteria.createAlias("events.glaCategory", "category"); criteria.setFetchMode("category", FetchMode.JOIN); criteria.createAlias("events.glaUser", "users"); criteria.setFetchMode("users", FetchMode.JOIN); if (!exactSearch) criteria.add(Restrictions.ilike("key", searchParameter)); else criteria.add(Restrictions.eq("key", searchParameter)); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); if (sort) { if (sortDirection.equals("asc")) criteria.addOrder(Order.asc(colName)); else criteria.addOrder(Order.desc(colName)); } return criteria.list(); }
From source file:com.indicator_engine.dao.GLAEventDaoImpl.java
License:Open Source License
/** * Adds a new GLA Entity Object to the Database. * @param glaEntity New GLA Entity Object to be saved. * @return ID of the Newly Created GLA Entity object in DB. **///from w w w . j a v a 2s. com @Override @Transactional(readOnly = true) public List<GLAEvent> searchEventsByAction(String searchParameter, boolean exactSearch, String colName, String sortDirection, boolean sort) { if (!exactSearch) searchParameter = "%" + searchParameter + "%"; Session session = factory.getCurrentSession(); Criteria criteria = session.createCriteria(GLAEvent.class); criteria.setFetchMode("entities", FetchMode.JOIN); criteria.setFetchMode("glaUser", FetchMode.JOIN); criteria.setFetchMode("glaCategory", FetchMode.JOIN); if (!exactSearch) criteria.add(Restrictions.ilike("action", searchParameter)); else criteria.add(Restrictions.eq("action", searchParameter)); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); if (sort) { if (sortDirection.equals("asc")) criteria.addOrder(Order.asc(colName)); else criteria.addOrder(Order.desc(colName)); } return criteria.list(); }
From source file:com.indicator_engine.dao.GLAIndicatorDaoImpl.java
License:Open Source License
/** * Loads an existing Indicator from the Database. Looks up using name in the Database. It does a similarity search in the database. * @param indicatorName Name of the Indicator used for lookup. * @return A List of similarly named Indicators present in the Database. */// w ww. j av a 2s .c om @Override @Transactional public List<GLAIndicator> loadByIndicatorByName(String indicatorName, boolean exact) { Session session = factory.getCurrentSession(); indicatorName = "%" + indicatorName + "%"; Criteria criteria = session.createCriteria(GLAIndicator.class); criteria.setFetchMode("queries", FetchMode.JOIN); criteria.setFetchMode("glaIndicatorProps", FetchMode.JOIN); if (exact) criteria.add(Restrictions.eq("indicator_name", indicatorName)); else criteria.add(Restrictions.ilike("indicator_name", indicatorName)); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria.list(); }