[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model/db AbstractDatabase.java,NONE,1.1 Dat
Status: Pre-Alpha
Brought to you by:
henryml
From: Jesper P. <je...@us...> - 2005-08-04 06:04:52
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/db In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3181 Added Files: AbstractDatabase.java DatabaseFactory.java Database.java HSQLDB.java PostgreSQL.java Log Message: Initial import --- NEW FILE: AbstractDatabase.java --- //--------------------------------------------------------------------------------- // $Id: AbstractDatabase.java,v 1.1 2005/08/04 06:04:43 jews Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model.db; import org.apache.log4j.Logger; /** * The abstract database */ public abstract class AbstractDatabase implements Database { /** The logger */ private static Logger log = Logger.getLogger(AbstractDatabase.class); /** The url */ private String url; /** The user */ private String user; /** The password */ private String password; /** Autodrop */ private boolean autodrop; /** * Constructor * @param url The url * @param user The user * @param password The password * @param autodrop The autodrop */ protected AbstractDatabase(String url, String user, String password, boolean autodrop) { this.url = url; this.user = user; this.password = password; this.autodrop = autodrop; } /** * Get the url * @return The url of the database */ public String getUrl() { return url; } /** * Set the url * @param url The url */ public void setUrl(String url) { this.url = url; } /** * Get the user * @return The user of the database */ public String getUser() { return user; } /** * Set the user * @param user The user */ public void setUser(String user) { this.user = user; } /** * Get the password of the user * @return The password */ public String getPassword() { return password; } /** * Set the password * @param password The password */ public void setPassword(String password) { this.password = password; } /** * Should the database be auto dropped ? * @return True if auto dropped; otherwise false */ public boolean getAutodrop() { return autodrop; } /** * Set the autodrop * @param autodrop The autodrop */ public void setAutodrop(boolean autodrop) { this.autodrop = autodrop; } /** * Get the name * @return The name of the database */ public abstract String getName(); /** * Get the type * @return The type of the database */ public abstract int getType(); } --- NEW FILE: PostgreSQL.java --- //--------------------------------------------------------------------------------- // $Id: PostgreSQL.java,v 1.1 2005/08/04 06:04:43 jews Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model.db; import org.apache.log4j.Logger; /** * The PostgreSQL database */ public class PostgreSQL extends AbstractDatabase { /** The logger */ private static Logger log = Logger.getLogger(PostgreSQL.class); /** The singleton */ private static PostgreSQL instance; /** * Constructor */ private PostgreSQL() { super("", "", "", false); } /** * Get the instance * @return The instance */ public static synchronized PostgreSQL getInstance() { if (instance == null) { instance = new PostgreSQL(); } return instance; } /** * Get the name * @return The name of the database */ public String getName() { return "PostgreSQL"; } /** * Get the type * @return The type of the database */ public int getType() { return Database.POSTGRESQL; } } --- NEW FILE: HSQLDB.java --- //--------------------------------------------------------------------------------- // $Id: HSQLDB.java,v 1.1 2005/08/04 06:04:43 jews Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model.db; import org.apache.log4j.Logger; /** * The HSQLDB database */ public class HSQLDB extends AbstractDatabase { /** The logger */ private static Logger log = Logger.getLogger(HSQLDB.class); /** The singleton */ private static HSQLDB instance; /** * Constructor */ private HSQLDB() { super("jdbc:hsqldb:mem:bprocessor", "", "", true); } /** * Get the instance * @return The instance */ public static synchronized HSQLDB getInstance() { if (instance == null) { instance = new HSQLDB(); } return instance; } /** * Get the name * @return The name of the database */ public String getName() { return "HSQLDB"; } /** * Get the type * @return The type of the database */ public int getType() { return Database.HSQLDB; } } --- NEW FILE: Database.java --- //--------------------------------------------------------------------------------- // $Id: Database.java,v 1.1 2005/08/04 06:04:43 jews Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model.db; /** * The database interface */ public interface Database { /** HSQLDB */ public static final int HSQLDB = 0; /** POSTGRESQL */ public static final int POSTGRESQL = 1; /** * Get the name * @return The name of the database */ public String getName(); /** * Get the type * @return The type of the database */ public int getType(); /** * Get the url * @return The url of the database */ public String getUrl(); /** * Set the url * @param url The url */ public void setUrl(String url); /** * Get the user * @return The user of the database */ public String getUser(); /** * Set the user * @param user The user */ public void setUser(String user); /** * Get the password of the user * @return The password */ public String getPassword(); /** * Set the password * @param password The password */ public void setPassword(String password); /** * Should the database be auto dropped ? * @return True if auto dropped; otherwise false */ public boolean getAutodrop(); /** * Set if the database should be autodropped * @param autodrop Should the database be autodropped ? */ public void setAutodrop(boolean autodrop); } --- NEW FILE: DatabaseFactory.java --- //--------------------------------------------------------------------------------- // $Id: DatabaseFactory.java,v 1.1 2005/08/04 06:04:43 jews Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model.db; import org.apache.log4j.Logger; /** * The database factory */ public class DatabaseFactory { /** The logger */ private static Logger log = Logger.getLogger(DatabaseFactory.class); /** The singleton */ private static DatabaseFactory instance; /** The current database */ private Database database; /** * Constructor */ private DatabaseFactory() { Database db = HSQLDB.getInstance(); setDatabase(Database.HSQLDB, db.getUrl(), db.getUser(), db.getPassword(), db.getAutodrop()); } /** * Get the instance * @return The instance */ public static synchronized DatabaseFactory getInstance() { if (instance == null) { instance = new DatabaseFactory(); } return instance; } /** * Get the database * @return The database */ public Database getDatabase() { return database; } /** * Set the database * @param type The database type * @param url The url * @param user The user * @param password The password * @param autodrop Autodrop tables */ public synchronized void setDatabase(int type, String url, String user, String password, boolean autodrop) { boolean known = true; HibernateUtil hb = HibernateUtil.getInstance(); if (type == Database.HSQLDB) { database = HSQLDB.getInstance(); } else if (type == Database.POSTGRESQL) { database = PostgreSQL.getInstance(); } else { log.error("Unknown database: " + type); log.warn("Keeping existing configuration"); known = false; } if (known) { database.setUrl(url); database.setUser(user); database.setPassword(password); database.setAutodrop(autodrop); hb.configure(); } } } |