com.github.aqiu202.starters.jpa.sql.BaseQuery Maven / Gradle / Ivy
package com.github.aqiu202.starters.jpa.sql;
import com.github.aqiu202.starters.jpa.sql.trans.MapBeanTransformer;
import com.github.aqiu202.starters.jpa.sql.trans.inter.ChangeableTransformer;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.transform.Transformers;
import org.springframework.data.domain.Pageable;
@SuppressWarnings({"unchecked"})
public class BaseQuery {
protected Query query;
protected Query countQuery;
protected ResultTransformer mapTransformer = MapBeanTransformer.INSTANCE;
protected ChangeableTransformer> beanTransformer;
protected Pageable pageable;
protected BaseQuery() {
}
protected BaseQuery(ChangeableTransformer> changeableTransformer) {
this.beanTransformer = changeableTransformer;
}
protected void pageable(Pageable pageable) {
this.pageable = pageable;
}
protected T one() {
if (beanTransformer != null) {
query.unwrap(org.hibernate.Query.class).setResultTransformer(beanTransformer);
}
return (T) this.object();
}
protected List list() {
if (beanTransformer != null) {
query.unwrap(org.hibernate.Query.class).setResultTransformer(beanTransformer);
}
this.handlePageable();
return (List) query.getResultList();
}
protected List