1 19 20 package org.apache.cayenne.dba.oracle; 21 22 import java.sql.CallableStatement ; 23 import java.sql.ResultSet ; 24 import java.sql.SQLException ; 25 import java.util.Collections ; 26 import java.util.HashMap ; 27 import java.util.List ; 28 import java.util.Map ; 29 30 import org.apache.cayenne.access.OperationObserver; 31 import org.apache.cayenne.access.QueryLogger; 32 import org.apache.cayenne.access.jdbc.ColumnDescriptor; 33 import org.apache.cayenne.access.jdbc.ProcedureAction; 34 import org.apache.cayenne.access.jdbc.RowDescriptor; 35 import org.apache.cayenne.access.types.ExtendedType; 36 import org.apache.cayenne.dba.DbAdapter; 37 import org.apache.cayenne.map.EntityResolver; 38 import org.apache.cayenne.map.ProcedureParameter; 39 import org.apache.cayenne.query.ProcedureQuery; 40 41 47 class OracleProcedureAction extends ProcedureAction { 48 49 OracleProcedureAction(ProcedureQuery query, DbAdapter adapter, 50 EntityResolver entityResolver) { 51 super(query, adapter, entityResolver); 52 } 53 54 57 protected void readProcedureOutParameters( 58 CallableStatement statement, 59 OperationObserver delegate) throws SQLException , Exception { 60 61 long t1 = System.currentTimeMillis(); 62 63 Map result = null; 65 List parameters = getProcedure().getCallParameters(); 66 for (int i = 0; i < parameters.size(); i++) { 67 ProcedureParameter parameter = (ProcedureParameter) parameters.get(i); 68 69 if (!parameter.isOutParam()) { 70 continue; 71 } 72 73 if (parameter.getType() == OracleAdapter.getOracleCursorType()) { 75 ResultSet rs = (ResultSet ) statement.getObject(i + 1); 76 77 try { 78 RowDescriptor rsDescriptor = describeResultSet( 79 rs, 80 processedResultSets++); 81 readResultSet(rs, rsDescriptor, query, delegate); 82 } 83 finally { 84 try { 85 rs.close(); 86 } 87 catch (SQLException ex) { 88 } 89 } 90 } 91 else { 93 if (result == null) { 94 result = new HashMap (); 95 } 96 97 ColumnDescriptor descriptor = new ColumnDescriptor(parameter); 98 ExtendedType type = getAdapter().getExtendedTypes().getRegisteredType( 99 descriptor.getJavaClass()); 100 Object val = type.materializeObject(statement, i + 1, descriptor 101 .getJdbcType()); 102 103 result.put(descriptor.getLabel(), val); 104 } 105 } 106 107 if (result != null && !result.isEmpty()) { 108 QueryLogger.logSelectCount(1, System.currentTimeMillis() - t1); 110 delegate.nextDataRows(query, Collections.singletonList(result)); 111 } 112 } 113 } 114 | Popular Tags |