Hello @TG_10272716
To query the object with latest revision and iteration you can use following query :
example works with WTParts
public static WTPart getPartLatestIterationBySubQuery(String partNumber)
{
Class targetClass = wt.part.WTPart.class;
try
{
QuerySpec subSelect = new QuerySpec();
subSelect.getFromClause().setAliasPrefix("B"); //sub FROM
int subIndex = subSelect.appendClassList(targetClass, false);
int[] fromIndicies = {subIndex};
ClassAttribute branchIDAtt = new ClassAttribute(targetClass, WTPart.BRANCH_IDENTIFIER); // IMPORTANT: SUB SELECT has to have own new CLASS ATTRIBUTE
SQLFunction maxFunction = SQLFunction.newSQLFunction(SQLFunction.MAXIMUM,
branchIDAtt);
subSelect.appendSelect(maxFunction, fromIndicies, false); //sub SELECT
ClassAttribute numberAtt = new ClassAttribute(targetClass, WTPart.NUMBER);
RelationalExpression theExpression = ConstantExpression.newExpression(partNumber, numberAtt.getColumnDescriptor().getJavaType());
SearchCondition theCondition = new SearchCondition(numberAtt, SearchCondition.EQUAL, theExpression);
subSelect.appendWhere(theCondition); //sub WHERE
//wt.query.ConditionsClause.
QuerySpec select = new QuerySpec();
int index = select.appendClassList(targetClass, true);
ClassAttribute brID = new ClassAttribute(targetClass, WTPart.BRANCH_IDENTIFIER); // IMPORTANT: SUB SELECT has to have own new CLASS ATTRIBUTE
select.appendWhere(new SearchCondition(brID, SearchCondition.IN,
new SubSelectExpression(subSelect))
, new int[]{index});
select.appendAnd();
ClassAttribute lastIter = new ClassAttribute(targetClass, WTPart.LATEST_ITERATION); // IMPORTANT: SUB SELECT has to have own new CLASS ATTRIBUTE
select.appendWhere(new SearchCondition(lastIter, SearchCondition.IS_TRUE));
select.setAdvancedQueryEnabled(true);//velmi dulezite nastavit advanced
QueryResult qr = PersistenceServerHelper.manager.query((StatementSpec) select);
while (qr.hasMoreElements())
{
Object[] nextObj = (Object[]) qr.nextElement();
return (WTPart) nextObj[0];
}
} catch (WTPropertyVetoException e)
{
e.printStackTrace();
} catch (PersistenceException e)
{
e.printStackTrace();
} catch (QueryException e)
{
e.printStackTrace();
} catch (WTException e)
{
e.printStackTrace();
}
return null;
}
This code is little bit faster then control all revisions one by one.
Hope this can help.
PetrH