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 ol...@apache.org on 2003/05/15 00:16:34 UTC
cvs commit: db-ojb/src/test/org/apache/ojb/otm OtmExamples.java
olegnitz 2003/05/14 15:16:34
Modified: src/test/org/apache/ojb spy.properties
src/test/org/apache/ojb/otm OtmExamples.java
Log:
Cache tests added
Revision Changes Path
1.3 +3 -0 db-ojb/src/test/org/apache/ojb/spy.properties
Index: spy.properties
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/spy.properties,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- spy.properties 15 Feb 2003 17:49:26 -0000 1.2
+++ spy.properties 14 May 2003 22:16:33 -0000 1.3
@@ -53,6 +53,9 @@
# the mysql open source driver
#realdriver=org.gjt.mm.mysql.Driver
+# the mysql open source driver
+#realdriver=org.postgresql.Driver
+
# the hsqldb jdbc driver (OJB testsuite and tutorials)
realdriver=org.hsqldb.jdbcDriver
1.5 +69 -0 db-ojb/src/test/org/apache/ojb/otm/OtmExamples.java
Index: OtmExamples.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/otm/OtmExamples.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- OtmExamples.java 19 Mar 2003 06:52:00 -0000 1.4
+++ OtmExamples.java 14 May 2003 22:16:33 -0000 1.5
@@ -3,8 +3,10 @@
import junit.framework.TestCase;
import org.apache.ojb.broker.Article;
+import org.apache.ojb.broker.ProductGroup;
import org.apache.ojb.broker.Identity;
import org.apache.ojb.broker.PersistenceBrokerFactory;
+import org.apache.ojb.otm.core.BaseConnection;
import org.apache.ojb.otm.core.Transaction;
import org.apache.ojb.otm.kit.SimpleKit;
@@ -54,12 +56,79 @@
Identity oid = _conn.getIdentity(example);
+ // get from the cache
tx = _kit.getTransaction(_conn);
tx.begin();
example = (Article) _conn.getObjectByIdentity(oid);
assertEquals("should be equal", 7, example.getProductGroupId());
assertEquals("should be equal", 333, example.getStock());
+ tx.commit();
+
+ // get from the database
+ tx = _kit.getTransaction(_conn);
+ ((BaseConnection) _conn).getKernelBroker().clearCache();
+ tx.begin();
+ example = (Article) _conn.getObjectByIdentity(oid);
+ assertEquals("should be equal", 7, example.getProductGroupId());
+ assertEquals("should be equal", 333, example.getStock());
_conn.deletePersistent(example);
+ tx.commit();
+ }
+ catch (Exception ex)
+ {
+ try
+ {
+ if (tx != null && tx.isInProgress())
+ {
+ tx.rollback();
+ }
+ }
+ catch (Exception ex2)
+ {
+ }
+ throw ex;
+ }
+ }
+
+ public void testOtmCache() throws Exception
+ {
+ Transaction tx = null;
+
+ //perform transaction
+ try
+ {
+ tx = _kit.getTransaction(_conn);
+ tx.begin();
+
+ Article article = Article.createInstance();
+ article.setArticleId(77777);
+ article.setStock(333);
+ ProductGroup pg = new ProductGroup();
+ pg.setId(77777);
+ pg.setName("1");
+ pg.add(article);
+ article.setProductGroup(pg);
+ _conn.makePersistent(pg);
+ _conn.makePersistent(article);
+
+ tx.commit();
+
+ Identity aOid = _conn.getIdentity(article);
+ Identity pgOid = _conn.getIdentity(pg);
+
+ tx = _kit.getTransaction(_conn);
+ tx.begin();
+ pg = (ProductGroup) _conn.getObjectByIdentity(pgOid);
+ pg.setName("2");
+ tx.rollback();
+
+ tx = _kit.getTransaction(_conn);
+ tx.begin();
+ article = (Article) _conn.getObjectByIdentity(aOid);
+ pg = (ProductGroup) article.getProductGroup();
+ assertEquals("should be equal", "1", pg.getName());
+ _conn.deletePersistent(article);
+ _conn.deletePersistent(pg);
tx.commit();
}
catch (Exception ex)