Skip to content

Commit 26b6d7f

Browse files
authored
Merge pull request nutzam#1595 from zmobs/patch-1
fix 读写分离不支持pg数据库的问题
2 parents 5680f26 + fbf8827 commit 26b6d7f

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/org/nutz/dao/impl/sql/run/NutDaoRunner.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,21 @@ public void setSlaveDataSource(DataSource slaveDataSource) {
176176
protected DataSource selectDataSource(Transaction t, DataSource master, ConnCallback callback) {
177177
if (this.slaveDataSource == null)
178178
return master;
179-
if (t == null && callback instanceof DaoInterceptorChain) {
180-
DaoInterceptorChain chain = (DaoInterceptorChain)callback;
181-
DaoStatement[] sts = chain.getDaoStatements();
182-
if (sts.length == 1 && (sts[0].isSelect() || sts[0].isForceExecQuery())) {
183-
return slaveDataSource;
179+
if(meta.getType() == DB.PSQL){
180+
if (callback instanceof DaoInterceptorChain) {
181+
DaoInterceptorChain chain = (DaoInterceptorChain)callback;
182+
DaoStatement[] sts = chain.getDaoStatements();
183+
if (sts.length == 1 && (sts[0].isSelect() || sts[0].isForceExecQuery())) {
184+
return slaveDataSource;
185+
}
186+
}
187+
}else {
188+
if (t == null && callback instanceof DaoInterceptorChain) {
189+
DaoInterceptorChain chain = (DaoInterceptorChain)callback;
190+
DaoStatement[] sts = chain.getDaoStatements();
191+
if (sts.length == 1 && (sts[0].isSelect() || sts[0].isForceExecQuery())) {
192+
return slaveDataSource;
193+
}
184194
}
185195
}
186196
return master;

0 commit comments

Comments
 (0)