@Test public void testAddInvoiceFuncWithMetaDataUsingArrayParams() throws Exception { initializeAddInvoiceWithMetaData(true); SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withFunctionName("add_invoice"); Number newId = adder.executeFunction(Number.class, 1103, 3); assertEquals(4, newId.intValue()); verifyAddInvoiceWithMetaData(true); verify(connection, atLeastOnce()).close(); }
@Test public void testCorrectFunctionStatement() throws Exception { initializeAddInvoiceWithMetaData(true); SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withFunctionName("add_invoice"); adder.compile(); verifyStatement(adder, "{? = call ADD_INVOICE(?, ?)}"); }
@Test public void testAddInvoiceFuncWithMetaDataUsingMapParamSource() throws Exception { initializeAddInvoiceWithMetaData(true); SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withFunctionName("add_invoice"); Number newId = adder.executeFunction(Number.class, new MapSqlParameterSource() .addValue("amount", 1103) .addValue("custid", 3)); assertEquals(4, newId.intValue()); verifyAddInvoiceWithMetaData(true); verify(connection, atLeastOnce()).close(); }
@Test public void testCorrectFunctionStatementNamed() throws Exception { initializeAddInvoiceWithMetaData(true); SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withNamedBinding().withFunctionName("add_invoice"); adder.compile(); verifyStatement(adder, "{? = call ADD_INVOICE(AMOUNT => ?, CUSTID => ?)}"); }
@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 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(); }
private SimpleJdbcCall createSimpleJdbcCall(String storedProcedureName) { final SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(this.dataSource); if (this.isFunction) { simpleJdbcCall.withFunctionName(storedProcedureName); } else { simpleJdbcCall.withProcedureName(storedProcedureName); } if (this.ignoreColumnMetaData) { simpleJdbcCall.withoutProcedureColumnMetaDataAccess(); } simpleJdbcCall.declareParameters(this.sqlParameters.toArray(new SqlParameter[this.sqlParameters.size()])); if (!this.returningResultSetRowMappers.isEmpty()) { for (Entry<String, RowMapper<?>> mapEntry : this.returningResultSetRowMappers.entrySet()) { simpleJdbcCall.returningResultSet(mapEntry.getKey(), mapEntry.getValue()); } } if (this.returnValueRequired) { simpleJdbcCall.withReturnValue(); } simpleJdbcCall.getJdbcTemplate().setSkipUndeclaredResults(this.skipUndeclaredResults); return simpleJdbcCall; }
@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; }
private SimpleJdbcCall createSimpleJdbcCall(String storedProcedureName) { final SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(this.dataSource); if (this.isFunction) { simpleJdbcCall.withFunctionName(storedProcedureName); } else { simpleJdbcCall.withProcedureName(storedProcedureName); } if (this.ignoreColumnMetaData) { simpleJdbcCall.withoutProcedureColumnMetaDataAccess(); } simpleJdbcCall.declareParameters(this.sqlParameters.toArray(new SqlParameter[this.sqlParameters.size()])); if (!this.returningResultSetRowMappers.isEmpty()) { for (Entry<String, RowMapper<?>> mapEntry : this.returningResultSetRowMappers.entrySet()) { simpleJdbcCall.returningResultSet(mapEntry.getKey(), mapEntry.getValue()); } } if (this.returnValueRequired) { simpleJdbcCall.withReturnValue(); } simpleJdbcCall.getJdbcTemplate().setSkipUndeclaredResults(this.skipUndeclaredResults); return simpleJdbcCall; }
@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 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); }
public void prepareSession(final long eventId, final long userId, final long groupId) { JdbcTemplate jt = (JdbcTemplate) _jdbc().getJdbcOperations(); // FIXME SimpleJdbcCall call = new SimpleJdbcCall(jt).withFunctionName("_prepare_session"); MapSqlParameterSource in = new MapSqlParameterSource(); in.addValue("_event_id", eventId); in.addValue("_user_id", userId); in.addValue("_group_id", groupId); call.executeFunction(void.class, in); }