JDOQL DATANUCLEUS filtering using String matches

爷,独闯天下 提交于 2020-01-01 19:41:17

问题


Using JDO with Datanucleus, I'm trying to filter some data from my database (using jdoql). I would like to use the regular expression for some sophisticated searchs, I found that JDO provide the String method "matches" that accepts a regular expression, and according to the DATANUCLEUS documentation, this method can receive any type of ExpReg:

matches(String pattern) : Returns whether string matches the passed expression. The pattern argument follows the rules of java.lang.String.matches method.

I was able to do filtering based on some regular expression (like " .* ", ".", ". * ") But not with others (like [abcd])

Can someone confirm that not all the set of regular expression syntax are supported ??

Query q = pm.newQuery(cl, "this.name.matches(filterName)");
q.declareParameters("String filterName");
List results = (List)q.execute("Bo.*");
return pm.detachCopyAll(results);

--> Return Book, Book2

But with : q.execute("B[aoe]ok")  return nothing !

Thanks


回答1:


After dozens of failed tests, i can say that (with DN 2.1) the MATCHES does not work (tested against JAVA string.matches(regex)): http://www.datanucleus.org/products/accessplatform_2_1/jdo/jdoql_methods.html

In my tests i have the following regex:

(PT)?999999990

Is translated by JDOQL into:

LIKE '(PT)<UNPRINTABLE>999999990'

The database contains many records like:
999999990
PT999999990
...

Also, depending on the REGEX, the JDOQL interpreter seems to change the expression...

The following regex:

(?i)(PT)?999999990 

Translated by JDOQL into:

LIKE '(PT)<UNPRINTABLE>999999990'


来源:https://stackoverflow.com/questions/20142608/jdoql-datanucleus-filtering-using-string-matches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!