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
.types
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.springframework
.jdbc
.datasource
.DriverManagerDataSource
;
17 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationUtils
;
18 import eu
.etaxonomy
.cdm
.database
.H2Mode
;
19 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
20 import eu
.etaxonomy
.cdm
.database
.LocalH2
;
27 public class H2DatabaseType
extends DatabaseTypeBase
{
28 private static final Logger logger
= Logger
.getLogger(H2DatabaseType
.class);
31 private String typeName
= "H2 Database";
34 private String classString
= "org.h2.Driver";
37 private String urlString
= "jdbc:h2:";
40 private String path
= getDefaultPath();
43 private int defaultPort
= 9092;
46 private String hibernateDialect
= "H2Dialect";
49 private String initMethod
= "init";
52 private String destroyMethod
= "destroy";
55 public String
getConnectionString(ICdmDataSource ds
, int port
){
56 H2Mode mode
= ds
.getMode();
57 String path
= ds
.getFilePath();
59 path
= getDefaultPath();
61 if (mode
.equals(H2Mode
.IN_MEMORY
)){
62 return urlString
+ "mem:";
63 }else if (mode
.equals(H2Mode
.EMBEDDED
)){
64 return urlString
+ "file:" + path
+ "/" + ds
.getDatabase();
65 }else if (mode
.equals(H2Mode
.TCP
)){
66 return urlString
+ "tcp://" + ds
.getServer() + ":" + port
+ "/" + path
+ "/" + ds
.getDatabase();
68 logger
.warn("Unrecognized mode for Database H2");
74 public H2DatabaseType() {
75 init (typeName
, classString
, urlString
, defaultPort
, hibernateDialect
);
79 public Class
<?
extends DriverManagerDataSource
> getDriverManagerDataSourceClass() {
84 * @see eu.etaxonomy.cdm.database.types.IDatabaseType#getInitMethod()
87 public String
getInitMethod() {
92 * @see eu.etaxonomy.cdm.database.types.IDatabaseType#getDestroyMethod()
95 public String
getDestroyMethod() {
99 private static final String
getDefaultPath(){
100 //String path = System.getProperty("user.dir");
101 File path
= CdmApplicationUtils
.getWritableResourceDir();
102 String subPath
= File
.separator
+ "h2" + File
.separator
+ "LocalH2";
103 return path
+ subPath
;