You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ma...@apache.org on 2004/02/05 19:33:29 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/otm/core BaseConnection.java

mattbaird    2004/02/05 10:33:29

  Modified:    src/java/org/apache/ojb/otm/core BaseConnection.java
  Log:
  add better error checking/reporting if no transaction exists, or transaction hasn't been started.
  
  Revision  Changes    Path
  1.27      +29 -6     db-ojb/src/java/org/apache/ojb/otm/core/BaseConnection.java
  
  Index: BaseConnection.java
  ===================================================================
  RCS file: /home/cvs//db-ojb/src/java/org/apache/ojb/otm/core/BaseConnection.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- BaseConnection.java	13 Sep 2003 23:50:40 -0000	1.26
  +++ BaseConnection.java	5 Feb 2004 18:33:29 -0000	1.27
  @@ -89,6 +89,7 @@
    *
    * <javadoc>
    *
  + * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird</a>
    * @author <a href="mailto:rraghuram@hotmail.com">Raghu Rajah</a>
    *
    */
  @@ -138,7 +139,7 @@
           else if (_tx != null)
           {
               throw new IllegalStateException(
  -                    "OTMConnection is already bound to the transactaction "
  +                    "OTMConnection is already bound to the transacaction "
                       + _tx);
           }
           else
  @@ -182,7 +183,8 @@
       public Object getObjectByIdentity(Identity oid, int lock)
           throws LockingException
       {
  -        Object object;
  +		checkTransaction("getObjectByIdentity");
  +		Object object;
           ObjectCopyStrategy copyStrategy;
   
           object = _editingContext.lookup(oid);
  @@ -208,7 +210,19 @@
           return object;
       }
   
  -    /**
  +	private void checkTransaction(String methodBeingCalled)
  +	{
  +		if (null==_tx)
  +		{
  +			throw new TransactionNotInProgressException(methodBeingCalled + " requires a valid transaction. Please make sure you have created a new transaction, and called begin() on it.");
  +		}
  +		if (!_tx.isInProgress())
  +		{
  +			throw new TransactionNotInProgressException(methodBeingCalled + " cannot be called before transaction begin() is called");
  +		}
  +	}
  +
  +	/**
        * @see org.apache.ojb.otm.OTMConnection#getObjectByIdentity(Identity)
        */
       public Object getObjectByIdentity(Identity oid)
  @@ -240,6 +254,7 @@
        */
       public Iterator getIteratorByQuery(Query query, int lock)
       {
  +		checkTransaction("getIteratorByQuery");
           return new OTMIterator(_pb.getIteratorByQuery(query), lock, null);
       }
   
  @@ -262,6 +277,7 @@
        */
       public Iterator getIteratorByOQLQuery(OQLQuery query, int lock)
       {
  +		checkTransaction("getIteratorByOQLQuery");
           if (query instanceof OTMOQLQueryImpl)
           {
               OTMOQLQueryImpl q = (OTMOQLQueryImpl) query;
  @@ -286,8 +302,8 @@
        */
       public Collection getCollectionByQuery(Query query, int lock)
       {
  +		checkTransaction("getCollectionByQuery");
           Collection col = _pb.getCollectionByQuery(query);
  -
           for (Iterator it = col.iterator(); it.hasNext(); )
           {
               insertObject(it.next(), lock);
  @@ -331,6 +347,10 @@
       public void invalidate(Identity oid)
               throws LockingException
       {
  +		if (null==_tx)
  +		{
  +			throw new TransactionNotInProgressException( "invalidate requires a valid transaction. Please make sure you have created a new transaction, and called begin() on it.");
  +		}
           // lock for write and mark as invalidated in the editing context
           _editingContext.insert(oid, null, LockType.WRITE_LOCK);
   
  @@ -363,8 +383,8 @@
       public void lockForWrite(Object object)
           throws LockingException
       {
  +		checkTransaction("lockForWrite");
           Identity oid = new Identity(object, _pb);
  -
           _editingContext.insert(oid, object, LockType.WRITE_LOCK);
       }
   
  @@ -374,6 +394,7 @@
       public void makePersistent(Object object)
           throws LockingException
       {
  +		checkTransaction("makePersistent");
           Identity oid = new Identity(object, _pb);
           _editingContext.insert(oid, object, LockType.READ_LOCK);
       }
  @@ -384,8 +405,8 @@
       public void deletePersistent(Object object)
           throws LockingException
       {
  +		checkTransaction("deletePersistent");
           Identity oid = new Identity(object, _pb);
  -
           _editingContext.deletePersistent(oid, object);
       }
   
  @@ -401,6 +422,7 @@
   
       public EnhancedOQLQuery newOQLQuery(int lock)
       {
  +		checkTransaction("newOQLQuery");
           OQLQueryImpl query = new OTMOQLQueryImpl(_pb.getPBKey(), lock);
           try
           {
  @@ -415,6 +437,7 @@
   
       public int getCount(Query query)
       {
  +		checkTransaction("getCount");
           return _pb.getCount(query);
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org