@Test public void testParameterApplicatorParametersOutOfOrder() throws Exception { StatementParameter param1 = new StatementParameter("MyValue1", "java.lang.String", StatementParameter.QueryType.constant); param1.setName("paramOne"); StatementParameter param5 = new StatementParameter("MyValue5", "java.lang.String", StatementParameter.QueryType.constant); param5.setName("paramFive"); StatementParameter param2 = new StatementParameter("MyValue2", "java.lang.String", StatementParameter.QueryType.constant); param2.setName("paramTwo"); StatementParameter param3 = new StatementParameter("MyValue3", "java.lang.String", StatementParameter.QueryType.constant); param3.setName("paramThree"); StatementParameter param4 = new StatementParameter("MyValue4", "java.lang.String", StatementParameter.QueryType.constant); param4.setName("paramFour"); parameters = new StatementParameterList(); parameters.add(param1); parameters.add(param5); parameters.add(param2); parameters.add(param3); parameters.add(param4); parameterApplicator.applyStatementParameters(message, mockStatement, parameters, fiveParamSqlStatement); verify(mockStatement).setObject(1, "MyValue1"); verify(mockStatement).setObject(2, "MyValue2"); verify(mockStatement).setObject(3, "MyValue3"); verify(mockStatement).setObject(4, "MyValue4"); verify(mockStatement).setObject(5, "MyValue5"); }
@Override public void applyStatementParameters(AdaptrisMessage message, PreparedStatement statement, StatementParameterCollection parameters, String originalSql) throws ServiceException { Matcher m = Pattern.compile(this.getParameterNameRegex()).matcher(originalSql); int counter = 0; while (m.find()) { counter++; String parameterName = m.group(); JdbcStatementParameter statementParameter = parameters.getParameterByName(parameterName.substring(this.getParameterNamePrefix() .length())); try { Args.notNull(statementParameter, "statementParameter"); statementParameter.apply(counter, statement, message); } catch (Exception ex) { throw ExceptionHelper.wrapServiceException(ex); } } }
NamedParameterApplicator implements ParameterApplicator { @Override public void applyStatementParameters(AdaptrisMessage message, PreparedStatement statement, StatementParameterCollection parameters, String originalSql) throws ServiceException { Matcher m = Pattern.compile(this.getParameterNameRegex()).matcher(originalSql); int counter = 0; while (m.find()) { counter++; String parameterName = m.group(); JdbcStatementParameter statementParameter = parameters.getParameterByName(parameterName.substring(this.getParameterNamePrefix() .length())); try { Args.notNull(statementParameter, "statementParameter"); statementParameter.apply(counter, statement, message); } catch (Exception ex) { throw ExceptionHelper.wrapServiceException(ex); } } } }
NamedParameterApplicator implements ParameterApplicator { @Override public void applyStatementParameters(AdaptrisMessage message, PreparedStatement statement, StatementParameterCollection parameters, String originalSql) throws ServiceException { Matcher m = Pattern.compile(this.getParameterNameRegex()).matcher(originalSql); int counter = 0; while (m.find()) { counter++; String parameterName = m.group(); JdbcStatementParameter statementParameter = parameters.getParameterByName(parameterName.substring(this.getParameterNamePrefix() .length())); try { Args.notNull(statementParameter, "statementParameter"); statementParameter.apply(counter, statement, message); } catch (Exception ex) { throw ExceptionHelper.wrapServiceException(ex); } } } NamedParameterApplicator(); }
NamedParameterApplicator implements ParameterApplicator { @Override public void applyStatementParameters(AdaptrisMessage message, PreparedStatement statement, StatementParameterCollection parameters, String originalSql) throws ServiceException { Matcher m = Pattern.compile(this.getParameterNameRegex()).matcher(originalSql); int counter = 0; while (m.find()) { counter++; String parameterName = m.group(); JdbcStatementParameter statementParameter = parameters.getParameterByName(parameterName.substring(this.getParameterNamePrefix() .length())); try { Args.notNull(statementParameter, "statementParameter"); statementParameter.apply(counter, statement, message); } catch (Exception ex) { throw ExceptionHelper.wrapServiceException(ex); } } } NamedParameterApplicator(); @Override void applyStatementParameters(AdaptrisMessage message, PreparedStatement statement,
                                       StatementParameterCollection parameters, String originalSql); @Override String prepareParametersToStatement(String originalStatement); String getParameterNamePrefix(); void setParameterNamePrefix(String s); String getParameterNameRegex(); void setParameterNameRegex(String regex); }
NamedParameterApplicator implements ParameterApplicator { @Override public void applyStatementParameters(AdaptrisMessage message, PreparedStatement statement, StatementParameterCollection parameters, String originalSql) throws ServiceException { Matcher m = Pattern.compile(this.getParameterNameRegex()).matcher(originalSql); int counter = 0; while (m.find()) { counter++; String parameterName = m.group(); JdbcStatementParameter statementParameter = parameters.getParameterByName(parameterName.substring(this.getParameterNamePrefix() .length())); try { Args.notNull(statementParameter, "statementParameter"); statementParameter.apply(counter, statement, message); } catch (Exception ex) { throw ExceptionHelper.wrapServiceException(ex); } } } NamedParameterApplicator(); @Override void applyStatementParameters(AdaptrisMessage message, PreparedStatement statement,
                                       StatementParameterCollection parameters, String originalSql); @Override String prepareParametersToStatement(String originalStatement); String getParameterNamePrefix(); void setParameterNamePrefix(String s); String getParameterNameRegex(); void setParameterNameRegex(String regex); static final String DEFAULT_PARAM_NAME_PREFIX; static final String DEFAULT_PARAM_NAME_REGEX; }