1 22 23 24 package com.mchange.v2.c3p0.dbms; 25 26 import java.lang.reflect.*; 27 import java.sql.*; 28 import com.mchange.v2.c3p0.*; 29 import com.mchange.v2.sql.SqlUtils; 30 import oracle.sql.BLOB; 31 import oracle.sql.CLOB; 32 import oracle.jdbc.driver.OracleConnection; 33 34 38 public final class OracleUtils 39 { 40 final static Class [] CREATE_TEMP_ARGS = new Class []{Connection.class, boolean.class, int.class}; 41 42 50 public static BLOB createTemporaryBLOB(Connection c3p0ProxyCon, boolean cache, int duration) throws SQLException 51 { 52 if (c3p0ProxyCon instanceof C3P0ProxyConnection) 53 { 54 try 55 { 56 C3P0ProxyConnection castCon = (C3P0ProxyConnection) c3p0ProxyCon; 57 Method m = BLOB.class.getMethod("createTemporary", CREATE_TEMP_ARGS); 58 Object [] args = new Object [] {C3P0ProxyConnection.RAW_CONNECTION, Boolean.valueOf( cache ), new Integer ( duration )}; 59 return (BLOB) castCon.rawConnectionOperation(m, null, args); 60 } 61 catch (InvocationTargetException e) 62 { 63 if (Debug.DEBUG) 64 e.printStackTrace(); 65 throw SqlUtils.toSQLException( e.getTargetException() ); 66 } 67 catch (Exception e) 68 { 69 if (Debug.DEBUG) 70 e.printStackTrace(); 71 throw SqlUtils.toSQLException( e ); 72 } 73 } 74 else if (c3p0ProxyCon instanceof OracleConnection) 75 return BLOB.createTemporary( c3p0ProxyCon, cache, duration ); 76 else 77 throw new SQLException("Cannot create an oracle BLOB from a Connection that is neither an oracle.jdbc.driver.Connection, " + 78 "nor a C3P0ProxyConnection wrapped around an oracle.jdbc.driver.Connection."); 79 } 80 81 89 public static CLOB createTemporaryCLOB(Connection c3p0ProxyCon, boolean cache, int duration) throws SQLException 90 { 91 if (c3p0ProxyCon instanceof C3P0ProxyConnection) 92 { 93 try 94 { 95 C3P0ProxyConnection castCon = (C3P0ProxyConnection) c3p0ProxyCon; 96 Method m = CLOB.class.getMethod("createTemporary", CREATE_TEMP_ARGS); 97 Object [] args = new Object [] {C3P0ProxyConnection.RAW_CONNECTION, Boolean.valueOf( cache ), new Integer ( duration )}; 98 return (CLOB) castCon.rawConnectionOperation(m, null, args); 99 } 100 catch (InvocationTargetException e) 101 { 102 if (Debug.DEBUG) 103 e.printStackTrace(); 104 throw SqlUtils.toSQLException( e.getTargetException() ); 105 } 106 catch (Exception e) 107 { 108 if (Debug.DEBUG) 109 e.printStackTrace(); 110 throw SqlUtils.toSQLException( e ); 111 } 112 } 113 else if (c3p0ProxyCon instanceof OracleConnection) 114 return CLOB.createTemporary( c3p0ProxyCon, cache, duration ); 115 else 116 throw new SQLException("Cannot create an oracle CLOB from a Connection that is neither an oracle.jdbc.driver.Connection, " + 117 "nor a C3P0ProxyConnection wrapped around an oracle.jdbc.driver.Connection."); 118 } 119 120 private OracleUtils() 121 {} 122 } 123 | Popular Tags |