diff options
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
|