Salome HOME
Refactoring continues: UserService is created instead of UserDirectory. Database...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / dao / som / Database.java
index 3d5790a3a0f763457e83ee749a87208a83b085fd..649b2f50f1c9f313da68bc817c98264d6d6d8c68 100644 (file)
@@ -6,39 +6,30 @@ package org.splat.dal.dao.som;
  * @copyright OPEN CASCADE 2012
  */
 
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
 import java.util.Properties;
-import java.io.File;
 import java.io.IOException;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
-import org.hibernate.Query;
 import org.hibernate.Session;
-import org.hibernate.SessionFactory;
 import org.hibernate.jdbc.Work;
 import org.apache.log4j.Logger;
 
 import org.splat.dal.bo.kernel.User;
-import org.splat.dal.bo.som.IDBuilder;
-import org.splat.dal.bo.som.ProgressState;
-import org.splat.dal.bo.som.SimulationContext;
-import org.splat.dal.bo.som.SimulationContextType;
-import org.splat.kernel.UserDirectory;
-import org.splat.kernel.InvalidPropertyException;
+import org.splat.service.UserService;
 import org.splat.service.technical.IndexService;
 import org.splat.service.technical.RepositoryService;
+import org.springframework.transaction.annotation.Transactional;
 
 public class Database extends org.splat.dal.dao.kernel.Database {
 
        private int uplevel = 0; // Level of database upgrade
        private RepositoryService _repositoryService;
        private IndexService _indexService;
-       private SessionFactory _sessionFactory;
+       private UserService _userService;
+       
 
        private static Database my = null; // Singleton instance
 
@@ -70,7 +61,21 @@ public class Database extends org.splat.dal.dao.kernel.Database {
        // Construction
        // ==============================================================================================================================
 
-       public Database getMe() {
+       private static Database myDB;
+
+       public static Database getInstance() {
+               if (myDB == null) {
+                       myDB = new Database();
+               }
+               return myDB; 
+       }
+       
+       public static Session getCurSession() {
+               // -----------------------------------
+               return getInstance().getSession();
+       }
+
+       public Database getCheckedDB() {
                // -------------------------------
                if (my == null)
                        try {
@@ -88,8 +93,9 @@ public class Database extends org.splat.dal.dao.kernel.Database {
        /**
         * Check version of the database schema.
         */
+       @Transactional(readOnly=true)
        private void checkVersion() {
-               getSessionFactory().getCurrentSession().doWork(new CheckVersion());
+               getSession().doWork(new CheckVersion());
        }
 
        // ==============================================================================================================================
@@ -109,12 +115,10 @@ public class Database extends org.splat.dal.dao.kernel.Database {
                getIndexService().create(); // May throw IOException if the index repository is improperly configured
 
                // Creation of the SIMER SQL tables
-               Session session = Database.getSession();
 
                // Population of the database with customized data
                this.populate();
 
-               session.flush();
                uplevel = 0; // The database is now up-to-date
        }
 
@@ -143,7 +147,7 @@ public class Database extends org.splat.dal.dao.kernel.Database {
                                        "label.sysadmin").addRole("sysadmin").setMailAddress(
                                        "noreply@salome-platform.org");
                        uprop.disableCheck();
-                       UserDirectory.createUser(uprop);
+                       getUserService().createUser(uprop);
                } catch (Exception e) {
                        // Let's continue, hoping the best...
                }
@@ -180,21 +184,18 @@ public class Database extends org.splat.dal.dao.kernel.Database {
        }
 
        /**
-        * Get the sessionFactory.
-        * 
-        * @return the sessionFactory
+        * Get the userService.
+        * @return the userService
         */
-       public SessionFactory getSessionFactory() {
-               return _sessionFactory;
+       public UserService getUserService() {
+               return _userService;
        }
 
        /**
-        * Set the sessionFactory.
-        * 
-        * @param sessionFactory
-        *            the sessionFactory to set
+        * Set the userService.
+        * @param userService the userService to set
         */
-       public void setSessionFactory(SessionFactory sessionFactory) {
-               _sessionFactory = sessionFactory;
+       public void setUserService(UserService userService) {
+               _userService = userService;
        }
 }
\ No newline at end of file