View Javadoc
1   /*
2    *    Copyright 2009-2023 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.guice.datasource.helper;
17  
18  import static com.google.inject.name.Names.named;
19  import static com.google.inject.util.Providers.guicify;
20  
21  import com.google.inject.Binder;
22  import com.google.inject.Key;
23  import com.google.inject.Module;
24  
25  /**
26   * Helper to bind <code>JDBC.driver</code> and <code>JDBC.url</code> properties.
27   */
28  public enum JdbcHelper implements Module {
29  
30    Cache("jdbc:Cache://${JDBC.host|localhost}:${JDBC.port|1972}/${JDBC.schema}", "com.intersys.jdbc.CacheDriver"),
31  
32    Daffodil_DB("jdbc:daffodilDB://${JDBC.host|localhost}:${JDBC.port|3456}/${JDBC.schema}",
33        "in.co.daffodil.db.rmi.RmiDaffodilDBDriver"),
34  
35    DB2("jdbc:db2://${JDBC.host|localhost}:${JDBC.port|50000}/${JDBC.schema}", "com.ibm.db2.jcc.DB2Driver"),
36  
37    DB2_DataDirect("jdbc:datadirect:db2://${JDBC.host|localhost}:${JDBC.port|50000}/DatabaseName=${JDBC.schema}",
38        "com.ddtek.jdbc.db2.DB2Driver"),
39  
40    DB2_AS400_JTOpen("jdbc:as400://${JDBC.host|localhost}", "com.ibm.as400.access.AS400JDBCDriver"),
41  
42    Firebird("jdbc:firebirdsql:${JDBC.host|localhost}/${JDBC.port|3050}:${JDBC.schema}", "org.firebirdsql.jdbc.FBDriver"),
43  
44    FrontBase("jdbc:FrontBase://${JDBC.host|localhost}/${JDBC.schema}", "jdbc.FrontBase.FBJDriver"),
45  
46    HP_Neoview("jdbc:hpt4jdbc://${neoview.system}:${JDBC.port}/:", "com.hp.t4jdbc.HPT4Driver"),
47  
48    HSQLDB_Server("jdbc:hsqldb:hsql://${JDBC.host|localhost}:${JDBC.port|9001}/${JDBC.schema}", "org.hsqldb.jdbcDriver"),
49  
50    HSQLDB_Embedded("jdbc:hsqldb:${JDBC.schema}", "org.hsqldb.jdbcDriver"),
51  
52    HSQLDB_IN_MEMORY_NAMED("jdbc:hsqldb:mem:${JDBC.schema|aname}", "org.hsqldb.jdbcDriver"),
53  
54    H2_IN_MEMORY_PRIVATE("jdbc:h2:mem", "org.h2.Driver"),
55  
56    H2_IN_MEMORY_NAMED("jdbc:h2:mem:${JDBC.schema}", "org.h2.Driver"),
57  
58    H2_SERVER_TCP("jdbc:h2:tcp://${JDBC.host|localhost}:${JDBC.port|9001}/${JDBC.schema}", "org.h2.Driver"),
59  
60    H2_SERVER_SSL("jdbc:h2:ssl://${JDBC.host|localhost}:${JDBC.port|9001}/${JDBC.schema}", "org.h2.Driver"),
61  
62    H2_FILE("jdbc:h2:file://${JDBC.schema}", "org.h2.Driver"),
63  
64    H2_EMBEDDED("jdbc:h2:${JDBC.schema}", "org.h2.Driver"),
65  
66    Informix(
67        "jdbc:informix-sqli://${JDBC.host|localhost}:${JDBC.port|1533}/${JDBC.schema}:informixserver=${dbservername}",
68        "com.informix.jdbc.IfxDriver"),
69  
70    Informix_DataDirect(
71        "jdbc:datadirect:informix://${JDBC.host|localhost}:${JDBC.port|1533};InformixServer=${informixserver};DatabaseServer=${JDBC.schema}",
72        "com.ddtek.jdbc.informix.InformixDriver"),
73  
74    Derby_Server("jdbc:derby://${JDBC.host|localhost}:${JDBC.port|1527}/${JDBC.schema}",
75        "org.apache.derby.jdbc.ClientDriver"),
76  
77    Derby_Embedded("jdbc:derby:${JDBC.schema};create=${derby.create|false}", "org.apache.derby.jdbc.EmbeddedDriver"),
78  
79    JDataStore("jdbc:borland:dslocal:${JDBC.schema}", "com.borland.datastore.jdbc.DataStoreDriver"),
80  
81    JDBC_ODBC_Bridge("jdbc:odbc:${ODBC.datasource}", "sun.jdbc.odbc.JdbcOdbcDriver"),
82  
83    MariaDB("jdbc:mariadb://${JDBC.host|localhost}:${JDBC.port|3306}/${JDBC.schema}", "org.mariadb.jdbc.Driver"),
84  
85    MariaDB_Aurora("jdbc:mysql:aurora//${JDBC.host|localhost}:${JDBC.port|3306}/${JDBC.schema}",
86        "org.mariadb.jdbc.Driver"),
87  
88    MariaDB_Sequential("jdbc:mysql:sequential//${JDBC.host|localhost}:${JDBC.port|3306}/${JDBC.schema}",
89        "org.mariadb.jdbc.Driver"),
90  
91    MariaDB_Loadbalance("jdbc:mysql:loadbalance//${JDBC.host|localhost}:${JDBC.port|3306}/${JDBC.schema}",
92        "org.mariadb.jdbc.Driver"),
93  
94    MariaDB_Replication("jdbc:mysql:replication//${JDBC.host|localhost}:${JDBC.port|3306}/${JDBC.schema}",
95        "org.mariadb.jdbc.Driver"),
96  
97    MaxDB("jdbc:sapdb://${JDBC.host|localhost}:${JDBC.port|7210}/${JDBC.schema}", "com.sap.dbtech.jdbc.DriverSapDB"),
98  
99    McKoi("jdbc:mckoi://${JDBC.host|localhost}:${JDBC.port|9157}/${JDBC.schema}", "com.mckoi.JDBCDriver"),
100 
101   Mimer("jdbc:mimer:${mimer.protocol}://${JDBC.host|localhost}:${JDBC.port|1360}/${JDBC.schema}",
102       "com.mimer.jdbc.Driver"),
103 
104   MySQL("jdbc:mysql://${JDBC.host|localhost}:${JDBC.port|3306}/${JDBC.schema}", "com.mysql.jdbc.Driver"),
105 
106   Netezza("jdbc:netezza://${JDBC.host|localhost}:${JDBC.port|5480}/${JDBC.schema}", "org.netezza.Driver"),
107 
108   Oracle_Thin("jdbc:oracle:thin:@${JDBC.host|localhost}:${JDBC.port|1521}:${oracle.sid|ORCL}",
109       "oracle.jdbc.OracleDriver"),
110 
111   Oracle_Service("jdbc:oracle:thin:@//${JDBC.host|localhost}:${JDBC.port|1521}/${oracle.servicename|ORCL}",
112       "oracle.jdbc.OracleDriver"),
113 
114   Oracle_OCI("jdbc:oracle:oci:@${JDBC.host|localhost}:${JDBC.port|1521}:${oracle.sid|ORCL}",
115       "oracle.jdbc.OracleDriver"),
116 
117   Oracle_DataDirect(
118       "jdbc:datadirect:oracle://${JDBC.host|localhost}:${JDBC.port|1521};ServiceName=${oracle.servicename|ORCL}",
119       "com.ddtek.jdbc.oracle.OracleDriver"),
120 
121   Pervasive("jdbc:pervasive://${JDBC.host|localhost}:${JDBC.port}/${JDBC.schema}", "pervasive.jdbc.PervasiveDriver"),
122 
123   Pointbase_Embedded(
124       "jdbc:pointbase:embedded:${JDBC.schema},database.home=${pointbase.home},create=${pointbase.create|false}",
125       "com.pointbase.jdbc.jdbcUniversalDriver"),
126 
127   Pointbase_Server(
128       "jdbc:pointbase:server://${JDBC.host|localhost}:${JDBC.port|9092}/${JDBC.schema},database.home=${pointbase.home},create=${pointbase.create|false}",
129       "com.pointbase.jdbc.jdbcUniversalDriver"),
130 
131   PostgreSQL("jdbc:postgresql://${JDBC.host|localhost}:${JDBC.port|5432}/${JDBC.schema}", "org.postgresql.Driver"),
132 
133   Progress("jdbc:jdbcProgress:T:${JDBC.host|localhost}:${JDBC.port|2055}:${JDBC.schema}",
134       "com.progress.sql.jdbc.JdbcProgressDriver"),
135 
136   SQL_Server_DataDirect(
137       "jdbc:datadirect:sqlserver://${JDBC.host|localhost}:${JDBC.port|1433};DatabaseName=${JDBC.schema|Northwind}",
138       "com.ddtek.jdbc.sqlserver.SQLServerDriver"),
139 
140   SQL_Server_jTDS(
141       "jdbc:jtds:sqlserver://${JDBC.host|localhost}:${JDBC.port|1433};DatabaseName=${JDBC.schema|Northwind};domain=${sqlserver.domain}",
142       "net.sourceforge.jtds.jdbc.Driver"),
143 
144   SQL_Server_MS_Driver(
145       "jdbc:microsoft:sqlserver://${JDBC.host|localhost}:${JDBC.port|1433};DatabaseName=${JDBC.schema|Northwind}",
146       "com.microsoft.jdbc.sqlserver.SQLServerDriver"),
147 
148   SQL_Server_2005_MS_Driver(
149       "jdbc:sqlserver://${JDBC.host|localhost}:${JDBC.port|1433};DatabaseName=${JDBC.schema|Northwind}",
150       "com.microsoft.sqlserver.jdbc.SQLServerDriver"),
151 
152   SQLITE_FILE("jdbc:sqlite:${JDBC.schema}", "org.sqlite.JDBC"),
153 
154   SQLITE_IN_MEMORY("jdbc:sqlite::memory:", "org.sqlite.JDBC"),
155 
156   Sybase_ASE_jTDS("jdbc:jtds:sybase://${JDBC.host|localhost}:${JDBC.port|5000};DatabaseName=${JDBC.schema}",
157       "net.sourceforge.jtds.jdbc.Driver"),
158 
159   Sybase_ASE_JConnect("jdbc:sybase:Tds:${JDBC.host|localhost}:${JDBC.port|5000}/${JDBC.schema}",
160       "com.sybase.jdbc3.jdbc.SybDriver"),
161 
162   Sybase_SQL_Anywhere_JConnect("jdbc:sybase:Tds:${JDBC.host|localhost}:${JDBC.port|2638}/${JDBC.schema}",
163       "com.sybase.jdbc3.jdbc.SybDriver"),
164 
165   Sybase_DataDirect("jdbc:datadirect:sybase://${JDBC.host|localhost}:${JDBC.port|2048};ServiceName=${JDBC.schema}",
166       "com.ddtek.jdbc.sybase.SybaseDriver");
167 
168   private static final String JDBC_DRIVER = "JDBC.driver";
169 
170   private static final String JDBC_URL = "JDBC.url";
171 
172   private final String urlTemplate;
173 
174   private final String driverClass;
175 
176   JdbcHelper(String urlTemplate, String driverClass) {
177     this.urlTemplate = urlTemplate;
178     this.driverClass = driverClass;
179   }
180 
181   @Override
182   public void configure(Binder binder) {
183     binder.bindConstant().annotatedWith(named(JDBC_DRIVER)).to(driverClass);
184     binder.bind(Key.get(String.class, named(JDBC_URL))).toProvider(guicify(new JdbcUrlAntFormatter(urlTemplate)));
185   }
186 
187 }