diff options
author | Simon Rettberg | 2023-05-22 11:15:52 +0200 |
---|---|---|
committer | Simon Rettberg | 2023-05-22 11:15:52 +0200 |
commit | 0c5b4321efd5cc7b3851b452f141459085360960 (patch) | |
tree | ae73933c0f02ec7ed40c0aef827295dd51c62f88 /src/main/java/org/openslx/imagemaster/db/Database.java | |
parent | Allow connecting a new session to a one-time access code (diff) | |
download | masterserver-0c5b4321efd5cc7b3851b452f141459085360960.tar.gz masterserver-0c5b4321efd5cc7b3851b452f141459085360960.tar.xz masterserver-0c5b4321efd5cc7b3851b452f141459085360960.zip |
Update Database classes to match dmsd
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/db/Database.java')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/db/Database.java | 27 |
1 files changed, 14 insertions, 13 deletions
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
|