Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.elsql;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import com.opengamma.elsql.ElSql;
import com.opengamma.elsql.SpringSqlParams;
import org.apache.camel.Exchange;
import org.apache.camel.ExtendedExchange;
import org.apache.camel.component.sql.ResultSetIterator;
import org.apache.camel.component.sql.ResultSetIteratorCompletion;
import org.apache.camel.component.sql.SqlConstants;
import org.apache.camel.component.sql.SqlOutputType;
import org.apache.camel.component.sql.SqlPrepareStatementStrategy;
import org.apache.camel.support.DefaultProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.core.PreparedStatementCreatorFactory;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterUtils;
import org.springframework.jdbc.core.namedparam.ParsedSql;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import static org.springframework.jdbc.support.JdbcUtils.closeConnection;
import static org.springframework.jdbc.support.JdbcUtils.closeResultSet;
import static org.springframework.jdbc.support.JdbcUtils.closeStatement;
public class ElsqlProducer extends DefaultProducer {
private static final Logger LOG = LoggerFactory.getLogger(ElsqlProducer.class);
private final ElSql elSql;
private final String elSqlName;
private final NamedParameterJdbcTemplate jdbcTemplate;
private final DataSource dataSource;
private final SqlPrepareStatementStrategy sqlPrepareStatementStrategy;
private final boolean batch;
public ElsqlProducer(final ElsqlEndpoint endpoint, final ElSql elSql, final String elSqlName,
final NamedParameterJdbcTemplate jdbcTemplate,
final DataSource dataSource, final SqlPrepareStatementStrategy sqlPrepareStatementStrategy,
final boolean batch) {
super(endpoint);
this.elSql = elSql;
this.elSqlName = elSqlName;
this.jdbcTemplate = jdbcTemplate;
this.dataSource = dataSource;
this.sqlPrepareStatementStrategy = sqlPrepareStatementStrategy;
this.batch = batch;
}
@Override
public ElsqlEndpoint getEndpoint() {
return (ElsqlEndpoint) super.getEndpoint();
}
@Override
public void process(final Exchange exchange) throws Exception {
final Object data = exchange.getIn().getBody();
final SqlParameterSource param = new ElsqlSqlMapSource(exchange, data);
final String sql = elSql.getSql(elSqlName, new SpringSqlParams(param));
LOG.debug("ElsqlProducer @{} using sql: {}", elSqlName, sql);
// special for processing stream list (batch not supported)
final SqlOutputType outputType = getEndpoint().getOutputType();
if (outputType == SqlOutputType.StreamList) {
processStreamList(exchange, sql, param);
return;
}
LOG.trace("jdbcTemplate.execute: {}", sql);
jdbcTemplate.execute(sql, param, new PreparedStatementCallback