List of usage examples for org.hibernate.criterion DetachedCriteria forClass
public static DetachedCriteria forClass(Class clazz)
From source file:com.salesmanager.core.service.reference.impl.dao.ModuleConfigurationDao.java
License:Open Source License
public Collection<ModuleConfiguration> findByConfigurationModuleAndCountryCode(String configurationModule, String countryIsoCode) {// ww w.java2 s . c o m try { List countryList = new ArrayList(); countryList.add(countryIsoCode); countryList.add(Constants.ALLCOUNTRY_ISOCODE); DetachedCriteria crit = DetachedCriteria.forClass(ModuleConfiguration.class); crit.add(Expression.in("id.countryIsoCode2", countryList)); crit.add(Expression.eq("id.configurationModule", configurationModule)); Collection list = this.getHibernateTemplate().findByCriteria(crit); List countrySpecificList = new ArrayList(); Iterator i = list.iterator(); while (i.hasNext()) { ModuleConfiguration cms = (ModuleConfiguration) i.next(); if (cms.getId().getCountryIsoCode2().equals(countryIsoCode)) { countrySpecificList.add(cms); } } if (countrySpecificList.size() > 0) { return countrySpecificList; } else { return list; } } catch (RuntimeException re) { log.error("get failed", re); throw re; } }
From source file:com.salesmanager.core.service.reference.impl.dao.ModuleConfigurationDao.java
License:Open Source License
public Collection<ModuleConfiguration> findByConfigurationKeyAndCountryCode(String configurationKey, String countryIsoCode) {/*w w w .j a v a 2s .co m*/ try { List countryList = new ArrayList(); countryList.add(countryIsoCode); countryList.add(Constants.ALLCOUNTRY_ISOCODE); DetachedCriteria crit = DetachedCriteria.forClass(ModuleConfiguration.class); crit.add(Expression.in("id.countryIsoCode2", countryList)); crit.add(Expression.eq("id.configurationKey", configurationKey)); Collection result = this.getHibernateTemplate().findByCriteria(crit); List countrySpecificList = new ArrayList(); Iterator i = result.iterator(); while (i.hasNext()) { ModuleConfiguration cms = (ModuleConfiguration) i.next(); if (cms.getId().getCountryIsoCode2().equals(countryIsoCode)) { countrySpecificList.add(cms); } } if (countrySpecificList.size() > 0) { return countrySpecificList; } else { return result; } } catch (RuntimeException re) { log.error("get failed", re); throw re; } }
From source file:com.sapienter.jbilling.server.metafields.db.MetaFieldDAS.java
License:Open Source License
@SuppressWarnings("unchecked") public List<MetaField> getAvailableFields(Integer entityId, EntityType[] entityType, Boolean primary) { DetachedCriteria query = DetachedCriteria.forClass(MetaField.class); query.add(Restrictions.eq("entityId", entityId)); query.add(Restrictions.in("entityType", entityType)); if (null != primary) { query.add(Restrictions.eq("primary", primary.booleanValue())); }/*w ww. j a v a 2 s. c o m*/ query.addOrder(Order.asc("displayOrder")); List<MetaField> result = null; try { result = (List<MetaField>) getHibernateTemplate().findByCriteria(query); } catch (Exception e) { LOG.error(e.getMessage()); e.printStackTrace(); LOG.error(e); } return result; }
From source file:com.sapienter.jbilling.server.metafields.db.MetaFieldDAS.java
License:Open Source License
@SuppressWarnings("unchecked") public MetaField getFieldByName(Integer entityId, EntityType[] entityType, String name, Boolean primary) { DetachedCriteria query = DetachedCriteria.forClass(MetaField.class); query.add(Restrictions.eq("entityId", entityId)); query.add(Restrictions.in("entityType", entityType)); query.add(Restrictions.eq("name", name)); if (null != primary) { query.add(Restrictions.eq("primary", primary.booleanValue())); }//from ww w. j a va 2s . c o m List<MetaField> fields = (List<MetaField>) getHibernateTemplate().findByCriteria(query); return !fields.isEmpty() ? fields.get(0) : null; }
From source file:com.sapienter.jbilling.server.metafields.db.MetaFieldDAS.java
License:Open Source License
public MetaField getFieldByNameTypeAndGroup(Integer entityId, EntityType[] entityType, String name, Integer groupId) {/* www . j ava2s . c om*/ DetachedCriteria query = DetachedCriteria.forClass(MetaField.class); query.add(Restrictions.eq("entityId", entityId)); query.add(Restrictions.in("entityType", entityType)); query.add(Restrictions.eq("name", name)); query.createAlias("metaFieldGroups", "groups", CriteriaSpecification.LEFT_JOIN); query.add(Restrictions.eq("groups.id", groupId)); query.add(Restrictions.eq("groups.entityType", EntityType.ACCOUNT_TYPE)); query.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<MetaField> fields = (List<MetaField>) getHibernateTemplate().findByCriteria(query); return !fields.isEmpty() ? fields.get(0) : null; }
From source file:com.sapienter.jbilling.server.metafields.db.MetaFieldDAS.java
License:Open Source License
public MetaField getFieldByNameAndGroup(Integer entityId, String name, Integer groupId) { DetachedCriteria query = DetachedCriteria.forClass(MetaField.class); query.add(Restrictions.eq("entityId", entityId)); query.add(Restrictions.eq("name", name)); query.createAlias("metaFieldGroups", "groups", CriteriaSpecification.LEFT_JOIN); query.add(Restrictions.eq("groups.id", groupId)); query.add(Restrictions.eq("groups.entityType", EntityType.ACCOUNT_TYPE)); query.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<MetaField> fields = (List<MetaField>) getHibernateTemplate().findByCriteria(query); return !fields.isEmpty() ? fields.get(0) : null; }
From source file:com.sapienter.jbilling.server.metafields.db.MetaFieldDAS.java
License:Open Source License
public List<MetaField> getMetaFieldsByEntity(Integer entityId) { DetachedCriteria query = DetachedCriteria.forClass(MetaField.class); query.add(Restrictions.eq("entityId", entityId)); List<MetaField> result = null; try {// w w w .ja va2 s . c o m result = (List<MetaField>) getHibernateTemplate().findByCriteria(query); } catch (Exception e) { LOG.error(e.getMessage()); e.printStackTrace(); LOG.error(e); } return result; }
From source file:com.sapienter.jbilling.server.metafields.db.MetaFieldGroupDAS.java
License:Open Source License
@SuppressWarnings("unchecked") public List<MetaFieldGroup> getAvailableFieldGroups(Integer entityId, EntityType entityType) { DetachedCriteria query = DetachedCriteria.forClass(MetaFieldGroup.class); query.add(Restrictions.eq("entityId", entityId)); query.add(Restrictions.eq("entityType", entityType)); query.add(Restrictions.eq("class", MetaFieldGroup.class)); query.addOrder(Order.asc("displayOrder")); return (List<MetaFieldGroup>) getHibernateTemplate().findByCriteria(query); }
From source file:com.sapienter.jbilling.server.metafields.db.MetaFieldGroupDAS.java
License:Open Source License
@SuppressWarnings("unchecked") public List<MetaFieldGroup> getAllAvailableFieldGroups(Integer entityId) { DetachedCriteria query = DetachedCriteria.forClass(MetaFieldGroup.class); query.add(Restrictions.eq("entityId", entityId)); query.addOrder(Order.asc("displayOrder")); return (List<MetaFieldGroup>) getHibernateTemplate().findByCriteria(query); }
From source file:com.sapienter.jbilling.server.metafields.db.MetaFieldGroupDAS.java
License:Open Source License
@SuppressWarnings("unchecked") public Integer getAllAvailableFieldGroupsCount(Integer entityId) { DetachedCriteria query = DetachedCriteria.forClass(MetaFieldGroup.class); query.setProjection(Projections.rowCount()).add(Restrictions.eq("entityId", entityId)) .addOrder(Order.asc("displayOrder")); List result = getHibernateTemplate().findByCriteria(query); return (Integer) result.get(0); }