return parse(config, baseResource, configResource);
/** * Returns a copy of this bundle with a different configuration. * <p> * This does not reload the underlying resources. * * @param config the new config, not null * @return a bundle with the config updated, not null */ public ElSql withConfig(ElSqlConfig config) { return new ElSql(_fragments.withConfig(config)); }
@Override public int commit(DefaultSqlEndpoint defaultSqlEndpoint, Exchange exchange, Object data, NamedParameterJdbcTemplate jdbcTemplate, SqlParameterSource parameterSource, String query) throws Exception { final SqlParameterSource param = new ElsqlSqlMapSource(exchange, data); final String sql = elSql.getSql(query, new SpringSqlParams(param)); LOG.debug("commit @{} using sql: {}", query, sql); return jdbcTemplate.execute(sql, param, new PreparedStatementCallback<Integer>() { @Override public Integer doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { ps.execute(); int updateCount = ps.getUpdateCount(); if (LOG.isTraceEnabled()) { LOG.trace("Update count {}", updateCount); } return updateCount; } }); }
@Override public int commitBatchComplete(DefaultSqlEndpoint endpoint, NamedParameterJdbcTemplate namedJdbcTemplate, SqlParameterSource parameterSource, String query) throws Exception { final SqlParameterSource param = new EmptySqlParameterSource(); final String sql = elSql.getSql(query, new SpringSqlParams(param)); LOG.debug("commitBatchComplete @{} using sql: {}", query, sql); return namedJdbcTemplate.execute(sql, param, new PreparedStatementCallback<Integer>() { @Override public Integer doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { ps.execute(); int updateCount = ps.getUpdateCount(); if (LOG.isTraceEnabled()) { LOG.trace("Update count {}", updateCount); } return updateCount; } }); }
@Override protected void doStart() throws Exception { super.doStart(); ObjectHelper.notNull(resourceUri, "resourceUri", this); if (elSqlConfig == null && databaseVendor != null) { elSqlConfig = databaseVendor.asElSqlConfig(); } else if (elSqlConfig == null) { elSqlConfig = ElSqlDatabaseVendor.Default.asElSqlConfig(); } // there can be multiple resources // so we have all this lovely code to turn that into an URL[] final List<URL> list = new ArrayList<>(); final Iterable it = ObjectHelper.createIterable(resourceUri); for (final Object path : it) { final URL url = ResourceHelper.resolveMandatoryResourceAsUrl(getCamelContext().getClassResolver(), path.toString()); list.add(url); } final URL[] urls = list.toArray(new URL[list.size()]); elSql = ElSql.parse(elSqlConfig, urls); }
final String sql = elSql.getSql(elSqlName, new SpringSqlParams(param)); LOG.debug("ElsqlProducer @{} using sql: {}", elSqlName, sql);
/** * Parses a bundle from a resource locating a file, specify the config. * <p> * This parses a list of resources, expressed as {@code URL}s. * Named blocks in later resources override blocks with the same name in earlier resources. * <p> * The config is designed to handle some, but not all, database differences. * Other differences are handled via the override resources passed in. * <p> * Each resource is a {@link URL}. A null URL is permitted and ignored. * This allows classpath resources, obtained from {@link Class#getResource(String)} * or {@link ClassLoader#getResource(String)} to be called and passed in directly * as those methods return null when the target does not exist. * * @param config the config to use, not null * @param resources the resources to load, not null, may contain nulls which are ignored * @return the external identifier, not null * @throws IllegalArgumentException if the input cannot be parsed or if none of the resources exists */ public static ElSql parse(ElSqlConfig config, URL... resources) { if (config == null) { throw new IllegalArgumentException("Config must not be null"); } if (resources == null) { throw new IllegalArgumentException("Resources must not be null"); } return new ElSql(SqlFragments.parseResource(resources, config)); }
@Override public Consumer createConsumer(final Processor processor) throws Exception { final SqlProcessingStrategy proStrategy = new ElsqlSqlProcessingStrategy(elSql); final SqlPrepareStatementStrategy preStategy = new ElsqlSqlPrepareStatementStrategy(); final Exchange dummy = createExchange(); final SqlParameterSource param = new ElsqlSqlMapSource(dummy, null); final String sql = elSql.getSql(elsqlName, new SpringSqlParams(param)); LOG.debug("ElsqlConsumer @{} using sql: {}", elsqlName, sql); final ElsqlConsumer consumer = new ElsqlConsumer(this, processor, namedJdbcTemplate, sql, param, preStategy, proStrategy); consumer.setMaxMessagesPerPoll(getMaxMessagesPerPoll()); consumer.setOnConsume(getOnConsume()); consumer.setOnConsumeFailed(getOnConsumeFailed()); consumer.setOnConsumeBatchComplete(getOnConsumeBatchComplete()); consumer.setBreakBatchOnConsumeFail(isBreakBatchOnConsumeFail()); consumer.setExpectedUpdateCount(getExpectedUpdateCount()); consumer.setUseIterator(isUseIterator()); consumer.setRouteEmptyResultSet(isRouteEmptyResultSet()); configureConsumer(consumer); return consumer; }