public OmniDTO retrieveMasterDetails(InputInfo inputInfo)
throws BaseSQLException {
if (inputInfo == null)
throw new IllegalArgumentException("inputInfo is null.");
ImplicitTransactionManager tm = TransactionManagerUtil.getImplicitTransactionManager();
OmniDTO returnTO = null;
try {
tm.beginTransactionImplicit();
InputInfo ip = inputInfo;
UserDatabaseConnection udc = findOrCreateConnection(ip);
udc.getConnection().setReadOnly(true);
returnTO = executeKeepConnection(udc, ip.getInputs(), ip.getProcessorType(), ip.getProcessorName(), ip.getOutputFilters());
log.debug("parent: " + returnTO);
//now execute child InputInfo
Collection<InputInfo> childList = ip.getChildInputInfoObjects();
for (InputInfo childIp : childList) {
// find all input parameters in childIp that need data from parent
List<String> connectorList = new ArrayList<String>();
Map<String, Object> childInputs = childIp.getInputs();
childInputs = convertKeyCase(childInputs);
for (Map.Entry<String, Object> entry : childInputs.entrySet()) {
String key = entry.getKey();
String value = (String)childInputs.get(key);
if (key != null && key.startsWith("&")) connectorList.add(value);
}
// create a select union query
String query = null;
if (DataProcessorTypes.NAMED_SQL_STATEMENT_PROCESSOR.equals(childIp.getProcessorType())) {
query = SqlConfig.getInstance().getSql(childIp.getProcessorName());
}
else
if (DataProcessorTypes.DIRECT_SQL_STATEMENT_PROCESSOR.equals(childIp.getProcessorType())) {
query = childIp.getProcessorName();
}
log.debug("child query1: " + query);
// check if parent has data
boolean parentHasData = false;
TableData parentRt = null;
if (returnTO != null) {
parentRt = returnTO.getTableData(ip.getProcessorName());
if (parentRt != null) {
int size = parentRt.getAllRows().size();
if (size > 0) parentHasData = true;
}
}
// construct child query
String childQuery = "";
if (query != null && connectorList.size() > 0 && parentHasData) {
childQuery = getNewChildQuery(query, childIp, parentRt.getAllRows());
}
else {
childQuery = query;
}
log.debug("child query2: " + childQuery);
if (parentHasData) {
udc = findOrCreateConnection(childIp);
OmniDTO returnTO2 =
executeKeepConnection(udc,
childIp.getInputs(),
DataProcessorTypes.DIRECT_SQL_STATEMENT_PROCESSOR,
childQuery,
childIp.getOutputFilters());
// merge child records with corresponding parent record
if (returnTO2 != null) {
linkParentWithChild(parentRt,
returnTO2.getTableData(childQuery),
childIp.getProcessorName(),
connectorList);
}
log.debug("returnTO2: " + returnTO2);
}
}
}
catch(SQLException ex) {
throw new BaseSQLException(ex);
}
catch(BaseSQLException bdex) {
throw bdex;
}
finally {
tm.releaseResourcesImplicit();
}
return returnTO;
}