From 0c5b4321efd5cc7b3851b452f141459085360960 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 22 May 2023 11:15:52 +0200 Subject: Update Database classes to match dmsd --- .../java/org/openslx/imagemaster/db/Database.java | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/main/java/org/openslx/imagemaster/db/Database.java') diff --git a/src/main/java/org/openslx/imagemaster/db/Database.java b/src/main/java/org/openslx/imagemaster/db/Database.java index 80997ea..340ccd4 100644 --- a/src/main/java/org/openslx/imagemaster/db/Database.java +++ b/src/main/java/org/openslx/imagemaster/db/Database.java @@ -44,8 +44,7 @@ public class Database * the class. In most cases that happens when the class is being * accessed for the first time during run time. */ - static - { + static { // Load connection info from class (TODO: Make pretty) Properties properties = new Properties(); try { @@ -103,7 +102,14 @@ public class Database } if ( !busyConnections.add( con ) ) throw new RuntimeException( "Tried to hand out a busy connection!" ); - return con; + try { + // By convention in our program we don't want auto commit + con.setAutoCommit( false ); + return con; + } catch ( SQLException e ) { + con.release(); + continue; + } } // No pooled connection if ( busyConnections.size() > 20 ) { @@ -145,16 +151,6 @@ public class Database pool.add( connection ); } - /** - * Return true if the given sql exception is "duplicate entry XXXX for key YYYY. - */ - public static boolean isDuplicateKeyException( SQLException e ) - { - return e != null && e.getErrorCode() == 1062; - } - - // - public static void printCharsetInformation() { LOGGER.info( "MySQL charset related variables:" ); @@ -182,4 +178,9 @@ public class Database LOGGER.info( "Busy: " + busyConnections.size() ); } + public static boolean isDuplicateKeyException( SQLException e ) + { + return e != null && e.getErrorCode() == 1062; + } + }// end class -- cgit v1.2.3-55-g7522