Author: brj
Date: Sun Feb 5 08:40:23 2006
New Revision: 375054
URL: http://svn.apache.org/viewcvs?rev=375054&view=rev
Log:
added testcase for ojb-94
Modified:
db/ojb/trunk/src/test/org/apache/ojb/broker/InheritanceMultipleTableTest.java
db/ojb/trunk/src/test/org/apache/ojb/repository_junit_inheritance.xml
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=375054&r1=375053&r2=375054&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
Sun Feb 5 08:40:23 2006
@@ -406,6 +406,60 @@
assertEquals(shareholder, result.iterator().next());
}
+ public void testQuery_2() throws Exception
+ {
+ long timestamp = System.currentTimeMillis();
+ Long id_2 = new Long(timestamp);
+ String name = "testInheritedReferences_" + timestamp;
+
+ Manager s1 = new Manager(id_2, name + "_Manager");
+ s1.setAddress(new Address(name + "_street_12"));
+ s1.addExecutive(new Executive(id_2, name + "_s1_1", null, s1));
+ s1.addExecutive(new Executive(id_2, name + "_s1_2", null, s1));
+
+ Manager s2 = new Manager(id_2, name + "_Manager");
+ s2.setAddress(new Address(name + "_street_333"));
+
+ Consortium consortium = new Consortium();
+ consortium.setName(name);
+ consortium.addManager(s1);
+ consortium.addManager(s2);
+
+ Identity oidCon;
+ Identity oidSH;
+ broker.beginTransaction();
+ broker.store(consortium);
+ broker.commitTransaction();
+ oidCon = broker.serviceIdentity().buildIdentity(consortium);
+ oidSH = broker.serviceIdentity().buildIdentity(s1);
+
+ broker.clearCache();
+ Consortium con = (Consortium) broker.getObjectByIdentity(oidCon);
+ assertNotNull(con);
+ assertNotNull(con.getManagers());
+ 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());
+ broker.clearCache();
+
+ Criteria crit = new Criteria()
+ .addEqualTo("name", consortium.getName())
+ .addEqualTo("managers.executives.address.street", name +
"_street_12")
+ .addEqualTo("managers.name", name + "_Manager");
+ 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());
+ assertEquals(consortium.getManagers().size(),
con2.getManagers().size());
+ }
+
public void testStoreDelete_2()
{
long timestamp = System.currentTimeMillis();
@@ -1377,6 +1431,15 @@
this.executives = executives;
}
+ public void addExecutive(Executive ex)
+ {
+ if(this.executives == null)
+ {
+ this.executives = new ArrayList();
+ }
+ this.executives.add(ex);
+ }
+
public Integer getConsortiumKey()
{
return consortiumKey;
@@ -1652,6 +1715,7 @@
private Integer id;
private String name;
private List shareholders;
+ private List managers;
public Consortium()
{
@@ -1687,6 +1751,15 @@
this.shareholders = shareholders;
}
+ public void addShareholder(Shareholder sh)
+ {
+ if(this.shareholders == null)
+ {
+ this.shareholders = new ArrayList();
+ }
+ this.shareholders.add(sh);
+ }
+
public boolean equals(Object obj)
{
if (!(obj instanceof Consortium))
@@ -1705,6 +1778,32 @@
{
return ToStringBuilder.reflectionToString(this,
ToStringStyle.MULTI_LINE_STYLE, false, Consortium.class);
}
+
+ /**
+ * @return the managers
+ */
+ public List getManagers()
+ {
+ return managers;
+ }
+
+ /**
+ * @param managers the managers to set
+ */
+ public void setManagers(List managers)
+ {
+ this.managers = managers;
+ }
+
+ public void addManager(Manager manager)
+ {
+ if(this.managers == null)
+ {
+ this.managers = new ArrayList();
+ }
+ this.managers.add(manager);
+ }
+
}
public static class Entity
Modified: db/ojb/trunk/src/test/org/apache/ojb/repository_junit_inheritance.xml
URL:
http://svn.apache.org/viewcvs/db/ojb/trunk/src/test/org/apache/ojb/repository_junit_inheritance.xml?rev=375054&r1=375053&r2=375054&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/repository_junit_inheritance.xml
(original)
+++ db/ojb/trunk/src/test/org/apache/ojb/repository_junit_inheritance.xml Sun
Feb 5 08:40:23 2006
@@ -288,6 +288,18 @@
>
<inverse-foreignkey field-ref="consortiumKey"/>
</collection-descriptor>
+
+ <collection-descriptor
+ name="managers"
+
element-class-ref="org.apache.ojb.broker.InheritanceMultipleTableTest$Manager"
+ proxy="false"
+ auto-retrieve="true"
+ auto-update="object"
+ auto-delete="object"
+ >
+ <inverse-foreignkey field-ref="consortiumKey"/>
+ </collection-descriptor>
+
</class-descriptor>
<class-descriptor
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]