---
apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    funktion.fabric8.io/kind: Connector
  name: jdbc
data:
  deployment.yml: |
    ---
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      labels:
        funktion.fabric8.io/kind: Subscription
        connector: jdbc
    spec:
      replicas: 1
      template:
        metadata:
          labels:
            funktion.fabric8.io/kind: Subscription
            connector: jdbc
        spec:
          containers:
          - image: funktion/connector-jdbc:${project.version}
            name: connector
  schema.yml: |
    ---
    component:
      kind: component
      scheme: jdbc
      syntax: jdbc:dataSourceName
      title: JDBC
      description: The jdbc component enables you to access databases through JDBC where SQL queries are sent in the message body.
      label: database,sql
      deprecated: false
      async: false
      producerOnly: true
      javaType: org.apache.camel.component.jdbc.JdbcComponent
      groupId: org.apache.camel
      artifactId: camel-jdbc
      version: 2.18.3
    componentProperties:
      dataSource:
        kind: property
        type: object
        javaType: javax.sql.DataSource
        deprecated: false
        secret: false
        description: To use the DataSource instance instead of looking up the data source by name from the registry.
        order: 0
    properties:
      dataSourceName:
        kind: path
        group: producer
        required: true
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: Name of DataSource to lookup in the Registry.
        order: 0
      allowNamedParameters:
        kind: parameter
        group: producer
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: true
        description: Whether to allow using named parameters in the queries.
        order: 1
      beanRowMapper:
        kind: parameter
        group: producer
        type: object
        javaType: org.apache.camel.component.jdbc.BeanRowMapper
        deprecated: false
        secret: false
        description: 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.
        order: 2
      outputClass:
        kind: parameter
        group: producer
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: Specify the full package and class name to use as conversion when outputType=SelectOne or SelectList.
        order: 3
      outputType:
        kind: parameter
        group: producer
        type: string
        javaType: org.apache.camel.component.jdbc.JdbcOutputType
        enum:
        - SelectOne
        - SelectList
        - StreamList
        deprecated: false
        secret: false
        defaultValue: SelectList
        description: Determines the output the producer should use.
        order: 4
      parameters:
        kind: parameter
        group: producer
        type: object
        javaType: java.util.Map<java.lang.String,java.lang.Object>
        prefix: statement.
        multiValue: true
        deprecated: false
        secret: false
        description: Optional parameters to the java.sql.Statement. For example to set maxRows fetchSize etc.
        order: 5
      prepareStatementStrategy:
        kind: parameter
        group: producer
        type: object
        javaType: org.apache.camel.component.jdbc.JdbcPrepareStatementStrategy
        deprecated: false
        secret: false
        description: Allows to plugin to use a custom org.apache.camel.component.jdbc.JdbcPrepareStatementStrategy to control preparation of the query and prepared statement.
        order: 6
      readSize:
        kind: parameter
        group: producer
        type: integer
        javaType: int
        deprecated: false
        secret: false
        description: The default maximum number of rows that can be read by a polling query. The default value is 0.
        order: 7
      resetAutoCommit:
        kind: parameter
        group: producer
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: true
        description: 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.
        order: 8
      transacted:
        kind: parameter
        group: producer
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: Whether transactions are in use.
        order: 9
      useGetBytesForBlob:
        kind: parameter
        group: producer
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: 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.
        order: 10
      useHeadersAsParameters:
        kind: parameter
        group: producer
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: 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.
        order: 11
      useJDBC4ColumnNameAndLabelSemantics:
        kind: parameter
        group: producer
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: true
        description: 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.
        order: 12
      synchronous:
        kind: parameter
        group: advanced
        label: advanced
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
        order: 13
  documentation.adoc: |+
    [[JDBC-JDBCComponent]]
    JDBC Component
    ~~~~~~~~~~~~~~

    The *jdbc* component enables you to access databases through JDBC, where
    SQL queries (SELECT) and operations (INSERT, UPDATE, etc) are sent in
    the message body. This component uses the standard JDBC API, unlike the
    link:sql-component.html[SQL Component] component, which uses
    spring-jdbc.

    Maven users will need to add the following dependency to their `pom.xml`
    for this component:

    [source,java]
    ------------------------------------------------------------
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jdbc</artifactId>
        <version>x.x.x</version>
        <!-- use the same version as your Camel core version -->
    </dependency>
    ------------------------------------------------------------

    This component can only be used to define producer endpoints, which
    means that you cannot use the JDBC component in a `from()` statement.

    [[JDBC-URIformat]]
    URI format
    ^^^^^^^^^^

    [source,java]
    -----------------------------
    jdbc:dataSourceName[?options]
    -----------------------------

    This component only supports producer endpoints.

    You can append query options to the URI in the following format,
    `?option=value&option=value&...`

    [[JDBC-Options]]
    Options
    ^^^^^^^




    // component options: START
    The JDBC component supports 1 options which are listed below.



    {% raw %}
    [width="100%",cols="2,1m,7",options="header"]
    |=======================================================================
    | Name | Java Type | Description
    | dataSource | DataSource | To use the DataSource instance instead of looking up the data source by name from the registry.
    |=======================================================================
    {% endraw %}
    // component options: END






    // endpoint options: START
    The JDBC component supports 14 endpoint options which are listed below:

    {% raw %}
    [width="100%",cols="2,1,1m,1m,5",options="header"]
    |=======================================================================
    | Name | Group | Default | Java Type | Description
    | dataSourceName | producer |  | String | *Required* Name of DataSource to lookup in the Registry.
    | allowNamedParameters | producer | true | boolean | Whether to allow using named parameters in the queries.
    | beanRowMapper | producer |  | 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.
    | outputClass | producer |  | String | Specify the full package and class name to use as conversion when outputType=SelectOne or SelectList.
    | outputType | producer | SelectList | JdbcOutputType | Determines the output the producer should use.
    | parameters | producer |  | Map | Optional parameters to the java.sql.Statement. For example to set maxRows fetchSize etc.
    | prepareStatementStrategy | producer |  | JdbcPrepareStatementStrategy | Allows to plugin to use a custom org.apache.camel.component.jdbc.JdbcPrepareStatementStrategy to control preparation of the query and prepared statement.
    | readSize | producer |  | int | The default maximum number of rows that can be read by a polling query. The default value is 0.
    | resetAutoCommit | producer | true | boolean | 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.
    | transacted | producer | false | boolean | Whether transactions are in use.
    | useGetBytesForBlob | producer | false | boolean | 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.
    | useHeadersAsParameters | producer | false | boolean | 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.
    | useJDBC4ColumnNameAndLabelSemantics | producer | true | boolean | 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.
    | synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
    |=======================================================================
    {% endraw %}
    // endpoint options: END



    [[JDBC-Result]]
    Result
    ^^^^^^

    By default the result is returned in the OUT body as an
    `ArrayList<HashMap<String, Object>>`. The `List` object contains the
    list of rows and the `Map` objects contain each row with the `String`
    key as the column name. You can use the option `outputType` to control
    the result.

    *Note:* This component fetches `ResultSetMetaData` to be able to return
    the column name as the key in the `Map`.

    [[JDBC-MessageHeaders]]
    Message Headers
    +++++++++++++++

    [width="100%",cols="10%,90%",options="header",]
    |=======================================================================
    |Header |Description

    |`CamelJdbcRowCount` |If the query is a `SELECT`, query the row count is returned in this OUT
    header.

    |`CamelJdbcUpdateCount` |If the query is an `UPDATE`, query the update count is returned in this
    OUT header.

    |`CamelGeneratedKeysRows` |*Camel 2.10:* Rows that contains the generated kets.

    |`CamelGeneratedKeysRowCount` |*Camel 2.10:* The number of rows in the header that contains generated
    keys.

    |`CamelJdbcColumnNames` |*Camel 2.11.1:* The column names from the ResultSet as a `java.util.Set`
    type.

    |`CamelJdbcParametes` |*Camel 2.12:* A `java.util.Map` which has the headers to be used if
    `useHeadersAsParameters` has been enabled.
    |=======================================================================

    [[JDBC-Generatedkeys]]
    Generated keys
    ^^^^^^^^^^^^^^

    *Available as of Camel 2.10*

    If you insert data using SQL INSERT, then the RDBMS may support auto
    generated keys. You can instruct the link:jdbc.html[JDBC] producer to
    return the generated keys in headers. +
     To do that set the header `CamelRetrieveGeneratedKeys=true`. Then the
    generated keys will be provided as headers with the keys listed in the
    table above.

    You can see more details in this
    https://svn.apache.org/repos/asf/camel/trunk/components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcGeneratedKeysTest.java[unit
    test].

    Using generated keys does not work with together with named parameters.

    [[JDBC-Usingnamedparameters]]
    Using named parameters
    ^^^^^^^^^^^^^^^^^^^^^^

    *Available as of Camel 2.12*

    In the given route below, we want to get all the projects from the
    projects table. Notice the SQL query has 2 named parameters, :?lic and
    :?min. +
     Camel will then lookup these parameters from the message headers.
    Notice in the example above we set two headers with constant value +
     for the named parameters:

    [source,java]
    ----------------------------------------------------------------------------------------
      from("direct:projects")
         .setHeader("lic", constant("ASF"))
         .setHeader("min", constant(123))
         .setBody("select * from projects where license = :?lic and id > :?min order by id")
         .to("jdbc:myDataSource?useHeadersAsParameters=true")
    ----------------------------------------------------------------------------------------

    You can also store the header values in a `java.util.Map` and store the
    map on the headers with the key `CamelJdbcParameters`.

    [[JDBC-Samples]]
    Samples
    ^^^^^^^

    In the following example, we fetch the rows from the customer table.

    First we register our datasource in the Camel registry as `testdb`:

    Then we configure a route that routes to the JDBC component, so the SQL
    will be executed. Note how we refer to the `testdb` datasource that was
    bound in the previous step:

    Or you can create a `DataSource` in Spring like this:

    We create an endpoint, add the SQL query to the body of the IN message,
    and then send the exchange. The result of the query is returned in the
    OUT body:

    If you want to work on the rows one by one instead of the entire
    ResultSet at once you need to use the link:splitter.html[Splitter] EIP
    such as:

    In Camel 2.13.x or older

    In Camel 2.14.x or newer

    [source,java]
    -------------------------------------------------------------------------------------------------
    from("direct:hello")
    // here we split the data from the testdb into new messages one by one
    // so the mock endpoint will receive a message per row in the table
    // the StreamList option allows to stream the result of the query without creating a List of rows
    // and notice we also enable streaming mode on the splitter
    .to("jdbc:testdb?outputType=StreamList")
      .split(body()).streaming()
      .to("mock:result");
    -------------------------------------------------------------------------------------------------

    [[JDBC-Sample-Pollingthedatabaseeveryminute]]
    Sample - Polling the database every minute
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    If we want to poll a database using the JDBC component, we need to
    combine it with a polling scheduler such as the link:timer.html[Timer]
    or link:quartz.html[Quartz] etc. In the following example, we retrieve
    data from the database every 60 seconds:

    [source,java]
    ------------------------------------------------------------------------------------------------------------------------------
    from("timer://foo?period=60000").setBody(constant("select * from customer")).to("jdbc:testdb").to("activemq:queue:customers");
    ------------------------------------------------------------------------------------------------------------------------------

    [[JDBC-Sample-MoveDataBetweenDataSources]]
    Sample - Move Data Between Data Sources +
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    A common use case is to query for data, process it and move it to
    another data source (ETL operations). In the following example, we
    retrieve new customer records from the source table every hour,
    filter/transform them and move them to a destination table:

    [source,java]
    ------------------------------------------------------------------------------------------------
    from("timer://MoveNewCustomersEveryHour?period=3600000")
        .setBody(constant("select * from customer where create_time > (sysdate-1/24)"))
        .to("jdbc:testdb")
        .split(body())
            .process(new MyCustomerProcessor()) //filter/transform results as needed
            .setBody(simple("insert into processed_customer values('${body[ID]}','${body[NAME]}')"))
            .to("jdbc:testdb");
    ------------------------------------------------------------------------------------------------

     

    [[JDBC-SeeAlso]]
    See Also
    ^^^^^^^^

    * link:configuring-camel.html[Configuring Camel]
    * link:component.html[Component]
    * link:endpoint.html[Endpoint]
    * link:getting-started.html[Getting Started]

    * link:sql.html[SQL]

