Question

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?

Was it helpful?

Solution

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);

OTHER TIPS

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top