package org.splat.dal.dao.kernel;
+
/**
*
* @author Daniel Brunier-Coulin
* @copyright OPEN CASCADE 2012
*/
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.jdbc.Work;
+import org.splat.service.technical.IndexService;
+import org.splat.service.technical.RepositoryService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
+import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.apache.log4j.Logger;
-
-public abstract class Database implements ApplicationContextAware {
+public abstract class Database extends HibernateDaoSupport implements
+ ApplicationContextAware {
/**
* The ApplicationContext.
/**
* Spring will call this method for initialize the applicationContext.
- * @param ctx the application context
- * @throws BeansException the BeanException
+ *
+ * @param ctx
+ * the application context
+ * @throws BeansException
+ * the BeanException
*/
- public void setApplicationContext(final ApplicationContext ctx) throws BeansException {
+ public void setApplicationContext(final ApplicationContext ctx)
+ throws BeansException {
_context = ctx;
}
/**
* Static for getting the context.
+ *
* @return ApplicationContext the application context
*/
public static ApplicationContext getContext() {
return _context;
}
-
-// private static String CONFIG_FILE = "/hibernate.cfg.xml";
- private static SessionFactory mySessionFactory = null;
-
- protected class CreateTables implements Work {
-// -----------------------------------------------
- protected Statement request;
-
- public void execute(Connection connex) throws SQLException
- {
- request = connex.createStatement();
-
-// Last identifier of Any objects
- String create = "CREATE TABLE `any` (" +
- "`rid` int(10) UNSIGNED NOT NULL," +
- "`version` tinytext NOT NULL," +
- "PRIMARY KEY (`rid`)" +
- ") ENGINE=MyISAM DEFAULT CHARSET=latin1";
- request.execute(create);
-
-// Relation from entities
- create = "CREATE TABLE `relation` (" +
- "`rid` int(10) UNSIGNED NOT NULL," +
- "`name` tinytext NOT NULL," +
- "`owner` int(10) NOT NULL," +
- "`refer` int(10) NOT NULL," +
- "PRIMARY KEY (`rid`)" +
- ") ENGINE=MyISAM DEFAULT CHARSET=latin1";
- request.execute(create);
-// Attribute objects
- create = "CREATE TABLE `attribute` (" +
- "`rid` int(10) UNSIGNED NOT NULL auto_increment," +
- "`type` tinytext NOT NULL," +
- "`owner` int(10) NOT NULL," +
- "`value` int(10) NOT NULL," +
- "PRIMARY KEY (`rid`)" +
- ") ENGINE=MyISAM DEFAULT CHARSET=latin1";
- request.execute(create);
+ // private static String CONFIG_FILE = "/hibernate.cfg.xml";
+ protected final static Logger logger = Logger.getLogger(Database.class);
-// Java String objects
- create = "CREATE TABLE `text` (" +
- "`rid` int(10) UNSIGNED NOT NULL auto_increment," +
- "`value` longtext NOT NULL," +
- "PRIMARY KEY (`rid`)" +
- ") ENGINE=MyISAM DEFAULT CHARSET=latin1";
- request.execute(create);
+ // ==============================================================================================================================
+ // Protected services
+ // ==============================================================================================================================
-// User and role objects
- create = "CREATE TABLE `user` (" +
- "`rid` int(10) UNSIGNED NOT NULL auto_increment," +
- "`username` varchar(32) NOT NULL," +
- "`password` varchar(32)," +
- "`first` tinytext NOT NULL," +
- "`last` tinytext NOT NULL," +
- "`display` tinytext," +
- "`email` tinytext," +
- "`organid` tinytext," +
- "PRIMARY KEY (`rid`)" +
- ") ENGINE=MyISAM DEFAULT CHARSET=latin1";
- request.execute(create);
-
- create = "CREATE TABLE `role` (" +
- "`username` varchar(32) NOT NULL," +
- "`role` varchar(32) NOT NULL," +
- "PRIMARY KEY (`username`)" +
- ") ENGINE=MyISAM DEFAULT CHARSET=latin1";
- request.execute(create);
- }
- }
-
- protected final static Logger logger = Logger.getLogger(Database.class);
-
-// ==============================================================================================================================
-// Public services
-// ==============================================================================================================================
-
- public static Session getSession () {
-// -----------------------------------
- return getInstance().getCurrentSession();
+ protected String getSchemaVersion() {
+ // ------------------------------------
+ return null;// TODO: Get schema version into specific object/table: getIDPool().getSchemaVersion();
}
-
-// ==============================================================================================================================
-// Protected services
-// ==============================================================================================================================
- protected String getSchemaVersion () {
-// ------------------------------------
- return null;//TODO: Get schema version into specific object/table: getIDPool().getSchemaVersion();
- }
-
- protected void setSchemaVersion (String version) {
-// ------------------------------------------------
-//TODO: Set schema version into specific object/table: myIDpool = new IDPool(version);
-// getSession().save(myIDpool);
- }
+ protected void setSchemaVersion(String version) {
+ // ------------------------------------------------
+ // TODO: Set schema version into specific object/table: myIDpool = new IDPool(version);
+ // getSession().save(myIDpool);
+ }
-// ==============================================================================================================================
-// Private services
-// ==============================================================================================================================
-
- private static SessionFactory getInstance () {
-// --------------------------------------------
- if (mySessionFactory == null) {
-// org.hibernate.cfg.Configuration cfg = new org.hibernate.cfg.Configuration();
- try {
- mySessionFactory = getContext().getBean(SessionFactory.class);
-// cfg.configure(); // The configuration file (hibernate.cfg.xml)) is supposed to be on the classpath
-// mySessionFactory = cfg.buildSessionFactory();
- }
- catch (Exception error) {
- logger.fatal("Could not initialize the Hibernate configuration, reason:", error);
- }
- }
- return mySessionFactory;
- }
+ // ==============================================================================================================================
+ // Private services
+ // ==============================================================================================================================
+//{
+// if (myDB == null) {
+// myDB = new Database();
+// }
+// return myDB;
+// }
}
\ No newline at end of file