Skip to content
Permalink
Browse files

fix: 加个通用方法,控制QueryTimeout

refer: #1469
  • Loading branch information...
wendal committed Jan 14, 2019
1 parent 5b37d89 commit 903edbd34d7550e1cdfc50c04880422593c7350f
@@ -339,4 +339,9 @@ protected ValueAdaptor getAdapterBy(Object value) {
Jdbcs.guessEntityFieldColumnType(mf);
return expert.getAdaptor(mf);
}

public DaoStatement setQueryTimeout(int timeout) {
getContext().setQueryTimeout(timeout);
return this;
}
}
@@ -233,16 +233,14 @@ private void _runSelect(Connection conn, DaoStatement st)
ResultSet rs = null;
Statement stat = null;
try {

// 木有参数,直接运行
if (null == paramMatrix || paramMatrix.length == 0
|| paramMatrix[0].length == 0) {
stat = conn.createStatement(st.getContext()
.getResultSetType(), ResultSet.CONCUR_READ_ONLY);
if (lastRow > 0)
stat.setMaxRows(lastRow); // 游标分页,现在总行数
if (st.getContext().getFetchSize() != 0)
stat.setFetchSize(st.getContext().getFetchSize());
afterCreateStatement(stat, st);
rs = stat.executeQuery(sql);
}
// 有参数,用缓冲语句
@@ -263,8 +261,7 @@ private void _runSelect(Connection conn, DaoStatement st)
ResultSet.CONCUR_READ_ONLY);
if (lastRow > 0)
stat.setMaxRows(lastRow);
if (st.getContext().getFetchSize() != 0)
stat.setFetchSize(st.getContext().getFetchSize());
afterCreateStatement(stat, st);
for (int i = 0; i < paramMatrix[0].length; i++) {
adaptors[i].set((PreparedStatement) stat,
paramMatrix[0][i], i + 1);
@@ -399,4 +396,11 @@ public OutParam(String name, int jdbcType) {
this.jdbcType = jdbcType;
}
}

protected void afterCreateStatement(Statement stat, DaoStatement st) throws SQLException {
if (st.getContext().getFetchSize() != 0)
stat.setFetchSize(st.getContext().getFetchSize());
if (st.getContext().getQueryTimeout() > 0)
stat.setQueryTimeout(st.getContext().getQueryTimeout());
}
}
@@ -255,4 +255,6 @@
String forPrint();

void setExpert(JdbcExpert expert);

DaoStatement setQueryTimeout(int timeout);
}
@@ -26,6 +26,8 @@
private Pager pager;

private Map<String, Object> attrs;

private int queryTimeout;

public SqlContext() {
// zozoh: 默认的,SQL 的游标类型是 TYPE_FORWARD_ONLY,即,使用各个数据库自有的分页语句
@@ -113,9 +115,14 @@ public Pager getPager() {

public void setPager(Pager pager) {
this.pager = pager;
// TODO 为何要这样写??为什么?!! SQLite死活不给我全部数据!! by wendal
// if (null != pager && pager.getPageSize() > 0)
// this.fetchSize = pager.getPageSize();
}

public int getQueryTimeout() {
return queryTimeout;
}

public void setQueryTimeout(int queryTimeout) {
this.queryTimeout = queryTimeout;
}

}

0 comments on commit 903edbd

Please sign in to comment.
You can’t perform that action at this time.