In addition to those required by the JDO spec, TJDO supports the following methods as extensions to the query mechanism:
Except for the limitations described below, all behave like their Java counterparts.char String.charAt(int index) int String.indexOf(String substr) int String.length() boolean String.startsWith(String substr, int toffset) String String.substring(int begin) String String.substring(int begin, int end) String String.toLowerCase() String String.toUpperCase()
These are all non-standard TriActive extensions to JDOQL. They are highly likely to work in TJDO no matter what database is in-use (DB portable) but are far less likely to be available in another vendor's JDO implementation (not very JDO portable). However, toLowerCase() and toUpperCase() are specifically mentioned in the current JDO spec as likely future additions.
String.indexOf() is used to perform the equivalent of
LIKE '%xyz%'
in SQL.
For example, the filter:
str.indexOf("xyz") >= 0
will effectively generate WHERE STR LIKE '%xyz%'
in the
resulting SQL.
String.indexOf() is very limited in that it can only be used in this exact context; that is, to test for the existence of an embedded substring. In other words, it can only be used as the X in a "X >= 0" subexpression. It cannot be used to otherwise obtain or filter on the index position of a substring; any occurrence of indexOf() must always be followed by the characters ">= 0" or an exception will be thrown.
When using Oracle, String.length() will not return reliable results for strings of lengths zero or one. To circumvent the fact Oracle equates empty strings with NULL, TJDO represents empty strings in the database by a single surrogate character '\001'. Therefore when the SQL LENGTH() function is executed "empty" strings will appear to have a length of one.
When I get time I have plans to add some methods from java.util.Map to allow querying the contents of persistent maps, and some from java.util.Date to pick apart date fields. Let me know if you feel you have a pressing need for any of them.
Methods under consideration:
boolean Map.containsKey(Object key) boolean Map.containsValue(Object value) boolean Map.isEmpty() Set Map.keySet() Collection Map.values() int Date.getDate() int Date.getHours() int Date.getMinutes() int Date.getMonth() int Date.getSeconds() int Date.getYear()