db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattba...@apache.org
Subject cvs commit: db-ojb/src/jca/org/apache/ojb/otm/connector OTMJCAConnection.java
Date Tue, 08 Jul 2003 22:41:48 GMT
mattbaird    2003/07/08 15:41:48

  Modified:    src/java/org/apache/ojb/otm OTMConnection.java
               src/test/org/apache/ojb/otm SwizzleTests.java
               src/java/org/apache/ojb/otm/core BaseConnection.java
               src/jca/org/apache/ojb/otm/connector OTMJCAConnection.java
  Log:
  - add invalidateAll functionality to OTM
  - add new swizzling test that shows failure
  
  Revision  Changes    Path
  1.9       +7 -0      db-ojb/src/java/org/apache/ojb/otm/OTMConnection.java
  
  Index: OTMConnection.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/otm/OTMConnection.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- OTMConnection.java	8 Jul 2003 06:05:36 -0000	1.8
  +++ OTMConnection.java	8 Jul 2003 22:41:47 -0000	1.9
  @@ -192,6 +192,12 @@
               throws LockingException;
   
   	/**
  +	 * clear the underlying caches
  +	 */
  +	public void invalidateAll()
  +			throws LockingException;
  +
  +	/**
   	 * returns a new OQL Query. This OQL query is Enhanced, meaning it does
   	 * the ODMG functionality as well as some additional OJB specific, non
   	 * portable functionality.
  @@ -210,4 +216,5 @@
        * Close the OTMConnection
        */
       public void close();
  +
   }
  
  
  
  1.6       +89 -2     db-ojb/src/test/org/apache/ojb/otm/SwizzleTests.java
  
  Index: SwizzleTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/otm/SwizzleTests.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SwizzleTests.java	28 Jun 2003 13:07:00 -0000	1.5
  +++ SwizzleTests.java	8 Jul 2003 22:41:48 -0000	1.6
  @@ -9,6 +9,8 @@
   import org.apache.ojb.otm.core.TransactionException;
   import org.apache.ojb.otm.lock.LockingException;
   import org.apache.ojb.otm.lock.LockType;
  +import org.apache.ojb.odmg.TestClassA;
  +import org.apache.ojb.odmg.TestClassB;
   
   import java.sql.Timestamp;
   import java.util.Iterator;
  @@ -60,7 +62,7 @@
   		Iterator it = _conn.getIteratorByQuery(q, LockType.WRITE_LOCK);
   		Object retval = null;
   		RelatedToContract r2c = new RelatedToContract();
  -		r2c.setPk("R2C"+TIME);
  +		r2c.setPk("R2C" + TIME);
   		r2c.setRelatedValue1("matt");
   		r2c.setRelatedValue2(34);
   		r2c.setRelatedValue3(new Timestamp(TIME));
  @@ -84,7 +86,7 @@
   			retval = it.next();
   		}
   		tx.commit();
  -		assertTrue("contract object should have a RelatedToContract instance attached", ((Effectiveness)retval).getVersion().getContract().getRelatedToContract()
!= null);
  +		assertTrue("contract object should have a RelatedToContract instance attached", ((Effectiveness)
retval).getVersion().getContract().getRelatedToContract() != null);
   	}
   
   	private void createTestData() throws TransactionException, LockingException
  @@ -165,5 +167,90 @@
   			_conn.deletePersistent(iter.next());
   		}
   		tx.commit();
  +	}
  +
  +	public void testSwizzle2() throws TransactionException, LockingException, PBFactoryException,
PersistenceBrokerException
  +	{
  +		clearTestData();
  +		TestClassA a = generateTestData();
  +		Transaction tx = _kit.getTransaction(_conn);
  +		tx.begin();
  +		_conn.makePersistent(a.getB());
  +		_conn.makePersistent(a);
  +		tx.commit();
  +		/**
  +		 * clear to start test
  +		 */
  +		_conn.invalidateAll();
  +		/**
  +		 * get A to make it and the related B in cache
  +		 */
  +		tx = _kit.getTransaction(_conn);
  +		tx.begin();
  +		Identity oid = _conn.getIdentity(a);
  +		TestClassA a1 = (TestClassA) _conn.getObjectByIdentity(oid);
  +		assertTrue(a1.getB() != null);
  +		assertTrue(a1.getB().getValue1().equals("hi there"));
  +		/**
  +		 * everything is good, update b
  +		 */
  +		tx.commit();
  +
  +		/**
  +		 * now get B and update it, do NOT get it by traversing A
  +		 */
  +		tx = _kit.getTransaction(_conn);
  +		tx.begin();
  +		Identity boid = _conn.getIdentity(a.getB());
  +		TestClassB b1 = (TestClassB) _conn.getObjectByIdentity(boid);
  +		assertTrue(b1 != null);
  +		assertTrue(b1.getValue1().equals("hi there"));
  +		/**
  +		 * everything is good, update b
  +		 */
  +		b1.setValue1("goodbye there");
  +		tx.commit();
  +
  +		/**
  +		 * now get A again and make sure the related B is updated to reflect
  +		 * the new value.
  +		 */
  +		tx = _kit.getTransaction(_conn);
  +		tx.begin();
  +		TestClassA a2 = (TestClassA) _conn.getObjectByIdentity(oid);
  +		assertTrue(a2.getB() != null);
  +		System.out.println("a2.getB().getValue1()" + a2.getB().getValue1());
  +		assertTrue(a2.getB().getValue1().equals("goodbye there"));
  +		tx.commit();
  +	}
  +
  +	private void clearTestData() throws LockingException
  +	{
  +		TestClassA a = generateTestData();
  +		Transaction tx = _kit.getTransaction(_conn);
  +		tx.begin();
  +		Identity oid = _conn.getIdentity(a);
  +		TestClassA a1 = (TestClassA) _conn.getObjectByIdentity(oid);
  +		if (a1 != null)
  +		{
  +			if (a1.getB() != null)
  +				_conn.deletePersistent(a1.getB());
  +			_conn.deletePersistent(a1);
  +		}
  +		tx.commit();
  +	}
  +
  +	private TestClassA generateTestData()
  +	{
  +		TestClassA tca = new TestClassA();
  +		tca.setOid("someoid");
  +		tca.setValue1("abc");
  +		tca.setValue2("123");
  +		tca.setValue3(5);
  +		TestClassB tcb = new TestClassB();
  +		tcb.setOid("boid");
  +		tcb.setValue1("hi there");
  +		tca.setB(tcb);
  +		return tca;
   	}
   }
  
  
  
  1.15      +10 -0     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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- BaseConnection.java	7 Jul 2003 22:54:15 -0000	1.14
  +++ BaseConnection.java	8 Jul 2003 22:41:48 -0000	1.15
  @@ -267,6 +267,16 @@
   
       }
   
  +	/**
  +	 * TODO remove all from editing context.
  +	 * @throws LockingException
  +	 */
  +	public void invalidateAll()
  +		throws LockingException
  +	{
  +		_pb.serviceObjectCache().clear();
  +	}
  +
       /**
        * @see org.apache.ojb.otm.OTMConnection#lockForWrite(Object)
        */
  
  
  
  1.5       +6 -0      db-ojb/src/jca/org/apache/ojb/otm/connector/OTMJCAConnection.java
  
  Index: OTMJCAConnection.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/jca/org/apache/ojb/otm/connector/OTMJCAConnection.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- OTMJCAConnection.java	2 Jul 2003 17:33:48 -0000	1.4
  +++ OTMJCAConnection.java	8 Jul 2003 22:41:48 -0000	1.5
  @@ -157,6 +157,12 @@
   		m_managedConnection.getConnection().invalidate(identity);
   	}
   
  +	public void invalidateAll() throws LockingException
  +	{
  +		isValidUnderlyingConnection();
  +		m_managedConnection.getConnection().invalidateAll();
  +	}
  +
   	public EnhancedOQLQuery newOQLQuery()
   	{
   		isValidUnderlyingConnection();
  
  
  

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


Mime
View raw message