1 9 package com.ziclix.python.sql.pipe.db; 10 11 import com.ziclix.python.sql.DataHandler; 12 import com.ziclix.python.sql.PyConnection; 13 import com.ziclix.python.sql.PyCursor; 14 import com.ziclix.python.sql.zxJDBC; 15 import org.python.core.Py; 16 17 import java.lang.reflect.Constructor ; 18 19 25 public abstract class BaseDB { 26 27 30 protected PyCursor cursor; 31 32 35 protected Class dataHandler; 36 37 40 protected String tableName; 41 42 45 protected PyConnection connection; 46 47 50 public BaseDB(PyConnection connection, Class dataHandler, String tableName) { 51 52 this.tableName = tableName; 53 this.dataHandler = dataHandler; 54 this.connection = connection; 55 this.cursor = this.cursor(); 56 } 57 58 65 protected PyCursor cursor() { 66 67 PyCursor cursor = this.connection.cursor(true); 68 DataHandler origDataHandler = cursor.getDataHandler(), newDataHandler = null; 69 70 if ((origDataHandler != null) && (this.dataHandler != null)) { 71 Constructor cons = null; 72 73 try { 74 Class [] args = new Class [1]; 75 76 args[0] = DataHandler.class; 77 cons = this.dataHandler.getConstructor(args); 78 } catch (Exception e) { 79 return cursor; 80 } 81 82 if (cons == null) { 83 String msg = zxJDBC.getString("invalidCons", new Object []{this.dataHandler.getName()}); 84 85 throw zxJDBC.makeException(msg); 86 } 87 88 try { 89 Object [] args = new Object [1]; 90 91 args[0] = origDataHandler; 92 newDataHandler = (DataHandler) cons.newInstance(args); 93 } catch (Exception e) { 94 return cursor; 95 } 96 97 if (newDataHandler != null) { 98 cursor.__setattr__("datahandler", Py.java2py(newDataHandler)); 99 } 100 } 101 102 return cursor; 103 } 104 } 105 | Popular Tags |