Is possible create a sub query using the ContentInstanceDBQuery? How?
public List getComunicados(String tipo, String idioma, String ano, int qtdePagina, int numPagina) throws ApplicationException, ValidationException
{
int startIndex = 0;
int endIndex = 0;
ArrayList retorno = new ArrayList();
ContentInstanceWhereClause mainClause = new ContentInstanceWhereClause();
mainClause.setMatchAny(false);
ContentInstanceWhereClause ctClause = new ContentInstanceWhereClause();
ContentType ctd = (ContentType)ContentType.findByName("RI_COMUNICADO");
ContentInstanceDBQuery queryB = new ContentInstanceDBQuery(new ContentTypeRef(ctd));
mainClause.addWhereClause(ctClause);
if(tipo != null && tipo != "") {
ContentInstanceWhereClause tipoClause = new ContentInstanceWhereClause();
tipoClause.checkAttribute("ARTIGO-DES-PAIS-ATR", StringQueryOp.EQUAL, tipo, false);
mainClause.addWhereClause(tipoClause);
}
if(ano != null && ano != "") {
Date dtInicial = new Date((Integer.parseInt(ano) - 1900),0,1,0,1,1);
Date fim = new Date((Integer.parseInt(ano) - 1900),11,31,23,59,59);
ContentInstanceWhereClause dateClause = new ContentInstanceWhereClause();
dateClause.checkAttribute("ARTIGO-DAT-ARTG", DateQueryOp.AFTER, dtInicial);
dateClause.checkAttribute("ARTIGO-DAT-ARTG", DateQueryOp.BEFORE, fim);
dateClause.setMatchAny(false);
mainClause.addWhereClause(dateClause);
}
if(idioma != null && idioma != "") {
ManagedObjectWhereClause ctChannels = new ContentInstanceWhereClause();
if(idioma.equals("pt")) {
ChannelRef channelPT = new ChannelRef("701377348248d310VgnVCM100000d8193a0aRCRD");
ctChannels.checkChannel(ObjectQueryOp.EQUAL, channelPT);
}
else if(idioma.equals("en")) {
ChannelRef channelEN = new ChannelRef("477f2c250839d310VgnVCM100000d8193a0aRCRD");
ctChannels.checkChannel(ObjectQueryOp.EQUAL, channelEN);
}
else if(idioma.equals("es")) {
ChannelRef channelES = new ChannelRef("4b3986dbcf5dd310VgnVCM100000d8193a0aRCRD");
ctChannels.checkChannel(ObjectQueryOp.EQUAL, channelES);
}
mainClause.addWhereClause(ctChannels);
}
queryB.setWhereClause(mainClause);
RequestParameters requestParameters = new RequestParameters();
requestParameters.setTopRelationOnly(true);
IPagingList iPagingList = QueryManager.execute(queryB, requestParameters);
qtdeTotal = iPagingList.size();
// paginacao
endIndex = startIndex + qtdePagina;
numPagina = numPagina+1;
List list = iPagingList.subList(numPagina, endIndex);
return list;
}