Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try with resource jdbc #20

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions framework/service/org/moqui/impl/InstanceServices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -723,15 +723,14 @@ along with this software (see the LICENSE.md file). If not, see
dbUserExists = false

javax.sql.XAConnection testXaCon = null
java.sql.Connection testCon = null
try {
testXaCon = ec.entity.getConfConnection(adminMap)
testCon = testXaCon.getConnection()
dbConnectSuccess = true
try (java.sql.Connection testCon = testXaCon.getConnection()) {
dbConnectSuccess = true
}
} catch (Exception e) {
logger.warn("Test connection failed", e)
} finally {
if (testCon != null) testCon.close()
if (testXaCon != null) testXaCon.close()
}

Expand Down Expand Up @@ -804,15 +803,14 @@ along with this software (see the LICENSE.md file). If not, see
dbUserExists = false

javax.sql.XAConnection testXaCon = null
java.sql.Connection testCon = null
try {
testXaCon = ec.entity.getConfConnection(adminMap)
testCon = testXaCon.getConnection()
try (java.sql.Connection testCon = testXaCon.getConnection()) {
dbConnectSuccess = true
}
} catch (Exception e) {
logger.warn("Test connection to Postgres failed", e)
} finally {
if (testCon != null) testCon.close()
if (testXaCon != null) testXaCon.close()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ class TransactionCache implements Synchronization {
}

void flushCache(boolean clearRead) {
Map<String, Connection> connectionByGroup = new HashMap<>()
try {
int writeInfoListSize = writeInfoList.size()
if (writeInfoListSize > 0) {
Expand All @@ -456,12 +455,7 @@ class TransactionCache implements Synchronization {
for (int i = 0; i < writeInfoListSize; i++) {
EntityWriteInfo ewi = (EntityWriteInfo) writeInfoList.get(i)
String groupName = ewi.evb.getEntityDefinition().getEntityGroupName()
Connection con = connectionByGroup.get(groupName)
if (con == null) {
con = efi.getConnection(groupName)
connectionByGroup.put(groupName, con)
}

try (Connection con = efi.getConnection(groupName)) {
if (ewi.writeMode.is(WriteMode.CREATE)) {
ewi.evb.basicCreate(con)
createCount++
Expand All @@ -472,6 +466,7 @@ class TransactionCache implements Synchronization {
ewi.evb.basicUpdate(con)
updateCount++
}
}
}
if (logger.isDebugEnabled()) logger.debug("Flushed TransactionCache in ${System.currentTimeMillis() - startTime}ms: ${createCount} creates, ${updateCount} updates, ${deleteCount} deletes, ${readOneCache.size()} read entries, ${readListCache.size()} entities with list cache")
}
Expand All @@ -489,9 +484,6 @@ class TransactionCache implements Synchronization {
} catch (Throwable t) {
logger.error("Error writing values from TransactionCache: ${t.toString()}", t)
throw new XAException("Error writing values from TransactionCache: + ${t.toString()}")
} finally {
// now close connections
for (Connection con in connectionByGroup.values()) con.close()
}
}

Expand Down
Loading
Loading