1 package com.lutris.appserver.server.sql.oracle; 2 3 import java.io.*; 4 import java.sql.*; 5 6 import com.lutris.appserver.server.sql.DBConnection; 7 import com.lutris.dods.builder.generator.query.RDBColumn; 8 import oracle.jdbc.OracleResultSet; 9 import oracle.sql.BLOB; 10 import org.enhydra.dods.DriverDependencies; 11 12 15 public class OracleDriverDependencies implements DriverDependencies { 16 17 public boolean isBlobAccessSpecial() { 18 return true; 19 } 20 21 public void insertBlob(DBConnection conn, byte[] cont, RDBColumn primary, RDBColumn column, String handle) throws SQLException { 22 if (null == cont) return; 23 PreparedStatement qb = null; 24 PreparedStatement pp = null; 25 ResultSet rs = null; 26 BLOB blob = null; 27 InputStream in = null; 28 OutputStream out = null; 29 try { 30 qb = conn.getConnection() 31 .prepareStatement("select " 32 + column.getColumnName() 33 +" from " 34 + column.getTableName() 35 + " where " 36 + primary.getColumnName() 37 + " = " 38 + handle 39 + " FOR UPDATE"); 40 rs = qb.executeQuery(); 41 rs.next(); 42 blob = ((OracleResultSet)rs).getBLOB(1); 43 44 in = new BufferedInputStream(new ByteArrayInputStream(cont)); 45 out = blob.getBinaryOutputStream(); 46 int chunk = blob.getChunkSize(); 47 byte[] buffer = new byte[chunk]; 48 int length = -1; 49 50 while ((length = in.read(buffer)) != -1) { 51 out.write ( buffer, 0, length ); 52 } 53 if (blob.length() != cont.length) 54 out.flush(); 55 } catch (IOException e) { 56 throw new SQLException("tweak failure",e.getMessage()); 57 } finally { 58 try { 59 if (out != null) out.close(); 60 if (in != null) in.close(); 61 if (rs != null) rs.close(); 62 if (qb != null) qb.close(); 63 if (pp != null) pp.close(); 64 } catch (Exception e2) {} 65 } 66 } 67 68 public byte[] readBlob(ResultSet rs, String colName) throws SQLException { 69 BLOB blob = ((OracleResultSet)rs).getBLOB(colName); 70 if (null == blob) return null; 71 return blob.getBytes(1L, (int)blob.length()); 72 } 73 } 74 | Popular Tags |