Salome HOME
Unit test is created for ScenarioService.getScenarioInfo method.
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / dao / som / Database.java
index ec6639d8e652b548b14158617b287864727d73cd..91f4ce1820394de19d1250f7705cc91ed634b790 100644 (file)
@@ -11,6 +11,7 @@ import java.sql.Connection;
 import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.Properties;
 
 import org.apache.log4j.Logger;
@@ -24,7 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 public class Database extends org.splat.dal.dao.kernel.AbstractDatabase {
 
-       public final static Logger LOG = org.splat.dal.dao.som.Database.LOG;
+       public final static Logger LOG = Logger.getLogger(org.splat.dal.dao.som.Database.class);
 
        private transient int _uplevel = 0; // Level of database upgrade
        private RepositoryService _repositoryService;
@@ -49,11 +50,19 @@ public class Database extends org.splat.dal.dao.kernel.AbstractDatabase {
                        DatabaseMetaData dbmdata = connex.getMetaData();
                        String dbname = connex.getCatalog();
                        ResultSet table = null;
+                       Statement st = connex.createStatement();
+                       _uplevel = -1; // Database not initialized
 
                        try {
                                table = dbmdata.getTables(dbname, null, "study", null);
                                if (table.next()) {
-                                       return;
+                                       table = dbmdata.getTables(dbname, null, "doctype", null);
+                                       if (table.next()) {
+                                               if (st.execute("SELECT name FROM doctype") &&
+                                                       st.getResultSet().next() ) {
+                                                       _uplevel = 0;
+                                               }
+                                       }
                                }
                        } catch (SQLException e) {
                                LOG.debug("Can't check the database version: ", e);
@@ -62,8 +71,10 @@ public class Database extends org.splat.dal.dao.kernel.AbstractDatabase {
                                if (table != null) {
                                        table.close();
                                }
+                               if (st != null) {
+                                       st.close();
+                               }
                        }
-                       _uplevel = -1; // Database not initialized
                }
        }
 
@@ -109,6 +120,9 @@ public class Database extends org.splat.dal.dao.kernel.AbstractDatabase {
        // ==============================================================================================================================
 
        public boolean isInitialized() {
+               if (LOG.isDebugEnabled()) {
+                       LOG.debug("The database is initialized: " + (_uplevel >= 0));
+               }
                return (_uplevel >= 0);
        }