cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Query Filter

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (7)

Answers (7)

Former Member
0 Kudos

Hi,

My earlier post is confusing,so I am posting again.

The way suggested is deprecated now.

I have used the following way to assemble multiple query filters together but with a "AND " condition only .

List queryFilters = new ArrayList(); QueryFilter queryFilterOne = QueryFilterFactory.createFilter("ROLLUMBER",Condition.EQ, rollNumber); QueryFilter queryFilterTwo = QueryFilterFactory.createFilter("NAME",Condition.EQ, "123"); queryFilters.add(queryFilterOne); queryFilters.add(queryFilterTwo); List students = studentServiceLocal.findByMultipleParameters(queryFilters, false, "xyz");

Please suggest me a way how I can also filter though "OR " condition between two query filters.I can see all earlier available ways in CAF are deprecated now.

I have tried all these for OR and find all of them as depricated in CE 7.1 .............Please suggest ........

//queryFilterOne.setAction(QueryFilter.OPERATION_OR);' //QueryFilterFactory.createBoolOperator(queryFilterOne.OPERATION_OR); //queryFilters.add(QueryFilter.OR); //queryFilters.add(queryFilterOne.setOperation(QueryFilter.OPERATION_OR));

Thanks in advance for your help.

Regards,

Sonali Das

Former Member
0 Kudos

>

> 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

>

> 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

Hi,

The way suggested is deprecated now.I have used the following way to assemble multiple query filters together but with a "AND " condition only .

Please suggest me a way how I can also filter though "OR " condition also.

I can see all earlier available ways in CAF are deprecated now.

List<QueryFilter> queryFilters = new ArrayList<QueryFilter>();			
		QueryFilter queryFilterOne = QueryFilterFactory.createFilter("ROLLUMBER",Condition.EQ, rollNumber);
		QueryFilter queryFilterTwo = QueryFilterFactory.createFilter("NAME",Condition.EQ, "123");
		
		
		
		queryFilters.add(queryFilterOne);		
		queryFilters.add(queryFilterTwo);		
		List<StudentDetails> students = studentServiceLocal.findByMultipleParameters(queryFilters, false, "xyz");

I have tried all these for OR and find all of them as depricated in CE 7.1 .............Please suggest some help.........

//queryFilterOne.setAction(QueryFilter.OPERATION_OR);'
//QueryFilterFactory.createBoolOperator(queryFilterOne.OPERATION_OR);
//queryFilters.add(QueryFilter.OR);
//queryFilters.add(queryFilterOne.setOperation(QueryFilter.OPERATION_OR));

Thanks in advance for your help.

Regards,

sonali

Former Member
0 Kudos

As Iven suggested.

The problem is solved. Thanks!

Former Member
0 Kudos

I'm not 100% sure, but I think that this error tells you that you need additional query filter between these two. For example

queryFilters.add(validFromDateFilter);

queryFilters.add(QueryFilter.AND);

queryFilters.add(statusFilter);

Hope that will help.

Former Member
0 Kudos

Ciao

Das Probelm is open... Any ideas?

Thanks and kind regards?

Ping

Former Member
0 Kudos

Hallo Maria

Thanks anyway. I knew this link and took a look again and again.

It doesnot help me.

I want to know how can I use the queyfilter more than 1 Criteria.

Regards

Ping

Former Member
0 Kudos

Hi Ping,

Maybe this link will be helpful for you: http://help.sap.com/saphelp_nwce10/helpdata/en/44/6359a603b13674e10000000a114a6b/frameset.htm

Best Regards,

Maria