/** * gets List of Data as "Entity". Always returns element as Entity Type "<E>" * * @param session Hibernate session * @param entityClass entityClass * @param search Search Model {@link SearchModel} * @param <E> * @return */ public static <E> List<E> listStrict(Session session, Class<E> entityClass, SearchModel search) { if (search.getFields() != null) { search.setFields(null); } HqlListConverter<E> hqlListConverter = new HqlListConverter<>(session, entityClass); List<E> userList = SearchQuery.createCriteria(entityClass, search).convert(hqlListConverter); return userList; }
/** * gets List of Data as "Entity" and "Total Count". Always returns element as Entity Type "<E>" * * @param session Hibernate session * @param entityClass entityClass * @param search Search Model {@link SearchModel} * @param <E> Entity Type also return type * @return */ public static <E> Pair<List<E>, Long> pairListStrict( Session session, Class<E> entityClass, SearchModel search) { if (search.getFields() != null) { search.setFields(null); } HqlPagingConverter<E> hqlPagingConverter = new HqlPagingConverter<>(session, entityClass); Pair<List<E>, Long> resultPair = SearchQuery.createCriteria(entityClass, search).convert(hqlPagingConverter); return resultPair; }
public static void fillSelectFieldsIfNotExist( Class<?> entityClass, Class<?> transformClass, SearchModel search) { if (search.getFields() == null || search.getFields().length == 0) { if (entityClass.equals(transformClass)) { Map<String, Field> fieldMap = SearchQuery.CacheFields.getCachedFields(transformClass); if (fieldMap != null && fieldMap.size() > 0) { search.setFields(fieldMap.keySet().toArray(new String[] {})); } } else { // Transform Class Map<String, Field> fieldMap = SearchQuery.CacheFields.getCachedFields(transformClass); Map<String, Field> entityFieldMap = SearchQuery.CacheFields.getCachedFields(entityClass); Set<String> selectSet = new HashSet<>(); for (Map.Entry<String, Field> transformFieldEntry : fieldMap.entrySet()) { if (entityFieldMap.keySet().contains(transformFieldEntry.getKey())) { selectSet.add(transformFieldEntry.getKey()); continue; } for (String entityFieldName : entityFieldMap.keySet()) { if (transformFieldEntry.getKey().startsWith(entityFieldName)) { String transformField = entityFieldName + "." + Strings.unCapitalizeFirstChar( transformFieldEntry.getKey().substring(entityFieldName.length())); selectSet.add(transformField); } } } search.setFields(selectSet.toArray(new String[] {})); } } }