1 package com.daffodilwoods.daffodildb.odbc; 2 3 import java.rmi.*; 4 import java.util.*; 5 6 import com.daffodilwoods.daffodildb.server.serversystem.*; 7 import com.daffodilwoods.database.resource.*; 8 import com.daffodilwoods.rmi.*; 9 import com.daffodilwoods.rmi.interfaces.*; 10 import in.co.daffodil.db.jdbc.*; 11 import java.lang.reflect.Constructor ; 12 public class OdbcConnection extends OdbcMetaData { 13 14 public static _Server ss ; 15 TreeMap serverMap; 16 17 public OdbcConnection(String daffodilDbHome) { 18 if(!daffodilDbHome.equalsIgnoreCase("")) 19 System.setProperty(_ServerSystem.DAFFODILDB_HOME,daffodilDbHome); 20 } 21 22 public OdbcConnection() { 23 } 24 25 public Object sqlConnect(String server,int port,String databasename,String username,String password,boolean create) throws Exception { 26 if(serverMap == null) 27 serverMap = new TreeMap(String.CASE_INSENSITIVE_ORDER); 28 String rmiString = "rmi://" + server+":"+port+"/DaffodilDB"; 29 _Server serverSystem = getServerSystemRmi(rmiString); 30 Properties prop = new Properties(); 31 prop.setProperty("user", username); 32 prop.setProperty("password", password); 33 prop.setProperty("create", create ? "true" : "false"); 34 _Connection con = serverSystem.getConnection(databasename, prop); 35 con.setAutoCommit(true); 36 con.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED); 37 return con; 38 } 39 40 41 public Object sqlConnect(String databsename,String username,String password,boolean create) throws Exception { 42 getServerSystem(); 43 Properties prop = new Properties(); 44 prop.setProperty("user", username); 45 prop.setProperty("password", password); 46 prop.setProperty("create", create ? "true" : "false"); 47 _Connection con = ss.getConnection(databsename, prop); 48 con.setAutoCommit(true); 49 con.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED); 50 return con; 51 } 52 53 public Object getPreparedStatement(Object conObject,String query) throws Exception { 54 _Connection con = (_Connection)conObject; 55 if(con == null) 56 throw new Exception (" connection disconnected "); 57 return con.getPreparedStatement(query,0) ; 58 } 59 60 private _Server getServerSystem() throws Exception { 61 if (ss == null) 62 ss = new ServerSystem(); 63 return ss; 64 } 65 private _Server getServerSystemRmi(String rmiUrl) throws Exception { 66 _Server rmiServer = (_Server)serverMap.get(rmiUrl); 67 if(rmiServer == null){ 68 Object rmiServerInterface = Naming.lookup(rmiUrl); 69 Constructor rmiServerConstructor = Class.forName("com.daffodilwoods.rmi.RmiServer").getConstructor(new Class []{_RmiServer.class}); 70 rmiServer = (_Server) rmiServerConstructor.newInstance(new Object []{rmiServerInterface}); 71 serverMap.put(rmiUrl,rmiServer); 72 } 73 return rmiServer; 74 } 75 76 public void close(Object obj) throws Exception { 77 _Connection con = (_Connection)obj; 78 con.close(); 79 } 80 81 public void commit(Object obj) throws Exception { 82 _Connection con = (_Connection)obj; 83 con.commit(); 84 } 85 86 public void rollback(Object obj) throws Exception { 87 _Connection con = (_Connection)obj; 88 con.rollback(); 89 } 90 91 public void setTransactionIsolation(Object obj,int int0) throws DException{ 92 _Connection con = (_Connection)obj; 93 con.setTransactionIsolation(int0); 94 } 95 public void setAutoCommit(Object obj,boolean boolean0) throws DException{ 96 _Connection con = (_Connection)obj; 97 con.setAutoCommit(boolean0); 98 } 99 public void setCurrentCatalog(Object obj,String string) throws DException{ 100 _Connection con = (_Connection)obj; 101 con.setCurrentCatalog(string); 102 } 103 public void setReadOnly(Object obj) throws DException{ 104 107 } 108 public String productVersion(String forFutureUse) throws Exception { 109 return new StringBuffer ("0").append(DatabaseProperties.databaseMajorVersion).append(".0").append(DatabaseProperties.databaseMinorVersion).append(".0000").toString(); 110 } 111 112 public String parse(String query) throws Exception { 113 return EscapeParser.parse(query); 114 } 115 123 public static String getErrorMessage(Object obj){ 124 Throwable th = (Throwable )obj; 125 return th.getMessage(); 126 } 127 128 public static String getErrorCode(Object obj){ 129 Throwable th = (Throwable )obj; 130 if(th instanceof DException){ 131 return ((DException)th).getSQLCode(); 132 } 133 return "HY000"; 134 } 135 } 136 | Popular Tags |