1 56 package org.objectstyle.cayenne.dba.oracle; 57 58 import java.sql.CallableStatement ; 59 import java.sql.ResultSet ; 60 import java.sql.SQLException ; 61 import java.util.Collections ; 62 import java.util.HashMap ; 63 import java.util.List ; 64 import java.util.Map ; 65 66 import org.objectstyle.cayenne.access.OperationObserver; 67 import org.objectstyle.cayenne.access.QueryLogger; 68 import org.objectstyle.cayenne.access.jdbc.ColumnDescriptor; 69 import org.objectstyle.cayenne.access.jdbc.ProcedureAction; 70 import org.objectstyle.cayenne.access.jdbc.RowDescriptor; 71 import org.objectstyle.cayenne.access.types.ExtendedType; 72 import org.objectstyle.cayenne.dba.DbAdapter; 73 import org.objectstyle.cayenne.map.EntityResolver; 74 import org.objectstyle.cayenne.map.ProcedureParameter; 75 import org.objectstyle.cayenne.query.ProcedureQuery; 76 77 83 class OracleProcedureAction extends ProcedureAction { 84 85 OracleProcedureAction(ProcedureQuery query, DbAdapter adapter, 86 EntityResolver entityResolver) { 87 super(query, adapter, entityResolver); 88 } 89 90 93 protected void readProcedureOutParameters( 94 CallableStatement statement, 95 OperationObserver delegate) throws SQLException , Exception { 96 97 long t1 = System.currentTimeMillis(); 98 99 Map result = null; 101 List parameters = getProcedure().getCallParameters(); 102 for (int i = 0; i < parameters.size(); i++) { 103 ProcedureParameter parameter = (ProcedureParameter) parameters.get(i); 104 105 if (!parameter.isOutParam()) { 106 continue; 107 } 108 109 if (parameter.getType() == OracleAdapter.getOracleCursorType()) { 111 ResultSet rs = (ResultSet ) statement.getObject(i + 1); 112 113 try { 114 RowDescriptor rsDescriptor = describeResultSet(rs, processedResultSets++); 115 readResultSet(rs, rsDescriptor, query, delegate); 116 } 117 finally { 118 try { 119 rs.close(); 120 } 121 catch (SQLException ex) { 122 } 123 } 124 } 125 else { 127 if (result == null) { 128 result = new HashMap (); 129 } 130 131 ColumnDescriptor descriptor = new ColumnDescriptor(parameter); 132 ExtendedType type = getAdapter() 133 .getExtendedTypes() 134 .getRegisteredType(descriptor.getJavaClass()); 135 Object val = type.materializeObject(statement, i + 1, descriptor 136 .getJdbcType()); 137 138 result.put(descriptor.getLabel(), val); 139 } 140 } 141 142 if (result != null && !result.isEmpty()) { 143 QueryLogger.logSelectCount(query.getLoggingLevel(), 1, System 145 .currentTimeMillis() 146 - t1); 147 delegate.nextDataRows(query, Collections.singletonList(result)); 148 } 149 } 150 } | Popular Tags |