Author: arminw
Date: Sun Nov 12 10:18:49 2006
New Revision: 474007
URL: http://svn.apache.org/viewvc?view=rev&rev=474007
Log:
modify test, add test
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml?view=diff&rev=474007&r1=474006&r2=474007
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml Sun Nov 12 10:18:49 2006
@@ -1833,44 +1833,64 @@
<column name="DESCRIPTION" type="VARCHAR" size="250"/>
</table>
- <table name="FIRST_">
+ <table name="TPS_FIRST">
<column
name="ID_"
type="INTEGER"
primaryKey="true"/>
<column
- name="NAME"
- type="VARCHAR"/>
+ name="NAME_"
+ type="VARCHAR"
+ size="250"/>
</table>
- <table name="SECOND_">
+ <table name="TPS_SECOND">
<column
name="ID_"
type="INTEGER"
primaryKey="true"/>
<column
- name="SECOND"
- type="VARCHAR"/>
- <column
+ name="SECOND_"
+ type="VARCHAR"
+ size="250"/>
+ <column
name="FIRST_FK"
type="INTEGER"/>
- <foreign-key foreignTable="FIRST_">
+ <foreign-key foreignTable="TPS_FIRST">
<reference local="FIRST_FK" foreign="ID_"/>
</foreign-key>
</table>
- <table name="THIRD_">
+ <table name="TPS_THIRD">
<column
name="ID_"
type="INTEGER"
primaryKey="true"/>
<column
- name="THIRD"
- type="VARCHAR"/>
+ name="THIRD_"
+ type="VARCHAR"
+ size="250"/>
+ <column
+ name="SECOND_FK"
+ type="INTEGER"/>
+ <foreign-key foreignTable="TPS_SECOND">
+ <reference local="SECOND_FK" foreign="ID_"/>
+ </foreign-key>
+ </table>
+
+ <table name="TPS_FOURTH">
+ <column
+ name="ID_"
+ type="INTEGER"
+ primaryKey="true"/>
<column
+ name="FOURTH_"
+ type="VARCHAR"
+ size="250"/>
+ <column
name="THIRD_FK"
type="INTEGER"/>
- <foreign-key foreignTable="THIRD_">
+ <foreign-key foreignTable="TPS_THIRD">
<reference local="THIRD_FK" foreign="ID_"/>
</foreign-key>
</table>
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java?view=diff&rev=474007&r1=474006&r2=474007
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java Sun Nov 12 10:18:49 2006
@@ -148,7 +148,7 @@
crit.addEqualTo("name", "manager_" + name);
q = QueryFactory.newQuery(Employee.class, crit);
Manager newM1 = (Manager) broker.getObjectByQuery(q);
-
+
broker.clearCache();
assertNotNull(newEm1);
@@ -178,7 +178,7 @@
// store company with Employee/Executive/Manager
Company company = prepareTestDataWithCompany(name);
Long id_2 = company.getId();
-
+
// add Shareholder too
Shareholder shareholder = new Shareholder(id_2, name);
shareholder.setShare(77);
@@ -272,9 +272,9 @@
String name = "testQueryInheritancedObjectsByPk_" + timestamp;
Long id_2 = new Long(timestamp);
- List insertedObjs = prepareForQueryTests(id_2, name);
+ List insertedObjs = prepareForQueryTests(id_2, name);
- // add Shareholder
+ // add Shareholder
Shareholder shareholder = new Shareholder(id_2, name);
shareholder.setShare(77);
shareholder.setDepartment("none");
@@ -284,7 +284,7 @@
broker.beginTransaction();
broker.store(shareholder);
broker.commitTransaction();
-
+
broker.clearCache();
Employee emp1;
@@ -306,7 +306,7 @@
assertNotNull(retrievedEmp);
assertSame(Executive.class, retrievedEmp.getClass());
assertEquals(emp1, retrievedEmp);
-
+
// retrieve Employee by pk
emp1 = (Employee) insertedObjs.get(5);
ident = broker.serviceIdentity().buildIdentity(emp1);
@@ -379,7 +379,7 @@
List newEmployees = newCompany.getEmployees();
assertNotNull(newEmployees);
assertEquals(company.getEmployees().size(), newEmployees.size());
-
+
List newExecutives = newCompany.getExecutives();
assertNotNull(newExecutives);
assertEquals(company.getExecutives().size(), newExecutives.size());
@@ -525,7 +525,7 @@
assertEquals(consortium.getId(), con.getId());
assertEquals(consortium.getName(), con.getName());
assertEquals(consortium.getManagers().size(), con.getManagers().size());
-
+
broker.clearCache();
Manager s1_new = (Manager) broker.getObjectByIdentity(oidSH);
assertNotNull(s1_new.getConsortiumKey());
@@ -538,7 +538,7 @@
Query q = QueryFactory.newQuery(Consortium.class, crit, true);
Collection result = broker.getCollectionByQuery(q);
assertEquals(1, result.size());
-
+
Consortium con2 = (Consortium) result.iterator().next();
assertEquals(consortium.getId(), con2.getId());
assertEquals(consortium.getName(), con2.getName());
@@ -906,7 +906,7 @@
private List prepareForQueryTests(Long id_2, String name)
{
List result = new ArrayList();
-
+
Manager m_1 = new Manager(id_2, name + "_manager_1");
Manager m_2 = new Manager(id_2, name + "_manager_2");
Manager m_3 = new Manager(id_2, name + "_manager_3");
@@ -936,7 +936,7 @@
broker.store(ex_2);
broker.store(em);
broker.commitTransaction();
-
+
return result;
}
@@ -965,14 +965,14 @@
executives.add(m_3);
executives.add(ex_1);
executives.add(ex_2);
-
+
Company company = new Company(null, name, employees, executives);
broker.beginTransaction();
broker.store(company);
broker.commitTransaction();
return company;
}
-
+
public void testQuery_InheritedObjects()
{
long timestamp = System.currentTimeMillis();
@@ -1116,13 +1116,13 @@
String name = "testQuery_ReferenceOuterJoin_" + timestamp;
prepareTestDataWithCompany(name);
//Long id_2 = company.getId();
-
+
// Store a dummy company
Company dummyComp = new Company(null, name + "_dummy", Collections.EMPTY_LIST, Collections.EMPTY_LIST);
broker.beginTransaction();
broker.store(dummyComp);
broker.commitTransaction();
-
+
broker.clearCache();
Criteria crit = new Criteria();
@@ -1149,7 +1149,7 @@
// should retrieve both companies
assertEquals(2, result.size());
}
-
+
public void testInsertQuery()
{
long timestamp = System.currentTimeMillis();
@@ -1457,15 +1457,74 @@
assertNull(newSecond);
assertNull(newThird);
}
+
+ public void testInheritanceViaAnonymousField_Serialized_1()
+ {
+ long timestamp = System.currentTimeMillis();
+ String name = "testInheritanceViaAnonymousField_Serialized_1_" + timestamp;
+ String t_name = "third_" + name;
+
+ Third third = new Third(t_name);
+ third.setThird("third");
+ third.setSecond("second");
+
+ broker.beginTransaction();
+ broker.store(third);
+ broker.commitTransaction();
+
+ Identity oid_3 = broker.serviceIdentity().buildIdentity(third);
+
+ broker.clearCache();
+
+ Third newThird = (Third) broker.getObjectByIdentity(oid_3);
+
+ assertNotNull(newThird);
+ assertEquals(t_name, newThird.getName());
+ assertEquals("third", third.getThird());
+ assertEquals("second", third.getSecond());
+
+ newThird.setName(newThird.getName() + "_updated");
+ newThird.setThird("third_updated");
+ newThird.setSecond("second_updated");
+
+ newThird = (Third) SerializationUtils.clone(newThird);
- public void testInsertDeletePerSubClassViaFK_Serialized()
+ broker.beginTransaction();
+ broker.store(newThird);
+ broker.commitTransaction();
+
+ broker.clearCache();
+
+ newThird = (Third) broker.getObjectByIdentity(oid_3);
+
+ assertNotNull(newThird);
+ assertEquals(t_name + "_updated", newThird.getName());
+ assertEquals("second_updated", newThird.getSecond());
+ assertEquals("third_updated", newThird.getThird());
+
+ newThird = (Third) SerializationUtils.clone(newThird);
+
+ broker.beginTransaction();
+ broker.delete(newThird);
+ broker.commitTransaction();
+
+ newThird = (Third) broker.getObjectByIdentity(oid_3);
+
+ assertNull(newThird);
+ }
+
+ public void testInheritanceViaAnonymousField_Serialized_2()
{
long timestamp = System.currentTimeMillis();
- String name = "testInsertDeletePerSubClassViaFK_Serialized_" + timestamp;
- First first = new First("first_" + name);
- Second second = new Second("second_" + name);
+ String name = "testInheritanceViaAnonymousField_2_" + timestamp;
+ String f_name = "first_" + name;
+ String s_name = "second_" + name;
+ String t_name = "third_" + name;
+
+ First first = new First(f_name);
+ Second second = new Second(s_name);
second.setSecond("second");
- Third third = new Third("third_" + name);
+ Third third = new Third(t_name);
third.setThird("third");
broker.beginTransaction();
@@ -1487,14 +1546,17 @@
assertNotNull(newFirst);
assertNotNull(newSecond);
assertNotNull(newThird);
+ assertEquals(f_name, newFirst.getName());
+ assertEquals(s_name, newSecond.getName());
+ assertEquals(t_name, newThird.getName());
assertEquals("second", second.getSecond());
assertEquals("third", third.getThird());
assertNull(third.getSecond());
- newFirst.setName(name + "_updated");
- newSecond.setName(name + "_updated");
+ newFirst.setName(newFirst.getName() + "_updated");
+ newSecond.setName(newSecond.getName() + "_updated");
newSecond.setSecond("second_updated");
- newThird.setName(name + "_updated");
+ newThird.setName(newThird.getName() + "_updated");
newThird.setThird("third_updated");
newThird.setSecond("third");
@@ -1517,13 +1579,32 @@
assertNotNull(newFirst);
assertNotNull(newSecond);
assertNotNull(newThird);
- assertEquals(name + "_updated", newFirst.getName());
- assertEquals(name + "_updated", newSecond.getName());
- assertEquals(name + "_updated", newThird.getName());
+ assertEquals(f_name + "_updated", newFirst.getName());
+ assertEquals(s_name + "_updated", newSecond.getName());
+ assertEquals(t_name + "_updated", newThird.getName());
assertEquals("second_updated", newSecond.getSecond());
assertEquals("third_updated", newThird.getThird());
assertEquals("third", newThird.getSecond());
+ Criteria c = new Criteria().addLike("name", "%" + name + "%");
+ Query q = QueryFactory.newQuery(First.class, c);
+ Collection result = broker.getCollectionByQuery(q);
+ assertEquals(3, result.size());
+ int count = 0;
+ for(Iterator iterator = result.iterator(); iterator.hasNext();)
+ {
+ Object o = iterator.next();
+ if(o instanceof Second)
+ {
+ count+=1;
+ if(o instanceof Third)
+ {
+ count+=7;
+ }
+ }
+ }
+ assertEquals("Wrong instances returned, expect First, Second, Third", 9, count);
+
newFirst = (First) SerializationUtils.clone(newFirst);
newSecond = (Second) SerializationUtils.clone(newSecond);
newThird = (Third) SerializationUtils.clone(newThird);
@@ -1543,6 +1624,70 @@
assertNull(newThird);
}
+ public void testInheritanceViaAnonymousField_Serialized_3()
+ {
+ if(ojbSkipKnownIssueProblem("Table-per-subclass inheritance issue, when field was overridden in sub-class"))
+ {
+ return;
+ }
+ long timestamp = System.currentTimeMillis();
+ String name = "testInheritanceViaAnonymousField_3_" + timestamp;
+ String t_name = "fourth_" + name;
+
+ Fourth fourth = new Fourth(t_name);
+ fourth.setFourth("fourth");
+ fourth.setThird("third");
+ fourth.setSecond("second");
+
+ broker.beginTransaction();
+ broker.store(fourth);
+ broker.commitTransaction();
+
+ Identity oid_3 = broker.serviceIdentity().buildIdentity(fourth);
+
+ broker.clearCache();
+
+ Fourth newFourth = (Fourth) broker.getObjectByIdentity(oid_3);
+
+ assertNotNull(newFourth);
+ assertEquals(t_name, newFourth.getName());
+ assertEquals("fourth", fourth.getFourth());
+ assertEquals("third", fourth.getThird());
+ assertEquals("second", fourth.getSecond());
+
+ newFourth.setName(newFourth.getName() + "_updated");
+ newFourth.setFourth("fourth_updated");
+ newFourth.setThird("third_updated");
+ newFourth.setSecond("second_updated");
+
+ newFourth = (Fourth) SerializationUtils.clone(newFourth);
+
+ broker.beginTransaction();
+ broker.store(newFourth);
+ broker.commitTransaction();
+
+ broker.clearCache();
+
+ newFourth = (Fourth) broker.getObjectByIdentity(oid_3);
+
+ assertNotNull(newFourth);
+ assertEquals(t_name + "_updated", newFourth.getName());
+ assertEquals("second_updated", newFourth.getSecond());
+ assertEquals("third_updated", newFourth.getThird());
+ assertEquals("fourth_updated", newFourth.getFourth());
+
+ newFourth = (Fourth) SerializationUtils.clone(newFourth);
+
+ broker.beginTransaction();
+ broker.delete(newFourth);
+ broker.commitTransaction();
+
+ newFourth = (Fourth) broker.getObjectByIdentity(oid_3);
+
+ assertNull(newFourth);
+ }
+
+
// /**
// * TODO: Should we support some kind of "declarative inheritance"? This test
// * try to use this kind of inheritance as class Dog expects some fields from a
@@ -2375,7 +2520,7 @@
public static class First implements Serializable
{
- private Integer id;
+ private int id;
private String name;
public First()
@@ -2387,12 +2532,12 @@
this.name = name;
}
- public Integer getId()
+ public int getId()
{
return id;
}
- public void setId(Integer id)
+ public void setId(int id)
{
this.id = id;
}
@@ -2410,6 +2555,19 @@
public static class Second extends First
{
+// //!! override field not allowed !!
+// private int id;
+// public int getId()
+// {
+// return id;
+// }
+//
+// public void setId(int id)
+// {
+// this.id = id;
+// }
+// //!!!!!
+
private String second;
public Second()
@@ -2434,6 +2592,19 @@
public static class Third extends Second
{
+// //!! override field not allowed !!
+// private int id;
+// public int getId()
+// {
+// return id;
+// }
+//
+// public void setId(int id)
+// {
+// this.id = id;
+// }
+// //!!!!!
+
private String third;
public Third()
@@ -2453,6 +2624,45 @@
public void setThird(String third)
{
this.third = third;
+ }
+ }
+
+ public static class Fourth extends Third
+ {
+ //##################################
+ //!! override field to show issue !!
+ private int id;
+ public int getId()
+ {
+ return id;
+ }
+
+ public void setId(int id)
+ {
+ this.id = id;
+ }
+ //!!!!!
+ //####################################
+
+ private String fourth;
+
+ public Fourth()
+ {
+ }
+
+ public Fourth(String name)
+ {
+ super(name);
+ }
+
+ public String getFourth()
+ {
+ return fourth;
+ }
+
+ public void setFourth(String fourth)
+ {
+ this.fourth = fourth;
}
}
}
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml?view=diff&rev=474007&r1=474006&r2=474007
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit_inheritance.xml Sun Nov 12 10:18:49 2006
@@ -426,7 +426,7 @@
<class-descriptor
class="org.apache.ojb.broker.InheritanceMultipleTableTest$First"
- table="FIRST_"
+ table="TPS_FIRST"
>
<field-descriptor
name="id"
@@ -437,7 +437,7 @@
/>
<field-descriptor
name="name"
- column="NAME"
+ column="NAME_"
jdbc-type="VARCHAR"
/>
</class-descriptor>
@@ -445,18 +445,18 @@
<class-descriptor
class="org.apache.ojb.broker.InheritanceMultipleTableTest$Second"
- table="SECOND_"
+ table="TPS_SECOND"
>
<field-descriptor
name="id"
column="ID_"
jdbc-type="INTEGER"
primarykey="true"
- autoincrement="true"
+ autoincrement="false"
/>
<field-descriptor
name="second"
- column="SECOND"
+ column="SECOND_"
jdbc-type="VARCHAR"
/>
<field-descriptor
@@ -474,19 +474,50 @@
<class-descriptor
class="org.apache.ojb.broker.InheritanceMultipleTableTest$Third"
- table="THIRD_"
+ table="TPS_THIRD"
>
<field-descriptor
name="id"
column="ID_"
jdbc-type="INTEGER"
primarykey="true"
- autoincrement="true"
+ autoincrement="false"
/>
<field-descriptor
name="third"
- column="THIRD"
+ column="THIRD_"
+ jdbc-type="VARCHAR"
+ />
+
+ <field-descriptor
+ name="secondFk"
+ column="SECOND_FK"
+ jdbc-type="INTEGER"
+ access="anonymous"
+ />
+
+ <reference-descriptor name="super"
+ class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Second"
+ >
+ <foreignkey field-ref="secondFk"/>
+ </reference-descriptor>
+</class-descriptor>
+<class-descriptor
+ class="org.apache.ojb.broker.InheritanceMultipleTableTest$Fourth"
+ table="TPS_FOURTH"
+>
+ <field-descriptor
+ name="id"
+ column="ID_"
+ jdbc-type="INTEGER"
+ primarykey="true"
+ autoincrement="false"
+ />
+
+ <field-descriptor
+ name="fourth"
+ column="FOURTH_"
jdbc-type="VARCHAR"
/>
@@ -498,7 +529,7 @@
/>
<reference-descriptor name="super"
- class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Second"
+ class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Third"
>
<foreignkey field-ref="thirdFk"/>
</reference-descriptor>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.