]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/org/splat/dal/dao/som/Database.java
Salome HOME
Modifications done to respect PMD rules. Versioning a document is fixed. Validation...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / dao / som / Database.java
index c87860648ea6377318c57020d3eb65b8f246574d..ec6639d8e652b548b14158617b287864727d73cd 100644 (file)
@@ -24,7 +24,9 @@ import org.springframework.transaction.annotation.Transactional;
 
 public class Database extends org.splat.dal.dao.kernel.AbstractDatabase {
 
-       private int uplevel = 0; // Level of database upgrade
+       public final static Logger LOG = org.splat.dal.dao.som.Database.LOG;
+
+       private transient int _uplevel = 0; // Level of database upgrade
        private RepositoryService _repositoryService;
        private IndexService _indexService;
        private UserService _userService;
@@ -40,33 +42,38 @@ public class Database extends org.splat.dal.dao.kernel.AbstractDatabase {
        protected class CheckVersion implements Work {
                /** 
                 * {@inheritDoc}
+                * @throws SQLException 
                 * @see org.hibernate.jdbc.Work#execute(java.sql.Connection)
                 */
                public void execute(final Connection connex) throws SQLException {
                        DatabaseMetaData dbmdata = connex.getMetaData();
                        String dbname = connex.getCatalog();
-                       ResultSet table;
+                       ResultSet table = null;
 
-                       table = dbmdata.getTables(dbname, null, "study", null);
-                       if (table.next()) {
-                               return;
+                       try {
+                               table = dbmdata.getTables(dbname, null, "study", null);
+                               if (table.next()) {
+                                       return;
+                               }
+                       } catch (SQLException e) {
+                               LOG.debug("Can't check the database version: ", e);
+                               throw e;
+                       } finally {
+                               if (table != null) {
+                                       table.close();
+                               }
                        }
-                       uplevel = -1; // Database not initialized
+                       _uplevel = -1; // Database not initialized
                }
        }
 
-       public final static Logger logger = org.splat.dal.dao.som.Database.logger;
-
        // ==============================================================================================================================
        // Construction
        // ==============================================================================================================================
 
-       private static Database myDB;
+       private static Database myDB = new Database();
 
        public static Database getInstance() {
-               if (myDB == null) {
-                       myDB = new Database();
-               }
                return myDB; 
        }
        
@@ -80,7 +87,7 @@ public class Database extends org.splat.dal.dao.kernel.AbstractDatabase {
                                my = this;
                                my.checkVersion();
                        } catch (Exception error) {
-                               logger.fatal("Could not access the database, reason:", error);
+                               LOG.fatal("Could not access the database, reason:", error);
                        }
                }
                return my;
@@ -102,11 +109,11 @@ public class Database extends org.splat.dal.dao.kernel.AbstractDatabase {
        // ==============================================================================================================================
 
        public boolean isInitialized() {
-               return (uplevel >= 0);
+               return (_uplevel >= 0);
        }
 
        public void initialize() throws IOException, SQLException {
-               logger.info("Creation of the database.");
+               LOG.info("Creation of the database.");
 
                // Creation of the Lucene index
                getIndexService().create(); // May throw IOException if the index repository is improperly configured
@@ -116,7 +123,7 @@ public class Database extends org.splat.dal.dao.kernel.AbstractDatabase {
                // Population of the database with customized data
                this.populate();
 
-               uplevel = 0; // The database is now up-to-date
+               _uplevel = 0; // The database is now up-to-date
        }
 
        // ==============================================================================================================================
@@ -145,6 +152,7 @@ public class Database extends org.splat.dal.dao.kernel.AbstractDatabase {
                        getUserService().createUser(uprop);
                } catch (Exception e) {
                        // Let's continue, hoping the best...
+                       LOG.debug(e.getMessage(), e);
                }
        }