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 org
.apache
.log4j
.Logger
;
16 import org
.springframework
.jdbc
.datasource
.DriverManagerDataSource
;
18 import eu
.etaxonomy
.cdm
.database
.types
.H2DatabaseType
;
19 import eu
.etaxonomy
.cdm
.database
.types
.HSqlDbDatabaseType
;
20 import eu
.etaxonomy
.cdm
.database
.types
.IDatabaseType
;
21 import eu
.etaxonomy
.cdm
.database
.types
.MySQLDatabaseType
;
22 import eu
.etaxonomy
.cdm
.database
.types
.OdbcDatabaseType
;
23 import eu
.etaxonomy
.cdm
.database
.types
.OracleDatabaseType
;
24 import eu
.etaxonomy
.cdm
.database
.types
.PostgreSQLDatabaseType
;
25 import eu
.etaxonomy
.cdm
.database
.types
.SqlServer2005DatabaseType
;
26 import eu
.etaxonomy
.cdm
.database
.types
.SqlServer2000DatabaseType
;
27 import eu
.etaxonomy
.cdm
.database
.types
.SybaseDatabaseType
;
33 public enum DatabaseTypeEnum
{
49 private DatabaseTypeEnum(int i
) {
53 this.dbType
= new HSqlDbDatabaseType(); break;
55 this.dbType
= new MySQLDatabaseType(); break;
57 this.dbType
= new OdbcDatabaseType(); break;
59 this.dbType
= new PostgreSQLDatabaseType(); break;
61 this.dbType
= new OracleDatabaseType(); break;
63 this.dbType
= new SqlServer2000DatabaseType(); break;
65 this.dbType
= new SqlServer2005DatabaseType(); break;
67 this.dbType
= new SybaseDatabaseType(); break;
69 this.dbType
= new H2DatabaseType(); break;
75 public IDatabaseType
getDatabaseType(){
80 private static final Logger logger
= Logger
.getLogger(DatabaseTypeEnum
.class);
81 protected IDatabaseType dbType
;
87 public String
getName(){
88 return dbType
.getName();
94 public String
getDriverClassName(){
95 return dbType
.getClassString();
99 * Returns the DriverManagerDataSource class that that the datasource needs to create a spring bean
100 * @return the DriverManagerDataSource class
102 public Class
<?
extends DriverManagerDataSource
> getDriverManagerDataSourceClass(){
103 return dbType
.getDriverManagerDataSourceClass();
109 public String
getUrl(){
110 return dbType
.getUrlString();
116 public String
getHibernateDialect(){
117 return dbType
.getHibernateDialect();
123 public int getDefaultPort(){
124 return dbType
.getDefaultPort();
128 * returns the connection string
129 * @param server the server, e.g. IP-Address
130 * @param database the database name on the server (e.g. "testDB")
131 * @param port the port number
132 * @return the connection string
134 public String
getConnectionString(ICdmDataSource cdmDataSource
){
135 String result
= dbType
.getConnectionString(cdmDataSource
);
136 logger
.debug("Connection String: " + result
);
143 * Returns the Name of the initialization method to be used when a hibernate datasource is created for this database
144 * @return String name of the init method
146 public String
getInitMethod(){
147 String result
= dbType
.getInitMethod();
148 logger
.debug("InitMethod: " + result
);
153 * Returns the Name of the destroying method to be used when a hibernate datasource representing this database is destroyed
154 * @return String name of the destroy method
156 public String
getDestroyMethod(){
157 String result
= dbType
.getDestroyMethod();
158 logger
.debug("DestroyMethod: " + result
);
163 * Returns a List of all available DatabaseEnums.
164 * @return List of DatabaseEnums
166 public static List
<DatabaseTypeEnum
> getAllTypes(){
167 List
<DatabaseTypeEnum
> result
= new ArrayList
<DatabaseTypeEnum
>();
168 for (DatabaseTypeEnum dbEnum
: DatabaseTypeEnum
.values()){
175 * Returns the DatabaseTypeEnum to a given DriverClass
176 * @param strDriverClass
177 * @return the according DatabaseTypeEnum. Null if the driver class does not exist.
179 public static DatabaseTypeEnum
getDatabaseEnumByDriverClass(String strDriverClass
){
180 for (DatabaseTypeEnum dbEnum
: DatabaseTypeEnum
.values()){
181 if (dbEnum
.getDriverClassName().equals(strDriverClass
)){
185 logger
.warn("Unknown driver class " + strDriverClass
==null ?
"null" : strDriverClass
);