I want to connect multiple datasources based on some conditions, i don't want to create multiple DBCPConnectionPool services to connect each database, i just want to check if my attribute value is oracle, then i have to connect my Oracle database by passing Oracle configurations like url ,driver name,user name and password, if it MySQL then i need to dynamically pass MySQL related configurations, could you please help with processors which i can use.
I am using updateAttribute processor and putting some conditions like below :
Attribute: db.url
Value: ${datasource:equals('Oracle'):ifElse('Oracle-jdbc-url', 'Myslq-jdbc-url')}
Attribute: db.username
Value: ${datasource:equals('Oracle'):ifElse('oracle-username', 'mysql-username')}
Attribute: db.password
Value: ${datasource:equals('Oracle'):ifElse('oracle-password', 'mysql-password')}.
so i am not sure how to pass or read these values to DBCPConnectionPool
You can use the
DBCPConnectionPoolLookupcontroller service for this. You set upDBCPConnectionPoolinstances for each database connection you want, then you add user-defined (aka dynamic) properties toDBCPConnectionPoolLookupwhere the name of the property is the value that thedatabase.nameattribute will contain, and the value of the user-defined property will be the correspondingDBCPConnectionPoolinstance.For example, if your
datasourceattribute contains "Oracle" or "MySQL" or something, you can useUpdateAttributeto setdatabase.nameto${datasource}, then create a DBCPConnectionPool for your Oracle connection and add a property namedOracleto the DBCPConnectionPoolLookup with the OracleDBCPConnectionPoolas the value.