Skip to content

Commit

Permalink
修改错误的字段名。
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasy0v0 committed Nov 7, 2024
1 parent e6fa127 commit aa6b0bf
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class SelectBuilder implements StatementConfigurator<SelectBuilder> {

private final List<Object> params;

SelectBuilder(DataSource dataSource, StatementConfiguration statementConfiguration,
SelectBuilder(DataSource dataSource,
StatementConfiguration statementConfiguration,
String sql, List<Object> params) {
this.dataSource = dataSource;
this.statementConfiguration = statementConfiguration;
Expand All @@ -38,8 +39,8 @@ public SelectBuilder setQueryTimeout(Integer queryTimeout) {
}

@Override
public SelectBuilder setMaxFieldSize(Integer maxFieldSize) {
getStatementConfiguration().setMaxFieldSize(maxFieldSize);
public SelectBuilder setFetchSize(Integer fetchSize) {
getStatementConfiguration().setFetchSize(fetchSize);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
public class StatementConfiguration {

private Integer queryTimeout;
private Integer maxFieldSize;
private Integer fetchSize;
private Integer maxRows;

public StatementConfiguration(Integer queryTimeout,
Integer maxFieldSize,
Integer fetchSize,
Integer maxRows) {
this.queryTimeout = queryTimeout;
this.maxFieldSize = maxFieldSize;
this.fetchSize = fetchSize;
this.maxRows = maxRows;
}

Expand All @@ -26,12 +26,12 @@ public void setQueryTimeout(Integer queryTimeout) {
this.queryTimeout = queryTimeout;
}

public Integer getMaxFieldSize() {
return maxFieldSize;
public Integer getFetchSize() {
return fetchSize;
}

public void setMaxFieldSize(Integer maxFieldSize) {
this.maxFieldSize = maxFieldSize;
public void setFetchSize(Integer fetchSize) {
this.fetchSize = fetchSize;
}

public Integer getMaxRows() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public interface StatementConfigurator<T> {

T setQueryTimeout(Integer queryTimeout);

T setMaxFieldSize(Integer maxFieldSize);
T setFetchSize(Integer fetchSize);

T setMaxRows(Integer maxRows);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public UpdateBuilder setQueryTimeout(Integer queryTimeout) {
}

@Override
public UpdateBuilder setMaxFieldSize(Integer maxFieldSize) {
getStatementConfiguration().setMaxFieldSize(maxFieldSize);
public UpdateBuilder setFetchSize(Integer fetchSize) {
getStatementConfiguration().setFetchSize(fetchSize);
return this;
}

Expand Down
16 changes: 8 additions & 8 deletions jdbc/src/main/java/com/github/fantasy0v0/swift/jdbc/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static <T> List<T> executeQuery(Connection conn, StatementConfiguration statemen
LogUtil.performance().info("executeQuery begin");
long startTime = System.nanoTime() / 1000;
String callerInfo = printCallerInfo();
LogUtil.sql().debug("executeQuery: {}, caller: {}", sql, callerInfo);
LogUtil.sql().debug("executeQuery: [{}], caller: {}", sql, callerInfo);
try (PreparedStatement statement = prepareStatement(conn, sql, statementConfiguration)) {
fillStatementParams(conn, statement, params, parameterHandler);
try (ResultSet resultSet = statement.executeQuery()) {
Expand All @@ -116,7 +116,7 @@ static <T> List<T> execute(Connection conn, StatementConfiguration statementConf
LogUtil.performance().info("execute begin");
long startTime = System.nanoTime() / 1000;
String callerInfo = printCallerInfo();
LogUtil.sql().debug("execute: {}, caller: {}", sql, callerInfo);
LogUtil.sql().debug("execute: [{}], caller: {}", sql, callerInfo);
try (PreparedStatement statement = prepareStatement(conn, sql, statementConfiguration)) {
fillStatementParams(conn, statement, params, parameterHandler);
boolean result = statement.execute();
Expand All @@ -140,7 +140,7 @@ static <T> List<T> executeBatch(Connection conn,
LogUtil.performance().info("executeBatch begin");
long startTime = System.nanoTime() / 1000;
String callerInfo = printCallerInfo();
LogUtil.sql().debug("executeBatch: {}, caller: {}", sql, callerInfo);
LogUtil.sql().debug("executeBatch: [{}], caller: {}", sql, callerInfo);
try (PreparedStatement statement = prepareStatement(conn, sql, null)) {
if (null != batch) {
for (List<Object> params : batch) {
Expand Down Expand Up @@ -171,7 +171,7 @@ static int executeUpdate(Connection conn, StatementConfiguration statementConfig
LogUtil.performance().info("executeUpdate begin");
long startTime = System.nanoTime() / 1000;
String callerInfo = printCallerInfo();
LogUtil.sql().debug("executeUpdate: {}, caller: {}", sql, callerInfo);
LogUtil.sql().debug("executeUpdate: [{}], caller: {}", sql, callerInfo);
try (PreparedStatement statement = prepareStatement(conn, sql, statementConfiguration)) {
fillStatementParams(conn, statement, params, parameterHandler);
return statement.executeUpdate();
Expand All @@ -188,7 +188,7 @@ static int[] executeUpdateBatch(Connection conn, StatementConfiguration statemen
LogUtil.performance().info("executeUpdateBatch begin");
long startTime = System.nanoTime() / 1000;
String callerInfo = printCallerInfo();
LogUtil.sql().debug("executeUpdateBatch: {}, caller: {}", sql, callerInfo);
LogUtil.sql().debug("executeUpdateBatch: [{}], caller: {}", sql, callerInfo);
try (PreparedStatement statement = prepareStatement(conn, sql, statementConfiguration)) {
for (List<Object> params : batch) {
fillStatementParams(conn, statement, params, parameterHandler);
Expand Down Expand Up @@ -250,9 +250,9 @@ private static PreparedStatement prepareStatement(Connection conn,
ps.setQueryTimeout(configuration.getQueryTimeout());
LogUtil.common().debug("setQueryTimeout: {}", configuration.getQueryTimeout());
}
if (null != configuration.getMaxFieldSize()) {
ps.setMaxFieldSize(configuration.getMaxFieldSize());
LogUtil.common().debug("setMaxFieldSize: {}", configuration.getMaxFieldSize());
if (null != configuration.getFetchSize()) {
ps.setFetchSize(configuration.getFetchSize());
LogUtil.common().debug("setFetchSize: {}", configuration.getFetchSize());
}
if (null != configuration.getMaxRows()) {
ps.setMaxRows(configuration.getMaxRows());
Expand Down
14 changes: 12 additions & 2 deletions jdbc/src/test/java/test/JDBCTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import test.container.JdbcContainer;

import javax.sql.DataSource;
import java.util.List;

import static com.github.fantasy0v0.swift.jdbc.JDBC.select;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class JDBCTest {

Expand All @@ -34,10 +37,17 @@ static void afterAll() {

@Test
void testStatement() {
log.debug("test");
select("""
List<Object[]> data = select("""
select * from student;
""").fetch();
log.debug("data size: {}", data.size());
assertTrue(data.size() > 2);

data = select("""
select * from student
""").setQueryTimeout(3).setFetchSize(1).setMaxRows(2).fetch();
log.debug("data size: {}", data.size());
assertEquals(2, data.size());
}

}
3 changes: 3 additions & 0 deletions jdbc/src/test/resources/simplelogger.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss:SSS
org.slf4j.simpleLogger.showThreadName=false
org.slf4j.simpleLogger.showLogName=false
org.slf4j.simpleLogger.showShortLogName=false

org.slf4j.simpleLogger.log.com.github.dockerjava=INFO
org.slf4j.simpleLogger.log.org.testcontainers.containers=INFO

0 comments on commit aa6b0bf

Please sign in to comment.