001    package railo.runtime.db;
002    
003    import railo.commons.lang.StringUtil;
004    
005    public class DBUtil {
006            
007            private static DataSourceDefintion DB2=new DataSourceDefintion("com.ddtek.jdbc.db2.DB2Driver","jdbc:datadirect:db2://{host}:{port};DatabaseName={database}",50000);
008            private static DataSourceDefintion FIREBIRD=new DataSourceDefintion("org.firebirdsql.jdbc.FBDriver","jdbc:firebirdsql://{host}:{port}/{path}{database}",3050);
009            private static DataSourceDefintion H2=new DataSourceDefintion("org.h2.Driver","jdbc:h2:{path}{database};MODE={mode}",-1);
010            private static DataSourceDefintion MSSQL=new DataSourceDefintion("net.sourceforge.jtds.jdbc.Driver","jdbc:jtds:sqlserver://{host}:{port}/{database}",1433);
011            private static DataSourceDefintion MYSQL=new DataSourceDefintion("org.gjt.mm.mysql.Driver","jdbc:mysql://{host}:{port}/{database}",3306);
012            private static DataSourceDefintion ORACLE=new DataSourceDefintion("oracle.jdbc.driver.OracleDriver","jdbc:oracle:{drivertype}:@{host}:{port}:{database}",1521);
013            private static DataSourceDefintion POSTGRESQL=new DataSourceDefintion("org.postgresql.Driver","jdbc:postgresql://{host}:{port}/{database}",5432);
014            private static DataSourceDefintion SYBASE=new DataSourceDefintion("net.sourceforge.jtds.jdbc.Driver","jdbc:jtds:sybase://{host}:{port}/{database}",7100);
015            
016            
017            public static DataSourceDefintion getDataSourceDefintionForType(String type, DataSourceDefintion defaultValue){
018                    if(StringUtil.isEmpty(type)) return defaultValue;
019                    type=type.trim().toLowerCase();
020                    // TODO this needs to be loaded dynamically from 
021                    if("db2".equals(type)) return DB2;
022                    if("firebird".equals(type)) return FIREBIRD;
023                    if("h2".equals(type)) return H2;
024                    if("mssql".equals(type)) return MSSQL;
025                    if("mysql".equals(type)) return MYSQL;
026                    if("oracle".equals(type)) return ORACLE;
027                    if("postgresql".equals(type) || "postgre".equals(type)) return POSTGRESQL;
028                    if("sybase".equals(type)) return SYBASE;
029                    return defaultValue;
030            }
031            public static class DataSourceDefintion{
032                    
033                    public final String className;
034                    public final String connectionString;
035                    public final int port;
036                    
037                    DataSourceDefintion(String className, String connectionString, int port){
038                            this.className=className;
039                            this.connectionString=connectionString;
040                            this.port=port;
041                    }
042            }
043    }