Index: src/conf/companyMapWithoutJoin.conf =================================================================== --- src/conf/companyMapWithoutJoin.conf (revision 0) +++ src/conf/companyMapWithoutJoin.conf (revision 0) @@ -0,0 +1,7 @@ +jdo.tck.description = Completeness test with companyMapWithoutJoin model. +jdo.tck.mapping.companyfactory = org.apache.jdo.tck.pc.companyMapWithoutJoin.CompanyFactoryPMClass +jdo.tck.testdata = org/apache/jdo/tck/pc/companyMapWithoutJoin/companyMapWithoutJoin.xml +jdo.tck.standarddata = +jdo.tck.mapping = 9 +jdo.tck.classes = org.apache.jdo.tck.mapping.CompletenessTestMap +jdo.tck.requiredOptions = Index: src/java/org/apache/jdo/tck/mapping/CompletenessTestMap.java =================================================================== --- src/java/org/apache/jdo/tck/mapping/CompletenessTestMap.java (revision 0) +++ src/java/org/apache/jdo/tck/mapping/CompletenessTestMap.java (revision 0) @@ -0,0 +1,128 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.mapping; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.companyMapWithoutJoin.CompanyFactoryRegistry; +import org.apache.jdo.tck.pc.companyMapWithoutJoin.CompanyModelReader; +import org.apache.jdo.tck.util.BatchTestRunner; +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +//import org.springframework.beans.factory.xml.XmlBeanFactory; + +/** + *Title:Completeness Test Map + *
+ *Keywords: mapping + *
+ *Assertion ID: A18.[not identified] + *
+ *Assertion Description: + */ + +public class CompletenessTestMap extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A18-[not identified] failed: "; + + /** */ + private final boolean isTestToBePerformed = isTestToBePerformed(); + + /** */ + protected List rootOids; + + /** */ + protected final String inputFilename = System.getProperty("jdo.tck.testdata"); + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(CompletenessTestMap.class); + } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + if (isTestToBePerformed) { + getPM(); + CompanyFactoryRegistry.registerFactory(pm); + CompanyModelReader reader = new CompanyModelReader(inputFilename); + addTearDownClass(reader.getTearDownClassesFromFactory()); + // persist test data + pm.currentTransaction().begin(); + List rootList = reader.getRootList(); + pm.makePersistentAll(rootList); + rootOids = new ArrayList(); + for (Iterator i = rootList.iterator(); i.hasNext(); ) { + Object pc = i.next(); + rootOids.add(pm.getObjectId(pc)); + } + pm.currentTransaction().commit(); + cleanupPM(); + } + } + + /** */ + public void test() { + if (isTestToBePerformed) { + // register the default factory + CompanyFactoryRegistry.registerFactory(); + // get new obj graph to compare persistent graph with + CompanyModelReader reader = new CompanyModelReader(inputFilename); + List rootList = reader.getRootList(); + + getPM(); + pm.currentTransaction().begin(); + // compare persisted and new + int size = rootList.size(); + StringBuffer msg = new StringBuffer(); + for (int i = 0; i < size; i++) { + DeepEquality expected = (DeepEquality) rootList.get(i); + Object oid = rootOids.get(i); + Object persisted = pm.getObjectById(oid); + EqualityHelper equalityHelper = new EqualityHelper(); + if (!expected.deepCompareFields(persisted, equalityHelper)) { + if (msg.length() > 0) { + msg.append("\n"); + } + msg.append("Expected this instance:\n " + + expected + "\n" + + "Got persistent instance:" + "\n " + + persisted + "\n" + + "Detailed list of differences follows...\n"); + msg.append(equalityHelper.getUnequalBuffer()); + } + } + pm.currentTransaction().commit(); + // fail test if at least one of the instances is not the expected one + if (msg.length() > 0) { + fail("CompletenessTestMap failed; see list of failures below:", + msg.toString()); + } + } + } +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Department.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Department.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Department.java (revision 0) @@ -0,0 +1,341 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.io.Serializable; +import java.io.ObjectInputStream; +import java.io.IOException; + +import java.util.Collections; +import java.util.Comparator; +import java.util.Map; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a department within a company. + */ +public class Department + implements IDepartment, Serializable, Comparable, Comparator, DeepEquality { + + public static final int RECOMMENDED_NO_OF_EMPS = 2; + + private long deptid; + private String name; + private Company company; + private Map roles; + + /** This is the JDO-required no-args constructor. The TCK relies on + * this constructor for testing PersistenceManager.newInstance(PCClass). + */ + public Department() {} + + /** + * Construct a Department instance. + * @param deptid The department id. + * @param name The name of the department. + */ + public Department(long deptid, String name) { + this.deptid = deptid; + this.name = name; + } + + /** + * Construct a Department instance. + * @param deptid The department id. + * @param name The name of the department. + * @param company The company that the department is associated with. + */ + public Department(long deptid, String name, ICompany company) { + this.deptid = deptid; + this.name = name; + this.company = (Company)company; + } + + /** + * Construct a Department instance. + * @param deptid The department id. + * @param name The name of the department. + * @param company The company that the department is associated with. + * @param roles Map of employees and their roles + */ + public Department(long deptid, String name, Company company, + Map roles) { + this.deptid = deptid; + this.name = name; + this.company = (Company)company; + this.roles = roles; + } + + /** + * Set the id associated with this object. + * @param id the id. + */ + public void setDeptid(long id) { + if (this.deptid != 0) + throw new IllegalStateException("Id is already set."); + this.deptid = id; + } + + /** + * Get the department id. + * @return The department id. + */ + public long getDeptid() { + return deptid; + } + + /** + * Get the name of the department. + * @return The name of the department. + */ + public String getName() { + return name; + } + + /** + * Set the name of the department. + * @param name The name to set for the department. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Get the company associated with the department. + * @return The company. + */ + public ICompany getCompany() { + return company; + } + + /** + * Set the company for the department. + * @param company The company to associate with the department. + */ + public void setCompany(ICompany company) { + this.company = (Company)company; + } + + /** + * Get the roles in the department as an unmodifiable set. + ******************* FIX?? + * @return The set of employees in the department, as an unmodifiable + * set. + */ + public Map getRoles() { + return roles; + } + + /** + * Add an role to the department. + * @param emp The role to add to the department. + */ + public void addRole(String role, Employee emp) { + roles.put(role, emp); + } + + /** + * Remove an role from the department. + * @param emp The role to remove from the department. + */ + public void removeRole(String key) { + roles.remove(key); + } + + /** + * Set the roles to be in this department. + * @param roles The roles for this department. + */ + public void setRoles(Map roles) { + this.roles = roles; + } + + /** + * Returns true if all the fields of this instance are + * deep equal to the coresponding fields of the other Department. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return true if all the fields are deep equal; + * false otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(Object other, + EqualityHelper helper) { + IDepartment otherDept = (IDepartment)other; + String where = "Department<" + deptid + ">"; + return + helper.equals(deptid, otherDept.getDeptid(), where + ".deptid") & + helper.equals(name, otherDept.getName(), where + ".name") & + helper.deepEquals(roles, otherDept.getRoles(), where + ".roles") & + helper.deepEquals(company, otherDept.getCompany(), where + ".company") ; + } + + /** + * Returns a String representation of a Department object. + * @return a String representation of a Department object. + */ + public String toString() { + return "Department(" + getFieldRepr()+ ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + protected String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(deptid); + rc.append(", name ").append(name); + return rc.toString(); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * @param o The Object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified object. + * @throws ClassCastException - if the specified object's type prevents + * it from being compared to this Object. + */ + public int compareTo(Object o) { + return compareTo((IDepartment)o); + } + + /** + * Compare two instances. This is a method in Comparator. + */ + public int compare(Object o1, Object o2) { + return compare((IDepartment)o1, (IDepartment)o2); + } + + /** + * Compares this object with the specified Department object for + * order. Returns a negative integer, zero, or a positive integer as + * this object is less than, equal to, or greater than the specified + * object. + * @param other The Department object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified + * Department object. + */ + public int compareTo(IDepartment other) { + return compare(this, other); + } + + /** + * Compares its two IDepartment arguments for order. Returns a negative + * integer, zero, or a positive integer as the first argument is less + * than, equal to, or greater than the second. + * @param o1 the first IDepartment object to be compared. + * @param o2 the second IDepartment object to be compared. + * @return a negative integer, zero, or a positive integer as the first + * object is less than, equal to, or greater than the second object. + */ + public static int compare(IDepartment o1, IDepartment o2) { + return EqualityHelper.compare(o1.getDeptid(), o2.getDeptid()); + } + + /** + * Indicates whether some other object is "equal to" this one. + * @param obj the object with which to compare. + * @return true if this object is the same as the obj + * argument; false otherwise. + */ + public boolean equals(Object obj) { + if (obj instanceof IDepartment) { + return compareTo((IDepartment)obj) == 0; + } + return false; + } + + /** + * Returns a hash code value for the object. + * @return a hash code value for this object. + */ + public int hashCode() { + return (int)deptid; + } + + /** + * The application identity class associated with the + * Department class. + */ + public static class Oid implements Serializable, Comparable { + + /** + * This field represents the application identifier field + * for the Department class. + * It must match in name and type with the field in the + * Department class. + */ + public long deptid; + + /** + * The required public, no-arg constructor. + */ + public Oid() { } + + /** + * A constructor to initialize the identifier field. + * @param deptid the deptid of the Department. + */ + public Oid(long deptid) { + this.deptid = deptid; + } + + public Oid(String s) { deptid = Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": " + deptid;} + + + /** */ + public boolean equals(java.lang.Object obj) { + if( obj==null || !this.getClass().equals(obj.getClass()) ) + return( false ); + Oid o = (Oid) obj; + if( this.deptid != o.deptid ) return( false ); + return( true ); + } + + /** */ + public int hashCode() { + return( (int) deptid ); + } + + protected static String justTheId(String str) { + return str.substring(str.indexOf(':') + 1); + } + + /** */ + public int compareTo(Object obj) { + // may throw ClassCastException which the user must handle + Oid other = (Oid) obj; + if( deptid < other.deptid ) return -1; + if( deptid > other.deptid ) return 1; + return 0; + } + + } + +} + Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryAbstractImpl.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryAbstractImpl.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryAbstractImpl.java (revision 0) @@ -0,0 +1,109 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import javax.jdo.PersistenceManager; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/* + * This class provides an implementation of CompanyFactory that sets all + * of the properties of the instance and defines abstract methods to + * construct the instance itself. It is intended to be subclassed by + * classes that implement only the methods to construct the instance. + */ +public abstract class CompanyFactoryAbstractImpl implements CompanyFactory { + + protected PersistenceManager pm; + + /** Logger */ + protected Log logger = + LogFactory.getFactory().getInstance("org.apache.jdo.tck"); + + /** true if debug logging is enabled. */ + protected boolean debug = logger.isDebugEnabled(); + + /** Creates a new instance of CompanyFactoryAbstractImpl */ + public CompanyFactoryAbstractImpl(PersistenceManager pm) { + this.pm = pm; + } + + abstract ICompany newCompany(); + abstract IDepartment newDepartment(); + abstract IFullTimeEmployee newFullTimeEmployee(); + abstract IPartTimeEmployee newPartTimeEmployee(); + + public ICompany newCompany(long companyid, String name, + java.util.Date founded) { + ICompany result = newCompany(); + if (debug) logger.debug("newCompany returned" + result); + result.setCompanyid(companyid); + result.setName(name); + result.setFounded(founded); + return result; + } + + public IDepartment newDepartment(long deptid, String name) { + IDepartment result = newDepartment(); + if (debug) logger.debug("newDepartment returned" + result); + result.setDeptid(deptid); + result.setName(name); + return result; + } + + + public IDepartment newDepartment(long deptid, String name, ICompany company) { + IDepartment result = newDepartment(); + if (debug) logger.debug("newDepartment returned" + result); + result.setDeptid(deptid); + result.setName(name); + result.setCompany(company); + return result; + } + + public IFullTimeEmployee newFullTimeEmployee(long personid, String first, + String last, String middle, java.util.Date born, + java.util.Date hired, String role, double sal) { + IFullTimeEmployee result = newFullTimeEmployee(); + if (debug) logger.debug("newFullTimeEmployee returned" + result); + result.setPersonid(personid); + result.setFirstname(first); + result.setLastname(last); + result.setMiddlename(middle); + result.setBirthdate(born); + result.setHiredate(hired); + result.setSalary(sal); + return result; + } + + public IPartTimeEmployee newPartTimeEmployee(long personid, String first, + String last, String middle, java.util.Date born, + java.util.Date hired, String role, double wage) { + IPartTimeEmployee result = newPartTimeEmployee(); + if (debug) logger.debug("newPartTimeEmployee returned" + result); + result.setPersonid(personid); + result.setFirstname(first); + result.setLastname(last); + result.setMiddlename(middle); + result.setBirthdate(born); + result.setHiredate(hired); + result.setWage(wage); + return result; + } + +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Person.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Person.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Person.java (revision 0) @@ -0,0 +1,329 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.io.Serializable; + +import java.text.SimpleDateFormat; + +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a person. + */ +public class Person + implements IPerson, Serializable, Comparable, Comparator, DeepEquality { + + private long personid; + private String firstname; + private String lastname; + private String middlename; + private Date birthdate; + + protected static SimpleDateFormat formatter = + new SimpleDateFormat("d/MMM/yyyy"); + + /** This is the JDO-required no-args constructor. */ + protected Person() {} + + /** + * Construct a Person instance. + * @param personid The person identifier. + * @param firstname The person's first name. + * @param lastname The person's last name. + * @param middlename The person's middle name. + * @param birthdate The person's birthdate. + */ + public Person(long personid, String firstname, String lastname, + String middlename, Date birthdate) { + this.personid = personid; + this.firstname = firstname; + this.lastname = lastname; + this.middlename = middlename; + this.birthdate = birthdate; + } + + /** + * Set the id associated with this object. + * @param id the id. + */ + public void setPersonid(long id) { + if (this.personid != 0) + throw new IllegalStateException("Id is already set."); + this.personid = id; + } + + /** + * Get the person's id. + * @return The personid. + */ + public long getPersonid() { + return personid; + } + + /** + * Set the person's id. + * @param personid The personid. + */ + public void setLastname(long personid) { + this.personid = personid; + } + + /** + * Get the person's last name. + * @return The last name. + */ + public String getLastname() { + return lastname; + } + + /** + * Set the person's last name. + * @param lastname The last name. + */ + public void setLastname(String lastname) { + this.lastname = lastname; + } + + /** + * Get the person's first name. + * @return The first name. + */ + public String getFirstname() { + return firstname; + } + + /** + * Set the person's first name. + * @param firstname The first name. + */ + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + /** + * Get the person's middle name. + * @return The middle name. + */ + public String getMiddlename() { + return middlename; + } + + /** + * Set the person's middle name. + * @param middlename The middle name. + */ + public void setMiddlename(String middlename) { + this.middlename = middlename; + } + + /** + * Get the person's birthdate. + * @return The person's birthdate. + */ + public Date getBirthdate() { + return birthdate; + } + + /** + * Set the person's birthdate. + * @param birthdate The person's birthdate. + */ + public void setBirthdate(Date birthdate) { + this. birthdate = birthdate; + } + + /** + * Returns a String representation of a Person object. + * @return a string representation of a Person object. + */ + public String toString() { + return "Person(" + getFieldRepr() + ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + protected String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(personid); + rc.append(", ").append(lastname); + rc.append(", ").append(firstname); + rc.append(", born ").append(formatter.format(birthdate)); + return rc.toString(); + } + + /** + * Returns true if all the fields of this instance are + * deep equal to the coresponding fields of the specified Person. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return true if all the fields are deep equal; + * false otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(Object other, + EqualityHelper helper) { + IPerson otherPerson = (IPerson)other; + String where = "Person<" + personid + ">"; + return + helper.equals(personid, otherPerson.getPersonid(), where + ".personid") & + helper.equals(firstname, otherPerson.getFirstname(), where + ".firstname") & + helper.equals(lastname, otherPerson.getLastname(), where + ".lastname") & + helper.equals(middlename, otherPerson.getMiddlename(), where + ".middlename") & + helper.equals(birthdate, otherPerson.getBirthdate(), where + ".birthdate") ; + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * @param o The Object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified object. + * @throws ClassCastException - if the specified object's type prevents + * it from being compared to this Object. + */ + public int compareTo(Object o) { + return compareTo((IPerson)o); + } + + /** + * Compare two instances. This is a method in Comparator. + */ + public int compare(Object o1, Object o2) { + return compare((IPerson)o1, (IPerson)o2); + } + + /** + * Compares this object with the specified Person object for + * order. Returns a negative integer, zero, or a positive integer as + * this object is less than, equal to, or greater than the specified + * object. + * @param other The Person object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified Person + * object. + */ + public int compareTo(IPerson other) { + return compare(this, other); + } + + /** + * Compares its two IPerson arguments for order. Returns a negative + * integer, zero, or a positive integer as the first argument is less + * than, equal to, or greater than the second. + * @param o1 the first IPerson object to be compared. + * @param o2 the second IPerson object to be compared. + * @return a negative integer, zero, or a positive integer as the first + * object is less than, equal to, or greater than the second object. + */ + public static int compare(IPerson o1, IPerson o2) { + return EqualityHelper.compare(o1.getPersonid(), o2.getPersonid()); + } + + /** + * Indicates whether some other object is "equal to" this one. + * @param obj the object with which to compare. + * @return true if this object is the same as the obj + * argument; false otherwise. + */ + public boolean equals(Object obj) { + if (obj instanceof IPerson) { + return compareTo((IPerson)obj) == 0; + } + return false; + } + + /** + * Returns a hash code value for the object. + * @return a hash code value for this object. + */ + public int hashCode() { + return (int)personid; + } + /** + * This class is used to represent the application identifier + * for the Person class. + */ + public static class Oid implements Serializable, Comparable { + + /** + * This field represents the identifier for the Person + * class. It must match a field in the Person class in + * both name and type. + */ + public long personid; + + /** + * The required public no-arg constructor. + */ + public Oid() { } + + /** + * Initialize the identifier. + * @param personid The person identifier. + */ + public Oid(long personid) { + this.personid = personid; + } + + public Oid(String s) { personid = Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": " + personid;} + + /** */ + public boolean equals(java.lang.Object obj) { + if( obj==null || + !this.getClass().equals(obj.getClass()) ) return( false ); + Oid o = (Oid) obj; + if( this.personid != o.personid ) return( false ); + return( true ); + } + + /** */ + public int hashCode() { + return( (int) personid ); + } + + protected static String justTheId(String str) { + return str.substring(str.indexOf(':') + 1); + } + + /** */ + public int compareTo(Object obj) { + // may throw ClassCastException which the user must handle + Oid other = (Oid) obj; + if( personid < other.personid ) return -1; + if( personid > other.personid ) return 1; + return 0; + } + + } + +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Company.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Company.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Company.java (revision 0) @@ -0,0 +1,331 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.io.Serializable; +import java.io.ObjectInputStream; +import java.io.IOException; + +import java.text.SimpleDateFormat; + +import java.util.Collections; +import java.util.Comparator; +import java.util.Set; +import java.util.HashSet; +import java.util.Date; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents information about a company. + */ +public class Company + implements ICompany, Serializable, Comparable, Comparator, DeepEquality { + + private long companyid; + private String name; + private Date founded; + private transient Set departments = new HashSet(); // element type is Department + + protected static SimpleDateFormat formatter = + new SimpleDateFormat("d/MMM/yyyy"); + + /** This is the JDO-required no-args constructor. The TCK relies on + * this constructor for testing PersistenceManager.newInstance(PCClass). + */ + public Company() {} + + /** + * Initialize the Company instance. + * @param companyid The company id. + * @param name The company name. + * @param founded The date the company was founded. + */ + public Company(long companyid, String name, Date founded) { + this.companyid = companyid; + this.name = name; + this.founded = founded; + } + + /** + * Get the company id. + * @return The company id. + */ + public long getCompanyid() { + return companyid; + } + + /** + * Set the id associated with this object. + * @param id the id. + */ + public void setCompanyid(long id) { + if (this.companyid != 0) + throw new IllegalStateException("Id is already set."); + this.companyid = id; + } + + /** + * Get the name of the company. + * @return The name of the company. + */ + public String getName() { + return name; + } + + /** + * Set the name of the company. + * @param name The value to use for the name of the company. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Get the date that the company was founded. + * @return The date the company was founded. + */ + public Date getFounded() { + return founded; + } + + /** + * Set the date that the company was founded. + * @param founded The date to set that the company was founded. + */ + public void setFounded(Date founded) { + this.founded = founded; + } + + /** + * Get the departments contained in the company. + * @return An unmodifiable Set that contains all the + * Departments of the company. + */ + public Set getDepartments() { + return Collections.unmodifiableSet(departments); + } + + /** + * Add a Department instance to the company. + * @param dept The Department instance to add. + */ + public void addDepartment(Department dept) { + departments.add(dept); + } + + /** + * Remove a Department instance from the company. + * @param dept The Department instance to remove. + */ + public void removeDepartment(Department dept) { + departments.remove(dept); + } + + /** + * Initialize the set of Departments in the company to the + * parameter. + * @param departments The set of Departments for the + * company. + */ + public void setDepartments(Set departments) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.departments = + (departments != null) ? new HashSet(departments) : null; + } + + /** Serialization support: initialize transient fields. */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException { + in.defaultReadObject(); + departments = new HashSet(); + } + + /** + * Returns a String representation of a Company object. + * @return a String representation of a Company object. + */ + public String toString() { + return "Company(" + getFieldRepr()+ ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + protected String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(companyid); + rc.append(", name ").append(name); + rc.append(", founded ").append(formatter.format(founded)); + return rc.toString(); + } + + /** + * Returns true if all the fields of this instance are + * deep equal to the coresponding fields of the specified Person. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return true if all the fields are deep equal; + * false otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(Object other, + EqualityHelper helper) { + ICompany otherCompany = (ICompany)other; + String where = "Company<" + companyid + ">"; + return + helper.equals(companyid, otherCompany.getCompanyid(), where + ".companyid") & + helper.equals(name, otherCompany.getName(), where + ".name") & + helper.equals(founded, otherCompany.getFounded(), where + ".founded") & + helper.deepEquals(departments, otherCompany.getDepartments(), where + ".departments"); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * @param o The Object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified object. + * @throws ClassCastException - if the specified object's type prevents + * it from being compared to this Object. + */ + public int compareTo(Object o) { + return compareTo((ICompany)o); + } + + /** + * Compare two instances. This is a method in Comparator. + */ + public int compare(Object o1, Object o2) { + return compare((ICompany)o1, (ICompany)o2); + } + + /** + * Compares this object with the specified Company object for + * order. Returns a negative integer, zero, or a positive integer as + * this object is less than, equal to, or greater than the specified + * object. + * @param other The Company object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified Company + * object. + */ + public int compareTo(ICompany other) { + return compare(this, other); + } + + /** + * Compares its two ICompany arguments for order. Returns a negative + * integer, zero, or a positive integer as the first argument is less + * than, equal to, or greater than the second. + * @param o1 the first ICompany object to be compared. + * @param o2 the second ICompany object to be compared. + * @return a negative integer, zero, or a positive integer as the first + * object is less than, equal to, or greater than the second object. + */ + public static int compare(ICompany o1, ICompany o2) { + return EqualityHelper.compare(o1.getCompanyid(), o2.getCompanyid()); + } + + /** + * Indicates whether some other object is "equal to" this one. + * @param obj the object with which to compare. + * @return true if this object is the same as the obj + * argument; false otherwise. + */ + public boolean equals(Object obj) { + if (obj instanceof ICompany) { + return compareTo((ICompany)obj) == 0; + } + return false; + } + + /** + * Returns a hash code value for the object. + * @return a hash code value for this object. + */ + public int hashCode() { + return (int)companyid; + } + + /** + * The class to be used as the application identifier + * for the Company class. It consists of both the company + * name and the date that the company was founded. + */ + public static class Oid implements Serializable, Comparable { + + /** + * This field is part of the identifier and should match in name + * and type with a field in the Company class. + */ + public long companyid; + + /** The required public no-arg constructor. */ + public Oid() { } + + /** + * Initialize the identifier. + * @param companyid The id of the company. + */ + public Oid(long companyid) { + this.companyid = companyid; + } + + public Oid(String s) { companyid = Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": " + companyid;} + + + /** */ + public boolean equals(Object obj) { + if (obj==null || !this.getClass().equals(obj.getClass())) + return false; + Oid o = (Oid) obj; + if (this.companyid != o.companyid) + return false; + return true; + } + + /** */ + public int hashCode() { + return (int)companyid; + } + + protected static String justTheId(String str) { + return str.substring(str.indexOf(':') + 1); + } + + /** */ + public int compareTo(Object obj) { + // may throw ClassCastException which the user must handle + Oid other = (Oid) obj; + if( companyid < other.companyid ) return -1; + if( companyid > other.companyid ) return 1; + return 0; + } + + } + +} + Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryConcreteClass.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryConcreteClass.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryConcreteClass.java (revision 0) @@ -0,0 +1,81 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.math.BigDecimal; + +import java.util.Date; + +import javax.jdo.PersistenceManager; + +/* + * This class is the company factory that uses constructors of the + * concrete classes. + */ +public class CompanyFactoryConcreteClass implements CompanyFactory { + + /** */ + public static final Class[] tearDownClasses = new Class[] { + PartTimeEmployee.class, FullTimeEmployee.class, + Department.class, Company.class + }; + + public CompanyFactoryConcreteClass(PersistenceManager pm) { + } + + public CompanyFactoryConcreteClass() { + } + + public ICompany newCompany(long companyid, + String name, Date founded) { + return new Company(companyid, name, founded); + } + + public IDepartment newDepartment(long deptid, String name) { + return new Department(deptid, name); + } + + public IDepartment newDepartment(long deptid, + String name, ICompany company) { + return new Department(deptid, name, company); + } + + public IFullTimeEmployee newFullTimeEmployee(long personid, + String first, String last, String middle, + Date born, Date hired, String role, double sal) { + return new FullTimeEmployee(personid, first, last, middle, + born, hired, role, sal); + } + + public IPartTimeEmployee newPartTimeEmployee(long personid, + String first, String last, String middle, + Date born, Date hired, String role, double wage) { + return new PartTimeEmployee(personid, first, last, middle, + born, hired, role, wage); + } + + public IPerson newPerson(long personid, + String firstname, String lastname, String middlename, + Date birthdate) { + return new Person(personid, firstname, lastname, middlename, + birthdate); + } + + public Class[] getTearDownClasses() { + return tearDownClasses; + } +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyModelReader.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyModelReader.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyModelReader.java (revision 0) @@ -0,0 +1,196 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.TimeZone; + +import org.apache.jdo.tck.util.ConversionHelper; +import org.springframework.beans.factory.xml.XmlBeanFactory; +import org.springframework.beans.propertyeditors.CustomDateEditor; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.InputStreamResource; + +/** + * Utility class to create a graph of company model instances from an xml + * representation. + * + * @author Michael Bouschen + */ +public class CompanyModelReader extends XmlBeanFactory { + + /** The format of date values in the xml representation */ + public static final String DATE_PATTERN = "d/MMM/yyyy"; + + /** The name of the root list bean. */ + public static final String ROOT_LIST_NAME = "root"; + + /** The bean-factory name in the xml input files. + */ + public static final String BEAN_FACTORY_NAME = "companyFactory"; + + /** The company factory instance. */ + private CompanyFactory companyFactory; + + /** + * Create a CompanyModelReader for the specified resourceName. + * @param resourceName the name of the resource + */ + public CompanyModelReader(String resourceName) { + // Use the class loader of the Company class to find the resource + this(resourceName, Company.class.getClassLoader()); + } + + /** + * Create a CompanyModelReader for the specified resourceName. + * @param resourceName the name of the resource + */ + public CompanyModelReader(String resourceName, ClassLoader classLoader) { + super(new ClassPathResource(resourceName, classLoader)); + configureFactory(); + } + + /** + * Create a CompanyModelReader for the specified InputStream. + * @param stream the input stream + */ + public CompanyModelReader(InputStream stream) { + super(new InputStreamResource(stream)); + configureFactory(); + } + + /** + * Returns a list of root objects. The method expects to find a bean + * called "root" of type list in the xml and returns it. + * @return a list of root instances + */ + public List getRootList() { + return (List)getBean(ROOT_LIST_NAME); + } + + /** + * Configure the CompanyModelReader, e.g. register CustomEditor classes + * to convert the string representation of a property into an instance + * of the right type. + */ + private void configureFactory() { + SimpleDateFormat formatter = new SimpleDateFormat(DATE_PATTERN, Locale.US); + formatter.setTimeZone(TimeZone.getTimeZone("America/New_York")); + CustomDateEditor dateEditor = + new CustomDateEditor(formatter, true); + registerCustomEditor(Date.class, dateEditor); + companyFactory = CompanyFactoryRegistry.getInstance(); + addSingleton(BEAN_FACTORY_NAME, companyFactory); + } + + // Convenience methods + + /** + * Convenience method returning a Company instance for the specified + * name. The method returns null if there is no Company + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or null if there no + * Company bean. + */ + public Company getCompany(String name) { + return (Company)getBean(name, Company.class); + } + + /** + * Convenience method returning a Department instance for the specified + * name. The method returns null if there is no Department + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or null if there no + * Department bean. + */ + public Department getDepartment(String name) { + return (Department)getBean(name, Department.class); + } + + /** + * Convenience method returning an Employee instance for the specified + * name. The method returns null if there is no Employee + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or null if there no + * Employee bean. + */ + public Employee getEmployee(String name) { + return (Employee)getBean(name, Employee.class); + } + + /** + * Convenience method returning a FullTimeEmployee instance for the + * specified name. The method returns null if there is no + * FullTimeEmployee bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or null if there no + * FullTimeEmployee bean. + */ + public FullTimeEmployee getFullTimeEmployee(String name) { + return (FullTimeEmployee)getBean(name, FullTimeEmployee.class); + } + + /** + * Convenience method returning a PartTimeEmployee instance for the + * specified name. The method returns null if there is no + * PartTimeEmployee bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or null if there no + * PartTimeEmployee bean. + */ + public PartTimeEmployee getPartTimeEmployee(String name) { + return (PartTimeEmployee)getBean(name, PartTimeEmployee.class); + } + + /** + * Convenience method returning a Person instance for the specified + * name. The method returns null if there is no Person + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or null if there no + * Person bean. + */ + public Person getPerson(String name) { + return (Person)getBean(name, Person.class); + } + + /** + * @return Returns the tearDownClasses. + */ + public Class[] getTearDownClassesFromFactory() { + return companyFactory.getTearDownClasses(); + } + + /** + * @return Returns the tearDownClasses. + */ + public static Class[] getTearDownClasses() { + return CompanyFactoryConcreteClass.tearDownClasses; + } + + public static Date stringToUtilDate(String value) { + return ConversionHelper.toUtilDate(DATE_PATTERN, "America/New_York", Locale.US, value); + } +} + Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryPMInterface.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryPMInterface.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryPMInterface.java (revision 0) @@ -0,0 +1,62 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import javax.jdo.PersistenceManager; + +/* + * CompanyFactoryPMInterface.java + * + * Created on August 29, 2005, 9:56 PM + * + */ +public class CompanyFactoryPMInterface + extends CompanyFactoryAbstractImpl { + + /** */ + public static final Class[] tearDownClasses = new Class[] { + IPartTimeEmployee.class, IFullTimeEmployee.class, + IDepartment.class, ICompany.class + }; + + /** + * Creates a new instance of CompanyFactoryPMInterface + */ + public CompanyFactoryPMInterface(PersistenceManager pm) { + super(pm); + } + + ICompany newCompany() { + return (ICompany)pm.newInstance(ICompany.class); + } + + IDepartment newDepartment() { + return (IDepartment)pm.newInstance(IDepartment.class); + } + + IFullTimeEmployee newFullTimeEmployee() { + return (IFullTimeEmployee)pm.newInstance(IFullTimeEmployee.class); + } + + IPartTimeEmployee newPartTimeEmployee() { + return (IPartTimeEmployee)pm.newInstance(IPartTimeEmployee.class); + } + + public Class[] getTearDownClasses() { + return tearDownClasses; + } +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IDepartment.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IDepartment.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IDepartment.java (revision 0) @@ -0,0 +1,37 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.util.Map; + +/** + * This interface represents the persistent state of Department. + * Javadoc was deliberately omitted because it would distract from + * the purpose of the interface. + */ +public interface IDepartment { + + long getDeptid(); + String getName(); + ICompany getCompany(); + Map getRoles(); + + void setDeptid(long deptid); + void setName(String name); + void setCompany(ICompany company); + void setRoles(Map roles); +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IPerson.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IPerson.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IPerson.java (revision 0) @@ -0,0 +1,41 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.util.Date; +import java.util.Map; + +/** + * This interface represents the persistent state of Person. + * Javadoc was deliberately omitted because it would distract from + * the purpose of the interface. + */ +public interface IPerson { + + long getPersonid(); + String getLastname(); + String getFirstname(); + String getMiddlename(); + Date getBirthdate(); + + void setPersonid(long personid); + void setLastname(String lastname); + void setFirstname(String firstname); + void setMiddlename(String middlename); + void setBirthdate(Date birthdate); + +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Employee.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Employee.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Employee.java (revision 0) @@ -0,0 +1,338 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.io.ObjectInputStream; +import java.io.IOException; + +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents an employee. + */ +public abstract class Employee extends Person implements IEmployee { + + private Date hiredate; + private double weeklyhours; + private Department department; + private Department fundingDept; + private String role; + private Employee manager; + private Employee mentor; + private Employee protege; + private Employee hradvisor; + private transient Set team = new HashSet(); // element-type is Employee + private transient Set hradvisees = new HashSet(); // element-type is Employee + + /** This is the JDO-required no-args constructor */ + protected Employee() {} + + /** + * Construct an Employee instance. + * @param personid The identifier for the person. + * @param firstname The first name of the employee. + * @param lastname The last name of the employee. + * @param middlename The middle name of the employee. + * @param birthdate The birth date of the employee. + * @param hiredate The date that the employee was hired. + */ + public Employee(long personid, String firstname, String lastname, + String middlename, Date birthdate, + Date hiredate, String role) { + super(personid, firstname, lastname, middlename, birthdate); + this.hiredate = hiredate; + this.role = role; + } + + /** + * Get the date that the employee was hired. + * @return The date the employee was hired. + */ + public Date getHiredate() { + return hiredate; + } + + /** + * Set the date that the employee was hired. + * @param hiredate The date the employee was hired. + */ + public void setHiredate(Date hiredate) { + this.hiredate = hiredate; + } + + /** + * Get the weekly hours of the employee. + * @return The number of hours per week that the employee works. + */ + public double getWeeklyhours() { + return weeklyhours; + } + + /** + * Set the number of hours per week that the employee works. + * @param weeklyhours The number of hours per week that the employee + * works. + */ + public void setWeeklyhours(double weeklyhours) { + this.weeklyhours = weeklyhours; + } + + /** + * Get the employee's department. + * @return The department associated with the employee. + */ + public IDepartment getDepartment() { + return department; + } + + /** + * Set the employee's department. + * @param department The department. + */ + public void setDepartment(IDepartment department) { + this.department = (Department)department; + } + + /** + * Get the employee's funding department. + * @return The funding department associated with the employee. + */ + public IDepartment getFundingDept() { + return fundingDept; + } + + /** + * Set the employee's funding department. + * @param department The funding department. + */ + public void setFundingDept(IDepartment department) { + this.fundingDept = (Department)department; + } + + /** + * Get the employee's manager. + * @return The employee's manager. + */ + public IEmployee getManager() { + return manager; + } + + /** + * Set the employee's manager. + * @param manager The employee's manager. + */ + public void setManager(IEmployee manager) { + this.manager = (Employee)manager; + } + + /** + * Get the employee's team. + * @return The set of Employees on this employee's team, + * returned as an unmodifiable set. + */ + public Set getTeam() { + return Collections.unmodifiableSet(team); + } + + /** + * Add an Employee to this employee's team. + * This method sets both sides of the relationship, modifying + * this employees team to include parameter emp and modifying + * emp to set its manager attribute to this object. + * @param emp The Employee to add to the team. + */ + public void addToTeam(Employee emp) { + team.add(emp); + emp.manager = this; + } + + /** + * Remove an Employee from this employee's team. + * This method will also set the emp manager to null. + * @param emp The Employee to remove from the team. + */ + public void removeFromTeam(Employee emp) { + team.remove(emp); + emp.manager = null; + } + + /** + * Set the employee's team. + * @param team The set of Employees. + */ + public void setTeam(Set team) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.team = (team != null) ? new HashSet(team) : null; + } + + /** + * Set the mentor for this employee. + * @param mentor The mentor for this employee. + */ + public void setMentor(IEmployee mentor) { + this.mentor = (Employee)mentor; + } + + /** + * Get the mentor for this employee. + * @return The mentor. + */ + public IEmployee getMentor() { + return mentor; + } + + /** + * Set the protege for this employee. + * @param protege The protege for this employee. + */ + public void setProtege(IEmployee protege) { + this.protege = (Employee)protege; + } + + /** + * Get the protege of this employee. + * @return The protege of this employee. + */ + public IEmployee getProtege() { + return protege; + } + + /** + * Set the HR advisor for this employee. + * @param hradvisor The hradvisor for this employee. + */ + public void setHradvisor(IEmployee hradvisor) { + this.hradvisor = (Employee)hradvisor; + } + + /** + * Get the HR advisor for the employee. + * @return The HR advisor. + */ + public IEmployee getHradvisor() { + return hradvisor; + } + + /** + * Get the HR advisees of this HR advisor. + * @return An unmodifiable Set containing the + * Employees that are HR advisees of this employee. + */ + public Set getHradvisees() { + return Collections.unmodifiableSet(hradvisees); + } + + /** + * Add an Employee as an advisee of this HR advisor. + * This method also sets the emp hradvisor to reference + * this object. In other words, both sides of the relationship are + * set. + * @param emp The employee to add as an advisee. + */ + public void addAdvisee(Employee emp) { + hradvisees.add(emp); + emp.hradvisor = this; + } + + /** + * Remove an Employee as an advisee of this HR advisor. + * This method also sets the emp hradvisor to null. + * In other words, both sides of the relationship are set. + * @param emp The employee to add as an HR advisee. + */ + public void removeAdvisee(Employee emp) { + hradvisees.remove(emp); + emp.hradvisor = null; + } + + /** + * Set the HR advisees of this HR advisor. + * @param hradvisees The Employees that are HR advisees of + * this employee. + */ + public void setHradvisees(Set hradvisees) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.hradvisees = (hradvisees != null) ? new HashSet(hradvisees) : null; + } + + /** Serialization support: initialize transient fields. */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException { + in.defaultReadObject(); + team = new HashSet(); + hradvisees = new HashSet(); + } + + /** + * Return a String representation of a Employee object. + * @return a String representation of a Employee object. + */ + public String toString() { + return "Employee(" + getFieldRepr() + ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + protected String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(super.getFieldRepr()); + rc.append(", hired ").append(formatter.format(hiredate)); + rc.append(", weeklyhours ").append(weeklyhours); + return rc.toString(); + } + + /** + * Returns true if all the fields of this instance are + * deep equal to the corresponding fields of the specified Employee. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return true if all the fields are deep equal; + * false otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(Object other, + EqualityHelper helper) { + IEmployee otherEmp = (IEmployee)other; + String where = "Employee<" + getPersonid() + ">"; + return super.deepCompareFields(otherEmp, helper) & + helper.equals(hiredate, otherEmp.getHiredate(), where + ".hiredate") & + helper.closeEnough(weeklyhours, otherEmp.getWeeklyhours(), where + ".weeklyhours") & + helper.deepEquals(department, otherEmp.getDepartment(), where + ".department") & + helper.deepEquals(fundingDept, otherEmp.getFundingDept(), where + ".fundingDept") & + helper.deepEquals(manager, otherEmp.getManager(), where + ".manager") & + helper.deepEquals(mentor, otherEmp.getMentor(), where + ".mentor") & + helper.deepEquals(protege, otherEmp.getProtege(), where + ".protege") & + helper.deepEquals(hradvisor, otherEmp.getHradvisor(), where + ".hradvisor") & + helper.deepEquals(team, otherEmp.getTeam(), where + ".team") & + helper.deepEquals(hradvisees, otherEmp.getHradvisees(), where + ".hradvisees"); + } + +} + Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/ICompany.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/ICompany.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/ICompany.java (revision 0) @@ -0,0 +1,38 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.util.Date; +import java.util.Set; + +/** + * This interface represents the persistent state of Company. + * Javadoc was deliberately omitted because it would distract from + * the purpose of the interface. + */ +public interface ICompany { + + long getCompanyid(); + Set getDepartments(); + Date getFounded(); + String getName(); + + void setCompanyid(long id); + void setDepartments(Set depts); + void setFounded(Date date); + void setName(String string); +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryPMClass.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryPMClass.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryPMClass.java (revision 0) @@ -0,0 +1,62 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import javax.jdo.PersistenceManager; + +/* + * CompanyFactoryPMInterface.java + * + * This class uses the PersistenceManager.newInstance method with the concrete + * class as a parameter. + */ +public class CompanyFactoryPMClass + extends CompanyFactoryAbstractImpl { + + /** */ + public static final Class[] tearDownClasses = new Class[] { + PartTimeEmployee.class, FullTimeEmployee.class, + Department.class, Company.class + }; + + /** + * Creates a new instance of CompanyFactoryPMClass + */ + public CompanyFactoryPMClass(PersistenceManager pm) { + super(pm); + } + + ICompany newCompany() { + return (ICompany)pm.newInstance(Company.class); + } + + IDepartment newDepartment() { + return (IDepartment)pm.newInstance(Department.class); + } + + IFullTimeEmployee newFullTimeEmployee() { + return (IFullTimeEmployee)pm.newInstance(FullTimeEmployee.class); + } + + IPartTimeEmployee newPartTimeEmployee() { + return (IPartTimeEmployee)pm.newInstance(PartTimeEmployee.class); + } + + public Class[] getTearDownClasses() { + return tearDownClasses; + } +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/FullTimeEmployee.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/FullTimeEmployee.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/FullTimeEmployee.java (revision 0) @@ -0,0 +1,108 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.util.Date; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a full-time employee. + */ +public class FullTimeEmployee extends Employee implements IFullTimeEmployee { + + private double salary; + + /** This is the JDO-required no-args constructor. The TCK relies on + * this constructor for testing PersistenceManager.newInstance(PCClass). + */ + public FullTimeEmployee() {} + + /** + * Construct a full-time employee. + * @param personid The person identifier. + * @param first The person's first name. + * @param last The person's last name. + * @param middle The person's middle name. + * @param born The person's birthdate. + * @param hired The date that the person was hired. + * @param sal The salary of the full-time employee. + */ + public FullTimeEmployee(long personid, String first, String last, + String middle, Date born, + Date hired, String role, double sal) { + super(personid, first, last, middle, born, hired, role); + salary = sal; + } + + /** + * Get the salary of the full time employee. + * @return The salary of the full time employee. + */ + public double getSalary() { + return salary; + } + + /** + * Set the salary for the full-time employee. + * @param salary The salary to set for the full-time employee. + */ + public void setSalary(double salary) { + this.salary = salary; + } + + /** + * Return a String representation of a FullTimeEmployee object. + * @return a String representation of a FullTimeEmployee object. + */ + public String toString() { + return "FullTimeEmployee(" + getFieldRepr() + ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + public String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(super.getFieldRepr()); + rc.append(", $").append(salary); + return rc.toString(); + } + + /** + * Returns true if all the fields of this instance are + * deep equal to the coresponding fields of the specified + * FullTimeEmployee. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return true if all the fields are deep equal; + * false otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(Object other, + EqualityHelper helper) { + IFullTimeEmployee otherEmp = (IFullTimeEmployee)other; + String where = "FullTimeEmployee<" + getPersonid() + ">"; + return super.deepCompareFields(otherEmp, helper) & + helper.closeEnough(salary, otherEmp.getSalary(), where + ".salary"); + } + +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/PartTimeEmployee.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/PartTimeEmployee.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/PartTimeEmployee.java (revision 0) @@ -0,0 +1,106 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.util.Date; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a part-time employee. + */ +public class PartTimeEmployee extends Employee implements IPartTimeEmployee { + private double wage; + + /** This is the JDO-required no-args constructor. The TCK relies on + * this constructor for testing PersistenceManager.newInstance(PCClass). + */ + public PartTimeEmployee() {} + + /** + * Construct a part-time employee. + * @param personid The identifier for the person. + * @param first The person's first name. + * @param last The person's last name. + * @param middle The person's middle name. + * @param born The person's birthdate. + * @param hired The date the person was hired. + * @param wage The person's wage. + */ + public PartTimeEmployee(long personid, String first, String last, + String middle, Date born, + Date hired, String role, double wage ) { + super(personid, first, last, middle, born, hired, role); + this.wage = wage; + } + + /** + * Get the wage of the part-time employee. + * @return The wage of the part-time employee. + */ + public double getWage() { + return wage; + } + + /** + * Set the wage of the part-time employee. + * @param wage The wage of the part-time employee. + */ + public void setWage(double wage) { + this.wage = wage; + } + + /** + * Returns a String representation of a PartTimeEmployee object. + * @return a String representation of a PartTimeEmployee object. + */ + public String toString() { + return "PartTimeEmployee(" + getFieldRepr() + ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + public String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(super.getFieldRepr()); + rc.append(", $" + wage); + return rc.toString(); + } + + /** + * Returns true if all the fields of this instance are + * deep equal to the coresponding fields of the specified + * PartTimeEmployee. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return true if all the fields are deep equal; + * false otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(Object other, + EqualityHelper helper) { + IPartTimeEmployee otherEmp = (IPartTimeEmployee)other; + String where = "PartTimeEmployee<" + getPersonid() + ">"; + return super.deepCompareFields(otherEmp, helper) & + helper.closeEnough(wage, otherEmp.getWage(), where + ".wage"); + } +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryRegistry.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryRegistry.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryRegistry.java (revision 0) @@ -0,0 +1,139 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.lang.reflect.Constructor; + +import java.math.BigDecimal; + +import java.util.Date; + +import javax.jdo.PersistenceManager; + +/* + * This is the registry for company factories. It is used for the + * CompletenessTest to create instances from input xml test data files. + * Factory instances that implement CompanyFactory interface are + * registered (using the singleton pattern). + *

Several registration methods are available. The default factory, + * which creates instances by construction, is automatically + * registered during class initialization. The default factory can + * also be registered by using the no-args method registerFactory(). + *

Non-default factories can be registered using the registerFactory + * method taking the factory as an argument. Non-default factories that + * have a single constructor argument PersistenceManager can be + * registered using either the method that explicitly names the class, + * or with the method that takes the class name from a system property. + */ +public class CompanyFactoryRegistry { + + /** The system property for factory name + */ + final static String FACTORY_PROPERTY_NAME = + "jdo.tck.mapping.companyfactory"; + + /** The factory name if the system property is not set. + */ + final static String DEFAULT_FACTORY_CLASS_NAME = + "org.apache.jdo.tck.pc.company.CompanyFactoryConcreteClass"; + + /** + * The default factory class name + */ + final static String FACTORY_CLASS_NAME; + + static { + String prop = System.getProperty(FACTORY_PROPERTY_NAME); + if ((prop == null) || (prop.length() == 0)) + prop = DEFAULT_FACTORY_CLASS_NAME; + FACTORY_CLASS_NAME = prop; + } + + /** + * This is the default company factory singleton. This is statically + * loaded regardless of the setting of the system property. + */ + final static CompanyFactory SINGLETON = new CompanyFactoryConcreteClass(); + + /** + * This is the currently registered factory. + */ + static CompanyFactory instance = SINGLETON; + + /** + * Creates a new instance of CompanyFactoryRegistry + */ + private CompanyFactoryRegistry() { + } + + /** + * Get the currently registered factory. + * @return the factory + */ + public static CompanyFactory getInstance() { + return instance; + } + + /** Register the default factory. + */ + public static void registerFactory() { + instance = SINGLETON; + } + + /** Register a factory using the default factory name from the + * system property. The factory must be available in the current + * class path and have a public constructor + * taking a PersistenceManager as a parameter. + * @param pm the PersistenceManager + */ + public static void registerFactory(PersistenceManager pm) { + registerFactory(FACTORY_CLASS_NAME, pm); + } + + /** Register a factory using the specified factoryName + * parameter. The factory class must be loadable by the current context + * classloader and have a public constructor + * taking a PersistenceManager as a parameter. + * @param factoryClassName the fully-qualified class name of the factory + * @param pm the PersistenceManager + */ + public static void registerFactory(String factoryClassName, + PersistenceManager pm) { + CompanyFactory factory = null; + try { + if (factoryClassName != null) { + Class factoryClass = Class.forName(factoryClassName); + Constructor ctor = factoryClass.getConstructor(new Class[] + {PersistenceManager.class}); + factory = (CompanyFactory) + ctor.newInstance(new Object[]{pm}); + } + registerFactory(factory); + } catch (Exception ex) { + throw new RuntimeException ("Unable to construct CompanyFactory " + + factoryClassName, ex); + } + } + + /** Register the factory. + * @param factory the factory + */ + public static void registerFactory(CompanyFactory factory) { + instance = factory!=null?factory:SINGLETON; + } + +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IEmployee.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IEmployee.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IEmployee.java (revision 0) @@ -0,0 +1,51 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.util.Date; +import java.util.Set; + +/** + * This interface represents the persistent state of Employee. + * Javadoc was deliberately omitted because it would distract from + * the purpose of the interface. + */ +public interface IEmployee extends IPerson { + + Date getHiredate(); + double getWeeklyhours(); + IDepartment getDepartment(); + IDepartment getFundingDept(); + IEmployee getManager(); + Set getTeam(); + IEmployee getMentor(); + IEmployee getProtege(); + IEmployee getHradvisor(); + Set getHradvisees(); + + void setHiredate(Date hiredate); + void setWeeklyhours(double weeklyhours); + void setDepartment(IDepartment department); + void setFundingDept(IDepartment department); + void setManager(IEmployee manager); + void setTeam(Set team); + void setMentor(IEmployee mentor); + void setProtege(IEmployee protege); + void setHradvisor(IEmployee hradvisor); + void setHradvisees(Set hradvisees); + +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IFullTimeEmployee.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IFullTimeEmployee.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IFullTimeEmployee.java (revision 0) @@ -0,0 +1,28 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +/** + * This interface represents the persistent state of FullTimeEmployee. + * Javadoc was deliberately omitted because it would distract from + * the purpose of the interface. + */ +public interface IFullTimeEmployee extends IEmployee { + + double getSalary(); + void setSalary(double salary); +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactory.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactory.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactory.java (revision 0) @@ -0,0 +1,45 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * CompanyFactory.java + * + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.math.BigDecimal; + +import java.util.Date; + +/** + * This interface is implemented by a factory class that can create + * Company model instances. The factory instance is registered with + * CompanyFactoryRegistry. + */ +public interface CompanyFactory { + ICompany newCompany(long companyid, String name, Date founded); + IDepartment newDepartment(long deptid, String name); + IDepartment newDepartment(long deptid, + String name, ICompany company); + IFullTimeEmployee newFullTimeEmployee(long personid, + String first, String last, String middle, + Date born, Date hired, String role, double sal); + IPartTimeEmployee newPartTimeEmployee(long personid, + String first, String last, String middle, + Date born, Date hired, String role, double wage); + Class[] getTearDownClasses(); +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IPartTimeEmployee.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IPartTimeEmployee.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IPartTimeEmployee.java (revision 0) @@ -0,0 +1,28 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +/** + * This interface represents the persistent state of PartTimeEmployee. + * Javadoc was deliberately omitted because it would distract from + * the purpose of the interface. + */ +public interface IPartTimeEmployee extends IEmployee { + + double getWage(); + void setWage(double wage); +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Company.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Company.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Company.java (revision 0) @@ -0,0 +1,331 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.io.Serializable; +import java.io.ObjectInputStream; +import java.io.IOException; + +import java.text.SimpleDateFormat; + +import java.util.Collections; +import java.util.Comparator; +import java.util.Set; +import java.util.HashSet; +import java.util.Date; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents information about a company. + */ +public class Company + implements ICompany, Serializable, Comparable, Comparator, DeepEquality { + + private long companyid; + private String name; + private Date founded; + private transient Set departments = new HashSet(); // element type is Department + + protected static SimpleDateFormat formatter = + new SimpleDateFormat("d/MMM/yyyy"); + + /** This is the JDO-required no-args constructor. The TCK relies on + * this constructor for testing PersistenceManager.newInstance(PCClass). + */ + public Company() {} + + /** + * Initialize the Company instance. + * @param companyid The company id. + * @param name The company name. + * @param founded The date the company was founded. + */ + public Company(long companyid, String name, Date founded) { + this.companyid = companyid; + this.name = name; + this.founded = founded; + } + + /** + * Get the company id. + * @return The company id. + */ + public long getCompanyid() { + return companyid; + } + + /** + * Set the id associated with this object. + * @param id the id. + */ + public void setCompanyid(long id) { + if (this.companyid != 0) + throw new IllegalStateException("Id is already set."); + this.companyid = id; + } + + /** + * Get the name of the company. + * @return The name of the company. + */ + public String getName() { + return name; + } + + /** + * Set the name of the company. + * @param name The value to use for the name of the company. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Get the date that the company was founded. + * @return The date the company was founded. + */ + public Date getFounded() { + return founded; + } + + /** + * Set the date that the company was founded. + * @param founded The date to set that the company was founded. + */ + public void setFounded(Date founded) { + this.founded = founded; + } + + /** + * Get the departments contained in the company. + * @return An unmodifiable Set that contains all the + * Departments of the company. + */ + public Set getDepartments() { + return Collections.unmodifiableSet(departments); + } + + /** + * Add a Department instance to the company. + * @param dept The Department instance to add. + */ + public void addDepartment(Department dept) { + departments.add(dept); + } + + /** + * Remove a Department instance from the company. + * @param dept The Department instance to remove. + */ + public void removeDepartment(Department dept) { + departments.remove(dept); + } + + /** + * Initialize the set of Departments in the company to the + * parameter. + * @param departments The set of Departments for the + * company. + */ + public void setDepartments(Set departments) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.departments = + (departments != null) ? new HashSet(departments) : null; + } + + /** Serialization support: initialize transient fields. */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException { + in.defaultReadObject(); + departments = new HashSet(); + } + + /** + * Returns a String representation of a Company object. + * @return a String representation of a Company object. + */ + public String toString() { + return "Company(" + getFieldRepr()+ ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + protected String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(companyid); + rc.append(", name ").append(name); + rc.append(", founded ").append(formatter.format(founded)); + return rc.toString(); + } + + /** + * Returns true if all the fields of this instance are + * deep equal to the coresponding fields of the specified Person. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return true if all the fields are deep equal; + * false otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(Object other, + EqualityHelper helper) { + ICompany otherCompany = (ICompany)other; + String where = "Company<" + companyid + ">"; + return + helper.equals(companyid, otherCompany.getCompanyid(), where + ".companyid") & + helper.equals(name, otherCompany.getName(), where + ".name") & + helper.equals(founded, otherCompany.getFounded(), where + ".founded") & + helper.deepEquals(departments, otherCompany.getDepartments(), where + ".departments"); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * @param o The Object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified object. + * @throws ClassCastException - if the specified object's type prevents + * it from being compared to this Object. + */ + public int compareTo(Object o) { + return compareTo((ICompany)o); + } + + /** + * Compare two instances. This is a method in Comparator. + */ + public int compare(Object o1, Object o2) { + return compare((ICompany)o1, (ICompany)o2); + } + + /** + * Compares this object with the specified Company object for + * order. Returns a negative integer, zero, or a positive integer as + * this object is less than, equal to, or greater than the specified + * object. + * @param other The Company object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified Company + * object. + */ + public int compareTo(ICompany other) { + return compare(this, other); + } + + /** + * Compares its two ICompany arguments for order. Returns a negative + * integer, zero, or a positive integer as the first argument is less + * than, equal to, or greater than the second. + * @param o1 the first ICompany object to be compared. + * @param o2 the second ICompany object to be compared. + * @return a negative integer, zero, or a positive integer as the first + * object is less than, equal to, or greater than the second object. + */ + public static int compare(ICompany o1, ICompany o2) { + return EqualityHelper.compare(o1.getCompanyid(), o2.getCompanyid()); + } + + /** + * Indicates whether some other object is "equal to" this one. + * @param obj the object with which to compare. + * @return true if this object is the same as the obj + * argument; false otherwise. + */ + public boolean equals(Object obj) { + if (obj instanceof ICompany) { + return compareTo((ICompany)obj) == 0; + } + return false; + } + + /** + * Returns a hash code value for the object. + * @return a hash code value for this object. + */ + public int hashCode() { + return (int)companyid; + } + + /** + * The class to be used as the application identifier + * for the Company class. It consists of both the company + * name and the date that the company was founded. + */ + public static class Oid implements Serializable, Comparable { + + /** + * This field is part of the identifier and should match in name + * and type with a field in the Company class. + */ + public long companyid; + + /** The required public no-arg constructor. */ + public Oid() { } + + /** + * Initialize the identifier. + * @param companyid The id of the company. + */ + public Oid(long companyid) { + this.companyid = companyid; + } + + public Oid(String s) { companyid = Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": " + companyid;} + + + /** */ + public boolean equals(Object obj) { + if (obj==null || !this.getClass().equals(obj.getClass())) + return false; + Oid o = (Oid) obj; + if (this.companyid != o.companyid) + return false; + return true; + } + + /** */ + public int hashCode() { + return (int)companyid; + } + + protected static String justTheId(String str) { + return str.substring(str.indexOf(':') + 1); + } + + /** */ + public int compareTo(Object obj) { + // may throw ClassCastException which the user must handle + Oid other = (Oid) obj; + if( companyid < other.companyid ) return -1; + if( companyid > other.companyid ) return 1; + return 0; + } + + } + +} + Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactory.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactory.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactory.java (revision 0) @@ -0,0 +1,45 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * CompanyFactory.java + * + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.math.BigDecimal; + +import java.util.Date; + +/** + * This interface is implemented by a factory class that can create + * Company model instances. The factory instance is registered with + * CompanyFactoryRegistry. + */ +public interface CompanyFactory { + ICompany newCompany(long companyid, String name, Date founded); + IDepartment newDepartment(long deptid, String name); + IDepartment newDepartment(long deptid, + String name, ICompany company); + IFullTimeEmployee newFullTimeEmployee(long personid, + String first, String last, String middle, + Date born, Date hired, String role, double sal); + IPartTimeEmployee newPartTimeEmployee(long personid, + String first, String last, String middle, + Date born, Date hired, String role, double wage); + Class[] getTearDownClasses(); +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryAbstractImpl.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryAbstractImpl.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryAbstractImpl.java (revision 0) @@ -0,0 +1,109 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import javax.jdo.PersistenceManager; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/* + * This class provides an implementation of CompanyFactory that sets all + * of the properties of the instance and defines abstract methods to + * construct the instance itself. It is intended to be subclassed by + * classes that implement only the methods to construct the instance. + */ +public abstract class CompanyFactoryAbstractImpl implements CompanyFactory { + + protected PersistenceManager pm; + + /** Logger */ + protected Log logger = + LogFactory.getFactory().getInstance("org.apache.jdo.tck"); + + /** true if debug logging is enabled. */ + protected boolean debug = logger.isDebugEnabled(); + + /** Creates a new instance of CompanyFactoryAbstractImpl */ + public CompanyFactoryAbstractImpl(PersistenceManager pm) { + this.pm = pm; + } + + abstract ICompany newCompany(); + abstract IDepartment newDepartment(); + abstract IFullTimeEmployee newFullTimeEmployee(); + abstract IPartTimeEmployee newPartTimeEmployee(); + + public ICompany newCompany(long companyid, String name, + java.util.Date founded) { + ICompany result = newCompany(); + if (debug) logger.debug("newCompany returned" + result); + result.setCompanyid(companyid); + result.setName(name); + result.setFounded(founded); + return result; + } + + public IDepartment newDepartment(long deptid, String name) { + IDepartment result = newDepartment(); + if (debug) logger.debug("newDepartment returned" + result); + result.setDeptid(deptid); + result.setName(name); + return result; + } + + + public IDepartment newDepartment(long deptid, String name, ICompany company) { + IDepartment result = newDepartment(); + if (debug) logger.debug("newDepartment returned" + result); + result.setDeptid(deptid); + result.setName(name); + result.setCompany(company); + return result; + } + + public IFullTimeEmployee newFullTimeEmployee(long personid, String first, + String last, String middle, java.util.Date born, + java.util.Date hired, String role, double sal) { + IFullTimeEmployee result = newFullTimeEmployee(); + if (debug) logger.debug("newFullTimeEmployee returned" + result); + result.setPersonid(personid); + result.setFirstname(first); + result.setLastname(last); + result.setMiddlename(middle); + result.setBirthdate(born); + result.setHiredate(hired); + result.setSalary(sal); + return result; + } + + public IPartTimeEmployee newPartTimeEmployee(long personid, String first, + String last, String middle, java.util.Date born, + java.util.Date hired, String role, double wage) { + IPartTimeEmployee result = newPartTimeEmployee(); + if (debug) logger.debug("newPartTimeEmployee returned" + result); + result.setPersonid(personid); + result.setFirstname(first); + result.setLastname(last); + result.setMiddlename(middle); + result.setBirthdate(born); + result.setHiredate(hired); + result.setWage(wage); + return result; + } + +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryConcreteClass.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryConcreteClass.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryConcreteClass.java (revision 0) @@ -0,0 +1,81 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.math.BigDecimal; + +import java.util.Date; + +import javax.jdo.PersistenceManager; + +/* + * This class is the company factory that uses constructors of the + * concrete classes. + */ +public class CompanyFactoryConcreteClass implements CompanyFactory { + + /** */ + public static final Class[] tearDownClasses = new Class[] { + PartTimeEmployee.class, FullTimeEmployee.class, + Department.class, Company.class + }; + + public CompanyFactoryConcreteClass(PersistenceManager pm) { + } + + public CompanyFactoryConcreteClass() { + } + + public ICompany newCompany(long companyid, + String name, Date founded) { + return new Company(companyid, name, founded); + } + + public IDepartment newDepartment(long deptid, String name) { + return new Department(deptid, name); + } + + public IDepartment newDepartment(long deptid, + String name, ICompany company) { + return new Department(deptid, name, company); + } + + public IFullTimeEmployee newFullTimeEmployee(long personid, + String first, String last, String middle, + Date born, Date hired, String role, double sal) { + return new FullTimeEmployee(personid, first, last, middle, + born, hired, role, sal); + } + + public IPartTimeEmployee newPartTimeEmployee(long personid, + String first, String last, String middle, + Date born, Date hired, String role, double wage) { + return new PartTimeEmployee(personid, first, last, middle, + born, hired, role, wage); + } + + public IPerson newPerson(long personid, + String firstname, String lastname, String middlename, + Date birthdate) { + return new Person(personid, firstname, lastname, middlename, + birthdate); + } + + public Class[] getTearDownClasses() { + return tearDownClasses; + } +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryPMClass.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryPMClass.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryPMClass.java (revision 0) @@ -0,0 +1,62 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import javax.jdo.PersistenceManager; + +/* + * CompanyFactoryPMInterface.java + * + * This class uses the PersistenceManager.newInstance method with the concrete + * class as a parameter. + */ +public class CompanyFactoryPMClass + extends CompanyFactoryAbstractImpl { + + /** */ + public static final Class[] tearDownClasses = new Class[] { + PartTimeEmployee.class, FullTimeEmployee.class, + Department.class, Company.class + }; + + /** + * Creates a new instance of CompanyFactoryPMClass + */ + public CompanyFactoryPMClass(PersistenceManager pm) { + super(pm); + } + + ICompany newCompany() { + return (ICompany)pm.newInstance(Company.class); + } + + IDepartment newDepartment() { + return (IDepartment)pm.newInstance(Department.class); + } + + IFullTimeEmployee newFullTimeEmployee() { + return (IFullTimeEmployee)pm.newInstance(FullTimeEmployee.class); + } + + IPartTimeEmployee newPartTimeEmployee() { + return (IPartTimeEmployee)pm.newInstance(PartTimeEmployee.class); + } + + public Class[] getTearDownClasses() { + return tearDownClasses; + } +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryPMInterface.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryPMInterface.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryPMInterface.java (revision 0) @@ -0,0 +1,62 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import javax.jdo.PersistenceManager; + +/* + * CompanyFactoryPMInterface.java + * + * Created on August 29, 2005, 9:56 PM + * + */ +public class CompanyFactoryPMInterface + extends CompanyFactoryAbstractImpl { + + /** */ + public static final Class[] tearDownClasses = new Class[] { + IPartTimeEmployee.class, IFullTimeEmployee.class, + IDepartment.class, ICompany.class + }; + + /** + * Creates a new instance of CompanyFactoryPMInterface + */ + public CompanyFactoryPMInterface(PersistenceManager pm) { + super(pm); + } + + ICompany newCompany() { + return (ICompany)pm.newInstance(ICompany.class); + } + + IDepartment newDepartment() { + return (IDepartment)pm.newInstance(IDepartment.class); + } + + IFullTimeEmployee newFullTimeEmployee() { + return (IFullTimeEmployee)pm.newInstance(IFullTimeEmployee.class); + } + + IPartTimeEmployee newPartTimeEmployee() { + return (IPartTimeEmployee)pm.newInstance(IPartTimeEmployee.class); + } + + public Class[] getTearDownClasses() { + return tearDownClasses; + } +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryRegistry.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryRegistry.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyFactoryRegistry.java (revision 0) @@ -0,0 +1,139 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.lang.reflect.Constructor; + +import java.math.BigDecimal; + +import java.util.Date; + +import javax.jdo.PersistenceManager; + +/* + * This is the registry for company factories. It is used for the + * CompletenessTest to create instances from input xml test data files. + * Factory instances that implement CompanyFactory interface are + * registered (using the singleton pattern). + *

Several registration methods are available. The default factory, + * which creates instances by construction, is automatically + * registered during class initialization. The default factory can + * also be registered by using the no-args method registerFactory(). + *

Non-default factories can be registered using the registerFactory + * method taking the factory as an argument. Non-default factories that + * have a single constructor argument PersistenceManager can be + * registered using either the method that explicitly names the class, + * or with the method that takes the class name from a system property. + */ +public class CompanyFactoryRegistry { + + /** The system property for factory name + */ + final static String FACTORY_PROPERTY_NAME = + "jdo.tck.mapping.companyfactory"; + + /** The factory name if the system property is not set. + */ + final static String DEFAULT_FACTORY_CLASS_NAME = + "org.apache.jdo.tck.pc.company.CompanyFactoryConcreteClass"; + + /** + * The default factory class name + */ + final static String FACTORY_CLASS_NAME; + + static { + String prop = System.getProperty(FACTORY_PROPERTY_NAME); + if ((prop == null) || (prop.length() == 0)) + prop = DEFAULT_FACTORY_CLASS_NAME; + FACTORY_CLASS_NAME = prop; + } + + /** + * This is the default company factory singleton. This is statically + * loaded regardless of the setting of the system property. + */ + final static CompanyFactory SINGLETON = new CompanyFactoryConcreteClass(); + + /** + * This is the currently registered factory. + */ + static CompanyFactory instance = SINGLETON; + + /** + * Creates a new instance of CompanyFactoryRegistry + */ + private CompanyFactoryRegistry() { + } + + /** + * Get the currently registered factory. + * @return the factory + */ + public static CompanyFactory getInstance() { + return instance; + } + + /** Register the default factory. + */ + public static void registerFactory() { + instance = SINGLETON; + } + + /** Register a factory using the default factory name from the + * system property. The factory must be available in the current + * class path and have a public constructor + * taking a PersistenceManager as a parameter. + * @param pm the PersistenceManager + */ + public static void registerFactory(PersistenceManager pm) { + registerFactory(FACTORY_CLASS_NAME, pm); + } + + /** Register a factory using the specified factoryName + * parameter. The factory class must be loadable by the current context + * classloader and have a public constructor + * taking a PersistenceManager as a parameter. + * @param factoryClassName the fully-qualified class name of the factory + * @param pm the PersistenceManager + */ + public static void registerFactory(String factoryClassName, + PersistenceManager pm) { + CompanyFactory factory = null; + try { + if (factoryClassName != null) { + Class factoryClass = Class.forName(factoryClassName); + Constructor ctor = factoryClass.getConstructor(new Class[] + {PersistenceManager.class}); + factory = (CompanyFactory) + ctor.newInstance(new Object[]{pm}); + } + registerFactory(factory); + } catch (Exception ex) { + throw new RuntimeException ("Unable to construct CompanyFactory " + + factoryClassName, ex); + } + } + + /** Register the factory. + * @param factory the factory + */ + public static void registerFactory(CompanyFactory factory) { + instance = factory!=null?factory:SINGLETON; + } + +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyModelReader.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyModelReader.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/CompanyModelReader.java (revision 0) @@ -0,0 +1,196 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.TimeZone; + +import org.apache.jdo.tck.util.ConversionHelper; +import org.springframework.beans.factory.xml.XmlBeanFactory; +import org.springframework.beans.propertyeditors.CustomDateEditor; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.InputStreamResource; + +/** + * Utility class to create a graph of company model instances from an xml + * representation. + * + * @author Michael Bouschen + */ +public class CompanyModelReader extends XmlBeanFactory { + + /** The format of date values in the xml representation */ + public static final String DATE_PATTERN = "d/MMM/yyyy"; + + /** The name of the root list bean. */ + public static final String ROOT_LIST_NAME = "root"; + + /** The bean-factory name in the xml input files. + */ + public static final String BEAN_FACTORY_NAME = "companyFactory"; + + /** The company factory instance. */ + private CompanyFactory companyFactory; + + /** + * Create a CompanyModelReader for the specified resourceName. + * @param resourceName the name of the resource + */ + public CompanyModelReader(String resourceName) { + // Use the class loader of the Company class to find the resource + this(resourceName, Company.class.getClassLoader()); + } + + /** + * Create a CompanyModelReader for the specified resourceName. + * @param resourceName the name of the resource + */ + public CompanyModelReader(String resourceName, ClassLoader classLoader) { + super(new ClassPathResource(resourceName, classLoader)); + configureFactory(); + } + + /** + * Create a CompanyModelReader for the specified InputStream. + * @param stream the input stream + */ + public CompanyModelReader(InputStream stream) { + super(new InputStreamResource(stream)); + configureFactory(); + } + + /** + * Returns a list of root objects. The method expects to find a bean + * called "root" of type list in the xml and returns it. + * @return a list of root instances + */ + public List getRootList() { + return (List)getBean(ROOT_LIST_NAME); + } + + /** + * Configure the CompanyModelReader, e.g. register CustomEditor classes + * to convert the string representation of a property into an instance + * of the right type. + */ + private void configureFactory() { + SimpleDateFormat formatter = new SimpleDateFormat(DATE_PATTERN, Locale.US); + formatter.setTimeZone(TimeZone.getTimeZone("America/New_York")); + CustomDateEditor dateEditor = + new CustomDateEditor(formatter, true); + registerCustomEditor(Date.class, dateEditor); + companyFactory = CompanyFactoryRegistry.getInstance(); + addSingleton(BEAN_FACTORY_NAME, companyFactory); + } + + // Convenience methods + + /** + * Convenience method returning a Company instance for the specified + * name. The method returns null if there is no Company + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or null if there no + * Company bean. + */ + public Company getCompany(String name) { + return (Company)getBean(name, Company.class); + } + + /** + * Convenience method returning a Department instance for the specified + * name. The method returns null if there is no Department + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or null if there no + * Department bean. + */ + public Department getDepartment(String name) { + return (Department)getBean(name, Department.class); + } + + /** + * Convenience method returning an Employee instance for the specified + * name. The method returns null if there is no Employee + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or null if there no + * Employee bean. + */ + public Employee getEmployee(String name) { + return (Employee)getBean(name, Employee.class); + } + + /** + * Convenience method returning a FullTimeEmployee instance for the + * specified name. The method returns null if there is no + * FullTimeEmployee bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or null if there no + * FullTimeEmployee bean. + */ + public FullTimeEmployee getFullTimeEmployee(String name) { + return (FullTimeEmployee)getBean(name, FullTimeEmployee.class); + } + + /** + * Convenience method returning a PartTimeEmployee instance for the + * specified name. The method returns null if there is no + * PartTimeEmployee bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or null if there no + * PartTimeEmployee bean. + */ + public PartTimeEmployee getPartTimeEmployee(String name) { + return (PartTimeEmployee)getBean(name, PartTimeEmployee.class); + } + + /** + * Convenience method returning a Person instance for the specified + * name. The method returns null if there is no Person + * bean with the specified name. + * @param name the name of the bean to return. + * @return the instance of the bean or null if there no + * Person bean. + */ + public Person getPerson(String name) { + return (Person)getBean(name, Person.class); + } + + /** + * @return Returns the tearDownClasses. + */ + public Class[] getTearDownClassesFromFactory() { + return companyFactory.getTearDownClasses(); + } + + /** + * @return Returns the tearDownClasses. + */ + public static Class[] getTearDownClasses() { + return CompanyFactoryConcreteClass.tearDownClasses; + } + + public static Date stringToUtilDate(String value) { + return ConversionHelper.toUtilDate(DATE_PATTERN, "America/New_York", Locale.US, value); + } +} + Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Department.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Department.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Department.java (revision 0) @@ -0,0 +1,341 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.io.Serializable; +import java.io.ObjectInputStream; +import java.io.IOException; + +import java.util.Collections; +import java.util.Comparator; +import java.util.Map; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a department within a company. + */ +public class Department + implements IDepartment, Serializable, Comparable, Comparator, DeepEquality { + + public static final int RECOMMENDED_NO_OF_EMPS = 2; + + private long deptid; + private String name; + private Company company; + private Map roles; + + /** This is the JDO-required no-args constructor. The TCK relies on + * this constructor for testing PersistenceManager.newInstance(PCClass). + */ + public Department() {} + + /** + * Construct a Department instance. + * @param deptid The department id. + * @param name The name of the department. + */ + public Department(long deptid, String name) { + this.deptid = deptid; + this.name = name; + } + + /** + * Construct a Department instance. + * @param deptid The department id. + * @param name The name of the department. + * @param company The company that the department is associated with. + */ + public Department(long deptid, String name, ICompany company) { + this.deptid = deptid; + this.name = name; + this.company = (Company)company; + } + + /** + * Construct a Department instance. + * @param deptid The department id. + * @param name The name of the department. + * @param company The company that the department is associated with. + * @param roles Map of employees and their roles + */ + public Department(long deptid, String name, Company company, + Map roles) { + this.deptid = deptid; + this.name = name; + this.company = (Company)company; + this.roles = roles; + } + + /** + * Set the id associated with this object. + * @param id the id. + */ + public void setDeptid(long id) { + if (this.deptid != 0) + throw new IllegalStateException("Id is already set."); + this.deptid = id; + } + + /** + * Get the department id. + * @return The department id. + */ + public long getDeptid() { + return deptid; + } + + /** + * Get the name of the department. + * @return The name of the department. + */ + public String getName() { + return name; + } + + /** + * Set the name of the department. + * @param name The name to set for the department. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Get the company associated with the department. + * @return The company. + */ + public ICompany getCompany() { + return company; + } + + /** + * Set the company for the department. + * @param company The company to associate with the department. + */ + public void setCompany(ICompany company) { + this.company = (Company)company; + } + + /** + * Get the roles in the department as an unmodifiable set. + ******************* FIX?? + * @return The set of employees in the department, as an unmodifiable + * set. + */ + public Map getRoles() { + return roles; + } + + /** + * Add an role to the department. + * @param emp The role to add to the department. + */ + public void addRole(String role, Employee emp) { + roles.put(role, emp); + } + + /** + * Remove an role from the department. + * @param emp The role to remove from the department. + */ + public void removeRole(String key) { + roles.remove(key); + } + + /** + * Set the roles to be in this department. + * @param roles The roles for this department. + */ + public void setRoles(Map roles) { + this.roles = roles; + } + + /** + * Returns true if all the fields of this instance are + * deep equal to the coresponding fields of the other Department. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return true if all the fields are deep equal; + * false otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(Object other, + EqualityHelper helper) { + IDepartment otherDept = (IDepartment)other; + String where = "Department<" + deptid + ">"; + return + helper.equals(deptid, otherDept.getDeptid(), where + ".deptid") & + helper.equals(name, otherDept.getName(), where + ".name") & + helper.deepEquals(roles, otherDept.getRoles(), where + ".roles") & + helper.deepEquals(company, otherDept.getCompany(), where + ".company") ; + } + + /** + * Returns a String representation of a Department object. + * @return a String representation of a Department object. + */ + public String toString() { + return "Department(" + getFieldRepr()+ ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + protected String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(deptid); + rc.append(", name ").append(name); + return rc.toString(); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * @param o The Object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified object. + * @throws ClassCastException - if the specified object's type prevents + * it from being compared to this Object. + */ + public int compareTo(Object o) { + return compareTo((IDepartment)o); + } + + /** + * Compare two instances. This is a method in Comparator. + */ + public int compare(Object o1, Object o2) { + return compare((IDepartment)o1, (IDepartment)o2); + } + + /** + * Compares this object with the specified Department object for + * order. Returns a negative integer, zero, or a positive integer as + * this object is less than, equal to, or greater than the specified + * object. + * @param other The Department object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified + * Department object. + */ + public int compareTo(IDepartment other) { + return compare(this, other); + } + + /** + * Compares its two IDepartment arguments for order. Returns a negative + * integer, zero, or a positive integer as the first argument is less + * than, equal to, or greater than the second. + * @param o1 the first IDepartment object to be compared. + * @param o2 the second IDepartment object to be compared. + * @return a negative integer, zero, or a positive integer as the first + * object is less than, equal to, or greater than the second object. + */ + public static int compare(IDepartment o1, IDepartment o2) { + return EqualityHelper.compare(o1.getDeptid(), o2.getDeptid()); + } + + /** + * Indicates whether some other object is "equal to" this one. + * @param obj the object with which to compare. + * @return true if this object is the same as the obj + * argument; false otherwise. + */ + public boolean equals(Object obj) { + if (obj instanceof IDepartment) { + return compareTo((IDepartment)obj) == 0; + } + return false; + } + + /** + * Returns a hash code value for the object. + * @return a hash code value for this object. + */ + public int hashCode() { + return (int)deptid; + } + + /** + * The application identity class associated with the + * Department class. + */ + public static class Oid implements Serializable, Comparable { + + /** + * This field represents the application identifier field + * for the Department class. + * It must match in name and type with the field in the + * Department class. + */ + public long deptid; + + /** + * The required public, no-arg constructor. + */ + public Oid() { } + + /** + * A constructor to initialize the identifier field. + * @param deptid the deptid of the Department. + */ + public Oid(long deptid) { + this.deptid = deptid; + } + + public Oid(String s) { deptid = Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": " + deptid;} + + + /** */ + public boolean equals(java.lang.Object obj) { + if( obj==null || !this.getClass().equals(obj.getClass()) ) + return( false ); + Oid o = (Oid) obj; + if( this.deptid != o.deptid ) return( false ); + return( true ); + } + + /** */ + public int hashCode() { + return( (int) deptid ); + } + + protected static String justTheId(String str) { + return str.substring(str.indexOf(':') + 1); + } + + /** */ + public int compareTo(Object obj) { + // may throw ClassCastException which the user must handle + Oid other = (Oid) obj; + if( deptid < other.deptid ) return -1; + if( deptid > other.deptid ) return 1; + return 0; + } + + } + +} + Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Employee.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Employee.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Employee.java (revision 0) @@ -0,0 +1,338 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.io.ObjectInputStream; +import java.io.IOException; + +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents an employee. + */ +public abstract class Employee extends Person implements IEmployee { + + private Date hiredate; + private double weeklyhours; + private Department department; + private Department fundingDept; + private String role; + private Employee manager; + private Employee mentor; + private Employee protege; + private Employee hradvisor; + private transient Set team = new HashSet(); // element-type is Employee + private transient Set hradvisees = new HashSet(); // element-type is Employee + + /** This is the JDO-required no-args constructor */ + protected Employee() {} + + /** + * Construct an Employee instance. + * @param personid The identifier for the person. + * @param firstname The first name of the employee. + * @param lastname The last name of the employee. + * @param middlename The middle name of the employee. + * @param birthdate The birth date of the employee. + * @param hiredate The date that the employee was hired. + */ + public Employee(long personid, String firstname, String lastname, + String middlename, Date birthdate, + Date hiredate, String role) { + super(personid, firstname, lastname, middlename, birthdate); + this.hiredate = hiredate; + this.role = role; + } + + /** + * Get the date that the employee was hired. + * @return The date the employee was hired. + */ + public Date getHiredate() { + return hiredate; + } + + /** + * Set the date that the employee was hired. + * @param hiredate The date the employee was hired. + */ + public void setHiredate(Date hiredate) { + this.hiredate = hiredate; + } + + /** + * Get the weekly hours of the employee. + * @return The number of hours per week that the employee works. + */ + public double getWeeklyhours() { + return weeklyhours; + } + + /** + * Set the number of hours per week that the employee works. + * @param weeklyhours The number of hours per week that the employee + * works. + */ + public void setWeeklyhours(double weeklyhours) { + this.weeklyhours = weeklyhours; + } + + /** + * Get the employee's department. + * @return The department associated with the employee. + */ + public IDepartment getDepartment() { + return department; + } + + /** + * Set the employee's department. + * @param department The department. + */ + public void setDepartment(IDepartment department) { + this.department = (Department)department; + } + + /** + * Get the employee's funding department. + * @return The funding department associated with the employee. + */ + public IDepartment getFundingDept() { + return fundingDept; + } + + /** + * Set the employee's funding department. + * @param department The funding department. + */ + public void setFundingDept(IDepartment department) { + this.fundingDept = (Department)department; + } + + /** + * Get the employee's manager. + * @return The employee's manager. + */ + public IEmployee getManager() { + return manager; + } + + /** + * Set the employee's manager. + * @param manager The employee's manager. + */ + public void setManager(IEmployee manager) { + this.manager = (Employee)manager; + } + + /** + * Get the employee's team. + * @return The set of Employees on this employee's team, + * returned as an unmodifiable set. + */ + public Set getTeam() { + return Collections.unmodifiableSet(team); + } + + /** + * Add an Employee to this employee's team. + * This method sets both sides of the relationship, modifying + * this employees team to include parameter emp and modifying + * emp to set its manager attribute to this object. + * @param emp The Employee to add to the team. + */ + public void addToTeam(Employee emp) { + team.add(emp); + emp.manager = this; + } + + /** + * Remove an Employee from this employee's team. + * This method will also set the emp manager to null. + * @param emp The Employee to remove from the team. + */ + public void removeFromTeam(Employee emp) { + team.remove(emp); + emp.manager = null; + } + + /** + * Set the employee's team. + * @param team The set of Employees. + */ + public void setTeam(Set team) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.team = (team != null) ? new HashSet(team) : null; + } + + /** + * Set the mentor for this employee. + * @param mentor The mentor for this employee. + */ + public void setMentor(IEmployee mentor) { + this.mentor = (Employee)mentor; + } + + /** + * Get the mentor for this employee. + * @return The mentor. + */ + public IEmployee getMentor() { + return mentor; + } + + /** + * Set the protege for this employee. + * @param protege The protege for this employee. + */ + public void setProtege(IEmployee protege) { + this.protege = (Employee)protege; + } + + /** + * Get the protege of this employee. + * @return The protege of this employee. + */ + public IEmployee getProtege() { + return protege; + } + + /** + * Set the HR advisor for this employee. + * @param hradvisor The hradvisor for this employee. + */ + public void setHradvisor(IEmployee hradvisor) { + this.hradvisor = (Employee)hradvisor; + } + + /** + * Get the HR advisor for the employee. + * @return The HR advisor. + */ + public IEmployee getHradvisor() { + return hradvisor; + } + + /** + * Get the HR advisees of this HR advisor. + * @return An unmodifiable Set containing the + * Employees that are HR advisees of this employee. + */ + public Set getHradvisees() { + return Collections.unmodifiableSet(hradvisees); + } + + /** + * Add an Employee as an advisee of this HR advisor. + * This method also sets the emp hradvisor to reference + * this object. In other words, both sides of the relationship are + * set. + * @param emp The employee to add as an advisee. + */ + public void addAdvisee(Employee emp) { + hradvisees.add(emp); + emp.hradvisor = this; + } + + /** + * Remove an Employee as an advisee of this HR advisor. + * This method also sets the emp hradvisor to null. + * In other words, both sides of the relationship are set. + * @param emp The employee to add as an HR advisee. + */ + public void removeAdvisee(Employee emp) { + hradvisees.remove(emp); + emp.hradvisor = null; + } + + /** + * Set the HR advisees of this HR advisor. + * @param hradvisees The Employees that are HR advisees of + * this employee. + */ + public void setHradvisees(Set hradvisees) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.hradvisees = (hradvisees != null) ? new HashSet(hradvisees) : null; + } + + /** Serialization support: initialize transient fields. */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException { + in.defaultReadObject(); + team = new HashSet(); + hradvisees = new HashSet(); + } + + /** + * Return a String representation of a Employee object. + * @return a String representation of a Employee object. + */ + public String toString() { + return "Employee(" + getFieldRepr() + ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + protected String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(super.getFieldRepr()); + rc.append(", hired ").append(formatter.format(hiredate)); + rc.append(", weeklyhours ").append(weeklyhours); + return rc.toString(); + } + + /** + * Returns true if all the fields of this instance are + * deep equal to the corresponding fields of the specified Employee. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return true if all the fields are deep equal; + * false otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(Object other, + EqualityHelper helper) { + IEmployee otherEmp = (IEmployee)other; + String where = "Employee<" + getPersonid() + ">"; + return super.deepCompareFields(otherEmp, helper) & + helper.equals(hiredate, otherEmp.getHiredate(), where + ".hiredate") & + helper.closeEnough(weeklyhours, otherEmp.getWeeklyhours(), where + ".weeklyhours") & + helper.deepEquals(department, otherEmp.getDepartment(), where + ".department") & + helper.deepEquals(fundingDept, otherEmp.getFundingDept(), where + ".fundingDept") & + helper.deepEquals(manager, otherEmp.getManager(), where + ".manager") & + helper.deepEquals(mentor, otherEmp.getMentor(), where + ".mentor") & + helper.deepEquals(protege, otherEmp.getProtege(), where + ".protege") & + helper.deepEquals(hradvisor, otherEmp.getHradvisor(), where + ".hradvisor") & + helper.deepEquals(team, otherEmp.getTeam(), where + ".team") & + helper.deepEquals(hradvisees, otherEmp.getHradvisees(), where + ".hradvisees"); + } + +} + Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/FullTimeEmployee.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/FullTimeEmployee.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/FullTimeEmployee.java (revision 0) @@ -0,0 +1,108 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.util.Date; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a full-time employee. + */ +public class FullTimeEmployee extends Employee implements IFullTimeEmployee { + + private double salary; + + /** This is the JDO-required no-args constructor. The TCK relies on + * this constructor for testing PersistenceManager.newInstance(PCClass). + */ + public FullTimeEmployee() {} + + /** + * Construct a full-time employee. + * @param personid The person identifier. + * @param first The person's first name. + * @param last The person's last name. + * @param middle The person's middle name. + * @param born The person's birthdate. + * @param hired The date that the person was hired. + * @param sal The salary of the full-time employee. + */ + public FullTimeEmployee(long personid, String first, String last, + String middle, Date born, + Date hired, String role, double sal) { + super(personid, first, last, middle, born, hired, role); + salary = sal; + } + + /** + * Get the salary of the full time employee. + * @return The salary of the full time employee. + */ + public double getSalary() { + return salary; + } + + /** + * Set the salary for the full-time employee. + * @param salary The salary to set for the full-time employee. + */ + public void setSalary(double salary) { + this.salary = salary; + } + + /** + * Return a String representation of a FullTimeEmployee object. + * @return a String representation of a FullTimeEmployee object. + */ + public String toString() { + return "FullTimeEmployee(" + getFieldRepr() + ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + public String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(super.getFieldRepr()); + rc.append(", $").append(salary); + return rc.toString(); + } + + /** + * Returns true if all the fields of this instance are + * deep equal to the coresponding fields of the specified + * FullTimeEmployee. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return true if all the fields are deep equal; + * false otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(Object other, + EqualityHelper helper) { + IFullTimeEmployee otherEmp = (IFullTimeEmployee)other; + String where = "FullTimeEmployee<" + getPersonid() + ">"; + return super.deepCompareFields(otherEmp, helper) & + helper.closeEnough(salary, otherEmp.getSalary(), where + ".salary"); + } + +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/ICompany.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/ICompany.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/ICompany.java (revision 0) @@ -0,0 +1,38 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.util.Date; +import java.util.Set; + +/** + * This interface represents the persistent state of Company. + * Javadoc was deliberately omitted because it would distract from + * the purpose of the interface. + */ +public interface ICompany { + + long getCompanyid(); + Set getDepartments(); + Date getFounded(); + String getName(); + + void setCompanyid(long id); + void setDepartments(Set depts); + void setFounded(Date date); + void setName(String string); +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IDepartment.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IDepartment.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IDepartment.java (revision 0) @@ -0,0 +1,37 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.util.Map; + +/** + * This interface represents the persistent state of Department. + * Javadoc was deliberately omitted because it would distract from + * the purpose of the interface. + */ +public interface IDepartment { + + long getDeptid(); + String getName(); + ICompany getCompany(); + Map getRoles(); + + void setDeptid(long deptid); + void setName(String name); + void setCompany(ICompany company); + void setRoles(Map roles); +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IEmployee.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IEmployee.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IEmployee.java (revision 0) @@ -0,0 +1,51 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.util.Date; +import java.util.Set; + +/** + * This interface represents the persistent state of Employee. + * Javadoc was deliberately omitted because it would distract from + * the purpose of the interface. + */ +public interface IEmployee extends IPerson { + + Date getHiredate(); + double getWeeklyhours(); + IDepartment getDepartment(); + IDepartment getFundingDept(); + IEmployee getManager(); + Set getTeam(); + IEmployee getMentor(); + IEmployee getProtege(); + IEmployee getHradvisor(); + Set getHradvisees(); + + void setHiredate(Date hiredate); + void setWeeklyhours(double weeklyhours); + void setDepartment(IDepartment department); + void setFundingDept(IDepartment department); + void setManager(IEmployee manager); + void setTeam(Set team); + void setMentor(IEmployee mentor); + void setProtege(IEmployee protege); + void setHradvisor(IEmployee hradvisor); + void setHradvisees(Set hradvisees); + +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IFullTimeEmployee.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IFullTimeEmployee.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IFullTimeEmployee.java (revision 0) @@ -0,0 +1,28 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +/** + * This interface represents the persistent state of FullTimeEmployee. + * Javadoc was deliberately omitted because it would distract from + * the purpose of the interface. + */ +public interface IFullTimeEmployee extends IEmployee { + + double getSalary(); + void setSalary(double salary); +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IPartTimeEmployee.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IPartTimeEmployee.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IPartTimeEmployee.java (revision 0) @@ -0,0 +1,28 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +/** + * This interface represents the persistent state of PartTimeEmployee. + * Javadoc was deliberately omitted because it would distract from + * the purpose of the interface. + */ +public interface IPartTimeEmployee extends IEmployee { + + double getWage(); + void setWage(double wage); +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IPerson.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IPerson.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/IPerson.java (revision 0) @@ -0,0 +1,41 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.util.Date; +import java.util.Map; + +/** + * This interface represents the persistent state of Person. + * Javadoc was deliberately omitted because it would distract from + * the purpose of the interface. + */ +public interface IPerson { + + long getPersonid(); + String getLastname(); + String getFirstname(); + String getMiddlename(); + Date getBirthdate(); + + void setPersonid(long personid); + void setLastname(String lastname); + void setFirstname(String firstname); + void setMiddlename(String middlename); + void setBirthdate(Date birthdate); + +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/PartTimeEmployee.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/PartTimeEmployee.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/PartTimeEmployee.java (revision 0) @@ -0,0 +1,106 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.util.Date; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a part-time employee. + */ +public class PartTimeEmployee extends Employee implements IPartTimeEmployee { + private double wage; + + /** This is the JDO-required no-args constructor. The TCK relies on + * this constructor for testing PersistenceManager.newInstance(PCClass). + */ + public PartTimeEmployee() {} + + /** + * Construct a part-time employee. + * @param personid The identifier for the person. + * @param first The person's first name. + * @param last The person's last name. + * @param middle The person's middle name. + * @param born The person's birthdate. + * @param hired The date the person was hired. + * @param wage The person's wage. + */ + public PartTimeEmployee(long personid, String first, String last, + String middle, Date born, + Date hired, String role, double wage ) { + super(personid, first, last, middle, born, hired, role); + this.wage = wage; + } + + /** + * Get the wage of the part-time employee. + * @return The wage of the part-time employee. + */ + public double getWage() { + return wage; + } + + /** + * Set the wage of the part-time employee. + * @param wage The wage of the part-time employee. + */ + public void setWage(double wage) { + this.wage = wage; + } + + /** + * Returns a String representation of a PartTimeEmployee object. + * @return a String representation of a PartTimeEmployee object. + */ + public String toString() { + return "PartTimeEmployee(" + getFieldRepr() + ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + public String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(super.getFieldRepr()); + rc.append(", $" + wage); + return rc.toString(); + } + + /** + * Returns true if all the fields of this instance are + * deep equal to the coresponding fields of the specified + * PartTimeEmployee. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return true if all the fields are deep equal; + * false otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(Object other, + EqualityHelper helper) { + IPartTimeEmployee otherEmp = (IPartTimeEmployee)other; + String where = "PartTimeEmployee<" + getPersonid() + ">"; + return super.deepCompareFields(otherEmp, helper) & + helper.closeEnough(wage, otherEmp.getWage(), where + ".wage"); + } +} Index: src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Person.java =================================================================== --- src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Person.java (revision 0) +++ src/java/org/apache/jdo/tck/pc/companyMapWithoutJoin/Person.java (revision 0) @@ -0,0 +1,329 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.apache.jdo.tck.pc.companyMapWithoutJoin; + +import java.io.Serializable; + +import java.text.SimpleDateFormat; + +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a person. + */ +public class Person + implements IPerson, Serializable, Comparable, Comparator, DeepEquality { + + private long personid; + private String firstname; + private String lastname; + private String middlename; + private Date birthdate; + + protected static SimpleDateFormat formatter = + new SimpleDateFormat("d/MMM/yyyy"); + + /** This is the JDO-required no-args constructor. */ + protected Person() {} + + /** + * Construct a Person instance. + * @param personid The person identifier. + * @param firstname The person's first name. + * @param lastname The person's last name. + * @param middlename The person's middle name. + * @param birthdate The person's birthdate. + */ + public Person(long personid, String firstname, String lastname, + String middlename, Date birthdate) { + this.personid = personid; + this.firstname = firstname; + this.lastname = lastname; + this.middlename = middlename; + this.birthdate = birthdate; + } + + /** + * Set the id associated with this object. + * @param id the id. + */ + public void setPersonid(long id) { + if (this.personid != 0) + throw new IllegalStateException("Id is already set."); + this.personid = id; + } + + /** + * Get the person's id. + * @return The personid. + */ + public long getPersonid() { + return personid; + } + + /** + * Set the person's id. + * @param personid The personid. + */ + public void setLastname(long personid) { + this.personid = personid; + } + + /** + * Get the person's last name. + * @return The last name. + */ + public String getLastname() { + return lastname; + } + + /** + * Set the person's last name. + * @param lastname The last name. + */ + public void setLastname(String lastname) { + this.lastname = lastname; + } + + /** + * Get the person's first name. + * @return The first name. + */ + public String getFirstname() { + return firstname; + } + + /** + * Set the person's first name. + * @param firstname The first name. + */ + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + /** + * Get the person's middle name. + * @return The middle name. + */ + public String getMiddlename() { + return middlename; + } + + /** + * Set the person's middle name. + * @param middlename The middle name. + */ + public void setMiddlename(String middlename) { + this.middlename = middlename; + } + + /** + * Get the person's birthdate. + * @return The person's birthdate. + */ + public Date getBirthdate() { + return birthdate; + } + + /** + * Set the person's birthdate. + * @param birthdate The person's birthdate. + */ + public void setBirthdate(Date birthdate) { + this. birthdate = birthdate; + } + + /** + * Returns a String representation of a Person object. + * @return a string representation of a Person object. + */ + public String toString() { + return "Person(" + getFieldRepr() + ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + protected String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(personid); + rc.append(", ").append(lastname); + rc.append(", ").append(firstname); + rc.append(", born ").append(formatter.format(birthdate)); + return rc.toString(); + } + + /** + * Returns true if all the fields of this instance are + * deep equal to the coresponding fields of the specified Person. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed. + * @return true if all the fields are deep equal; + * false otherwise. + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance. + */ + public boolean deepCompareFields(Object other, + EqualityHelper helper) { + IPerson otherPerson = (IPerson)other; + String where = "Person<" + personid + ">"; + return + helper.equals(personid, otherPerson.getPersonid(), where + ".personid") & + helper.equals(firstname, otherPerson.getFirstname(), where + ".firstname") & + helper.equals(lastname, otherPerson.getLastname(), where + ".lastname") & + helper.equals(middlename, otherPerson.getMiddlename(), where + ".middlename") & + helper.equals(birthdate, otherPerson.getBirthdate(), where + ".birthdate") ; + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * @param o The Object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified object. + * @throws ClassCastException - if the specified object's type prevents + * it from being compared to this Object. + */ + public int compareTo(Object o) { + return compareTo((IPerson)o); + } + + /** + * Compare two instances. This is a method in Comparator. + */ + public int compare(Object o1, Object o2) { + return compare((IPerson)o1, (IPerson)o2); + } + + /** + * Compares this object with the specified Person object for + * order. Returns a negative integer, zero, or a positive integer as + * this object is less than, equal to, or greater than the specified + * object. + * @param other The Person object to be compared. + * @return a negative integer, zero, or a positive integer as this + * object is less than, equal to, or greater than the specified Person + * object. + */ + public int compareTo(IPerson other) { + return compare(this, other); + } + + /** + * Compares its two IPerson arguments for order. Returns a negative + * integer, zero, or a positive integer as the first argument is less + * than, equal to, or greater than the second. + * @param o1 the first IPerson object to be compared. + * @param o2 the second IPerson object to be compared. + * @return a negative integer, zero, or a positive integer as the first + * object is less than, equal to, or greater than the second object. + */ + public static int compare(IPerson o1, IPerson o2) { + return EqualityHelper.compare(o1.getPersonid(), o2.getPersonid()); + } + + /** + * Indicates whether some other object is "equal to" this one. + * @param obj the object with which to compare. + * @return true if this object is the same as the obj + * argument; false otherwise. + */ + public boolean equals(Object obj) { + if (obj instanceof IPerson) { + return compareTo((IPerson)obj) == 0; + } + return false; + } + + /** + * Returns a hash code value for the object. + * @return a hash code value for this object. + */ + public int hashCode() { + return (int)personid; + } + /** + * This class is used to represent the application identifier + * for the Person class. + */ + public static class Oid implements Serializable, Comparable { + + /** + * This field represents the identifier for the Person + * class. It must match a field in the Person class in + * both name and type. + */ + public long personid; + + /** + * The required public no-arg constructor. + */ + public Oid() { } + + /** + * Initialize the identifier. + * @param personid The person identifier. + */ + public Oid(long personid) { + this.personid = personid; + } + + public Oid(String s) { personid = Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": " + personid;} + + /** */ + public boolean equals(java.lang.Object obj) { + if( obj==null || + !this.getClass().equals(obj.getClass()) ) return( false ); + Oid o = (Oid) obj; + if( this.personid != o.personid ) return( false ); + return( true ); + } + + /** */ + public int hashCode() { + return( (int) personid ); + } + + protected static String justTheId(String str) { + return str.substring(str.indexOf(':') + 1); + } + + /** */ + public int compareTo(Object obj) { + // may throw ClassCastException which the user must handle + Oid other = (Oid) obj; + if( personid < other.personid ) return -1; + if( personid > other.personid ) return 1; + return 0; + } + + } + +} Index: src/jdo/applicationidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package.jdo =================================================================== --- src/jdo/applicationidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package.jdo (revision 0) +++ src/jdo/applicationidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package.jdo (revision 0) @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: src/jdo/applicationidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package.jdo =================================================================== --- src/jdo/applicationidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package.jdo (revision 0) +++ src/jdo/applicationidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package.jdo (revision 0) @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: src/jdo/datastoreidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package.jdo =================================================================== --- src/jdo/datastoreidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package.jdo (revision 0) +++ src/jdo/datastoreidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package.jdo (revision 0) @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: src/jdo/datastoreidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package.jdo =================================================================== --- src/jdo/datastoreidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package.jdo (revision 0) +++ src/jdo/datastoreidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package.jdo (revision 0) @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: src/orm/applicationidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package-standard9.orm =================================================================== --- src/orm/applicationidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package-standard9.orm (revision 0) +++ src/orm/applicationidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package-standard9.orm (revision 0) @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: src/orm/applicationidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package-standard9.orm =================================================================== --- src/orm/applicationidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package-standard9.orm (revision 0) +++ src/orm/applicationidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package-standard9.orm (revision 0) @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: src/orm/datastoreidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package-standard9.orm =================================================================== --- src/orm/datastoreidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package-standard9.orm (revision 0) +++ src/orm/datastoreidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package-standard9.orm (revision 0) @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: src/orm/datastoreidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package-standard9.orm =================================================================== --- src/orm/datastoreidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package-standard9.orm (revision 0) +++ src/orm/datastoreidentity/org/apache/jdo/tck/pc/companyMapWithoutJoin/package-standard9.orm (revision 0) @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: src/sql/derby/applicationidentity/schema9.sql =================================================================== --- src/sql/derby/applicationidentity/schema9.sql (revision 0) +++ src/sql/derby/applicationidentity/schema9.sql (revision 0) @@ -0,0 +1,69 @@ +-- SchemaType: application identity + +connect 'jdbc:derby:jdotckdb;create=true' user 'tckuser' password 'tckuser'; + +CREATE SCHEMA applicationidentity9; +SET SCHEMA applicationidentity9; + +------------------------- +-- company +------------------------- + +ALTER TABLE departments DROP CONSTRAINT EMP_MO_FK; +ALTER TABLE departments DROP CONSTRAINT DEPTS_COMP_FK; +ALTER TABLE persons DROP CONSTRAINT PERS_DEPT_FK; +ALTER TABLE persons DROP CONSTRAINT PERS_FUNDDEPT_FK; +ALTER TABLE persons DROP CONSTRAINT PERS_MANAGER_FK; +ALTER TABLE persons DROP CONSTRAINT PERS_MENTOR_FK; +ALTER TABLE persons DROP CONSTRAINT PERS_HRADVISOR_FK; +DROP TABLE persons; +DROP TABLE departments; +DROP TABLE companies; + +CREATE TABLE companies ( + ID INTEGER NOT NULL, + NAME VARCHAR(32) NOT NULL, + FOUNDEDDATE VARCHAR(32) NOT NULL, + CONSTRAINT COMPS_PK PRIMARY KEY (ID) +); + +CREATE TABLE departments ( + ID INTEGER NOT NULL, + NAME VARCHAR(32) NOT NULL, + EMP_OF_THE_MONTH INTEGER, + COMPANYID INTEGER, + DISCRIMINATOR VARCHAR(255), + CONSTRAINT DEPTS_COMP_FK FOREIGN KEY (COMPANYID) REFERENCES companies, + CONSTRAINT DEPTS_PK PRIMARY KEY (ID) +); + +CREATE TABLE persons ( + PERSONID INTEGER NOT NULL, + FIRSTNAME VARCHAR(32) NOT NULL, + LASTNAME VARCHAR(32) NOT NULL, + MIDDLENAME VARCHAR(32), + BIRTHDATE VARCHAR(32) NOT NULL, + DISCRIMINATOR varchar(64) NOT NULL, + EMPID INTEGER NOT NULL, + HIREDATE VARCHAR(32), + WEEKLYHOURS REAL, + DEPARTMENT INTEGER, + FUNDINGDEPT INTEGER, + MANAGER INTEGER, + MENTOR INTEGER, + HRADVISOR INTEGER, + SALARY REAL, + WAGE REAL, + CONSTRAINT PERS_DEPT_FK FOREIGN KEY (DEPARTMENT) REFERENCES departments, + CONSTRAINT PERS_FUNDDEPT_FK FOREIGN KEY (FUNDINGDEPT) + REFERENCES departments, + CONSTRAINT PERS_MANAGER_FK FOREIGN KEY (MANAGER) REFERENCES persons, + CONSTRAINT PERS_MENTOR_FK FOREIGN KEY (MENTOR) REFERENCES persons, + CONSTRAINT PERS_HRADVISOR_FK FOREIGN KEY (HRADVISOR) REFERENCES persons, + CONSTRAINT PERS_PK PRIMARY KEY (PERSONID) +); + +ALTER TABLE departments + ADD CONSTRAINT EMP_MO_FK FOREIGN KEY + (EMP_OF_THE_MONTH) REFERENCES persons(PERSONID); + Index: src/sql/derby/datastoreidentity/schema9.sql =================================================================== --- src/sql/derby/datastoreidentity/schema9.sql (revision 0) +++ src/sql/derby/datastoreidentity/schema9.sql (revision 0) @@ -0,0 +1,72 @@ +-- SchemaType: datastore identity + +connect 'jdbc:derby:jdotckdb;create=true' user 'tckuser' password 'tckuser'; + +CREATE SCHEMA datastoreidentity9; +SET SCHEMA datastoreidentity9; + +------------------------- +-- company +------------------------- + +ALTER TABLE departments DROP CONSTRAINT EMP_MO_FK; +ALTER TABLE departments DROP CONSTRAINT DEPTS_COMP_FK; +ALTER TABLE persons DROP CONSTRAINT PERS_DEPT_FK; +ALTER TABLE persons DROP CONSTRAINT PERS_FUNDDEPT_FK; +ALTER TABLE persons DROP CONSTRAINT PERS_MANAGER_FK; +ALTER TABLE persons DROP CONSTRAINT PERS_MENTOR_FK; +ALTER TABLE persons DROP CONSTRAINT PERS_HRADVISOR_FK; +DROP TABLE persons; +DROP TABLE departments; +DROP TABLE companies; + +CREATE TABLE companies ( + DATASTORE_IDENTITY INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY, + ID INTEGER NOT NULL, + NAME VARCHAR(32) NOT NULL, + FOUNDEDDATE VARCHAR(32) NOT NULL, + CONSTRAINT COMPS_PK PRIMARY KEY (DATASTORE_IDENTITY) +); + +CREATE TABLE departments ( + DATASTORE_IDENTITY INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY, + ID INTEGER NOT NULL, + NAME VARCHAR(32) NOT NULL, + EMP_OF_THE_MONTH INTEGER, + COMPANYID INTEGER, + DISCRIMINATOR VARCHAR(255), + CONSTRAINT DEPTS_COMP_FK FOREIGN KEY (COMPANYID) REFERENCES companies, + CONSTRAINT DEPTS_PK PRIMARY KEY (DATASTORE_IDENTITY) +); + +CREATE TABLE persons ( + DATASTORE_IDENTITY INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY, + PERSONID INTEGER NOT NULL, + FIRSTNAME VARCHAR(32) NOT NULL, + LASTNAME VARCHAR(32) NOT NULL, + MIDDLENAME VARCHAR(32), + BIRTHDATE VARCHAR(32) NOT NULL, + DISCRIMINATOR varchar(64) NOT NULL, + EMPID INTEGER NOT NULL, + HIREDATE VARCHAR(32), + WEEKLYHOURS REAL, + DEPARTMENT INTEGER, + FUNDINGDEPT INTEGER, + MANAGER INTEGER, + MENTOR INTEGER, + HRADVISOR INTEGER, + SALARY REAL, + WAGE REAL, + CONSTRAINT PERS_DEPT_FK FOREIGN KEY (DEPARTMENT) REFERENCES departments, + CONSTRAINT PERS_FUNDDEPT_FK FOREIGN KEY (FUNDINGDEPT) + REFERENCES departments, + CONSTRAINT PERS_MANAGER_FK FOREIGN KEY (MANAGER) REFERENCES persons, + CONSTRAINT PERS_MENTOR_FK FOREIGN KEY (MENTOR) REFERENCES persons, + CONSTRAINT PERS_HRADVISOR_FK FOREIGN KEY (HRADVISOR) REFERENCES persons, + CONSTRAINT PERS_PK PRIMARY KEY (DATASTORE_IDENTITY) +); + +ALTER TABLE departments + ADD CONSTRAINT EMP_MO_FK FOREIGN KEY + (EMP_OF_THE_MONTH) REFERENCES persons(PERSONID); + Index: src/testdata/org/apache/jdo/tck/pc/companyMapWithoutJoin/companyMapWithoutJoin.xml =================================================================== --- src/testdata/org/apache/jdo/tck/pc/companyMapWithoutJoin/companyMapWithoutJoin.xml (revision 0) +++ src/testdata/org/apache/jdo/tck/pc/companyMapWithoutJoin/companyMapWithoutJoin.xml (revision 0) @@ -0,0 +1,151 @@ + + + + + Company instances for CompletenessTest with Map without join table + + + + + + + + + + + 1 + Sun Microsystems, Inc. + 11/Apr/1952 + + + + + + + + + + 1 + Development + + + + + + + + + + + + + + + + + + 2 + Human Resources + + + + + + + + + + + + + + + 1 + emp1First + emp1Last + emp1Middle + 10/Jun/1970 + 1/Jan/1999 + role1 + 60000 + 40 + + + + + + + 2 + emp2First + emp2Last + emp2Middle + 22/Dec/1975 + 1/Jul/2003 + role2 + 47000 + 40 + + + + + + + + + + + + + + 3 + emp3First + emp3Last + emp3Middle + 5/Sep/1972 + 15/Aug/2002 + role3 + 67.00 + 19 + + + + + + + 4 + emp4First + emp4Last + emp4Middle + 6/Sep/1973 + 15/Apr/2001 + role4 + 37.00 + + + + + + + 5 + emp5First + emp5Last + emp5Middle + 5/Jul/1962 + 15/Aug/1998 + role5 + 73000 + + + + + + + + + + + + + + + Index: src/testdata/org/apache/jdo/tck/pc/companyMapWithoutJoin/companyMapWithoutJoin.xml =================================================================== --- src/testdata/org/apache/jdo/tck/pc/companyMapWithoutJoin/companyMapWithoutJoin.xml (revision 0) +++ src/testdata/org/apache/jdo/tck/pc/companyMapWithoutJoin/companyMapWithoutJoin.xml (revision 0) @@ -0,0 +1,151 @@ + + + + + Company instances for CompletenessTest with Map without join table + + + + + + + + + + + 1 + Sun Microsystems, Inc. + 11/Apr/1952 + + + + + + + + + + 1 + Development + + + + + + + + + + + + + + + + + + 2 + Human Resources + + + + + + + + + + + + + + + 1 + emp1First + emp1Last + emp1Middle + 10/Jun/1970 + 1/Jan/1999 + role1 + 60000 + 40 + + + + + + + 2 + emp2First + emp2Last + emp2Middle + 22/Dec/1975 + 1/Jul/2003 + role2 + 47000 + 40 + + + + + + + + + + + + + + 3 + emp3First + emp3Last + emp3Middle + 5/Sep/1972 + 15/Aug/2002 + role3 + 67.00 + 19 + + + + + + + 4 + emp4First + emp4Last + emp4Middle + 6/Sep/1973 + 15/Apr/2001 + role4 + 37.00 + + + + + + + 5 + emp5First + emp5Last + emp5Middle + 5/Jul/1962 + 15/Aug/1998 + role5 + 73000 + + + + + + + + + + + + + + +