Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/db
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3250
Modified Files:
HibernateUtil.java
Log Message:
Use database factory
Index: HibernateUtil.java
===================================================================
RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/db/HibernateUtil.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** HibernateUtil.java 1 Aug 2005 10:33:37 -0000 1.2
--- HibernateUtil.java 4 Aug 2005 06:05:04 -0000 1.3
***************
*** 35,44 ****
private static final ThreadLocal TL = new ThreadLocal();
- /** MODE_HSQLDB */
- public static final int MODE_HSQLDB = 0;
-
- /** MODE_POSTGRESQL */
- public static final int MODE_POSTGRESQL = 1;
-
/**
* Constructor
--- 35,38 ----
***************
*** 46,50 ****
private HibernateUtil() {
sf = null;
- setMode(MODE_HSQLDB, true, "jdbc:hsqldb:mem:bprocessor", "", "");
}
--- 40,43 ----
***************
*** 61,73 ****
/**
! * Set the mode of the persistence layer
! * @param mode The mode
! * @param autodrop Should the database be dropped ?
! * @param url The connection url
! * @param user The user name
! * @param password The password
*/
! public synchronized void setMode(int mode, boolean autodrop,
! String url, String user, String password) {
try {
if (sf != null && !sf.isClosed()) {
--- 54,60 ----
/**
! * Configure the persistence layer
*/
! synchronized void configure() {
try {
if (sf != null && !sf.isClosed()) {
***************
*** 76,95 ****
Configuration cfg = new Configuration();
! if (mode == MODE_HSQLDB) {
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
cfg.setProperty("hibernate.use_outer_join", "false");
cfg.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
! } else if (mode == MODE_POSTGRESQL) {
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
cfg.setProperty("hibernate.use_outer_join", "true");
cfg.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
} else {
! log.error("Unsupported database: " + mode);
! log.warn("Defaulting to HSQLDB/Memory");
! url = "jdbc:hsqldb:mem:bprocessor";
! user = null;
! password = null;
! autodrop = true;
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
cfg.setProperty("hibernate.use_outer_join", "false");
--- 63,80 ----
Configuration cfg = new Configuration();
+ Database db = DatabaseFactory.getInstance().getDatabase();
+ int type = db.getType();
! if (type == Database.HSQLDB) {
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
cfg.setProperty("hibernate.use_outer_join", "false");
cfg.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
! } else if (type == Database.POSTGRESQL) {
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
cfg.setProperty("hibernate.use_outer_join", "true");
cfg.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
} else {
! log.error("Unsupported database: " + type);
! log.warn("Defaulting to HSQLDB");
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
cfg.setProperty("hibernate.use_outer_join", "false");
***************
*** 97,101 ****
}
! if (autodrop) {
cfg.setProperty("hibernate.hbm2ddl.auto", "create-drop");
} else {
--- 82,86 ----
}
! if (db.getAutodrop()) {
cfg.setProperty("hibernate.hbm2ddl.auto", "create-drop");
} else {
***************
*** 106,116 ****
cfg.setProperty("hibernate.order_updates", "true");
! cfg.setProperty("hibernate.connection.url", url);
! if (user != null && !user.trim().equals("")) {
! cfg.setProperty("hibernate.connection.username", user);
! }
! if (password != null && !password.trim().equals("")) {
! cfg.setProperty("hibernate.connection.password", password);
}
--- 91,101 ----
cfg.setProperty("hibernate.order_updates", "true");
! cfg.setProperty("hibernate.connection.url", db.getUrl());
! if (db.getUser() != null && !db.getUser().trim().equals("")) {
! cfg.setProperty("hibernate.connection.username", db.getUser());
! if (db.getPassword() != null && !db.getPassword().trim().equals("")) {
! cfg.setProperty("hibernate.connection.password", db.getPassword());
! }
}
|