On 10 January 2014 06:50, <[email protected]> wrote:
> Thanks Dan,
>
> I saw the OIDMarshallaer code and used the other separated character than
> reserved characters for ISIS. Its working fine.
>
> But thing is that we have to restrict the PK fields not to have this
> separated character in its values. I hope JDO in future fixes this
> limitation may be by using similar EmbeddedId technique from JPA where we
> don't have bother about joining/splitting PK fields
>
>
Another option would be to encode the string. Looking at
com.google.common.io.BaseEncoding (part of guava, so already on the
classpath for Isis applications), the base32 encoding does not use any of
the restricted separators.
For example:
public class OmGeoLocationPK implements java.io.Serializable {
private static encode(String str) {
return
BaseEncoding.base32().encode(str.getBytes(Charset.forName("UTF-8")));
}
private static decode(String str) {
return new String(BaseEncoding.base32().decode(str),
Charset.forName("UTF-8"));
}
...
public OmGeoLocationPK(String key){
StringTokenizer token = new StringTokenizer(decode(key), "_");
this.locationId = token.nextToken();
this.orgId = token.nextToken();
}
...
public String toString() {
return encode(locationId + "_" + this.orgId);
}
}
Another option might be to make this part of the JdoObjectIdSerializer
class so that it done transparently by the framework. But that would have
the disadvantage of encoding all strings. Anyone have any opinions on this?
Dan