Skip to content

Commit

Permalink
2.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
sim-wangyan committed Mar 23, 2024
1 parent 13cac26 commit 2c22891
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 58 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<maven.test.skip>true</maven.test.skip>
<sqli.annotation.version>1.0.0</sqli.annotation.version>
<sqli.version>2.1.8</sqli.version>
<jackson.version>2.13.4.2</jackson.version>
<jackson.version>2.17.0</jackson.version>
<sl4j.version>1.7.30</sl4j.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
* @author Sim
*/
public interface PageSqlSupport {
String buildPageSql(String originSql, long start, long rows, long last);
StringBuilder buildPageSql(StringBuilder sb, long start, long rows, long last);
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ private Dialect getCurrentDialect() {
}

@Override
public String buildPageSql(String sql, long start, long rows,long last) {
return getCurrentDialect().buildPageSql(sql,start,rows,last);
public StringBuilder buildPageSql(StringBuilder sb, long start, long rows,long last) {
return getCurrentDialect().buildPageSql(sb,start,rows,last);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,15 @@ public String getKey(){
}

@Override
public String buildPageSql(String origin, long start, long rows,long last) {
public StringBuilder buildPageSql(StringBuilder sb, long start, long rows,long last) {

if (rows == 0)
return origin;
StringBuilder sb = new StringBuilder();
sb.append(origin);
return sb;
sb.append(SqlScript.LIMIT).append(rows);
if (last == 0 && start > 0){
sb.append(SqlScript.OFFSET).append(start);
}
return sb.toString();
return sb;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ public String getKey(){
return "oracle";
}
@Override
public String buildPageSql(String origin, long start, long rows,long last) {
public StringBuilder buildPageSql(StringBuilder sb, long start, long rows,long last) {

if (rows > 0)
return ORACLE_PAGINATION.replace(ORACLE_PAGINATION_REGX_END, String.valueOf(start + rows))
if (rows > 0) {
String origin = sb.toString();
ORACLE_PAGINATION.replace(ORACLE_PAGINATION_REGX_END, String.valueOf(start + rows))
.replace(ORACLE_PAGINATION_REGX_BEGIN, String.valueOf(start)).replace(ORACLE_PAGINATION_REGX_SQL, origin);
return origin;

sb = new StringBuilder();
sb.append(origin);
}
return sb;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public interface Dao extends QueryForCache {

boolean createBatch(List<? extends Object> objList);

<T> boolean createOrReplaceBatch(List<T> objList);
<T> boolean remove(KeyOne<T> keyOne);

<T> boolean removeIn(Keys<T> keys);
Expand Down
31 changes: 0 additions & 31 deletions sqli-repo/src/main/java/io/xream/sqli/repository/dao/DaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,37 +114,6 @@ public boolean createBatch(List<? extends Object> objList) {
}
}

@Override
public <T> boolean createOrReplaceBatch(List<T> objList) {

if (objList.isEmpty())
return false;
Object obj = objList.get(0);
Class clz = obj.getClass();
String createSql = getSql(clz, SqlInit.CREATE);

final String sql = this.dialect.createOrReplaceSql(createSql);

SqliLoggerProxy.debug(clz, sql);

Parsed parsed = Parser.get(clz);
JdbcHelper.BatchObjectValues batchObjectValues = () -> {
List<Collection<Object>> valuesList = new ArrayList<>();
for (Object o : objList) {
Collection<Object> values= ObjectDataConverter.objectToListForCreate(o, parsed, dialect);
valuesList.add(values);
}
return valuesList;
};

final int batchSize = 500;
try {
return this.jdbcHelper.createBatch(clz, sql, batchObjectValues, batchSize, this.dialect);
} catch (Exception e) {
throw ExceptionTranslator.onRollback(clz, e, logger);
}
}

@Override
public <T> boolean remove(KeyOne<T> keyOne) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ protected static SqlBuilder getInstance() {
return instance;
}

protected String buildPageSql(String sql, int page, int rows, Dialect dialect) {
int start = (page - 1) * rows;

return dialect.buildPageSql(sql, start, rows,0);
}
// protected String buildPageSql(String sql, int page, int rows, Dialect dialect) {
// int start = (page - 1) * rows;
//
// return dialect.buildPageSql(sql, start, rows,0);
// }

/**
* 拼接SQL
Expand Down Expand Up @@ -126,9 +126,9 @@ public List<SqlBuilt> getSubList() {
}
});

String sql = sqlBuilt.getSql().toString();
StringBuilder sqlBuilder = sqlBuilt.getSql();
if (SqliStringUtil.isNotNull(q.getLastSqlSegment())) {
sql = sql + " " + q.getLastSqlSegment();
sqlBuilder.append(SPACE).append(q.getLastSqlSegment());
}

int page = q.getPage();
Expand All @@ -137,11 +137,11 @@ public List<SqlBuilt> getSubList() {
int start = (page - 1) * rows;
long last = q.getLast();

sql = dialect.buildPageSql(sql, start, rows,last);
sqlBuilder = dialect.buildPageSql(sqlBuilder, start, rows,last);

StringBuilder sb = new StringBuilder();
sb.append(sql);
sqlBuilt.setSql(sb);
// StringBuilder sb = new StringBuilder();
// sb.append(sql);
sqlBuilt.setSql(sqlBuilder);
ObjectDataConverter.log(q, valueList);

return sqlBuilt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

import io.xream.sqli.api.BaseRepository;
import io.xream.sqli.api.RepositoryX;
import io.xream.sqli.builder.*;
import io.xream.sqli.builder.In;
import io.xream.sqli.builder.Q;
import io.xream.sqli.builder.Qr;
import io.xream.sqli.builder.RemoveRefreshCreate;
import io.xream.sqli.core.*;
import io.xream.sqli.exception.PersistenceException;
import io.xream.sqli.exception.QSyntaxException;
Expand Down

0 comments on commit 2c22891

Please sign in to comment.