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.jdbc;
018    
019    import java.util.Map;
020    import javax.sql.DataSource;
021    
022    import org.apache.camel.Component;
023    import org.apache.camel.Consumer;
024    import org.apache.camel.Processor;
025    import org.apache.camel.Producer;
026    import org.apache.camel.impl.DefaultEndpoint;
027    
028    /**
029     * @version $Revision:520964 $
030     */
031    public class JdbcEndpoint extends DefaultEndpoint {
032        private int readSize;
033        private DataSource dataSource;
034        private Map<String, Object> parameters;
035        private boolean useJDBC4ColumnNameAndLabelSemantics = true;
036    
037        public JdbcEndpoint() {
038        }
039    
040        public JdbcEndpoint(String endpointUri, Component component, DataSource dataSource) {
041            super(endpointUri, component);
042            this.dataSource = dataSource;
043        }
044    
045        public boolean isSingleton() {
046            return true;
047        }
048    
049        public Consumer createConsumer(Processor processor) throws Exception {
050            throw new UnsupportedOperationException("Not supported");
051        }
052    
053        public Producer createProducer() throws Exception {
054            return new JdbcProducer(this, dataSource, readSize, parameters);
055        }
056    
057        public int getReadSize() {
058            return readSize;
059        }
060    
061        public void setReadSize(int readSize) {
062            this.readSize = readSize;
063        }
064    
065        public DataSource getDataSource() {
066            return dataSource;
067        }
068    
069        public void setDataSource(DataSource dataSource) {
070            this.dataSource = dataSource;
071        }
072    
073        public Map<String, Object> getParameters() {
074            return parameters;
075        }
076    
077        /**
078         * Optional parameters to the {@link java.sql.Statement}.
079         * <p/>
080         * For example to set maxRows, fetchSize etc.
081         * 
082         * @param parameters parameters which will be set using reflection
083         */
084        public void setParameters(Map<String, Object> parameters) {
085            this.parameters = parameters;
086        }
087    
088        public boolean isUseJDBC4ColumnNameAndLabelSemantics() {
089            return useJDBC4ColumnNameAndLabelSemantics;
090        }
091    
092        /**
093         * Sets whether to use JDBC 4 or JDBC 3.0 or older semantic when retrieving column name.
094         * <p/>
095         * JDBC 4.0 uses columnLabel to get the column name where as JDBC 3.0 uses both columnName or columnLabel.
096         * Unfortunately JDBC drivers behave differently so you can use this option to work out issues around your
097         * JDBC driver if you get problem using this component
098         * <p/>
099         * This option is default <tt>true</tt>.
100         *
101         * @param useJDBC4ColumnNameAndLabelSemantics  <tt>true</tt> to use JDBC 4.0 semantics, <tt>false</tt> to use JDBC 3.0.
102         */
103        public void setUseJDBC4ColumnNameAndLabelSemantics(boolean useJDBC4ColumnNameAndLabelSemantics) {
104            this.useJDBC4ColumnNameAndLabelSemantics = useJDBC4ColumnNameAndLabelSemantics;
105        }
106    
107        @Override
108        protected String createEndpointUri() {
109            return "jdbc";
110        }
111    }