1 9 package com.ziclix.python.sql.handler; 10 11 import com.ziclix.python.sql.DataHandler; 12 import org.python.core.Py; 13 import org.python.core.PyFile; 14 import org.python.core.PyObject; 15 16 import java.math.BigDecimal ; 17 import java.sql.PreparedStatement ; 18 import java.sql.ResultSet ; 19 import java.sql.SQLException ; 20 import java.sql.Types ; 21 22 29 public class PostgresqlDataHandler extends RowIdHandler { 30 31 36 public PostgresqlDataHandler(DataHandler datahandler) { 37 super(datahandler); 38 } 39 40 protected String getRowIdMethodName() { 41 return "getLastOID"; 42 } 43 44 53 public PyObject getPyObject(ResultSet set, int col, int type) throws SQLException { 54 55 PyObject obj = Py.None; 56 57 switch (type) { 58 59 case Types.NUMERIC: 60 case Types.DECIMAL: 61 62 BigDecimal bd = set.getBigDecimal(col, -1); 69 70 obj = (bd == null) ? Py.None : Py.newFloat(bd.doubleValue()); 71 break; 72 73 case Types.OTHER: 74 75 try { 78 obj = super.getPyObject(set, col, type); 79 } catch (SQLException e) { 80 obj = super.getPyObject(set, col, Types.VARCHAR); 81 } 82 break; 83 84 default : 85 obj = super.getPyObject(set, col, type); 86 } 87 88 return (set.wasNull() || (obj == null)) ? Py.None : obj; 89 } 90 91 100 public void setJDBCObject(PreparedStatement stmt, int index, PyObject object, int type) throws SQLException { 101 102 if (DataHandler.checkNull(stmt, index, object, type)) { 103 return; 104 } 105 106 switch (type) { 107 108 case Types.LONGVARCHAR: 109 110 String varchar; 111 if (object instanceof PyFile) { 113 varchar = ((PyFile) object).read(); 114 } else { 115 varchar = (String ) object.__tojava__(String .class); 116 } 117 118 stmt.setObject(index, varchar, type); 119 break; 120 121 default : 122 super.setJDBCObject(stmt, index, object, type); 123 } 124 } 125 } 126 | Popular Tags |