Ok,
Right now I get the object to marshall using OOLQuery.execute() which binds
to the transaction it's called in. I had a look at the load method in the
API docs. I don't see anything in the api describing how to use it or the
Complex object required for the identity.
Is there an example around that uses it?
Here's how my data service is structured now. If I could do the equivalent
with load(...) then it sounds worth a try.
In my xsp page i call:
MyLib.getInstance().createObject("my.packages.className", 55);
Here's the defn:
public class MyLib {
// - use getInstance to get the singleton
// ... initialization and other methods ...
public DocumentFragment getById(String className, int id) {
DocumentFragment frag = document.createDocumentFragment();
try {
db = jdo.getDatabase();
Marshaller marshal = new Marshaller( frag );
marshal.setMapping( mapping );
db.begin();
Object obj = getObjectById( className, id );
if( obj != null ) marshal.marshal( obj );
else {
int ndx = className.lastIndexOf('.');
String shortName = (ndx >= 0) ? className.substring(ndx+1) :
className;
frag.appendChild( createErrorElement("There is no "+
shortName +" with id = "+ id +".") );
}
db.commit();
}
catch (Exception e) { frag.appendChild(createErrorElement(e)); }
finally {
try {
db.close();
}
catch (Exception close_e) {
}
return frag;
}
}
protected Object getObjectById(String className, int id )
throws QueryException, PersistenceException {
if ( !className.startsWith("my.packages") )
className = "my.packages." + className;
Object result = null;
OQLQuery oqlQuery = db.getOQLQuery( "SELECT x FROM "+ className +" x
WHERE id = $1" );
oqlQuery.bind(id);
QueryResults results = oqlQuery.execute();
if( results.hasMore() ) result = results.next();
results.close();
oqlQuery.close();
return result;
}
}//MyLib
-----Original Message-----
From: dom [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 25, 2002 3:01 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] LockNotGrantedException
this will only work if you only want to display an object e.i. read it
Put back the begin and commit. It might without but I haven't tried.
When you use load specify the access mode as readonly
Look at the javadoc of ...jdo.Database.load(type,identiry, accessMode)
The accessMode should be Database.ReadOnly, this will exclude your object
from the transaction
If you know you're going to manipulate the object check it out in Exclusive
or Shared
Exclusive will lock up your object so it will slow down your app but at
least you'll know that you have it locked
-dom
----- Original Message -----
From: Richard Lawson <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, January 25, 2002 6:43 PM
Subject: Re: [castor-dev] LockNotGrantedException
> Thanks,
> I gave it a spin. I have a general method to retrieve objects by their id
so
> I commented out the Database.begin() and Database.commit() lines and got a
> new error: "No transaction in progress for the current thread
> org.exolab.castor.jdo.TransactionNotInProgressException".
>
> I don't have the luxury of marking some objects read-only in the mapping
> file. Most times i want to read a product object, but sometimes I want to
> update it. Maybe I'm missing the point.
> - rich
>
>
> -----Original Message-----
> From: dom [mailto:[EMAIL PROTECTED]]
> Sent: Friday, January 25, 2002 2:06 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [castor-dev] LockNotGrantedException
>
>
> for objects that you know you're only going to read you could load them
> outside of a transaction all together
> by specifying READ ONLY access. that way your objects will not use any
locks
>
> -dom
> ----- Original Message -----
> From: Richard Lawson <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, January 25, 2002 5:53 PM
> Subject: [castor-dev] LockNotGrantedException
>
>
> > Hi folks,
> > I've inherited a project that uses JDO to persist objects to the
database
> > and do the marshalling/unmarshalling between the java objects and the
> > DocumentFragements that represent them. I'm new to this, but it seems a
> > pretty good strategy so far.
> >
> > The problem is that I have deeply nested collections and quite often the
> > users get LockNotGrantedException when trying to commit objects.
> > I understand that this can happen when there are read locks in other
> > instances and your transaction tries to aquire a write lock. Is is
> possible
> > that the read locks are not being released?
> >
> > Also, in the cases when I know that the user will only be reading and I
> have
> > created the xml for their UI, how can i make sure that the object is
> > destroyed and the lock released?
> >
> > Any help would be a godsend. - thanks in advance
> >
> > Richard Lawson
> > email: [EMAIL PROTECTED]
> >
> > -----------------------------------------------------------
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> > unsubscribe castor-dev
> >
> >
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev