SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate) .withSchemaName(schema) .withCatalogName(package) .withProcedureName(procedure)(); ... jdbcCall.addDeclaredParameter(new SqlParameter(paramName, OracleTypes.NUMBER)); ... jdbcCall.execute(callParams);
@Test public void testNoSuchStoredProcedure() throws Exception { final String NO_SUCH_PROC = "x"; SQLException sqlException = new SQLException("Syntax error or access violation exception", "42000"); given(databaseMetaData.getDatabaseProductName()).willReturn("MyDB"); given(databaseMetaData.getDatabaseProductName()).willReturn("MyDB"); given(databaseMetaData.getUserName()).willReturn("me"); given(databaseMetaData.storesLowerCaseIdentifiers()).willReturn(true); given(callableStatement.execute()).willThrow(sqlException); given(connection.prepareCall("{call " + NO_SUCH_PROC + "()}")).willReturn(callableStatement); SimpleJdbcCall sproc = new SimpleJdbcCall(dataSource).withProcedureName(NO_SUCH_PROC); thrown.expect(BadSqlGrammarException.class); thrown.expect(exceptionCause(sameInstance(sqlException))); try { sproc.execute(); } finally { verify(callableStatement).close(); verify(connection, atLeastOnce()).close(); } }
public void execute() { for (Object[] args:argsList) { String message = "execute update for table : " + table.name + " - args : "; for (Object arg:args) { message += "[" + arg + "]"; } logger.info(message); try { jdbcCall.execute(args); } catch (Exception e) { logger.error(message + "failed : " + e.getClass().getSimpleName() + " - " + e.getMessage()); } } } }
@Override public void callProcedure(String procedureName, Map<String, Object> inParameters) { jdbcCall = jdbcCall.withProcedureName(procedureName); logger.info("-- SQL参数:[{}]", inParameters); jdbcCall.execute(inParameters); }
private <T> Map<String, Object> executeImpl(String procedureName, MapSqlParameterSource paramsSource, CallCreator callCreator, RowMapper<T> mapper) { SimpleJdbcCall call = getCall(procedureName, callCreator, mapper); return call.execute(paramsSource); }
@Override public void callProcedure(String procedureName) { jdbcCall = jdbcCall.withProcedureName(procedureName); jdbcCall.execute(); }
@Override public Map<String, Object> callProcedureQueryOut(String procedureName, Map<String, Object> inParameters) { jdbcCall = jdbcCall.withProcedureName(procedureName); logger.info("-- SQL参数:[{}]", inParameters); return jdbcCall.execute(inParameters); }
SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate) .withSchemaName(schema) .withCatalogName(package) .withProcedureName(procedure)(); ... jdbcCall.addDeclaredParameter(new SqlParameter(paramName, OracleTypes.NUMBER)); ... jdbcCall.execute(callParams);
@Override public List callProcedureQueryListBeans(String procedureName, Map<String, Object> inParameters, Class<?> outBeansType) { jdbcCall = jdbcCall.withProcedureName(procedureName); if (outBeansType != null) { jdbcCall = jdbcCall.returningResultSet("list_beans", generateRowMapper(outBeansType)); } List list = (List) jdbcCall.execute(inParameters).get("list_beans"); logger.info("-- SQL参数:[{}]", inParameters); logger.info("-- 响应条目:[{}]", list.size()); return list; }
/*** * CheckDBConnection calls a simple "select 1" SP to verify DB is up & running. * * @return True if DB is up & running. */ public boolean checkDBConnection() { return new SimpleJdbcCall(jdbcTemplate).withProcedureName("CheckDBConnection").execute() != null; }
SimpleJdbcCall call = Util.getSimpleJdbcCallInstance(); call.setProcedureName("PROCED_CONDOMINIAL"); call.declareParameters( new SqlParameter("CONDOMINIO", Types.VARCHAR), new SqlParameter("BLOCO", Types.VARCHAR),, new SqlOutParameter("P_NUMERO", Types.NUMERIC), new SqlOutParameter("P_LOG", Types.VARCHAR)); Map<String, Object> parametros = new HashMap<String, Object>(); parametros.put("CONDOMINIO_IC", descricaoCondominio); parametros.put("BLOCO_IC", imovelCondominial.getBloco()); Map<String, Object> out = call.execute(parametros); BigDecimal chave = (BigDecimal) out.get("P_NUMERO"); imovelCondominial.setId(chave.longValue());
@Override public String getEntityNameByIdAndType(Guid objectId, VdcObjectType vdcObjectType) { MapSqlParameterSource parameterSource = sqlParameterSourceProvider.get() .addValue("entity_id", objectId) .addValue("object_type", vdcObjectType.getValue()); Map<String, Object> dbResults = new SimpleJdbcCall(jdbcTemplate) .withFunctionName("fn_get_entity_name") .execute(parameterSource); String resultKey = dbEngineDialect.getFunctionReturnKey(); return dbResults.get(resultKey) != null ? dbResults.get(resultKey).toString() : null; }
@Override public void updateLastAdminCheckStatus(Guid... userIds) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource().addValue("userIds", StringUtils.join(userIds, ",")); new SimpleJdbcCall(getJdbcTemplate()).withProcedureName("UpdateLastAdminCheckStatus").execute(parameterSource); }
SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(dataSource); simpleJdbcCall.withCatalogName("dbo"); simpleJdbcCall.withProcedureName("procedureA "); simpleJdbcCall.setAccessCallParameterMetaData(false); simpleJdbcCall.declareParameters(new new SqlOutParameter("a",Types.NUMERIC)); simpleJdbcCall.execute();
@Override public boolean isQuotaInUse(Quota quota){ MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("quota_id", quota.getId()); Map<String, Object> dbResults = new SimpleJdbcCall(getJdbcTemplate()).withFunctionName("IsQuotaInUse").execute( parameterSource); String resultKey = getDialect().getFunctionReturnKey(); return dbResults.get(resultKey) != null && (Boolean) dbResults.get(resultKey); }
@Override public void saveOrUpdate(DbUser user) { setIdIfNeeded(user); new SimpleJdbcCall(getJdbcTemplate()).withProcedureName("InsertOrUpdateUser") .execute(new DbUserMapSqlParameterSource(user)); }
@Override public void save(DbUser user) { setIdIfNeeded(user); new SimpleJdbcCall(getJdbcTemplate()).withProcedureName("InsertUser") .execute(new DbUserMapSqlParameterSource(user)); }
@Override public boolean isMemBalloonEnabled(Guid vmId) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("vm_id", vmId); Map<String, Object> dbResults = new SimpleJdbcCall(getJdbcTemplate()).withFunctionName("isMemBalloonEnabled").execute( parameterSource); String resultKey = getDialect().getFunctionReturnKey(); return (Boolean) dbResults.getOrDefault(resultKey, false); }
@Override public int getTimeToWaitForNextPmOp(String vdsName, String event) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("vds_name", vdsName) .addValue("event", event) .addValue("wait_for_sec", Config.getValue(ConfigValues.FenceQuietTimeBetweenOperationsInSec)); Map<String, Object> dbResults = new SimpleJdbcCall(getJdbcTemplate()).withFunctionName("get_seconds_to_wait_before_pm_operation") .execute( parameterSource); String resultKey = dbEngineDialect.getFunctionReturnKey(); return (Integer) dbResults.getOrDefault(resultKey, 0); }
@Override public void save(VdsStatic vds) { Guid id = vds.getId(); if (Guid.isNullOrEmpty(id)) { id = Guid.newGuid(); vds.setId(id); } new SimpleJdbcCall(getJdbcTemplate()).withProcedureName("InsertVdsStatic") .execute(getInsertOrUpdateParams(vds)); }