提交 2a46b084 编写于 作者: MaxKey单点登录官方's avatar MaxKey单点登录官方

GA

上级 d6651d03
......@@ -13,7 +13,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
......
package org.apache.mybatis.jpa;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URL;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.ibatis.io.VFS;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
/**
* @author Hans Westerbeek
* @author Eddú Meléndez
* @author Kazuki Shimizu
*/
public class SpringBootVFS extends VFS {
private final ResourcePatternResolver resourceResolver;
public SpringBootVFS() {
this.resourceResolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader());
}
@Override
public boolean isValid() {
return true;
}
@Override
protected List<String> list(URL url, String path) throws IOException {
String urlString = url.toString();
String baseUrlString = urlString.endsWith("/") ? urlString : urlString.concat("/");
Resource[] resources = resourceResolver.getResources(baseUrlString + "**/*.class");
return Stream.of(resources).map(resource -> preserveSubpackageName(baseUrlString, resource, path))
.collect(Collectors.toList());
}
private static String preserveSubpackageName(final String baseUrlString, final Resource resource,
final String rootPath) {
try {
return rootPath + (rootPath.endsWith("/") ? "" : "/")
+ resource.getURL().toString().substring(baseUrlString.length());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ public class DB2Dialect extends Dialect {
@Override
public String getLimitString(String sql, JpaPagination pagination) {
if ( pagination.getPageResults() == 0 ) {
if ( pagination.getPageSize() == 0 ) {
return sql + " fetch first " + pagination.getStartRow() + " rows only";
}
StringBuilder pagingSelectSql = new StringBuilder( sql.length() + 200 )
......@@ -30,7 +30,7 @@ public class DB2Dialect extends Dialect {
)
.append( sql ) //nest the main query in an outer select
.append(" fetch first ")
.append(pagination.getPageResults())
.append(pagination.getPageSize())
.append(" rows only ) as inner2_ ) as inner1_ where rownumber_ > " )
.append(pagination.getStartRow())
.append(" order by rownumber_");
......@@ -40,9 +40,9 @@ public class DB2Dialect extends Dialect {
@Override
public String getPreparedStatementLimitString(String sql, JpaPagination pagination) {
//LIMIT #{pageResults} OFFSET #{startRow}
if(pagination.getPageResults()>0&&pagination.getStartRow()>0){
if(pagination.getPageSize()>0&&pagination.getStartRow()>0){
return sql + " LIMIT ? , ?";
}else if(pagination.getPageResults()>0){
}else if(pagination.getPageSize()>0){
return sql + " LIMIT ? ";
}else{
return sql + " LIMIT ?";
......@@ -53,11 +53,11 @@ public class DB2Dialect extends Dialect {
public void setLimitParamters(PreparedStatement preparedStatement,int parameterSize,JpaPagination pagination) {
try {
if(pagination.getPageResults()>0&&pagination.getStartRow()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
}else if(pagination.getPageResults()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
if(pagination.getPageSize()>0&&pagination.getStartRow()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
}else if(pagination.getPageSize()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
}else{
preparedStatement.setInt(++parameterSize, 1000);
}
......
......@@ -31,7 +31,7 @@ public class DerbyDialect extends Dialect {
pagingSelectSql.append( " offset " ).append( pagination.getStartRow() ).append( " rows fetch next " );
}
pagingSelectSql.append( pagination.getPageResults() ).append( " rows only" );
pagingSelectSql.append( pagination.getPageSize() ).append( " rows only" );
return pagingSelectSql.toString();
......@@ -40,9 +40,9 @@ public class DerbyDialect extends Dialect {
@Override
public String getPreparedStatementLimitString(String sql, JpaPagination pagination) {
//LIMIT #{pageResults} OFFSET #{startRow}
if(pagination.getPageResults()>0&&pagination.getStartRow()>0){
if(pagination.getPageSize()>0&&pagination.getStartRow()>0){
return sql + " LIMIT ? , ?";
}else if(pagination.getPageResults()>0){
}else if(pagination.getPageSize()>0){
return sql + " LIMIT ? ";
}else{
return sql + " LIMIT ?";
......@@ -53,11 +53,11 @@ public class DerbyDialect extends Dialect {
public void setLimitParamters(PreparedStatement preparedStatement,int parameterSize,JpaPagination pagination) {
try {
if(pagination.getPageResults()>0&&pagination.getStartRow()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
}else if(pagination.getPageResults()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
if(pagination.getPageSize()>0&&pagination.getStartRow()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
}else if(pagination.getPageSize()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
}else{
preparedStatement.setInt(++parameterSize, 1000);
}
......
......@@ -28,21 +28,21 @@ public class MySQLDialect extends Dialect {
public String getLimitString(String sql, JpaPagination pagination) {
//LIMIT #{pageResults} OFFSET #{startRow}
pagination.calculate();
if(pagination.getPageResults()>0&&pagination.getStartRow()>0){
return sql + " LIMIT "+pagination.getStartRow()+" , " +pagination.getPageResults();
}else if(pagination.getPageResults()>0){
return sql + " LIMIT "+pagination.getPageResults();
if(pagination.getPageSize()>0&&pagination.getStartRow()>0){
return sql + " LIMIT "+pagination.getStartRow()+" , " +pagination.getPageSize();
}else if(pagination.getPageSize()>0){
return sql + " LIMIT "+pagination.getPageSize();
}else{
return sql + " LIMIT "+pagination.getPageResults();
return sql + " LIMIT "+pagination.getPageSize();
}
}
@Override
public String getPreparedStatementLimitString(String sql, JpaPagination pagination) {
//LIMIT #{pageResults} OFFSET #{startRow}
if(pagination.getPageResults()>0&&pagination.getStartRow()>0){
if(pagination.getPageSize()>0&&pagination.getStartRow()>0){
return sql + " LIMIT ? , ?";
}else if(pagination.getPageResults()>0){
}else if(pagination.getPageSize()>0){
return sql + " LIMIT ? ";
}else{
return sql + " LIMIT ?";
......@@ -53,11 +53,11 @@ public class MySQLDialect extends Dialect {
public void setLimitParamters(PreparedStatement preparedStatement,int parameterSize,JpaPagination pagination) {
try {
if(pagination.getPageResults()>0&&pagination.getStartRow()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
}else if(pagination.getPageResults()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
if(pagination.getPageSize()>0&&pagination.getStartRow()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
}else if(pagination.getPageSize()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
}else{
preparedStatement.setInt(++parameterSize, 1000);
}
......
......@@ -21,7 +21,7 @@ public class OracleDialect extends Dialect {
@Override
public String getLimitString(String sql, JpaPagination pagination) {
if ( pagination.getPageResults() == 0 ) {
if ( pagination.getPageSize() == 0 ) {
return sql + " fetch first " + pagination.getStartRow() + " rows only";
}
StringBuilder pagingSelect = new StringBuilder( sql.length() + 200 )
......@@ -40,9 +40,9 @@ public class OracleDialect extends Dialect {
@Override
public String getPreparedStatementLimitString(String sql, JpaPagination pagination) {
//LIMIT #{pageResults} OFFSET #{startRow}
if(pagination.getPageResults()>0&&pagination.getStartRow()>0){
if(pagination.getPageSize()>0&&pagination.getStartRow()>0){
return sql + " LIMIT ? , ?";
}else if(pagination.getPageResults()>0){
}else if(pagination.getPageSize()>0){
return sql + " LIMIT ? ";
}else{
return sql + " LIMIT ?";
......@@ -53,11 +53,11 @@ public class OracleDialect extends Dialect {
public void setLimitParamters(PreparedStatement preparedStatement,int parameterSize,JpaPagination pagination) {
try {
if(pagination.getPageResults()>0&&pagination.getStartRow()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
}else if(pagination.getPageResults()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
if(pagination.getPageSize()>0&&pagination.getStartRow()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
}else if(pagination.getPageSize()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
}else{
preparedStatement.setInt(++parameterSize, 1000);
}
......
......@@ -21,10 +21,10 @@ public class PostgreSQLDialect extends Dialect {
@Override
public String getLimitString(String sql, JpaPagination pagination) {
//LIMIT #{pageResults} OFFSET #{startRow}
if(pagination.getPageResults()>0&&pagination.getStartRow()>0){
return sql + " LIMIT " + pagination.getPageResults()+" , "+pagination.getStartRow() ;
}else if(pagination.getPageResults()>0){
return sql + " LIMIT " + pagination.getPageResults();
if(pagination.getPageSize()>0&&pagination.getStartRow()>0){
return sql + " LIMIT " + pagination.getPageSize()+" , "+pagination.getStartRow() ;
}else if(pagination.getPageSize()>0){
return sql + " LIMIT " + pagination.getPageSize();
}else{
return sql + " LIMIT 1000";
}
......@@ -33,9 +33,9 @@ public class PostgreSQLDialect extends Dialect {
@Override
public String getPreparedStatementLimitString(String sql, JpaPagination pagination) {
//LIMIT #{pageResults} OFFSET #{startRow}
if(pagination.getPageResults()>0&&pagination.getStartRow()>0){
if(pagination.getPageSize()>0&&pagination.getStartRow()>0){
return sql + " LIMIT ? , ?";
}else if(pagination.getPageResults()>0){
}else if(pagination.getPageSize()>0){
return sql + " LIMIT ? ";
}else{
return sql + " LIMIT ?";
......@@ -46,11 +46,11 @@ public class PostgreSQLDialect extends Dialect {
public void setLimitParamters(PreparedStatement preparedStatement,int parameterSize,JpaPagination pagination) {
try {
if(pagination.getPageResults()>0&&pagination.getStartRow()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
}else if(pagination.getPageResults()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
if(pagination.getPageSize()>0&&pagination.getStartRow()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
}else if(pagination.getPageSize()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
}else{
preparedStatement.setInt(++parameterSize, 1000);
}
......
......@@ -23,9 +23,9 @@ public class SQLServerDialect extends Dialect {
@Override
public String getLimitString(String sql, JpaPagination pagination) {
StringBuilder pagingSelectSql = new StringBuilder( "" );
if(pagination.getPageResults()>0){
if(pagination.getPageSize()>0){
pagingSelectSql.append("SELECT TOP "+pagination.getPageResults()+" * FROM ( ");
pagingSelectSql.append("SELECT TOP "+pagination.getPageSize()+" * FROM ( ");
pagingSelectSql.append("SELECT ROW_NUMBER() OVER() AS ROWNUMBER,MYBATIS_QUERY_TEMP_TABLE.* FROM ( ");
pagingSelectSql.append("MYBATIS_QUERY_TEMP_TABLE ) MYBATIS_QUERY_TEMP_PAGE ");
if(pagination.getStartRow()>0){
......@@ -40,9 +40,9 @@ public class SQLServerDialect extends Dialect {
@Override
public String getPreparedStatementLimitString(String sql, JpaPagination pagination) {
//LIMIT #{pageResults} OFFSET #{startRow}
if(pagination.getPageResults()>0&&pagination.getStartRow()>0){
if(pagination.getPageSize()>0&&pagination.getStartRow()>0){
return sql + " LIMIT ? , ?";
}else if(pagination.getPageResults()>0){
}else if(pagination.getPageSize()>0){
return sql + " LIMIT ? ";
}else{
return sql + " LIMIT ?";
......@@ -53,11 +53,11 @@ public class SQLServerDialect extends Dialect {
public void setLimitParamters(PreparedStatement preparedStatement,int parameterSize,JpaPagination pagination) {
try {
if(pagination.getPageResults()>0&&pagination.getStartRow()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
}else if(pagination.getPageResults()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageResults());
if(pagination.getPageSize()>0&&pagination.getStartRow()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
}else if(pagination.getPageSize()>0){
preparedStatement.setInt(++parameterSize, pagination.getPageSize());
}else{
preparedStatement.setInt(++parameterSize, 1000);
}
......
......@@ -110,7 +110,7 @@ public class JpaBaseService <T extends JpaBaseDomain> {
*/
public JpaPageResults<T> queryPageResults(T entity) {
entity.setPageResultSelectUUID(entity.generateId());
entity.setStartRow(calculateStartRow(entity.getPage() ,entity.getPageResults()));
entity.setStartRow(calculateStartRow(entity.getPageNumber() ,entity.getPageSize()));
entity.setPageable(true);
List<T> resultslist=getMapper().queryPageResults(entity);
......@@ -118,13 +118,13 @@ public class JpaBaseService <T extends JpaBaseDomain> {
Integer totalPage=resultslist.size();
Integer totalCount = 0;
if(entity.getPage()==1&&totalPage<entity.getPageResults()) {
if(entity.getPageNumber()==1&&totalPage<entity.getPageSize()) {
totalCount=totalPage;
}else {
totalCount=parseCount(getMapper().queryPageResultsCount(entity));
}
return new JpaPageResults<T>(entity.getPage(),entity.getPageResults(),totalPage,totalCount,resultslist);
return new JpaPageResults<T>(entity.getPageNumber(),entity.getPageSize(),totalPage,totalCount,resultslist);
}
......@@ -138,7 +138,7 @@ public class JpaBaseService <T extends JpaBaseDomain> {
@SuppressWarnings("unchecked")
public JpaPageResults<T> queryPageResults(String mapperId,T entity) {
entity.setPageResultSelectUUID(entity.generateId());
entity.setStartRow(calculateStartRow(entity.getPage() ,entity.getPageResults()));
entity.setStartRow(calculateStartRow(entity.getPageNumber() ,entity.getPageSize()));
entity.setPageable(true);
List<T> resultslist=null;
......@@ -152,13 +152,13 @@ public class JpaBaseService <T extends JpaBaseDomain> {
Integer totalPage=resultslist.size();
Integer totalCount = 0;
if(entity.getPage()==1&&totalPage<entity.getPageResults()) {
if(entity.getPageNumber()==1&&totalPage<entity.getPageSize()) {
totalCount=totalPage;
}else {
totalCount=parseCount(getMapper().queryPageResultsCount(entity));
}
return new JpaPageResults<T>(entity.getPage(),entity.getPageResults(),totalPage,totalCount,resultslist);
return new JpaPageResults<T>(entity.getPageNumber(),entity.getPageSize(),totalPage,totalCount,resultslist);
}
/**
......@@ -373,7 +373,7 @@ public class JpaBaseService <T extends JpaBaseDomain> {
* @return
*/
public Integer calculateTotalPage(JpaBaseDomain entity,Integer totalCount){
return (totalCount + entity.getPageResults() - 1) / entity.getPageResults();
return (totalCount + entity.getPageSize() - 1) / entity.getPageSize();
}
/**
......@@ -382,7 +382,7 @@ public class JpaBaseService <T extends JpaBaseDomain> {
* @param pageResults
* @return
*/
public Integer calculateStartRow(Integer page,Integer pageResults){
return (page - 1) * pageResults;
public Integer calculateStartRow(Integer page,Integer pageSize){
return (page - 1) * pageSize;
}
}
......@@ -18,12 +18,12 @@ public class JpaPagination {
*
*/
@JsonIgnore
protected int pageResults = 20;
protected int pageSize = 20;
/**
*
*/
@JsonIgnore
protected int page=1;
protected int pageNumber=1;
/**
*
*/
......@@ -41,7 +41,7 @@ public class JpaPagination {
*
*/
@JsonIgnore
protected String sord;
protected String sortOrder;
/**
*
*/
......@@ -67,16 +67,16 @@ public class JpaPagination {
public void setRows(int rows) {
this.rows = rows;
this.pageResults = rows;
this.pageSize = rows;
calculate();
}
@JsonIgnore
public int getPage() {
return page;
public int getPageNumber() {
return pageNumber;
}
public void setPage(int page) {
this.page = page;
public void setPageNumber(int pageNumber) {
this.pageNumber = pageNumber;
calculate();
}
@JsonIgnore
......@@ -89,12 +89,12 @@ public class JpaPagination {
setSortKey();
}
@JsonIgnore
public String getSord() {
return sord;
public String getSortOrder() {
return sortOrder;
}
public void setSord(String sord) {
this.sord = sord;
public void setSortOrder(String sortOrder) {
this.sortOrder = sortOrder;
setSortKey();
}
......@@ -116,18 +116,18 @@ public class JpaPagination {
}
public void calculate() {
if (this.page >= 1 && this.pageResults > 0){
startRow = (this.page - 1) * this.pageResults;
endRow = startRow + this.pageResults;
if (this.pageNumber >= 1 && this.pageSize > 0){
startRow = (this.pageNumber - 1) * this.pageSize;
endRow = startRow + this.pageSize;
}
}
@JsonIgnore
public int getPageResults() {
return pageResults;
public int getPageSize() {
return pageSize;
}
public void setPageResults(int pageResults) {
this.pageResults = pageResults;
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
@JsonIgnore
public String getSortKey() {
......@@ -138,8 +138,8 @@ public class JpaPagination {
* create sortKey from sidx & sord,eg order by name asc
*/
public void setSortKey() {
if(sidx!=null && sord!=null && !sidx.equals("") && !sord.equals("")){
sortKey=" "+sidx+" "+sord+" ";
if(sidx!=null && sortOrder!=null && !sidx.equals("") && !sortOrder.equals("")){
sortKey=" "+sidx+" "+sortOrder+" ";
setOrderBy();
}
......@@ -158,7 +158,7 @@ public class JpaPagination {
*/
public void setOrderBy() {
if(sortKey!=null && !sortKey.equals("")){
orderBy=" ORDER BY "+sidx+" "+sord+" ";
orderBy=" ORDER BY "+sidx+" "+sortOrder+" ";
}
}
......@@ -192,9 +192,9 @@ public class JpaPagination {
*/
@Override
public String toString() {
return "Pagination [rows=" + rows + ", pageResults=" + pageResults
+ ", page=" + page + ", startRow=" + startRow + ", endRow="
+ endRow + ", sidx=" + sidx + ", sord=" + sord + ", sortKey="
return "Pagination [rows=" + rows + ", pageResults=" + pageSize
+ ", page=" + pageNumber + ", startRow=" + startRow + ", endRow="
+ endRow + ", sidx=" + sidx + ", sord=" + sortOrder + ", sortKey="
+ sortKey + ", orderBy=" + orderBy + ", pageable=" + pageable
+ "]";
}
......
......@@ -80,8 +80,8 @@ public class MyBatisTestRunner {
//student.setId("af04d610-6092-481e-9558-30bd63ef783c");
student.setStdGender("M");
//student.setStdMajor(政治");
student.setPageResults(10);
student.setPage(2);
student.setPageSize(10);
student.setPageNumber(2);
_logger.info("queryPageResults "+service.queryPageResults(student));
}
......@@ -92,8 +92,8 @@ public class MyBatisTestRunner {
Students student=new Students();
student.setStdGender("M");
//student.setStdMajor(政治");
student.setPageResults(10);
student.setPage(2);
student.setPageSize(10);
student.setPageNumber(2);
_logger.info("queryPageResults by mapperId "+service.queryPageResults("queryPageResults1",student));
......
......@@ -39,8 +39,6 @@ public class DemoDomain extends JpaBaseDomain{
protected int status;
protected int sortOrder;
protected String createdBy;
@JsonSerialize(using=JsonDateTimeSerializer.class)
......@@ -101,23 +99,6 @@ public class DemoDomain extends JpaBaseDomain{
/**
* @return the sortOrder
*/
public int getSortOrder() {
return sortOrder;
}
/**
* @param sortOrder the sortOrder to set
*/
public void setSortOrder(int sortOrder) {
this.sortOrder = sortOrder;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册