Skip to content

Commit

Permalink
jdbc uses same connection for executing subqueries of a upsert query #18
Browse files Browse the repository at this point in the history
  • Loading branch information
isuru89 committed May 27, 2017
1 parent d9b4118 commit 3411234
Showing 1 changed file with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class QJdbcExecutor implements QExecutor {
private final QJdbcPoolFetcher poolFetcher
private Connection connection
private final boolean returnRaw
private final boolean reusable
private boolean reusable

/**
* Creates an executor with custom connection.
Expand Down Expand Up @@ -403,27 +403,36 @@ class QJdbcExecutor implements QExecutor {
return new LinkedList<>();
}

if (scriptList.type == QScriptListType.UPSERT) {
if (scriptList.scripts.size() < 3) {
throw new NyException('Not defined either select, insert, or update query in UPSERT query!')
}
final boolean prevReusable = reusable
reusable = true

try {
if (scriptList.type == QScriptListType.UPSERT) {
if (scriptList.scripts.size() < 3) {
throw new NyException('Not defined either select, insert, or update query in UPSERT query!')
}

NyQLResult result = execute(scriptList.scripts[0]) as NyQLResult
if (result.isEmpty()) {
// insert
return execute(scriptList.scripts[1])
} else {
// records exist... update
return execute(scriptList.scripts[2])
}

NyQLResult result = execute(scriptList.scripts[0]) as NyQLResult
if (result.isEmpty()) {
// insert
return execute(scriptList.scripts[1])
} else {
// records exist... update
return execute(scriptList.scripts[2])
List results = []
for (QScript qScript : scriptList.scripts) {
def res = execute(qScript)
results.add(res)
}
return results
}

} else {
List results = []
for (QScript qScript : scriptList.scripts) {
def res = execute(qScript)
results.add(res)
}
return results
} finally {
reusable = prevReusable
closeConnection()
}
}

Expand Down

0 comments on commit 3411234

Please sign in to comment.