Skip to Content
0
Former Member
Dec 06, 2007 at 04:13 PM

Problem with Query Filter

50 Views

Hi experts

I try to implement one find-method using more than one Query filters. the following is code:

public MyExampleList getAllMyExampleList(
	javax.xml.datatype.XMLGregorianCalendar fromDateStart,
	javax.xml.datatype.XMLGregorianCalendar fromDateEnd)
			throws com.sap.caf.rt.exception.CAFServiceException {
		
		String method="getAllMyExampleList(XMLGregorianCalendar,XMLGregorianCalendar)";
		_location.entering(method);
		
		java.util.Date lowDate = DateUtils.toDate(fromDateStart);
		java.util.Date highDate = DateUtils.toDate(fromDateEnd);
		
		QueryFilter validFromDateFilter = null;
		List<QueryFilter> queryFilters = new ArrayList<QueryFilter>();
		
		if(lowDate != null && highDate != null) {
			validFromDateFilter = QueryFilterFactory.createFilterForBetween("validFrom", new Timestamp(lowDate.getTime()), new Timestamp(highDate.getTime()));
	    
		  } else if(lowDate != null) {
			  validFromDateFilter = QueryFilterFactory.createFilter("validFrom", Condition.GE, new java.sql.Timestamp(lowDate.getTime()));

		  } else if(highDate != null) {
			  validFromDateFilter = QueryFilterFactory.createFilter("validFrom", Condition.LE, new java.sql.Timestamp(highDate.getTime()));

		  } else {
			  validFromDateFilter = QueryFilterFactory.createFilter("*");

		  }   

		QueryFilter statusFilter =  QueryFilterFactory.createFilter("status", Condition.EQ, new Short((short)10)); //status = 10
		queryFilters.add(validFromDateFilter);
		queryFilters.add(statusFilter);
		
		QueryFilter[] _filtersArray = new com.sap.caf.rt.bol.util.QueryFilter[queryFilters.size()];
		queryFilters.toArray(_filtersArray);
		_location.debugT(method, "queryFilter size " + _filtersArray.length);
		myExampleServiceLocal myExampleService = this.getMyExampleService();
		List<MyExample> _list = (List<MyExample>)myExampleService.findByMultipleParameters(_filtersArray, false, "findByMultipleParameters");
		_location.debugT(method, "myExample list size: " + _list.size());
		_location.exiting(method);
		MyExampleList allMyExampleList= new MyExampleList();
		allMyExampleList.setMyExample(_list);
		return allMyExampleList;
	}

As you see.. I have one Business object "MyExample". And I want to get a list of this objects with the following restriction:

1. between the validFrom and validTo (validFrom, validTo is the attributes of "MyExample")

2. the memberStatus is 10 (memberStatus is the attribute of "MyExample");

But I got the error as following:

com.sap.caf.rt.exception.CAFBaseRuntimeException: Unexpected QueryFilter at index 1. Expected QueryFilter which represents [OPERATION_OR|OPERATION_AND].

I use the Netweaver 7.1 SP3..

One advice from me: In the javadoc please give some examples how to use the method.

Thanks in advance and

Kind regards!

Ping