private OAuth2AccessToken readAccessTokenFromSecureStore(String tokenKey) { if (tokenKey.length() > TOKEN_KEY_MAX_LENGTH) { throw new IllegalArgumentException(Messages.TOKEN_KEY_FORMAT_NOT_VALID); } SqlParameter storeNameParam = new SqlParameter(Types.VARCHAR); SqlParameter forXsApplicationUserParam = new SqlParameter(Types.BOOLEAN); SqlParameter keyParam = new SqlParameter(Types.VARCHAR); SqlOutParameter valueParam = new SqlOutParameter("VALUE", Types.VARBINARY); List<SqlParameter> paramList = Arrays.asList(storeNameParam, forXsApplicationUserParam, keyParam, valueParam); Map<String, Object> result = null; try { result = callRetrieve(tokenKey, paramList, PROCEDURE_SECURESTORE_RETRIEVE); } catch (BadSqlGrammarException e) { throwIfShouldNotIgnore(e, RETRIEVE_PROCEDURE_NAME); result = callRetrieve(tokenKey, paramList, PROCEDURE_SECURESTORE_RETRIEVE_LEGACY); } byte[] tokenBytes = (byte[]) result.get("VALUE"); if (tokenBytes == null) { throw new IllegalArgumentException(Messages.TOKEN_NOT_FOUND_IN_SECURE_STORE); } byte[] decompressedBytes = CompressUtil.decompress(tokenBytes); OAuth2AccessToken accessToken = TokenUtil.createToken(new String(decompressedBytes, StandardCharsets.UTF_8)); return accessToken; }
/** * 调用存储过程的方法:存储过程实现具体看PKG_SYS.sql * <B>方法名称:</B>清空文件缓存方法<BR> * <B>概要说明:</B>清空文件缓存方法<BR> * @return List<String> 主键KEY集合 */ public List<String> clearFileKeys() { SimpleJdbcCall call = new SimpleJdbcCall(this.getJdbcTemplate()). withCatalogName("PKG_SYS").withProcedureName("CLEAR_FILES"). declareParameters(new SqlOutParameter("P_RET_REFCUR", OracleTypes.CURSOR)); Map<String, Object> m = call.execute(); if(m.values().size() > 0){ String temp = m.values().toArray()[0].toString().replace("[", "").replace("]", ""); String[] keys = temp.split(","); List<String> ret = new ArrayList<String>(); for(String key : keys){ String temp1 = key.replace("{", "").replace("}", ""); if(!StringUtils.isBlank(temp1)){ ret.add(temp1.split("\\=")[1]); } } return ret; } return Collections.emptyList(); }
public TemplateStoredProcedure(JdbcTemplate jdbcTemplate, Template template) { this.template = template; setDataSource(jdbcTemplate.getDataSource()); setSql(template.getProcedureName()); for (Object parameter : template.getParameterList()) { if (parameter instanceof InputParameter) { InputParameter inputParameter = (InputParameter) parameter; declareParameter(new SqlParameter(inputParameter.getName(), inputParameter.getSqlType())); inputParameterList.add(inputParameter); } else if (parameter instanceof OutParameter) { OutParameter outParameter = (OutParameter) parameter; declareParameter(new SqlOutParameter(outParameter.getOutValueMapKey(), outParameter.getSqlType())); setFunction(false); } } LOG.debug("Compiling stored procedure: {}", template.getProcedureName()); compile(); }
@Test public void testAddInvoiceProcWithoutMetaDataUsingMapParamSource() throws Exception { initializeAddInvoiceWithoutMetaData(false); SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withProcedureName("add_invoice"); adder.declareParameters( new SqlParameter("amount", Types.INTEGER), new SqlParameter("custid", Types.INTEGER), new SqlOutParameter("newid", Types.INTEGER)); Number newId = adder.executeObject(Number.class, new MapSqlParameterSource(). addValue("amount", 1103). addValue("custid", 3)); assertEquals(4, newId.intValue()); verifyAddInvoiceWithoutMetaData(false); verify(connection, atLeastOnce()).close(); }
@Override public String [] get() throws Exception { SimpleJdbcCall call = new SimpleJdbcCall(this.getJdbcTemplate()); call.withFunctionName("usecase01_get"); call.withSchemaName("public"); call.withoutProcedureColumnMetaDataAccess(); call.declareParameters(new SqlOutParameter("testcolumn", java.sql.Types.ARRAY)); MapSqlParameterSource map = new MapSqlParameterSource(); Map<String, Object> result = call.execute(map); Jdbc4Array jdbc4Array = (Jdbc4Array)result.get("testcolumn"); try { Object o = jdbc4Array.getArray(); Logger.getLogger(PostgresArrayImpl.class.getName()).log(Level.SEVERE, null, o); return (String [])o; } catch (SQLException ex) { Logger.getLogger(PostgresArrayImpl.class.getName()).log(Level.SEVERE, null, ex); throw ex; } }
@Override public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) { if (meta.getSqlType() == Types.OTHER && REF_CURSOR_NAME.equals(meta.getTypeName())) { return new SqlOutParameter(parameterName, getRefCursorSqlType(), new ColumnMapRowMapper()); } else { return super.createDefaultOutParameter(parameterName, meta); } }
@Override public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) { if (meta.getSqlType() == Types.OTHER && "refcursor".equals(meta.getTypeName())) { return new SqlOutParameter(parameterName, getRefCursorSqlType(), new ColumnMapRowMapper()); } else { return super.createDefaultOutParameter(parameterName, meta); } }
/** * 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 */ public SqlParameter createReturnResultSetParameter(String parameterName, RowMapper<?> rowMapper) { if (this.metaDataProvider.isReturnResultSetSupported()) { return new SqlReturnResultSet(parameterName, rowMapper); } else { if (this.metaDataProvider.isRefCursorSupported()) { return new SqlOutParameter(parameterName, this.metaDataProvider.getRefCursorSqlType(), rowMapper); } else { throw new InvalidDataAccessApiUsageException("Return of a ResultSet from a stored procedure is not supported."); } } }
public StoredProcedureConfiguredViaJdbcTemplate(JdbcTemplate t) { setJdbcTemplate(t); setSql(SQL); declareParameter(new SqlParameter("intIn", Types.INTEGER)); declareParameter(new SqlOutParameter("intOut", Types.INTEGER)); compile(); }
public AddInvoice(DataSource ds) { setDataSource(ds); setSql(SQL); declareParameter(new SqlParameter("amount", Types.INTEGER)); declareParameter(new SqlParameter("custid", Types.INTEGER)); declareParameter(new SqlOutParameter("newid", Types.INTEGER)); compile(); }
public ParameterMapperStoredProcedure(DataSource ds) { setDataSource(ds); setSql(SQL); declareParameter(new SqlParameter("in", Types.VARCHAR)); declareParameter(new SqlOutParameter("out", Types.VARCHAR)); compile(); }
public SqlTypeValueStoredProcedure(DataSource ds) { setDataSource(ds); setSql(SQL); declareParameter(new SqlParameter("in", Types.ARRAY, "NUMBERS")); declareParameter(new SqlOutParameter("out", Types.VARCHAR)); compile(); }
@Test public void validateInOutParameter() { operation.setDataSource(new DriverManagerDataSource()); operation.setSql("DUMMY_PROC"); operation.declareParameter(new SqlOutParameter("DUMMY_OUT_PARAM", Types.VARCHAR)); operation.declareParameter(new SqlInOutParameter("DUMMY_IN_OUT_PARAM", Types.VARCHAR)); operation.validateParameters(new Object[] {"DUMMY_VALUE1", "DUMMY_VALUE2"}); }
@Test public void testAddInvoiceProcWithoutMetaDataUsingArrayParams() throws Exception { initializeAddInvoiceWithoutMetaData(false); SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withProcedureName("add_invoice"); adder.declareParameters( new SqlParameter("amount", Types.INTEGER), new SqlParameter("custid", Types.INTEGER), new SqlOutParameter("newid", Types.INTEGER)); Number newId = adder.executeObject(Number.class, 1103, 3); assertEquals(4, newId.intValue()); verifyAddInvoiceWithoutMetaData(false); verify(connection, atLeastOnce()).close(); }
@Test public void testAddInvoiceFuncWithoutMetaDataUsingMapParamSource() throws Exception { initializeAddInvoiceWithoutMetaData(true); SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withFunctionName("add_invoice"); adder.declareParameters( new SqlOutParameter("return", Types.INTEGER), new SqlParameter("amount", Types.INTEGER), new SqlParameter("custid", Types.INTEGER)); Number newId = adder.executeFunction(Number.class, new MapSqlParameterSource() .addValue("amount", 1103) .addValue("custid", 3)); assertEquals(4, newId.intValue()); verifyAddInvoiceWithoutMetaData(true); verify(connection, atLeastOnce()).close(); }
@Test public void testAddInvoiceFuncWithoutMetaDataUsingArrayParams() throws Exception { initializeAddInvoiceWithoutMetaData(true); SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withFunctionName("add_invoice"); adder.declareParameters( new SqlOutParameter("return", Types.INTEGER), new SqlParameter("amount", Types.INTEGER), new SqlParameter("custid", Types.INTEGER)); Number newId = adder.executeFunction(Number.class, 1103, 3); assertEquals(4, newId.intValue()); verifyAddInvoiceWithoutMetaData(true); verify(connection, atLeastOnce()).close(); }
@Test public void testMatchParameterValuesAndSqlInOutParameters() throws Exception { final String TABLE = "customers"; final String USER = "me"; given(databaseMetaData.getDatabaseProductName()).willReturn("MyDB"); given(databaseMetaData.getUserName()).willReturn(USER); given(databaseMetaData.storesLowerCaseIdentifiers()).willReturn(true); List<SqlParameter> parameters = new ArrayList<SqlParameter>(); parameters.add(new SqlParameter("id", Types.NUMERIC)); parameters.add(new SqlInOutParameter("name", Types.NUMERIC)); parameters.add(new SqlOutParameter("customer_no", Types.NUMERIC)); MapSqlParameterSource parameterSource = new MapSqlParameterSource(); parameterSource.addValue("id", 1); parameterSource.addValue("name", "Sven"); parameterSource.addValue("customer_no", "12345XYZ"); context.setProcedureName(TABLE); context.initializeMetaData(dataSource); context.processParameters(parameters); Map<String, Object> inParameters = context.matchInParameterValuesWithCallParameters(parameterSource); assertEquals("Wrong number of matched in parameter values", 2, inParameters.size()); assertTrue("in parameter value missing", inParameters.containsKey("id")); assertTrue("in out parameter value missing", inParameters.containsKey("name")); assertTrue("out parameter value matched", !inParameters.containsKey("customer_no")); List<String> names = context.getOutParameterNames(); assertEquals("Wrong number of out parameters", 2, names.size()); List<SqlParameter> callParameters = context.getCallParameters(); assertEquals("Wrong number of call parameters", 3, callParameters.size()); }
/** * 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 */ public SqlParameter createReturnResultSetParameter(String parameterName, RowMapper rowMapper) { if (this.metaDataProvider.isReturnResultSetSupported()) { return new SqlReturnResultSet(parameterName, rowMapper); } else { if (this.metaDataProvider.isRefCursorSupported()) { return new SqlOutParameter(parameterName, this.metaDataProvider.getRefCursorSqlType(), rowMapper); } else { throw new InvalidDataAccessApiUsageException("Return of a ResultSet from a stored procedure is not supported."); } } }
public AddInvoiceUsingObjectArray(DataSource ds) { setDataSource(ds); setSql(SQL); declareParameter(new SqlParameter("amount", Types.INTEGER)); declareParameter(new SqlParameter("custid", Types.INTEGER)); declareParameter(new SqlOutParameter("newid", Types.INTEGER)); compile(); }
public void testValidateInOutParameter() { TestRdbmsOperation operation = new TestRdbmsOperation(); operation.setDataSource(new DriverManagerDataSource()); operation.setSql("DUMMY_PROC"); operation.declareParameter(new SqlOutParameter("DUMMY_OUT_PARAM", Types.VARCHAR)); operation.declareParameter(new SqlInOutParameter("DUMMY_IN_OUT_PARAM", Types.VARCHAR)); operation.validateParameters(new Object[] {"DUMMY_VALUE1", "DUMMY_VALUE2"}); }
@Override public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) { return new SqlOutParameter(parameterName, meta.getSqlType()); }
public NumericWithScaleStoredProcedure(DataSource ds) { setDataSource(ds); setSql(SQL); declareParameter(new SqlOutParameter("out", Types.DECIMAL, 4)); compile(); }
public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) { return new SqlOutParameter(parameterName, meta.getSqlType()); }