List of usage examples for org.hibernate.criterion DetachedCriteria forEntityName
@SuppressWarnings("UnusedDeclaration") public static DetachedCriteria forEntityName(String entityName)
From source file:ro.cs.ts.model.dao.impl.DaoExchangeImpl.java
License:Open Source License
/** * Get a list of exchanges by projectDetailId * //from w w w . j a va 2 s . c o m * @author Adelina * * @param projectDetailId * @return */ public List<Exchange> getByProjectDetailId(Integer projectDetailId) { logger.debug("getByProjectDetailId - START"); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.exchangeEntity); dc.add(Restrictions.eq("projectDetailId", projectDetailId)); dc.add(Restrictions.ne("status", IConstant.NOM_EXCHANGE_STATUS_DELETED)); List<Exchange> res = (List<Exchange>) getHibernateTemplate().findByCriteria(dc); logger.debug("getByProjectDetailId - END"); return res; }
From source file:ro.cs.ts.model.dao.impl.DaoNotificationImpl.java
License:Open Source License
public List<Notification> getNotificationsFromSearch(SearchNotificationBean searchNotificationBean, boolean isDeleteAction) { logger.debug("getNotificationsFromSearch - START "); /*Once a Projection is being set to a Detached Criteria object, it cannot be removed anymore, so two identical DetachedCriteria objects must be created: /* www .j a v a 2 s. co m*/ -dcCount ( on which the projection is being set )used to retrieve the number of distinct results which is set when the request didn't come from the pagination area and needed further more to set the current page after a delete action; -dc used to retrieve the result set after the current page has been set in case of a delete action */ // set search criterion DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.notificationEntity); DetachedCriteria dcCount = DetachedCriteria.forEntityName(IModelConstant.notificationEntity); dc.add(Restrictions.eq("receiverId", searchNotificationBean.getReceiverId())); dcCount.add(Restrictions.eq("receiverId", searchNotificationBean.getReceiverId())); if (searchNotificationBean.getStartDate() != null) { dc.add(Expression.ge("issuedDate", searchNotificationBean.getStartDate())); dcCount.add(Expression.ge("issuedDate", searchNotificationBean.getStartDate())); } if (searchNotificationBean.getEndDate() != null) { dc.add(Expression.le("issuedDate", searchNotificationBean.getEndDate())); dcCount.add(Expression.le("issuedDate", searchNotificationBean.getEndDate())); } if (searchNotificationBean.getMessage() != null && !"".equals(searchNotificationBean.getMessage())) { dc.add(Restrictions.ilike("message", "%".concat(searchNotificationBean.getMessage()).concat("%"))); dcCount.add(Restrictions.ilike("message", "%".concat(searchNotificationBean.getMessage()).concat("%"))); } // check if I have to order the results if (searchNotificationBean.getSortParam() != null && !"".equals(searchNotificationBean.getSortParam())) { // if I have to, check if I have to order them ascending or descending if (searchNotificationBean.getSortDirection() == -1) { // ascending dc.addOrder(Order.asc(searchNotificationBean.getSortParam())); } else { // descending dc.addOrder(Order.desc(searchNotificationBean.getSortParam())); } } // if the request didn't come from the pagination area, // it means that I have to set the number of results and pages if (isDeleteAction || searchNotificationBean.getNbrOfResults() == -1) { boolean isSearch = false; if (searchNotificationBean.getNbrOfResults() == -1) { isSearch = true; } // set the countDistinct restriction dcCount.setProjection(Projections.distinct(Projections.countDistinct(IModelConstant.notificationId))); int nbrOfResults = ((Integer) getHibernateTemplate().findByCriteria(dcCount, 0, 0).get(0)).intValue(); searchNotificationBean.setNbrOfResults(nbrOfResults); logger.debug("NbrOfResults " + searchNotificationBean.getNbrOfResults()); logger.debug("----> searchOrganisationBean.getResults " + searchNotificationBean.getResultsPerPage()); // get the number of pages if (nbrOfResults % searchNotificationBean.getResultsPerPage() == 0) { searchNotificationBean.setNbrOfPages(nbrOfResults / searchNotificationBean.getResultsPerPage()); } else { searchNotificationBean.setNbrOfPages(nbrOfResults / searchNotificationBean.getResultsPerPage() + 1); } // after a notification is deleted, the same page has to be displayed; // only when all the notifications from last page are deleted, the previous page will be shown if (isDeleteAction && (searchNotificationBean.getCurrentPage() > searchNotificationBean.getNbrOfPages())) { searchNotificationBean.setCurrentPage(searchNotificationBean.getNbrOfPages()); } else if (isSearch) { searchNotificationBean.setCurrentPage(1); } } List<Notification> res = getHibernateTemplate().findByCriteria(dc, Long.valueOf( (searchNotificationBean.getCurrentPage() - 1) * searchNotificationBean.getResultsPerPage()) .intValue(), Long.valueOf(searchNotificationBean.getResultsPerPage()).intValue()); if (res != null) { logger.debug("results size : ".concat(String.valueOf(res.size()))); } else { logger.debug("results size: 0"); } logger.debug("getNotificationsFromSearch - END"); return res; }
From source file:ro.cs.ts.model.dao.impl.DaoNotificationSettingImpl.java
License:Open Source License
/** * Checks if there are saved settings in the database for the specific parameters * @author alexandru.dobre/*from ww w . j a v a 2 s . c o m*/ */ public boolean hasSettings(Integer projectDetailId, Integer userId, Integer organizationId) { logger.debug("hasSettings - START"); DetachedCriteria dcCount = DetachedCriteria.forEntityName(IModelConstant.notificationSettingEntity); if (projectDetailId != null) { dcCount.add(Restrictions.eq("projectDetailId", projectDetailId)); } else { dcCount.add(Restrictions.isNull("projectDetailId")); } if (userId != null) { dcCount.add(Restrictions.eq("userId", userId)); } if (organizationId != null) { dcCount.add(Restrictions.eq("organizationId", organizationId)); } dcCount.setProjection(Projections.countDistinct("notificationSettingsId")); int nbrOfResults = ((Integer) getHibernateTemplate().findByCriteria(dcCount, 0, 0).get(0)).intValue(); logger.debug("hasSettings - END results: " + nbrOfResults); if (nbrOfResults > 0) return true; return false; }
From source file:ro.cs.ts.model.dao.impl.DaoNotificationSettingImpl.java
License:Open Source License
/** * Returns a list of settings for the specified parameters * @author alexandru.dobre//from w w w . j a va2 s . c o m */ public List<NotificationSetting> getSettings(Integer projectDetailId, Integer userId, Integer organizationId) { logger.debug("getSettings - START"); DetachedCriteria dcCount = DetachedCriteria.forEntityName(IModelConstant.notificationSettingEntity); if (projectDetailId != null) { dcCount.add(Restrictions.eq("projectDetailId", projectDetailId)); } else { dcCount.add(Restrictions.isNull("projectDetailId")); } if (userId != null) { dcCount.add(Restrictions.eq("userId", userId)); } if (organizationId != null) { dcCount.add(Restrictions.eq("organizationId", organizationId)); } List<NotificationSetting> nsl = getHibernateTemplate().findByCriteria(dcCount, 0, 0); logger.debug("getSettings - END result size: " + nsl.size()); return nsl; }
From source file:ro.cs.ts.model.dao.impl.DaoNotificationSettingImpl.java
License:Open Source License
/** * Returns the status for a speciffic setting or null if it has not been set yet * @author alexandru.dobre//from www. j a v a 2s . c o m */ public Byte getStatusForSetting(Integer projectDetailId, Integer userId, Integer organizationId, byte setting) { logger.debug("getStatusForSetting - START"); DetachedCriteria dcCount = DetachedCriteria.forEntityName(IModelConstant.notificationSettingEntity); if (projectDetailId != null) { dcCount.add(Restrictions.eq("projectDetailId", projectDetailId)); } else { dcCount.add(Restrictions.isNull("projectDetailId")); } if (userId != null) { dcCount.add(Restrictions.eq("userId", userId)); } if (organizationId != null) { dcCount.add(Restrictions.eq("organizationId", organizationId)); } if (organizationId != null) { dcCount.add(Restrictions.eq("setting", setting)); } List<NotificationSetting> nsl = getHibernateTemplate().findByCriteria(dcCount, 0, 0); logger.debug("getStatusForSetting - END result size: " + nsl.size()); if (nsl.size() > 0) { return new Byte(nsl.get(0).getStatus()); } else { return null; } }
From source file:ro.cs.ts.model.dao.impl.DaoNotificationSettingImpl.java
License:Open Source License
/** * Returns the language setting for the specified user or null if one is not yet set * @author alexandru.dobre//from w w w . j av a 2 s .com * */ public NotificationSetting getLanguage(Integer userId) { logger.debug("getLanguage - START"); DetachedCriteria dcCount = DetachedCriteria.forEntityName(IModelConstant.notificationSettingEntity); dcCount.add(Restrictions.eq("userId", userId)); dcCount.add(Restrictions.eq("organizationId", -1)); List<NotificationSetting> nsl = getHibernateTemplate().findByCriteria(dcCount, 0, 0); logger.debug("getSettings - END result size: " + nsl.size()); if (nsl.size() > 0) { return nsl.get(0); } else { return null; } }
From source file:ro.cs.ts.model.dao.impl.DaoPersonDetailImpl.java
License:Open Source License
/** * Gets the PersonDetail identified by the specified personId * @author Coni/*from w w w. j ava 2 s . c om*/ * @param personId * @return */ public PersonDetail getByPersonId(int personId) { logger.debug("getByPersonId - START"); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.personDetailEntity); dc.add(Restrictions.eq("personId", personId)); dc.add(Restrictions.ne("status", IConstant.NOM_PERSON_DETAIL_STATUS_DELETED)); List<PersonDetail> res = (List<PersonDetail>) getHibernateTemplate().findByCriteria(dc); logger.debug("getByPersonId - END"); if (res != null && res.size() > 0) { return res.get(0); } else { return null; } }
From source file:ro.cs.ts.model.dao.impl.DaoPersonDetailImpl.java
License:Open Source License
/** * Checks if the person has details associated * // w ww.j a va 2 s . c om * @author Adelina * * @param personId * @return */ public boolean hasPersonDetail(Integer personId) { logger.debug("hasPersonDetail - START "); List<PersonDetail> personDetails = new ArrayList<PersonDetail>(); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.personDetailSimpleEntity); dc.add(Restrictions.eq("personId", personId)); dc.add(Restrictions.ne("status", IConstant.NOM_PERSON_DETAIL_STATUS_DELETED)); personDetails = getHibernateTemplate().findByCriteria(dc); logger.debug("hasPersonDetail - END "); if (personDetails.size() > 0) { return true; } else { return false; } }
From source file:ro.cs.ts.model.dao.impl.DaoPersonDetailImpl.java
License:Open Source License
/** * Returns PersonDetail entities that use the Currency with the id currencyId * @author Coni//ww w . ja v a 2 s . com * @param currencyId * @return * @throws BusinessException */ public List<PersonDetail> getByCurrencyId(int currencyId) { logger.debug("getByCurrencyId - START"); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.personDetailEntity); dc.add(Restrictions.eq("costPriceCurrencyId", currencyId)); dc.add(Restrictions.ne("status", IConstant.NOM_PERSON_DETAIL_STATUS_DELETED)); List<PersonDetail> res = getHibernateTemplate().findByCriteria(dc); logger.debug("getByCurrencyId - END"); return res; }
From source file:ro.cs.ts.model.dao.impl.DaoPersonDetailImpl.java
License:Open Source License
/** * Gets the PersonDetail identified by the specified personId, with currencies * // w ww .j a v a 2 s. com * @author Adelina * * @param personId * @return */ public PersonDetail getByPersonWithCurrencies(int personId) { logger.debug("getByPersonWithCurrencies - START"); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.personDetailWithCurrencyEntity); dc.add(Restrictions.eq("personId", personId)); dc.add(Restrictions.ne("status", IConstant.NOM_PERSON_DETAIL_STATUS_DELETED)); List<PersonDetail> res = (List<PersonDetail>) getHibernateTemplate().findByCriteria(dc); logger.debug("getByPersonWithCurrencies - END"); if (res != null && res.size() > 0) { return res.get(0); } else { return new PersonDetail(); } }