Hi guys,
I've made a lot of changes on my script processor and now I'm properly
getting an instance of DBCPService however when I try to use the connection
I got the error org.apache.commons.dbcp.SQLNestedException: Cannot get a
connection, pool error Timeout waiting for idle object.
I know the connection is ok because the upstream processor uses the same
DBCP instance to access the same database.
the code I'm using on my InvokeScriptedProcessor is:
void onTrigger(ProcessContext context, ProcessSessionFactory
sessionFactory) throws ProcessException {
def session = sessionFactory.createSession()
def flowFile = session.get()
if(!flowFile) return
def properties = context.getProperties()
log.info("Properties {}", properties)
def String lookupKey =
context.getProperty(LOOKUP_FIELD)?.evaluateAttributeExpressions()?.getValue()
log.info('Lookup key {}', lookupKey)
def dbcpService =
context.getProperty(DBCP_SERVICE).asControllerService(DBCPService)
def Integer queryTimeout =
context.getProperty(QUERY_TIMEOUT).asTimePeriod(TimeUnit.SECONDS).intValue()
try
{
def con = dbcpService.getConnection()
def st = con.createStatement()
st.setQueryTimeout(queryTimeout)
def selectQuery = "select * from PERSONS where id=${lookupKey}"
log.info("Executing query {}", selectQuery)
boolean results = st.execute(selectQuery)
log.info("Results {}-{}", lookupKey, results)
session.transfer(flowFile, REL_SUCCESS)
session.commit()
} catch (final Throwable t) {
log.error('{} failed to process due to {}', [this, t] as Object[])
session.rollback(true)
throw t
}
}
Any hints?