@Override public <T extends GettableById> List<T> get( Class<T> bookEntityClass, int from, int to, Map<String, List<Criterion>> restrictions, OrderByFilter filter) { validateTransaction(); Criteria criteria = getSession().createCriteria(bookEntityClass); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setFirstResult(from); if (to != 0) criteria.setMaxResults(to); for (String key : restrictions.keySet()) { if (key.equals(RestrictionsFields.MAIN_RESTRICTIONS)) { for (Criterion restriction : restrictions.get(RestrictionsFields.MAIN_RESTRICTIONS)) criteria.add(restriction); } else if (restrictions.get(key).size() > 0) { Criteria c = criteria.createCriteria(key); for (Criterion restriction : restrictions.get(key)) c.add(restriction); } } if (filter != null) { if (filter.getDirection().equals(OrderByFilter.ASC)) criteria.addOrder(Order.asc(filter.field)); else criteria.addOrder(Order.desc(filter.field)); } return criteria.list(); }
@Override public <T extends GettableById> Number count(Class<T> currentClass, Criterion... restrictions) { validateTransaction(); Criteria criteria = getSession().createCriteria(currentClass); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setProjection(Projections.rowCount()); for (Criterion restriction : restrictions) criteria.add(restriction); return ((Number) criteria.uniqueResult()); }
@Override public <T extends GettableById> Collection<Integer> getIds( Class<T> currentClass, Criterion... restrictions) { validateTransaction(); Criteria criteria = getSession().createCriteria(currentClass); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setProjection(Projections.id()); for (Criterion restriction : restrictions) criteria.add(restriction); return criteria.list(); }
private <P> Criteria buildProjectionCriteria( Class<P> projectClass, Criteria criteria, Projection projections, boolean distinctResult) { if (distinctResult) { criteria.setProjection(Projections.distinct(projections)); } else { criteria.setProjection(projections); } return criteria.setResultTransformer(Transformers.aliasToBean(projectClass)); }
@Override public <T extends GettableById> List<T> get( Class<T> bookEntityClass, int from, int to, Criterion... restrictions) { validateTransaction(); Criteria criteria = getSession().createCriteria(bookEntityClass); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setFirstResult(from); if (to != 0) criteria.setMaxResults(to); for (Criterion restriction : restrictions) criteria.add(restriction); return criteria.list(); }
@Override public <T extends GettableById> List<T> get( Class<T> bookEntityClass, int from, int to, OrderByFilter filter) { validateTransaction(); Criteria criteria = getSession().createCriteria(bookEntityClass); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setFirstResult(from); if (to != 0) criteria.setMaxResults(to); if (filter != null) { if (filter.getDirection().equals(OrderByFilter.ASC)) criteria.addOrder(Order.asc(filter.field)); else criteria.addOrder(Order.desc(filter.field)); } return criteria.list(); }
@Override public <T extends GettableById> Number count( Class<T> currentClass, Map<String, List<Criterion>> restrictions) { validateTransaction(); Criteria criteria = getSession().createCriteria(currentClass); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setProjection(Projections.rowCount()); for (String key : restrictions.keySet()) { if (key.equals(RestrictionsFields.MAIN_RESTRICTIONS)) { for (Criterion restriction : restrictions.get(RestrictionsFields.MAIN_RESTRICTIONS)) criteria.add(restriction); } else if (restrictions.get(key).size() > 0) { Criteria c = criteria.createCriteria(key); for (Criterion restriction : restrictions.get(key)) c.add(restriction); } } return ((Number) criteria.uniqueResult()); }
@Override public <T extends GettableById> List<T> get( Class<T> bookKeywordEntityClass, String bookKeywordEntity, int offset, int limit, HashMap<String, FetchMode> fetchMode, HashMap<String, String> alias, Criterion... criterions) { validateTransaction(); Criteria criteria = getSession().createCriteria(bookKeywordEntityClass, bookKeywordEntity); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setFirstResult(offset); if (limit != 0) criteria.setMaxResults(limit); for (Criterion restriction : criterions) criteria.add(restriction); for (Map.Entry<String, FetchMode> stringObjectEntry : fetchMode.entrySet()) { criteria.setFetchMode(stringObjectEntry.getKey(), stringObjectEntry.getValue()); } for (Map.Entry<String, String> stringObjectEntry : alias.entrySet()) { criteria.createAlias(stringObjectEntry.getKey(), stringObjectEntry.getValue()); } return criteria.list(); }