
com.web.spring.datatable.TableQuery Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-jquery-datatable Show documentation
Show all versions of spring-jquery-datatable Show documentation
Spring extension to work with the great jQuery plugin DataTables
package com.web.spring.datatable;
import com.library.common.ReflectHelper;
import com.library.common.StringHelper;
import com.web.spring.datatable.annotations.SqlCondition;
import com.web.spring.datatable.annotations.SqlIndex;
import com.web.spring.datatable.annotations.SqlIndexOperator;
import com.web.spring.datatable.util.Validate;
import javax.persistence.*;
import java.lang.reflect.Field;
import java.math.BigInteger;
import java.util.*;
public class TableQuery {
private static HashMap innodbMap = new HashMap<>();
private static boolean isInnodbFlag = false;
private EntityManager entityManager;
private Class entiteClass;
private DatatablesCriterias criterias;
private Long totalCount = 0L;
private int displayRecordsLength = 0;
private String customSQL = "";
private List selectColumnList = new ArrayList<>();
private HashMap fieldTypeMap = new HashMap<>();
private String entiteTableName = "";
public TableQuery(EntityManager entityManager, Class entiteClass, DatatablesCriterias criterias) {
this.entityManager = entityManager;
this.entiteClass = entiteClass;
this.criterias = criterias;
init();
}
public TableQuery(EntityManager entityManager, Class entiteClass, DatatablesCriterias criterias, String customSQL) {
this.entityManager = entityManager;
this.entiteClass = entiteClass;
this.criterias = criterias;
this.customSQL = customSQL;
String[] columnArray = StringHelper.getBetweenString(this.customSQL.toLowerCase(), "select", "from").split(",");
for (String aColumnArray : columnArray) {
if (aColumnArray.toLowerCase().contains("as")) {
selectColumnList.add(aColumnArray.substring(aColumnArray.indexOf("as") + 2).trim());
} else {
selectColumnList.add(aColumnArray.trim());
}
}
init();
}
@SuppressWarnings("unchecked")
public void init() {
if (this.entiteClass.isAnnotationPresent(Table.class)) {
Table table = (Table) this.entiteClass.getAnnotation(Table.class);
this.entiteTableName = table.name();
} else {
this.entiteTableName = this.entiteClass.getSimpleName();
}
if (!isInnodbFlag) {
Query query = this.entityManager.createNativeQuery("SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE engine = 'InnoDB'");
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy