001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.db; 020 021import lucee.commons.lang.StringUtil; 022 023public class DBUtil { 024 025 private static DataSourceDefintion DB2=new DataSourceDefintion("com.ddtek.jdbc.db2.DB2Driver","jdbc:datadirect:db2://{host}:{port};DatabaseName={database}",50000); 026 private static DataSourceDefintion FIREBIRD=new DataSourceDefintion("org.firebirdsql.jdbc.FBDriver","jdbc:firebirdsql://{host}:{port}/{path}{database}",3050); 027 private static DataSourceDefintion H2=new DataSourceDefintion("org.h2.Driver","jdbc:h2:{path}{database};MODE={mode}",-1); 028 private static DataSourceDefintion MSSQL=new DataSourceDefintion("net.sourceforge.jtds.jdbc.Driver","jdbc:jtds:sqlserver://{host}:{port}/{database}",1433); 029 private static DataSourceDefintion MYSQL=new DataSourceDefintion("org.gjt.mm.mysql.Driver","jdbc:mysql://{host}:{port}/{database}",3306); 030 private static DataSourceDefintion ORACLE=new DataSourceDefintion("oracle.jdbc.driver.OracleDriver","jdbc:oracle:{drivertype}:@{host}:{port}:{database}",1521); 031 private static DataSourceDefintion POSTGRESQL=new DataSourceDefintion("org.postgresql.Driver","jdbc:postgresql://{host}:{port}/{database}",5432); 032 private static DataSourceDefintion SYBASE=new DataSourceDefintion("net.sourceforge.jtds.jdbc.Driver","jdbc:jtds:sybase://{host}:{port}/{database}",7100); 033 034 035 public static DataSourceDefintion getDataSourceDefintionForType(String type, DataSourceDefintion defaultValue){ 036 if(StringUtil.isEmpty(type)) return defaultValue; 037 type=type.trim().toLowerCase(); 038 // TODO this needs to be loaded dynamically from 039 if("db2".equals(type)) return DB2; 040 if("firebird".equals(type)) return FIREBIRD; 041 if("h2".equals(type)) return H2; 042 if("mssql".equals(type)) return MSSQL; 043 if("mysql".equals(type)) return MYSQL; 044 if("oracle".equals(type)) return ORACLE; 045 if("postgresql".equals(type) || "postgre".equals(type)) return POSTGRESQL; 046 if("sybase".equals(type)) return SYBASE; 047 return defaultValue; 048 } 049 public static class DataSourceDefintion{ 050 051 public final String className; 052 public final String connectionString; 053 public final int port; 054 055 DataSourceDefintion(String className, String connectionString, int port){ 056 this.className=className; 057 this.connectionString=connectionString; 058 this.port=port; 059 } 060 } 061}