Thomas -
You are The Man. Thanks a ton!
On Aug 25, 10:57 pm, "Thomas Mueller" <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> > OK - I know that I am stretching the limits of stupidity by asking
> > this one, but is there any way to write a java class to search an
> > object that is stored within the database without first pulling the
> > object out of the db and reserializing it?
>
> There are multiple ways to do that.
>
> 1) The 'deserialize' part could be done in user defined a function as in:
>
> package com.acme;
> public class Util {
> public static Object get(byte[] data, String method) throws Exception {
> Object obj = ObjectUtils.deserialize(data);
> Method m = obj.getClass().getMethod(method, new Class[0]);
> return m.invoke(obj, new Object[0]);
> }}
>
> CREATE ALIAS GET FOR "com.acme.Util.get";
> SELECT * FROM TEST WHERE GET(DATA, 'toString')='Hello';
>
> 2) You can extend method 1) by creating 'computed columns' for each
> field you need to indexing. See
> also:http://www.h2database.com/html/features.html#computed_columns
> Example:
> CREATE TABLE TEST(ID IDENTITY, DATA OBJECT, TO_STRING VARCHAR AS
> GET(DATA, 'toString'));
> CREATE INDEX IDX_TEST_TO_STRING ON TEST(TO_STRING);
>
> 3) You could index all fields using the Lucene fulltext feature of H2
> and a special Lucene parser that deserialized the object and for each
> getter method lists the field name and value. It's probably more
> efficient if you know the fields you need to index however.
>
> Regards,
> Thomas
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---