}
JODBOperationContext context = new JODBOperationContext(_session,ticket,sortDataCache,null,null,excludedObjects,true);
IndexDataIterator indexIterator = null;
boolean skipConventionalSorting = false;
FieldRecord indexDataIteratorFieldRecord = null;//used for iteraion through indexed data
QueryNode indexedNode = null;
TypeConstraint typeConstraint = null;
try{
Vector<ConstraintBase> vectorOfConstraints = _constraints._constraints;
for (int i = 0; i < vectorOfConstraints.size(); i++) {
ConstraintBase nextCandidate = vectorOfConstraints.elementAt(i);
if(nextCandidate instanceof TypeConstraint){
if(typeConstraint == null){
typeConstraint = (TypeConstraint) nextCandidate;
}else{
typeConstraint = null;//multiple type constraints
break;
}
}
}
if(typeConstraint != null){
//boolean useIndexDataFromIterator = false;
JODBIndexingRootAgent indexingRootAgent = _session.getIndexingRootAgent();
ClassDescriptor classDescriptor = _session.getDescriptorForClass((Class)typeConstraint.getObject());
JODBIndexingAgent indexingAgent = null;
if(sortDataCache!=null){
//lookup indexing data to optimize query
SortNodeRecord[] sortRecords = sortDataCache.getSortNodes();
int fieldId = classDescriptor.getFieldIDForName(sortRecords[0]._fullPath);
if(fieldId!=-1){
indexingAgent = indexingRootAgent.getIndexingAgent(fieldId, base);
if(indexingAgent!=null){
indexIterator = indexingAgent.getIndexIterator(sortRecords[0]._orderAscending);
indexedNode = _descendants.get(sortRecords[0]._fullPath);
skipConventionalSorting = sortRecords.length == 1;
}
}
}
if(indexIterator == null){
//search first index
Iterator<String> descendants = _descendants.keySet().iterator();
while (descendants.hasNext() && indexIterator == null) {
String next = descendants.next();
Field field = classDescriptor.getFieldForName(next);
if(field==null){
continue;
}
indexingAgent = indexingRootAgent.getIndexingAgent(field, base);
if(indexingAgent!=null){
indexIterator = indexingAgent.getIndexIterator(true);
indexedNode = _descendants.get(next);
}
}
}
if(indexingAgent!=null && indexedNode != null){
Field field = classDescriptor.getFieldForID(indexingAgent.getFieldId(), null);
Class fieldType = field.getType();
if(fieldType.isPrimitive()){
indexDataIteratorFieldRecord = new FieldRecord();
indexDataIteratorFieldRecord._fieldID = indexingAgent.getFieldId();
indexDataIteratorFieldRecord._category = FIELD_CATEGORIES.PRIMITIVE;
indexDataIteratorFieldRecord._fieldTypeID = base.getClassTypeSubstitutionID(fieldType.getName());
}
}