workingMemory );
return;
}
InternalFactHandle handle = (InternalFactHandle) leftTuple.getObject();
DroolsQuery queryObject = (DroolsQuery) handle.getObject();
if ( queryObject.getAction() != null ) {
// we already have an insert scheduled for this query, but have re-entered it
// do nothing
return;
}
Object[] argTemplate = this.queryElement.getArgTemplate(); // an array of declr, variable and literals
Object[] args = new Object[argTemplate.length]; // the actual args, to be created from the template
// first copy everything, so that we get the literals. We will rewrite the declarations and variables next
System.arraycopy( argTemplate,
0,
args,
0,
args.length );
int[] declIndexes = this.queryElement.getDeclIndexes();
for ( int i = 0, length = declIndexes.length; i < length; i++ ) {
Declaration declr = (Declaration) argTemplate[declIndexes[i]];
Object tupleObject = leftTuple.get( declr ).getObject();
Object o;
if ( tupleObject instanceof DroolsQuery ) {
// If the query passed in a Variable, we need to use it
ArrayElementReader arrayReader = (ArrayElementReader) declr.getExtractor();
if ( ((DroolsQuery) tupleObject).getVariables()[arrayReader.getIndex()] != null ) {
o = Variable.v;
} else {
o = declr.getValue( workingMemory,
tupleObject );
}
} else {
o = declr.getValue( workingMemory,
tupleObject );
}
args[declIndexes[i]] = o;
}
int[] varIndexes = this.queryElement.getVariableIndexes();
for ( int i = 0, length = varIndexes.length; i < length; i++ ) {
if ( argTemplate[varIndexes[i]] == Variable.v ) {
// Need to check against the arg template, as the varIndexes also includes re-declared declarations
args[varIndexes[i]] = Variable.v;
}
}
queryObject.setParameters( args );
((UnificationNodeViewChangedEventListener) queryObject.getQueryResultCollector()).setVariables( varIndexes );
QueryUpdateAction action = new QueryUpdateAction( context,
handle,
leftTuple,
this );