Class JdbcEndpoint

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.CamelContextAware, org.apache.camel.Endpoint, org.apache.camel.IsSingleton, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.HasId, org.apache.camel.StatefulService, org.apache.camel.SuspendableService

    @UriEndpoint(firstVersion="1.2.0",
                 scheme="jdbc",
                 title="JDBC",
                 syntax="jdbc:dataSourceName",
                 producerOnly=true,
                 category={DATABASE,SQL},
                 headersClass=JdbcConstants.class)
    public class JdbcEndpoint
    extends org.apache.camel.support.DefaultEndpoint
    Access databases through SQL and JDBC.
    • Field Summary

      • Fields inherited from class org.apache.camel.support.service.BaseService

        BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.apache.camel.Consumer createConsumer​(org.apache.camel.Processor processor)  
      protected String createEndpointUri()  
      org.apache.camel.Producer createProducer()  
      BeanRowMapper getBeanRowMapper()  
      ConnectionStrategy getConnectionStrategy()  
      DataSource getDataSource()  
      String getDataSourceName()  
      String getOutputClass()  
      JdbcOutputType getOutputType()  
      Map<String,​Object> getParameters()  
      JdbcPrepareStatementStrategy getPrepareStatementStrategy()  
      int getReadSize()  
      boolean isAllowNamedParameters()  
      boolean isResetAutoCommit()  
      boolean isTransacted()  
      boolean isUseGetBytesForBlob()  
      boolean isUseHeadersAsParameters()  
      boolean isUseJDBC4ColumnNameAndLabelSemantics()  
      void setAllowNamedParameters​(boolean allowNamedParameters)
      Whether to allow using named parameters in the queries.
      void setBeanRowMapper​(BeanRowMapper beanRowMapper)
      To use a custom org.apache.camel.component.jdbc.BeanRowMapper when using outputClass.
      void setConnectionStrategy​(ConnectionStrategy connectionStrategy)
      To use a custom strategy for working with connections.
      void setDataSource​(DataSource dataSource)
      The data source to use
      void setDataSourceName​(String dataSourceName)
      Name of DataSource to lookup in the Registry.
      void setOutputClass​(String outputClass)
      Specify the full package and class name to use as conversion when outputType=SelectOne or SelectList.
      void setOutputType​(JdbcOutputType outputType)
      Determines the output the producer should use.
      void setParameters​(Map<String,​Object> parameters)
      Optional parameters to the Statement.
      void setPrepareStatementStrategy​(JdbcPrepareStatementStrategy prepareStatementStrategy)
      Allows the plugin to use a custom org.apache.camel.component.jdbc.JdbcPrepareStatementStrategy to control preparation of the query and prepared statement.
      void setReadSize​(int readSize)
      The default maximum number of rows that can be read by a polling query.
      void setResetAutoCommit​(boolean resetAutoCommit)
      Camel will set the autoCommit on the JDBC connection to be false, commit the change after executed the statement and reset the autoCommit flag of the connection at the end, if the resetAutoCommit is true.
      void setTransacted​(boolean transacted)
      Whether transactions are in use.
      void setUseGetBytesForBlob​(boolean useGetBytesForBlob)
      To read BLOB columns as bytes instead of string data.
      void setUseHeadersAsParameters​(boolean useHeadersAsParameters)
      Set this option to true to use the prepareStatementStrategy with named parameters.
      void setUseJDBC4ColumnNameAndLabelSemantics​(boolean useJDBC4ColumnNameAndLabelSemantics)
      Sets whether to use JDBC 4 or JDBC 3.0 or older semantic when retrieving column name.
      • Methods inherited from class org.apache.camel.support.DefaultEndpoint

        configureConsumer, configureExchange, configurePollingConsumer, configureProperties, createAsyncProducer, createExchange, createExchange, createPollingConsumer, doInit, doStart, doStop, equals, getCamelContext, getComponent, getEndpointKey, getEndpointUri, getExceptionHandler, getExchangePattern, getId, getPollingConsumerBlockTimeout, getPollingConsumerQueueSize, hashCode, isAutowiredEnabled, isBridgeErrorHandler, isLazyStartProducer, isLenientProperties, isPollingConsumerBlockWhenFull, isPollingConsumerCopy, isSingleton, setAutowiredEnabled, setBridgeErrorHandler, setCamelContext, setComponent, setEndpointUri, setEndpointUriIfNotSpecified, setExceptionHandler, setExchangePattern, setLazyStartProducer, setPollingConsumerBlockTimeout, setPollingConsumerBlockWhenFull, setPollingConsumerCopy, setPollingConsumerQueueSize, setProperties, toString
      • Methods inherited from class org.apache.camel.support.service.BaseService

        build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
      • Methods inherited from interface org.apache.camel.Endpoint

        getEndpointBaseUri, isSingletonProducer
      • Methods inherited from interface org.apache.camel.Service

        build, close, init, start, stop
      • Methods inherited from interface org.apache.camel.ShutdownableService

        shutdown
      • Methods inherited from interface org.apache.camel.StatefulService

        getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
      • Methods inherited from interface org.apache.camel.SuspendableService

        isSuspended, resume, suspend
    • Constructor Detail

      • JdbcEndpoint

        public JdbcEndpoint()
      • JdbcEndpoint

        public JdbcEndpoint​(String endpointUri,
                            org.apache.camel.Component component,
                            DataSource dataSource)
    • Method Detail

      • createConsumer

        public org.apache.camel.Consumer createConsumer​(org.apache.camel.Processor processor)
                                                 throws Exception
        Throws:
        Exception
      • createProducer

        public org.apache.camel.Producer createProducer()
                                                 throws Exception
        Throws:
        Exception
      • getDataSourceName

        public String getDataSourceName()
      • setDataSourceName

        public void setDataSourceName​(String dataSourceName)
        Name of DataSource to lookup in the Registry. If the name is dataSource or default, then Camel will attempt to lookup a default DataSource from the registry, meaning if there is a only one instance of DataSource found, then this DataSource will be used.
      • getReadSize

        public int getReadSize()
      • setReadSize

        public void setReadSize​(int readSize)
        The default maximum number of rows that can be read by a polling query. The default value is 0.
      • isTransacted

        public boolean isTransacted()
      • setTransacted

        public void setTransacted​(boolean transacted)
        Whether transactions are in use.
      • isResetAutoCommit

        public boolean isResetAutoCommit()
      • setResetAutoCommit

        public void setResetAutoCommit​(boolean resetAutoCommit)
        Camel will set the autoCommit on the JDBC connection to be false, commit the change after executed the statement and reset the autoCommit flag of the connection at the end, if the resetAutoCommit is true. If the JDBC connection doesn't support to reset the autoCommit flag, you can set the resetAutoCommit flag to be false, and Camel will not try to reset the autoCommit flag. When used with XA transactions you most likely need to set it to false so that the transaction manager is in charge of committing this tx.
      • getDataSource

        public DataSource getDataSource()
      • setDataSource

        public void setDataSource​(DataSource dataSource)
        The data source to use
      • setParameters

        public void setParameters​(Map<String,​Object> parameters)
        Optional parameters to the Statement.

        For example to set maxRows, fetchSize etc.

        Parameters:
        parameters - parameters which will be set using reflection
      • isUseJDBC4ColumnNameAndLabelSemantics

        public boolean isUseJDBC4ColumnNameAndLabelSemantics()
      • setUseJDBC4ColumnNameAndLabelSemantics

        public void setUseJDBC4ColumnNameAndLabelSemantics​(boolean useJDBC4ColumnNameAndLabelSemantics)
        Sets whether to use JDBC 4 or JDBC 3.0 or older semantic when retrieving column name.

        JDBC 4.0 uses columnLabel to get the column name where as JDBC 3.0 uses both columnName or columnLabel. Unfortunately JDBC drivers behave differently so you can use this option to work out issues around your JDBC driver if you get problem using this component

        This option is default true.

        Parameters:
        useJDBC4ColumnNameAndLabelSemantics - true to use JDBC 4.0 semantics, false to use JDBC 3.0.
      • setPrepareStatementStrategy

        public void setPrepareStatementStrategy​(JdbcPrepareStatementStrategy prepareStatementStrategy)
        Allows the plugin to use a custom org.apache.camel.component.jdbc.JdbcPrepareStatementStrategy to control preparation of the query and prepared statement.
      • isAllowNamedParameters

        public boolean isAllowNamedParameters()
      • setAllowNamedParameters

        public void setAllowNamedParameters​(boolean allowNamedParameters)
        Whether to allow using named parameters in the queries.
      • isUseHeadersAsParameters

        public boolean isUseHeadersAsParameters()
      • setUseHeadersAsParameters

        public void setUseHeadersAsParameters​(boolean useHeadersAsParameters)
        Set this option to true to use the prepareStatementStrategy with named parameters. This allows to define queries with named placeholders, and use headers with the dynamic values for the query placeholders.
      • setOutputType

        public void setOutputType​(JdbcOutputType outputType)
        Determines the output the producer should use.
      • getOutputClass

        public String getOutputClass()
      • setOutputClass

        public void setOutputClass​(String outputClass)
        Specify the full package and class name to use as conversion when outputType=SelectOne or SelectList.
      • setBeanRowMapper

        public void setBeanRowMapper​(BeanRowMapper beanRowMapper)
        To use a custom org.apache.camel.component.jdbc.BeanRowMapper when using outputClass. The default implementation will lower case the row names and skip underscores, and dashes. For example "CUST_ID" is mapped as "custId".
      • isUseGetBytesForBlob

        public boolean isUseGetBytesForBlob()
      • setUseGetBytesForBlob

        public void setUseGetBytesForBlob​(boolean useGetBytesForBlob)
        To read BLOB columns as bytes instead of string data.

        This may be needed for certain databases such as Oracle where you must read BLOB columns as bytes.

      • setConnectionStrategy

        public void setConnectionStrategy​(ConnectionStrategy connectionStrategy)
        To use a custom strategy for working with connections. Do not use a custom strategy when using the spring-jdbc component because a special Spring ConnectionStrategy is used by default to support Spring Transactions.
      • createEndpointUri

        protected String createEndpointUri()
        Overrides:
        createEndpointUri in class org.apache.camel.support.DefaultEndpoint