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 br...@apache.org on 2006/03/04 13:31:41 UTC
svn commit: r383101 -
/db/ojb/trunk/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
Author: brj
Date: Sat Mar 4 04:31:39 2006
New Revision: 383101
URL: http://svn.apache.org/viewcvs?rev=383101&view=rev
Log:
new testcase InheritanceMultipleTableTest#testLookupByIdentity_2
Modified:
db/ojb/trunk/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java?rev=383101&r1=383100&r2=383101&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java Sat Mar 4 04:31:39 2006
@@ -11,11 +11,14 @@
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
+import org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl;
import org.apache.ojb.broker.metadata.ClassDescriptor;
import org.apache.ojb.broker.query.Criteria;
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.query.QueryByCriteria;
import org.apache.ojb.broker.query.QueryFactory;
+import org.apache.ojb.broker.util.logging.LoggerFactory;
+import org.apache.ojb.broker.util.logging.PoorMansLoggerImpl;
import org.apache.ojb.junit.PBTestCase;
/**
@@ -81,6 +84,45 @@
assertEquals(ex1.getId(), newEx1.getId());
assertEquals(ex1.getId_2(), newEx1.getId_2());
+ }
+
+ /**
+ * Bug:
+ * this test show a problem when using table-per-subclass inheritance
+ * and method PB.getByIdentity. When the real class of the Identity is not
+ * correct the returned object has the wrong type. For table-per-class inheritance strategy
+ * this behavior will be correct, but in this case OJB should anyway detect the correct
+ * type of the result.
+ * Strange: When set logging property
+ * org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.LogLevel=DEBUG
+ * instead of WARN, the test will pass.
+ */
+ public void testLookupByIdentity_2()
+ {
+// PoorMansLoggerImpl logger = (PoorMansLoggerImpl) LoggerFactory.getLogger(SqlGeneratorDefaultImpl.class);
+// logger.setLevel("DEBUG");
+// logger.setLevel("WARN");
+
+ long timestamp = System.currentTimeMillis();
+ Long id_2 = new Long(timestamp);
+ String name = "testLookupByIdentity_2_" + timestamp;
+ Executive executive = new Executive(id_2, "executive_" + name, "department_1", null);
+
+ broker.beginTransaction();
+ broker.store(executive);
+ broker.commitTransaction();
+ broker.clearCache();
+
+ // we build the Identity with "wrong" real class specified
+ // (which is Executive, not Employee), but this shouldn't matter
+ // because OJB should detect the correct type on query
+ Identity oid = broker.serviceIdentity().buildIdentity(
+ Employee.class, new String[]{"id", "id_2"}, new Object[]{executive.getId(), executive.getId_2()});
+ Object result = broker.getObjectByIdentity(oid);
+
+ System.out.println("Result: " + result);
+ assertEquals(Executive.class.getName(), result.getClass().getName());
+ assertEquals(executive, result);
}
public void testQueryInheritancedObjects()
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org