0

In my API it is currently possible to filter on all fields that exists in the database.

Filtering is implemented in FilterUtils.java in the API project. This translates the url parameters to a Apache Cayenne search and returns the result to the resource.

In the "Main" project there are generated classes for each database table in com.foo.bar.auto these are extended by classes in com.foo.bar. The classes in com.foo.bar can have custom functions. An example is Document.getAccount.

Document.getAccount is exposed in the API, but it is not able to filter it because it's not a database field. I need to be able to filter fields like Document.getAccount.

Is it possible to register these functions in Cayenne somehow?

The syntax for searching on custom fields needs to be equal to todays filtering syntax. So when searching for account it should look like this: Document?filter=account(EQ)1234.

Any ideas? All help is appreciated.

mrlarssen
  • 325
  • 8
  • 19

1 Answers1

0

Your best bet is to split your filter keys into persistent and non-persistent properties. Then you'd build 2 expressions, one for each subset of keys. Use the first expression to build a query to fetch from DB, and the second one - to filter the returned result in memory:

Expression p = ...
Expression np = ...

SelectQuery query = new SelectQuery(Document.class, p);
List<Document> docs = context.performQuery(query);

List<Document> filteredDocs = np.filterObjects(p);
andrus_a
  • 2,528
  • 1
  • 16
  • 10