1

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

Jugu
  • 787
  • 1
  • 9
  • 23
  • i'm sure if you looked at the log (such as the SQL invoked) you'd likely understand better – DataNucleus Nov 22 '13 at 11:50
  • Thanks, but where can I see the sql invoked from the javax.jdo.Query ? There is no sql trace in the log files. – Jugu Nov 25 '13 at 14:54
  • There is SQL in the log file ... when the developer configures their logging to the right level (DEBUG), as per the publically visible DataNucleus docs. – DataNucleus Nov 25 '13 at 14:56
  • I can found it, thanks (http://www.datanucleus.org/products/accessplatform/logging.html) – Jugu Nov 25 '13 at 15:13
  • I'm having the same problem. MATCHES does not return any result (regex was tested with java code and works fine). – marcolopes Mar 19 '15 at 17:00

1 Answers1

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'
marcolopes
  • 9,232
  • 14
  • 54
  • 65