001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.camel.component.sql; 018 019 import org.apache.camel.Component; 020 import org.apache.camel.Consumer; 021 import org.apache.camel.Processor; 022 import org.apache.camel.Producer; 023 import org.apache.camel.impl.DefaultEndpoint; 024 import org.springframework.jdbc.core.JdbcTemplate; 025 026 /** 027 * SQL Endpoint. Endpoint URI should contain valid SQL statement, but instead of 028 * question marks (that are parameter placeholders), sharp signs should be used. 029 * This is because in camel question mark has other meaning. 030 */ 031 public class SqlEndpoint extends DefaultEndpoint { 032 private JdbcTemplate jdbcTemplate; 033 private String query; 034 035 public SqlEndpoint() { 036 } 037 038 public SqlEndpoint(String uri, Component component, JdbcTemplate jdbcTemplate, String query) { 039 super(uri, component); 040 this.jdbcTemplate = jdbcTemplate; 041 this.query = query; 042 } 043 044 public Consumer createConsumer(Processor processor) throws Exception { 045 throw new UnsupportedOperationException("Not implemented"); 046 } 047 048 public Producer createProducer() throws Exception { 049 return new SqlProducer(this, query, jdbcTemplate); 050 } 051 052 public boolean isSingleton() { 053 return true; 054 } 055 056 public JdbcTemplate getJdbcTemplate() { 057 return jdbcTemplate; 058 } 059 060 public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { 061 this.jdbcTemplate = jdbcTemplate; 062 } 063 064 public String getQuery() { 065 return query; 066 } 067 068 public void setQuery(String query) { 069 this.query = query; 070 } 071 072 @Override 073 protected String createEndpointUri() { 074 return "sql:" + query; 075 } 076 }