private void executeSQL(ExecutionContext executionContext, Fragment source) throws SmooksException {
Connection connection = AbstractDataSource.getConnection(datasource, executionContext);
BeanContext beanContext = executionContext.getBeanContext();
Map<String, Object> beanMap = beanContext.getBeanMap();
try {
if(!statementExec.isJoin()) {
if(statementExec.getStatementType() == StatementType.QUERY) {
if(resultSetScope == ResultSetScope.EXECUTION) {
beanContext.addBean(resultSetBeanId, statementExec.executeUnjoinedQuery(connection), source);
} else {
List<Map<String, Object>> resultMap;
// Cached in the application context...
ApplicationContext appContext = executionContext.getContext();
ResultSetContextObject rsContextObj = ResultSetContextObject.getInstance(rsAppContextKey, appContext);
if(rsContextObj.hasExpired()) {
synchronized (rsContextObj) {
if(rsContextObj.hasExpired()) {
rsContextObj.resultSet = statementExec.executeUnjoinedQuery(connection);
rsContextObj.expiresAt = System.currentTimeMillis() + resultSetTTL;
}
}
}
resultMap = rsContextObj.resultSet;
beanContext.addBean(resultSetBeanId, resultMap, source);
}
} else {
statementExec.executeUnjoinedUpdate(connection);
}
} else {
if(statementExec.getStatementType() == StatementType.QUERY) {
List<Map<String, Object>> resultMap = new ArrayList<Map<String, Object>>();
statementExec.executeJoinedQuery(connection, beanMap, resultMap);
beanContext.addBean(resultSetBeanId, resultMap, source);
} else {
if(resultSetBeanId == null) {
statementExec.executeJoinedUpdate(connection, beanMap);
} else {
Object resultSetObj = beanContext.getBean(resultSetBeanId);
if(resultSetObj != null) {
try {
@SuppressWarnings("unchecked")
List<Map<String, Object>> resultSet = (List<Map<String, Object>>) resultSetObj;
statementExec.executeJoinedStatement(connection, resultSet);