|
1 |
| -# jdbc |
2 |
| -Database connector for elastic.io implemented with JDBC |
| 1 | +# JDBC-component |
| 2 | +## Description |
| 3 | +This is an open source component for working with object-relational database management systems on [elastic.io platform](http://www.elastic.io "elastic.io platform"). |
| 4 | +### Purpose |
| 5 | +With this component you will have following triggers: |
3 | 6 |
|
4 |
| -This project is licensed under Apache 2.0 License. |
| 7 | +``SELECT`` - this trigger will execute an [SQL](https://en.wikipedia.org/wiki/SQL "SQL") query that returns multiple results, it has limitations on the query and suited only for SELECT type of queries. The trigger will remember last execution timestamp and let you build queries on it. |
| 8 | + |
| 9 | +``GET ROWS POLLING`` - this trigger will execute select query from specified table with simple criteria of selected datetime or timestamp table. The trigger will remember last execution timestamp and let you build queries on it. |
| 10 | + |
| 11 | +Following actions are inside: |
| 12 | + |
| 13 | +``SELECT`` - this action will execute an [SQL](https://en.wikipedia.org/wiki/SQL "SQL") query that returns multiple results, it has limitations on the query and suited only for SELECT type of queries. |
| 14 | + |
| 15 | +``LOOKUP BY PRIMARY KEY`` - this action will execute select query from specified table, as criteria can be used only [PRIMARY KEY](https://en.wikipedia.org/wiki/Primary_key "PRIMARY KEY"). The action returns only one result (a primary key is unique). |
| 16 | + |
| 17 | +``UPSERT BY PRIMARY KEY`` - this action will execute select command from specified table, as search criteria can be used only [PRIMARY KEY](https://en.wikipedia.org/wiki/Primary_key "PRIMARY KEY"), and execute insert command by PRIMARY KEY with specified field, if result does not found, else - action will execute update command by PRIMARY KEY with specified field. The action returns only one result row (a primary key is unique). |
| 18 | + |
| 19 | +``DELETE BY PRIMARY KEY`` - this action will execute delete query from specified table, as criteria can be used only [PRIMARY KEY](https://en.wikipedia.org/wiki/Primary_key "PRIMARY KEY"). The action returns an integer value that indicates the number of rows affected, the returned value can be 0 or 1 (a primary key is unique). |
| 20 | +### How works |
| 21 | + |
| 22 | +### Requirements |
| 23 | +Before you can deploy any code into elastic.io **you must be a registered elastic.io platform user**. Please see our home page at [http://www.elastic.io](http://www.elastic.io) to learn how. |
| 24 | +#### Environment variables |
| 25 | +For unit-testing is needed to specify following environment variables: |
| 26 | +1. Connection to MSSQL: |
| 27 | + - ``CONN_USER_MSSQL`` - user login |
| 28 | + - ``CONN_PASSWORD_MSSQL`` - user password |
| 29 | + - ``CONN_DBNAME_MSSQL`` - DataBase name |
| 30 | + - ``CONN_HOST_MSSQL`` - DataBase host |
| 31 | + - ``CONN_PORT_MSSQL`` - DataBase port |
| 32 | +2. Connection to MySQL: |
| 33 | + - ``CONN_USER_MYSQL`` - user login |
| 34 | + - ``CONN_PASSWORD_MYSQL`` - user password |
| 35 | + - ``CONN_DBNAME_MYSQL`` - DataBase name |
| 36 | + - ``CONN_HOST_MYSQL`` - DataBase host |
| 37 | + - ``CONN_PORT_MYSQL`` - DataBase port |
| 38 | +3. Connection to Oracle: |
| 39 | + - ``CONN_USER_ORACLE`` - user login |
| 40 | + - ``CONN_PASSWORD_ORACLE`` - user password |
| 41 | + - ``CONN_DBNAME_ORACLE`` - DataBase name |
| 42 | + - ``CONN_HOST_ORACLE`` - DataBase host |
| 43 | + - ``CONN_PORT_ORACLE`` - DataBase port |
| 44 | +4. Connection to PostgreSQL: |
| 45 | + - ``CONN_USER_POSTGRESQL`` - user login |
| 46 | + - ``CONN_PASSWORD_POSTGRESQL`` - user password |
| 47 | + - ``CONN_DBNAME_POSTGRESQL`` - DataBase name |
| 48 | + - ``CONN_HOST_POSTGRESQL`` - DataBase host |
| 49 | + - ``CONN_PORT_POSTGRESQL`` - DataBase port |
| 50 | +#### Others |
| 51 | +## Credentials |
| 52 | +You may use following properties to configure a connection: |
| 53 | + |
| 54 | +You can add the authorisation methods during the integration flow design or by going to your Settings > Security credentials > REST client and adding there. |
| 55 | +### DB Engine |
| 56 | +You are able to choose one of existing database types: |
| 57 | + |
| 58 | + |
| 59 | +### Connection URI |
| 60 | +In the Connection URI field please provide hostname of the server, e.g. ``acme.com`` |
| 61 | +### Connection port |
| 62 | +In the Connection port field please provide port of the server instance, as by default: |
| 63 | +- ``3306`` - MySQL |
| 64 | +- ``5432`` - PostgreSQL |
| 65 | +- ``1521`` - Oracle |
| 66 | +- ``1433`` - MSSQL |
| 67 | +### Database Name |
| 68 | +In the Database Name field please provide name of database at the instance that you want to interact with. |
| 69 | +### User |
| 70 | +In the User field please provide a username that has permissions to interact with the Database. |
| 71 | +### Password |
| 72 | +In the Password field please provide a password of the user that has permissions to interact with the Database. |
| 73 | + |
| 74 | +Validation will start right after click on a Save button. You will be able to continue working with component after validation if all provided credentials will be valid. |
| 75 | +## Triggers |
| 76 | +### Select trigger |
| 77 | +You are able to provide SELECT query with last execution timestamp as WHERE clause criteria. |
| 78 | + |
| 79 | +Before executing the the statement %%EIO_LAST_POLL%% will be replaced with ISO Date of the last execution or max value of the last pooled datetime, for example ``2018-08-01T00:00:00.000``. |
| 80 | +During the first execution, date will be equal to ["start" of Unix Time](https://en.wikipedia.org/wiki/Unix_time) - ``1970-01-01 00:00:00.000``. |
| 81 | +Precision of the polling clause can be till milliseconds. |
| 82 | +The format of ``Start Polling From (optional)`` field should be like ``yyyy-mm-dd hh:mi:ss[.sss]``, where |
| 83 | +- ``yyyy`` - year |
| 84 | +- ``mm`` - month |
| 85 | +- ``dd`` - day |
| 86 | +- ``hh`` - hour |
| 87 | +- ``mi`` - minute |
| 88 | +- ``ss`` - second |
| 89 | +- ``sss`` - millisecond (optional) |
| 90 | +### Get Rows Polling trigger |
| 91 | +This trigger can polling data from provided table. As WHERE clause you can use column, which has datatype like DATE or TIMESTAMP. |
| 92 | + |
| 93 | +Before executing the the statement %%EIO_LAST_POLL%% will be replaced with ISO Date of the last execution or max value of the last pooled datetime, for example ``2018-08-01T00:00:00.000``. |
| 94 | +During the first execution, date will be equal to ["start" of Unix Time](https://en.wikipedia.org/wiki/Unix_time) - ``1970-01-01 00:00:00.000``. |
| 95 | +Precision of the polling clause can be till milliseconds. |
| 96 | +The format of ``Start Polling From (optional)`` field should be like ``yyyy-mm-dd hh:mi:ss[.sss]``, where |
| 97 | +- ``yyyy`` - year |
| 98 | +- ``mm`` - month |
| 99 | +- ``dd`` - day |
| 100 | +- ``hh`` - hour |
| 101 | +- ``mi`` - minute |
| 102 | +- ``ss`` - second |
| 103 | +- ``sss`` - millisecond (optional) |
| 104 | + |
| 105 | +### SELECT trigger (Deprecated) |
| 106 | +This action exists in JDBC component only for backward compatibility. New [**Select trigger**](#select-trigger) is recommended to use. |
| 107 | + |
| 108 | + |
| 109 | +## Actions |
| 110 | +### Select action |
| 111 | + |
| 112 | +The action will execute an [SQL](https://en.wikipedia.org/wiki/SQL "SQL") query that can return multiple results, it has limitations on the query and suited only for SELECT type of queries. |
| 113 | +In SQL query you can use clause variables with specific data types. |
| 114 | +Internally we use prepared statements, so all incoming data is |
| 115 | +validated against SQL injection, however we had to build a connection from JavaScript types to the SQL data types |
| 116 | +therefore when doing a prepared statements, you would need to add ``:type`` to **each prepared statement variable**. |
| 117 | + |
| 118 | +For example if you have a following SQL statement: |
| 119 | + |
| 120 | +```sql |
| 121 | +SELECT |
| 122 | +FROM users |
| 123 | +WHERE userid = @id AND language = @lang |
| 124 | +``` |
| 125 | + |
| 126 | +you should add ``:type`` to each ``@parameter`` so your SQL query will looks like this: |
| 127 | + |
| 128 | +```sql |
| 129 | +SELECT |
| 130 | +FROM users |
| 131 | +WHERE userid = @id:number AND language = @lang:string |
| 132 | +``` |
| 133 | + |
| 134 | +Following types are supported: |
| 135 | + * ``string`` |
| 136 | + * ``number`` |
| 137 | + * ``bigint`` |
| 138 | + * ``boolean`` |
| 139 | + * ``float`` |
| 140 | + * ``date`` |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | +Checkbox ``Don't throw Error on an Empty Result`` allows to emit an empty response, otherwise you will get an error on empty response. |
| 145 | + |
| 146 | +#### Input fields description |
| 147 | +Component supports dynamic incoming metadata - as soon as your query is in place it will be parsed and incoming metadata will be generated accordingly. |
| 148 | + |
| 149 | +### Lookup Row By Primary Key |
| 150 | + |
| 151 | + |
| 152 | +The action will execute select query from a ``Table`` dropdown field, as criteria can be used only [PRIMARY KEY](https://en.wikipedia.org/wiki/Primary_key "PRIMARY KEY"). The action returns only one result (a primary key is unique). |
| 153 | +Checkbox ``Don't throw Error on an Empty Result`` allows to emit an empty response, otherwise you will get an error on empty response. |
| 154 | +#### Input fields description |
| 155 | + |
| 156 | +As an input metadata you will get a Primary Key field to provide the data inside as a clause value. |
| 157 | + |
| 158 | +### Upsert Row By Primary Key action |
| 159 | +The action will execute ``SELECT`` command from a ``Tables`` dropdown field, as search criteria can be used only [PRIMARY KEY](https://en.wikipedia.org/wiki/Primary_key "PRIMARY KEY"), and execute ``INSERT`` command by PRIMARY KEY with specified field, if result does not found, else - action will execute ``UPDATE`` command by PRIMARY KEY with specified field. The action returns only one result row (a primary key is unique). |
| 160 | +1. Find and select jdbc-component in the component repository |
| 161 | + |
| 162 | + |
| 163 | +2. Create new or select existing credentials |
| 164 | + |
| 165 | + |
| 166 | +3. Select action "Upsert Row By Primary Key" from list |
| 167 | + |
| 168 | + |
| 169 | +4. Select table from ``Table`` dropdown list |
| 170 | + |
| 171 | + |
| 172 | +5. Specify input data (field with red asterisk is Primary key), and click "Continue" |
| 173 | + |
| 174 | + |
| 175 | +6. Retrieving sample |
| 176 | + |
| 177 | + |
| 178 | +7. Retrieve sample result |
| 179 | + |
| 180 | + |
| 181 | +8. Click "Continue" |
| 182 | + |
| 183 | + |
| 184 | +9. Finish component configuration |
| 185 | + |
| 186 | + |
| 187 | +#### Input fields description |
| 188 | +As an input metadata you will get all fields of selected table. [PRIMARY KEY](https://en.wikipedia.org/wiki/Primary_key "PRIMARY KEY") is required field (will mark as asterisk) and other input fields are optional. |
| 189 | + |
| 190 | + |
| 191 | +### Delete Row By Primary Key action |
| 192 | + |
| 193 | +The action will execute delete query from a ``Table`` dropdown field, as criteria can be used only [PRIMARY KEY](https://en.wikipedia.org/wiki/Primary_key "PRIMARY KEY"). The action returns count of affected rows. |
| 194 | +Checkbox ``Don't throw Error on an Empty Result`` allows to emit an empty response, otherwise you will get an error on empty response. |
| 195 | +#### Input fields description |
| 196 | + |
| 197 | +As an input metadata you will get a Primary Key field to provide the data inside as a clause value. |
| 198 | + |
| 199 | +### Create or update record action (Deprecated) |
| 200 | +This action exists in JDBC component only for backward compatibility. [**Upsert row by primary key**](#upsert-row-by-primary-key-action) Action is recommended to use. |
| 201 | + |
| 202 | +## Current limitations |
| 203 | +1. Only tables with one [PRIMARY KEY](https://en.wikipedia.org/wiki/Primary_key "PRIMARY KEY") is supported. You will see the message ``Table has not Primary Key. Should be one Primary Key |
| 204 | +``, if the selected table doesn't have a primary key. Also, you will see the message ``Composite Primary Key is not supported |
| 205 | +``, if the selected table has composite primary key. |
| 206 | +2. Only following versions of database types are supported: |
| 207 | +- ``MySQL`` - compatible with MySQL Server 5.5, 5.6, 5.7 and 8.0. |
| 208 | +- ``PostgreSQL`` - compatible with PostgreSQL 8.2 and higher |
| 209 | +- ``Oracle`` - compatible with Oracle Database 8.1.7 - 12.1.0.2 |
| 210 | +- ``MSSQL`` - compatible with Microsoft SQL Server 2008 R2 and higher |
| 211 | +3. The current implementation of the action ``Upsert By Primary Key`` doesn't mark non-nullable fields as required fields at a dynamic metadata. In case of updating such fields with an empty value you will get SQL Exception ``Cannot insert the value NULL into...``. You should manually fill in all non-nullable fields with previous data, if you want to update part of columns in a row, even if data in that fields doesn't change. |
| 212 | + |
| 213 | +## Known issues |
| 214 | +No known issues are there yet. |
| 215 | + |
| 216 | +## License |
| 217 | +Apache-2.0 © [elastic.io GmbH](https://www.elastic.io "elastic.io GmbH") |
| 218 | + |
| 219 | +## <System> API and Documentation links |
| 220 | +[elastic.io iPaaS Documentation](https://support.elastic.io/support/home "elastic.io iPaaS Documentation") |
0 commit comments