1

I'm currently working with the versant object database (using jvi), and have a case where I need to query the database based on an object id.

The problem is I'm running some performance tests on the database using the pole position framework, and one of the tests in that framework requires me to fetch an object from the database using either an object reference or a low level object id. Thus, I'm not allowed to reference specific fields in the employee object, but must perform the query on the object in its entirety. So, it's not allowed for me to go "select * from Employee e where e.id = 4", I need it to use the entire object.

What I'm trying to achieve is something along the lines of

Employee employee = new Employee("Mr. Pickles");
session.commit();

FundVQLQuery q = new FundVQLQuery(session, 
                 "select * from Employee employee where employee = $1");
q.bind(employee);
q.execute();

However, this throws an EVJ_NOT_A_VALID_KEY_TYPE error. Does anyone know the correct way of doing this?

Mia Clarke
  • 8,134
  • 3
  • 49
  • 62
  • What kinds of things are you finding out the hard way? Is this Java or C++? – John Jun 03 '09 at 01:47
  • It's java. I'm finding out the hard way that the way I'm trying to acheive this is wrong, because I get a EVJ_NOT_A_VALID_KEY_TYPE, which means I can't bind the parameter to an object of the type employee. – Mia Clarke Jun 03 '09 at 08:04

4 Answers4

6

Sure you figured this out (post was months ago). What you want to do is use the GetObjectId first, to get the VOD Id of the object, then query the DB;

id = session.GetObjectId(employee);

Chris Holmes
  • 11,444
  • 12
  • 50
  • 64
  • Actually, I never figured it out, so thank you! Problem is that because of this: http://meta.stackexchange.com/questions/1413/why-an-answer-cant-be-accepted-after-an-unresolved-bounty I can't mark your answer as accepted, which frankly is silly. I do thank you, though, for taking the time to answer this. However, all readers of this thread should know that this is the answer to this question. You rock! – Mia Clarke Dec 01 '09 at 15:19
1

This is how I did the whole roundtrip object → OID → object:

First you get the OID with TransSession.getOidAsLong.

TransSession session = ...;
Employee employee = new Employee("Mr. Pickles");
long oid = TransSession.getOidAsLong(employee);
session.commit();

Once you have the object ID, just grab the object from its Handle.

TransSession session = ...;
Employee employee = (Employee)session.returnHandleFromLong(oid).handleToObject();

No VQL needed.

gustafc
  • 28,465
  • 7
  • 73
  • 99
-1

You can try this,

FundVQLQuery vql = FundVQLQuery (session, 
   "select selfoid from Employee where name = $1"); 
vql.bind ("Mr. Pickles");
HandleEnumeration e = vql.execute (); 
while ( e.hasmoreHandles() ) {
    Handle handle = e.nexthandle(); 
}

It will return all Employees with the name "Mr. Pickles", Then loop through them.

Bernie Perez
  • 12,513
  • 13
  • 46
  • 55
  • Thank you Bernie, but unfortunatly the restraints were such that I had to bind the query to an object id, not on an object property. – Mia Clarke Nov 26 '09 at 11:03
-1

Usually keys are integers and not strings. You are creating an Employee using just his name, perhaps the correct identifier to use is his employeeId. I need some more information on the table to know for sure.

Mike Pone
  • 18,705
  • 13
  • 53
  • 68
  • Hi Mike, thanks for your answer. The problem is I'm running some performance tests on the database using the pole position framework, and one of the tests in that framework requires me to fetch an object from the database using either an object reference or a low level object id. Thus, I'm not allowed to reference specific fields in the employee object, but must perform the query on the object in its entirety. So, it's not allowed for me to go "select * from Employee e where e.id = 4", I need it to use the entire object. – Mia Clarke Jun 06 '09 at 12:12
  • but you still need to atleast populate the key field. If the key field is EmployeeID then it needs to be populated in the object for this to work. Double check what the primary key(s) on the employee table are. – Mike Pone Jun 08 '09 at 16:03
  • It's an object database, so keys really aren't nessecary. – Mia Clarke Jun 09 '09 at 11:53