I would have done the following, which does the same thing, but is more readable in my
mind;
public static void save(Object object) throws PersistenceBrokerException
{
PersistenceBroker pbroker = PersistenceBrokerFactory.defaultPersistenceBroker();
try
{
pbroker.beginTransaction();
pbroker.store(object);
pbroker.commitTransaction();
}
finally
{
/**
* transaction should be closed, if it's not, something went wrong
*/
if (pbroker != null && pbroker.isInTransaction())
{
pbroker.abortTransaction();
}
/**
* always close the broker
*/
if (pbroker != null)
{
pbroker.close();
}
}
}
but that's just me.
-----Original Message-----
From: Michael Wiessler [mailto:[EMAIL PROTECTED]
Sent: Sat 7/12/2003 3:10 PM
To: OJB Mailing List
Cc:
Subject: your comments on my example save()-Method
Hi there,
here is my proposal for an example save()-Method, using the
PersistenceBroker-API,
working with any oject.
I've put it in a class called BasicORMapper.
It seems to work quite stable.
I've implemented a delte() and several load()-Methods similar to this
save()-Method.
All methods are static.
What do you thik about this implementation ?
Would you do it in another way ?
Have I overseen any pitfalls ?
thank you for your feedback
Michael
following : the code ;)
----------------------------------------------------------------------------
--------------
public static void save(Object object) throws PersistenceBrokerException
{
// Get a broker from the Pool
PersistenceBroker pbroker =
PersistenceBrokerFactory.defaultPersistenceBroker();
if (pbroker.isInTransaction()) // Just to be sure ;)
{
pbroker.abortTransaction();
}
pbroker.beginTransaction(); // Starting the transaction
try
{
pbroker.store(object); // store the object
try
{
pbroker.commitTransaction(); // committing the
transaction
}
catch (TransactionAbortedException taex) // if not able
to commit
{
pbroker.abortTransaction(); // Start a roll-back
pbroker.close(); // close the broker - return
it to connection-pool
throw new PersistenceBrokerException();
}
}
catch (PersistenceBrokerException e) // If not able to store
{
pbroker.close(); // close the broker - return
it to
connection-pool
throw new PersistenceBrokerException();
}
pbroker.close(); // close the broker - return it to
connection-pool
}
----------------------------------------------------------------------------
--------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]