List of usage examples for org.springframework.jdbc.core SqlOutParameter SqlOutParameter
public SqlOutParameter(String name, int sqlType, RowMapper<?> rm)
From source file:org.metis.jdbc.WdsStoredProcedure.java
public WdsStoredProcedure(SqlStmnt stmt) throws Exception { super(stmt.getJdbcTemplate(), stmt.getStoredProcName()); setFunction(stmt.isFunction());//from ww w . ja v a2 s . co m myStmt = stmt; // Parameters should be declared in the same order that // they are declared in the stored procedure. The one exception // are result sets, which must be defined first!! // // Here's something I found as to why - When you make any private // static class of StoreProcedure, then in its constructor you must // declare SqlReturnResultSet before you declare SqlParameter. // Otherwise you will not be able to find return data from // StoredProcedure execution. Still not sure what this means // and why its so. // for (SqlToken sqlToken : myStmt.getSortedKeyTokens()) { if (sqlToken.isRset()) { declareParameter(new SqlReturnResultSet(sqlToken.getKey(), myStmt)); } } // now do the other parameters // iterate through tokens in proper sequence; parameters must be // declared according to the sequence in which they appear in the // statement for (SqlToken sqlToken : myStmt.getSortedKeyTokens()) { // skip result sets if (sqlToken.isRset()) { continue; } switch (sqlToken.getMode()) { case IN: declareParameter(new SqlParameter(sqlToken.getKey(), sqlToken.getJdbcType().getType())); break; case OUT: // look for CURSOR types if (sqlToken.isCursor()) { // if it is a cursor then check to see if it is Oracle or // some other DBMS and set the type accrodingly int type = (myStmt.getMetisController().isOracle()) ? ORACLE_CURSOR : Types.OTHER; declareParameter(new SqlOutParameter(sqlToken.getKey(), type, myStmt)); } else { declareParameter(new SqlOutParameter(sqlToken.getKey(), sqlToken.getJdbcType().getType())); } break; case INOUT: // note: you can't have cursors as IN params - doesn't // make sense, so don't check for them when its an INOUT declareParameter(new SqlInOutParameter(sqlToken.getKey(), sqlToken.getJdbcType().getType())); break; default: throw new Exception("WdsStoredProcedure: this invalid mode was provided: " + sqlToken.getMode()); } } // specify whether this is a function super.setFunction(myStmt.isFunction()); // compile the statement compile(); }
From source file:org.codehaus.grepo.procedure.compile.ProcedureCompilationUtils.java
/** * @param out The annotation./*from w ww. j a v a 2s.c om*/ * @param context The procedure execution context. * @return Returns the created descriptor. * @throws ConfigurationException in case of errors. */ public static ProcedureParamDescriptor createParamDescriptor(Out out, ProcedureExecutionContext context) throws ConfigurationException { SqlParameter sp = null; if (out.scale() >= 0) { sp = new SqlOutParameter(out.name(), out.sqlType(), out.scale()); } else if (StringUtils.isNotEmpty(out.typeName())) { if (isResultHandlerSpecified(out.resultHandlerId(), out.resultHandler())) { // we have a result handler specified... Object resultHandler = retrieveResultHandler(context, out.resultHandlerId(), out.resultHandler()); if (ClassUtils.isAssignableFrom(SqlReturnType.class, resultHandler.getClass())) { sp = new SqlOutParameter(out.name(), out.sqlType(), out.typeName(), (SqlReturnType) resultHandler); } else { // unsupported/invalid result handler... throw new ConfigurationException(String.format(INVALID_RESULTHANDLER_ERROR1, resultHandler.getClass(), SqlReturnType.class)); } } else { sp = new SqlOutParameter(out.name(), out.sqlType(), out.typeName()); } } else { if (isResultHandlerSpecified(out.resultHandlerId(), out.resultHandler())) { // we have a result handler specified... Object resultHandler = retrieveResultHandler(context, out.resultHandlerId(), out.resultHandler()); if (ClassUtils.isAssignableFrom(RowMapper.class, resultHandler.getClass())) { sp = new SqlOutParameter(out.name(), out.sqlType(), (RowMapper<?>) resultHandler); } else if (ClassUtils.isAssignableFrom(RowCallbackHandler.class, resultHandler.getClass())) { sp = new SqlOutParameter(out.name(), out.sqlType(), (RowCallbackHandler) resultHandler); } else if (ClassUtils.isAssignableFrom(ResultSetExtractor.class, resultHandler.getClass())) { sp = new SqlOutParameter(out.name(), out.sqlType(), (ResultSetExtractor<?>) resultHandler); } else { // unsupported/invalid result handler... throw new ConfigurationException( String.format(INVALID_RESULTHANDLER_ERROR3, resultHandler.getClass(), RowMapper.class, RowCallbackHandler.class, ResultSetExtractor.class)); } } else { sp = new SqlOutParameter(out.name(), out.sqlType()); } } return new ProcedureParamDescriptor(sp.getName(), ProcedureParamType.OUT, sp, out.index()); }
From source file:org.springframework.jdbc.core.metadata.CallMetaDataContext.java
/** * Create a ReturnResultSetParameter/SqlOutParameter depending on the support provided * by the JDBC driver used for the database in use. * @param parameterName the name of the parameter (also used as the name of the List returned in the output) * @param rowMapper a RowMapper implementation used to map the data returned in the result set * @return the appropriate SqlParameter/*from www. j a v a2 s. c om*/ */ public SqlParameter createReturnResultSetParameter(String parameterName, RowMapper<?> rowMapper) { CallMetaDataProvider provider = obtainMetaDataProvider(); if (provider.isReturnResultSetSupported()) { return new SqlReturnResultSet(parameterName, rowMapper); } else { if (provider.isRefCursorSupported()) { return new SqlOutParameter(parameterName, provider.getRefCursorSqlType(), rowMapper); } else { throw new InvalidDataAccessApiUsageException( "Return of a ResultSet from a stored procedure is not supported."); } } }