2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.database
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
15 import javax
.sql
.DataSource
;
17 import org
.apache
.log4j
.Logger
;
19 import eu
.etaxonomy
.cdm
.database
.types
.H2DatabaseType
;
20 import eu
.etaxonomy
.cdm
.database
.types
.HSqlDbDatabaseType
;
21 import eu
.etaxonomy
.cdm
.database
.types
.IDatabaseType
;
22 import eu
.etaxonomy
.cdm
.database
.types
.MySQLDatabaseType
;
23 import eu
.etaxonomy
.cdm
.database
.types
.OdbcDatabaseType
;
24 import eu
.etaxonomy
.cdm
.database
.types
.OracleDatabaseType
;
25 import eu
.etaxonomy
.cdm
.database
.types
.PostgreSQLDatabaseType
;
26 import eu
.etaxonomy
.cdm
.database
.types
.SqlServer2005DatabaseType
;
27 import eu
.etaxonomy
.cdm
.database
.types
.SybaseDatabaseType
;
33 public enum DatabaseTypeEnum
{
48 private static final String P6SPY_DRIVER_CLASS_NAME
= "com.p6spy.engine.spy.P6SpyDriver";
49 private boolean useP6Spy
= false;
53 * @return the useP6Spy
55 public boolean isUseP6Spy() {
60 * @param useP6Spy the useP6Spy to set
62 public void setUseP6Spy(boolean useP6Spy
) {
63 this.useP6Spy
= useP6Spy
;
70 private DatabaseTypeEnum(int i
) {
74 this.dbType
= new HSqlDbDatabaseType(); break;
76 this.dbType
= new MySQLDatabaseType(); break;
78 this.dbType
= new OdbcDatabaseType(); break;
80 this.dbType
= new PostgreSQLDatabaseType(); break;
82 this.dbType
= new OracleDatabaseType(); break;
84 // this.dbType = new SqlServer2000DatabaseType(); break;
86 this.dbType
= new SqlServer2005DatabaseType(); break;
88 this.dbType
= new SybaseDatabaseType(); break;
90 this.dbType
= new H2DatabaseType(); break;
96 public IDatabaseType
getDatabaseType(){
101 private static final Logger logger
= Logger
.getLogger(DatabaseTypeEnum
.class);
102 protected IDatabaseType dbType
;
108 public String
getName(){
109 return dbType
.getName();
115 public String
getDriverClassName(){
117 return P6SPY_DRIVER_CLASS_NAME
;
120 return dbType
.getClassString();
125 * Returns the DataSource class that that the datasource needs to create a spring bean
126 * @return the DataSource class
128 public Class
<?
extends DataSource
> getDataSourceClass(){
129 return dbType
.getDataSourceClass();
135 public String
getUrl(){
136 return dbType
.getUrlString();
142 public String
getHibernateDialect(){
143 return dbType
.getHibernateDialect();
149 public int getDefaultPort(){
150 return dbType
.getDefaultPort();
154 * returns the connection string
155 * @param server the server, e.g. IP-Address
156 * @param database the database name on the server (e.g. "testDB")
157 * @param port the port number
158 * @return the connection string
160 public String
getConnectionString(ICdmDataSource cdmDataSource
){
161 String result
= dbType
.getConnectionString(cdmDataSource
);
162 logger
.debug("Connection String: " + result
);
169 * Returns the Name of the initialization method to be used when a hibernate datasource is created for this database
170 * @return String name of the init method
172 public String
getInitMethod(){
173 String result
= dbType
.getInitMethod();
174 logger
.debug("InitMethod: " + result
);
179 * Returns the Name of the destroying method to be used when a hibernate datasource representing this database is destroyed
180 * @return String name of the destroy method
182 public String
getDestroyMethod(){
183 String result
= dbType
.getDestroyMethod();
184 logger
.debug("DestroyMethod: " + result
);
189 * Returns a List of all available DatabaseEnums.
190 * @return List of DatabaseEnums
192 public static List
<DatabaseTypeEnum
> getAllTypes(){
193 List
<DatabaseTypeEnum
> result
= new ArrayList
<DatabaseTypeEnum
>();
194 for (DatabaseTypeEnum dbEnum
: DatabaseTypeEnum
.values()){
201 * Returns the DatabaseTypeEnum to a given DriverClass
202 * @param strDriverClass
203 * @return the according DatabaseTypeEnum. Null if the driver class does not exist.
205 public static DatabaseTypeEnum
getDatabaseEnumByDriverClass(String strDriverClass
){
206 for (DatabaseTypeEnum dbEnum
: DatabaseTypeEnum
.values()){
207 if (dbEnum
.getDriverClassName().equals(strDriverClass
)){
211 logger
.warn("Unknown driver class " + strDriverClass
==null ?
"null" : strDriverClass
);