public <T> List<T> findByCriateria(String query, Object[] params, Class<T> entityClass) {
List<T> list = new ArrayList<T>();
if (StringUtils.isBlank(query)) {
throw new ActiveSessionException(ErrorMessageEnum.INVALID_QUERY);
}
for (int i = 0; i < params.length; i++) {
int paramNumber = i + 1;
String replace = "?" + paramNumber;
query = StringUtils.replace(query, replace, params[i].toString());
}
HashMap<String, String> methodNameAndFieldName = new HashMap<String, String>();
HashMap<String, String> fieldNameAndColumnName = new HashMap<String, String>();
List<String> getMethods = new ArrayList<String>();
ArrayList<String> columnNames = new ArrayList<String>();
StringBuilder columns = new StringBuilder();
try {
prepareteState = connect.prepareStatement(query);
resultSet = prepareteState.executeQuery();
while (resultSet.next()) {
T entity = entityClass.newInstance();
Field fields[] = entityClass.getDeclaredFields(); //getting all declared fields in entity class into array
initializeMethodNameAndFieldName(fields, methodNameAndFieldName, getMethods);
Method[] methods = getEntityMethods(entity);
initilizeColumnNamesAndFieldNamesAndColumnNames(methods, getMethods, columnNames, columns, methodNameAndFieldName, fieldNameAndColumnName);
if (columns.length() == 0) {
throw new ActiveSessionException(ErrorMessageEnum.ILLIGAL_COLUMN_ANNOTATION_EXCEPTION);
}
HashMap<String, Object> data = initializeData(resultSet, columnNames);
entity = initilizeFieldsOfEntityObject(fields, entityClass, entity, data, fieldNameAndColumnName);
list.add(entity);
}
} catch (Exception e) {
throw new ActiveSessionException(e.getMessage(), e);
}
return list;
}