From jdo-commits-return-1841-apmail-db-jdo-commits-archive=www.apache.org@db.apache.org Thu Jul 19 20:53:41 2007 Return-Path: Delivered-To: apmail-db-jdo-commits-archive@www.apache.org Received: (qmail 15364 invoked from network); 19 Jul 2007 20:53:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Jul 2007 20:53:41 -0000 Received: (qmail 9573 invoked by uid 500); 19 Jul 2007 20:53:14 -0000 Mailing-List: contact jdo-commits-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-commits@db.apache.org Received: (qmail 9513 invoked by uid 99); 19 Jul 2007 20:53:14 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jul 2007 13:53:14 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jul 2007 13:53:07 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 4D5771A9820; Thu, 19 Jul 2007 13:52:47 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r557767 [3/4] - in /db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc: company/ companyAnnotatedApp/ companyAnnotatedDS/ companyAnnotatedFC/ companyAnnotatedPI/ Date: Thu, 19 Jul 2007 20:52:33 -0000 To: jdo-commits@db.apache.org From: mcaisse@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070719205247.4D5771A9820@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSDepartment.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSDepartment.java?view=auto&rev=557767 ============================================================================== --- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSDepartment.java (added) +++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSDepartment.java Thu Jul 19 13:52:29 2007 @@ -0,0 +1,435 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.companyAnnotatedFC; + +import javax.jdo.annotations.*; + +import java.io.Serializable; +import java.io.ObjectInputStream; +import java.io.IOException; + +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.Set; +import org.apache.jdo.tck.pc.company.ICompany; +import org.apache.jdo.tck.pc.company.IDepartment; +import org.apache.jdo.tck.pc.company.IEmployee; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a department within a company. + */ +@PersistenceCapable(table="departments") +@Inheritance(strategy=InheritanceStrategy.NEW_TABLE) +@Discriminator(strategy=DiscriminatorStrategy.CLASS_NAME, + column="DISCRIMINATOR") +@DatastoreIdentity(strategy=IdGeneratorStrategy.IDENTITY, + column="DATASTORE_IDENTITY") +public class FCDSDepartment + implements IDepartment, Serializable, Comparable, Comparator, DeepEquality { + + public static final int RECOMMENDED_NO_OF_EMPS = 2; + + @Column(name="ID") + private long deptid; + @Column(name="NAME") + private String name; + @Column(name="COMPANYID") + private FCDSCompany company; + @Column(name="EMP_OF_THE_MONTH") + private FCDSEmployee employeeOfTheMonth; + @Field(persistenceModifier=FieldPersistenceModifier.PERSISTENT, + mappedBy="department") + @Element(types=org.apache.jdo.tck.pc.companyAnnotatedFC.FCDSEmployee.class) + private transient Set employees = new HashSet(); + @Element(types=org.apache.jdo.tck.pc.companyAnnotatedFC.FCDSEmployee.class) + @Field(persistenceModifier=FieldPersistenceModifier.PERSISTENT, + mappedBy="fundingDept") + private transient Set fundedEmps = new HashSet(); + + /** This is the JDO-required no-args constructor. The TCK relies on + * this constructor for testing PersistenceManager.newInstance(PCClass). + */ + public FCDSDepartment() {} + + /** + * Construct a Department instance. + * @param deptid The department id. + * @param name The name of the department. + */ + public FCDSDepartment(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 FCDSDepartment(long deptid, String name, ICompany company) { + this.deptid = deptid; + this.name = name; + this.company = (FCDSCompany)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 employeeOfTheMonth The employee of the month the + * department is associated with. + */ + public FCDSDepartment(long deptid, String name, ICompany company, + IEmployee employeeOfTheMonth) { + this.deptid = deptid; + this.name = name; + this.company = (FCDSCompany)company; + this.employeeOfTheMonth = (FCDSEmployee)employeeOfTheMonth; + } + + /** + * 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 = (FCDSCompany)company; + } + + /** + * Get the employee of the month associated with the department. + * @return The employee of the month. + */ + public IEmployee getEmployeeOfTheMonth() { + return employeeOfTheMonth; + } + + /** + * Set the employee of the month for the department. + * @param employeeOfTheMonth The employee of the month to + * associate with the department. + */ + public void setEmployeeOfTheMonth(IEmployee employeeOfTheMonth) { + this.employeeOfTheMonth = (FCDSEmployee)employeeOfTheMonth; + } + + /** + * Get the employees in the department as an unmodifiable set. + * @return The set of employees in the department, as an unmodifiable + * set. + */ + public Set getEmployees() { + return Collections.unmodifiableSet(employees); + } + + /** + * Add an employee to the department. + * @param emp The employee to add to the department. + */ + public void addEmployee(FCDSEmployee emp) { + employees.add(emp); + } + + /** + * Remove an employee from the department. + * @param emp The employee to remove from the department. + */ + public void removeEmployee(FCDSEmployee emp) { + employees.remove(emp); + } + + /** + * Set the employees to be in this department. + * @param employees The set of employees for this department. + */ + public void setEmployees(Set employees) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.employees = (employees != null) ? new HashSet(employees) : null; + } + + /** + * Get the funded employees in the department as an unmodifiable set. + * @return The set of funded employees in the department, as an + * unmodifiable set. + */ + public Set getFundedEmps() { + return Collections.unmodifiableSet(fundedEmps); + } + + /** + * Add an employee to the collection of funded employees of this + * department. + * @param emp The employee to add to the department. + */ + public void addFundedEmp(FCDSEmployee emp) { + fundedEmps.add(emp); + } + + /** + * Remove an employee from collection of funded employees of this + * department. + * @param emp The employee to remove from the department. + */ + public void removeFundedEmp(FCDSEmployee emp) { + fundedEmps.remove(emp); + } + + /** + * Set the funded employees to be in this department. + * @param employees The set of funded employees for this department. + */ + public void setFundedEmps(Set employees) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.fundedEmps = (fundedEmps != null) ? new HashSet(employees) : null; + } + + /** Serialization support: initialize transient fields. */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException { + in.defaultReadObject(); + employees = new HashSet(); + fundedEmps = new HashSet(); + } + + /** + * + * Returns true if all the fields of this instance are + * deep equal to the coresponding fields of the other FCDSDepartment. + * + * @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) { + FCDSDepartment otherDept = (FCDSDepartment)other; + String where = "FCDepartment<" + deptid + ">"; + return + helper.equals(deptid, otherDept.getDeptid(), where + ".deptid") & + helper.equals(name, otherDept.getName(), where + ".name") & + helper.deepEquals(company, otherDept.getCompany(), where + ".company") & + helper.deepEquals(employeeOfTheMonth, otherDept.getEmployeeOfTheMonth(), where + ".employeeOfTheMonth") & + helper.deepEquals(employees, otherDept.getEmployees(), where + ".employees") & + helper.deepEquals(fundedEmps, otherDept.getFundedEmps(), where + ".fundedEmps"); + } + + /** + * Returns a String representation of a FCDSDepartment object. + * + * @return a String representation of a FCDSDepartment object. + */ + public String toString() { + return "FCDepartment(" + 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((FCDSDepartment)o); + } + + /** + * Compare two instances. This is a method in Comparator. + */ + public int compare(Object o1, Object o2) { + return compare((FCDSDepartment)o1, (FCDSDepartment)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(FCDSDepartment 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(FCDSDepartment o1, FCDSDepartment 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 FCDSDepartment) { + return compareTo((FCDSDepartment)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; + } + + } + +} + Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSDepartment.java ------------------------------------------------------------------------------ svn:eol-style = LF Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSEmployee.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSEmployee.java?view=auto&rev=557767 ============================================================================== --- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSEmployee.java (added) +++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSEmployee.java Thu Jul 19 13:52:29 2007 @@ -0,0 +1,509 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.companyAnnotatedFC; + +import javax.jdo.annotations.*; + +import java.io.ObjectInputStream; +import java.io.IOException; + +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; +import org.apache.jdo.tck.pc.company.IDentalInsurance; +import org.apache.jdo.tck.pc.company.IDepartment; +import org.apache.jdo.tck.pc.company.IEmployee; +import org.apache.jdo.tck.pc.company.IMedicalInsurance; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents an employee. + */ +@PersistenceCapable +@Inheritance(strategy=InheritanceStrategy.SUPERCLASS_TABLE) +@DatastoreIdentity(strategy=IdGeneratorStrategy.IDENTITY, column="DATASTORE_IDENTITY") +public abstract class FCDSEmployee extends FCDSPerson implements IEmployee { + + @Column(name="HIREDATE") + private Date hiredate; + @Column(name="WEEKLYHOURS") + private double weeklyhours; + @Field(mappedBy="employee") + private FCDSDentalInsurance dentalInsurance; + @Field(mappedBy="employee") + private FCDSMedicalInsurance medicalInsurance; + @Column(name="DEPARTMENT") + private FCDSDepartment department; + @Column(name="FUNDINGDEPT") + private FCDSDepartment fundingDept; + @Column(name="MANAGER") + private FCDSEmployee manager; + @Column(name="MENTOR") + private FCDSEmployee mentor; + @Field(mappedBy="mentor") + private FCDSEmployee protege; + @Column(name="HRADVISOR") + private FCDSEmployee hradvisor; + @Field(persistenceModifier=FieldPersistenceModifier.PERSISTENT, + mappedBy="reviewers") + @Element(types=org.apache.jdo.tck.pc.companyAnnotatedFC.FCDSProject.class) + private transient Set reviewedProjects = new HashSet(); + @Field(persistenceModifier=FieldPersistenceModifier.PERSISTENT, + mappedBy="members") + @Element(types=org.apache.jdo.tck.pc.companyAnnotatedFC.FCDSProject.class) + private transient Set projects = new HashSet(); + @Field(persistenceModifier=FieldPersistenceModifier.PERSISTENT, + mappedBy="manager") + @Element(types=org.apache.jdo.tck.pc.companyAnnotatedFC.FCDSEmployee.class) + private transient Set team = new HashSet(); + @Field(persistenceModifier=FieldPersistenceModifier.PERSISTENT, + mappedBy="hradvisor") + @Element(types=org.apache.jdo.tck.pc.companyAnnotatedFC.FCDSEmployee.class) + private transient Set hradvisees = new HashSet(); + + + /** This is the JDO-required no-args constructor */ + protected FCDSEmployee() {} + + /** + * Construct an FCDSEmployee 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 FCDSEmployee(long personid, String firstname, String lastname, + String middlename, Date birthdate, + Date hiredate) { + super(personid, firstname, lastname, middlename, birthdate); + this.hiredate = hiredate; + } + + /** + * Construct an FCDSEmployee 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 address The address of the employee. + * @param hiredate The date that the employee was hired. + */ + public FCDSEmployee(long personid, String firstname, String lastname, + String middlename, Date birthdate, FCDSAddress address, + Date hiredate) { + super(personid, firstname, lastname, middlename, birthdate, address); + this.hiredate = hiredate; + } + + /** + * 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 reviewed projects. + * @return The reviewed projects as an unmodifiable set. + */ + public Set getReviewedProjects() { + return Collections.unmodifiableSet(reviewedProjects); + } + + /** + * Add a reviewed project. + * @param project A reviewed project. + */ + public void addReviewedProjects(FCDSProject project) { + reviewedProjects.add(project); + } + + /** + * Remove a reviewed project. + * @param project A reviewed project. + */ + public void removeReviewedProject(FCDSProject project) { + reviewedProjects.remove(project); + } + + /** + * Set the reviewed projects for the employee. + * @param reviewedProjects The set of reviewed projects. + */ + public void setReviewedProjects(Set reviewedProjects) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.reviewedProjects = + (reviewedProjects != null) ? new HashSet(reviewedProjects) : null; + } + + /** + * Get the employee's projects. + * @return The employee's projects are returned as an unmodifiable + * set. + */ + public Set getProjects() { + return Collections.unmodifiableSet(projects); + } + + /** + * Add a project for the employee. + * @param project The project. + */ + public void addProject(FCDSProject project) { + projects.add(project); + } + + /** + * Remove a project from an employee's set of projects. + * @param project The project. + */ + public void removeProject(FCDSProject project) { + projects.remove(project); + } + + /** + * Set the projects for the employee. + * @param projects The set of projects of the employee. + */ + public void setProjects(Set projects) { + // workaround: create a new HashSet, because fostore does not + // support LinkedHashSet + this.projects = (projects != null) ? new HashSet(projects) : null; + } + + /** + * Get the dental insurance of the employee. + * @return The employee's dental insurance. + */ + public FCDSDentalInsurance getDentalInsurance() { + return dentalInsurance; + } + + /** + * Set the dental insurance object for the employee. + * @param dentalInsurance The dental insurance object to associate with + * the employee. + */ + public void setDentalInsurance(IDentalInsurance dentalInsurance) { + this.dentalInsurance = (FCDSDentalInsurance)dentalInsurance; + } + /** + * Get the medical insurance of the employee. + * @return The employee's medical insurance. + */ + public IMedicalInsurance getMedicalInsurance() { + return medicalInsurance; + } + + /** + * Set the medical insurance object for the employee. + * @param medicalInsurance The medical insurance object to associate + * with the employee. + */ + public void setMedicalInsurance(IMedicalInsurance medicalInsurance) { + this.medicalInsurance = (FCDSMedicalInsurance)medicalInsurance; + } + + /** + * 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 = (FCDSDepartment)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 = (FCDSDepartment)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 = (FCDSEmployee)manager; + } + + /** + * Get the employee's team. + * + * @return The set of FCDSEmployees on this employee's team, + * returned as an unmodifiable set. + */ + public Set getTeam() { + return Collections.unmodifiableSet(team); + } + + /** + * Add an FCDSEmployee 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 FCDSEmployee to add to the team. + */ + public void addToTeam(FCDSEmployee emp) { + team.add(emp); + emp.manager = this; + } + + /** + * Remove an FCDSEmployee from this employee's team. + * This method will also set the emp manager to null. + * + * @param emp The FCDSEmployee to remove from the team. + */ + public void removeFromTeam(FCDSEmployee emp) { + team.remove(emp); + emp.manager = null; + } + + /** + * Set the employee's team. + * + * @param team The set of FCDSEmployees. + */ + 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 = (FCDSEmployee)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 = (FCDSEmployee)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 = (FCDSEmployee)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 + * FCDSEmployees that are HR advisees of this employee. + */ + public Set getHradvisees() { + return Collections.unmodifiableSet(hradvisees); + } + + /** + * Add an FCDSEmployee 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(FCDSEmployee emp) { + hradvisees.add(emp); + emp.hradvisor = this; + } + + /** + * Remove an FCDSEmployee 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(FCDSEmployee emp) { + hradvisees.remove(emp); + emp.hradvisor = null; + } + + /** + * Set the HR advisees of this HR advisor. + * + * @param hradvisees The FCDSEmployees 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(); + reviewedProjects = new HashSet(); + projects = new HashSet(); + team = new HashSet(); + hradvisees = new HashSet(); + } + + /** + * Return a String representation of a FCDSEmployee object. + * + * @return a String representation of a FCDSEmployee object. + */ + public String toString() { + return "FCEmployee(" + 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 FCDSEmployee. + * + * @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) { + FCDSEmployee otherEmp = (FCDSEmployee)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(dentalInsurance, otherEmp.getDentalInsurance(), where + ".dentalInsurance") & + helper.deepEquals(medicalInsurance, otherEmp.getMedicalInsurance(), where + ".medicalInsurance") & + 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(reviewedProjects, otherEmp.getReviewedProjects(), where + ".reviewedProjects") & + helper.deepEquals(projects, otherEmp.getProjects(), where + ".projects") & + helper.deepEquals(team, otherEmp.getTeam(), where + ".team") & + helper.deepEquals(hradvisees, otherEmp.getHradvisees(), where + ".hradvisees"); + } + +} + Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSEmployee.java ------------------------------------------------------------------------------ svn:eol-style = LF Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSFullTimeEmployee.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSFullTimeEmployee.java?view=auto&rev=557767 ============================================================================== --- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSFullTimeEmployee.java (added) +++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSFullTimeEmployee.java Thu Jul 19 13:52:29 2007 @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.companyAnnotatedFC; + +import javax.jdo.annotations.*; + +import java.util.Date; +import org.apache.jdo.tck.pc.company.IAddress; +import org.apache.jdo.tck.pc.company.IFullTimeEmployee; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a full-time employee. + */ +@PersistenceCapable +@Inheritance(strategy=InheritanceStrategy.SUPERCLASS_TABLE) +@DatastoreIdentity(strategy=IdGeneratorStrategy.IDENTITY, column="DATASTORE_IDENTITY") +public class FCDSFullTimeEmployee extends FCDSEmployee + implements IFullTimeEmployee { + + @Column(name="SALARY") + private double salary; + + /** This is the JDO-required no-args constructor. The TCK relies on + * this constructor for testing PersistenceManager.newInstance(PCClass). + */ + public FCDSFullTimeEmployee() {} + + /** + * 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 FCDSFullTimeEmployee(long personid, String first, String last, + String middle, Date born, + Date hired, double sal) { + super(personid, first, last, middle, born, hired); + salary = sal; + } + + /** + * 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 addr The person's address. + * @param hired The date that the person was hired. + * @param sal The salary of the full-time employee. + */ + public FCDSFullTimeEmployee(long personid, String first, String last, + String middle, Date born, IAddress addr, + Date hired, double sal) { + super(personid, first, last, middle, born, (FCDSAddress)addr, hired); + 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 FCDSFullTimeEmployee object. + * + * @return a String representation of a FCDSFullTimeEmployee object. + */ + public String toString() { + return "FCFullTimeEmployee(" + 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 + * FCDSFullTimeEmployee. + * + * @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) { + FCDSFullTimeEmployee otherEmp = (FCDSFullTimeEmployee)other; + String where = "FCFullTimeEmployee<" + getPersonid() + ">"; + return super.deepCompareFields(otherEmp, helper) & + helper.closeEnough(salary, otherEmp.getSalary(), where + ".salary"); + } + +} Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSFullTimeEmployee.java ------------------------------------------------------------------------------ svn:eol-style = LF Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSInsurance.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSInsurance.java?view=auto&rev=557767 ============================================================================== --- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSInsurance.java (added) +++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSInsurance.java Thu Jul 19 13:52:29 2007 @@ -0,0 +1,301 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.companyAnnotatedFC; + +import javax.jdo.annotations.*; + +import java.io.Serializable; + +import java.util.Comparator; +import org.apache.jdo.tck.pc.company.IEmployee; +import org.apache.jdo.tck.pc.company.IInsurance; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents an insurance carrier selection for a particular + * FCDSEmployee. + */ +@PersistenceCapable(table="insuranceplans") +@Inheritance(strategy=InheritanceStrategy.NEW_TABLE) +@Discriminator(strategy=DiscriminatorStrategy.CLASS_NAME, + column="DISCRIMINATOR", indexed="true") +@Index(name="INS_DISCRIMINATOR_INDEX", unique="false", + columns=@Column(name="DISCRIMINATOR")) +@DatastoreIdentity(strategy=IdGeneratorStrategy.IDENTITY, + column="DATASTORE_IDENTITY") +public class FCDSInsurance + implements IInsurance, Serializable, Comparable, Comparator, DeepEquality { + + @Column(name="INSID") + private long insid; + @Column(name="CARRIER") + private String carrier; + @Column(name="EMPLOYEE") + private FCDSEmployee employee; + + /** This is the JDO-required no-args constructor. */ + protected FCDSInsurance() {} + + /** + * Construct an FCDSInsurance instance. + * + * @param insid The insurance instance identifier. + * @param carrier The insurance carrier. + */ + protected FCDSInsurance(long insid, String carrier) { + this.insid = insid; + this.carrier = carrier; + } + + /** + * Construct an FCDSInsurance instance. + * + * @param insid The insurance instance identifier. + * @param carrier The insurance carrier. + * @param employee The employee associated with this insurance. + */ + protected FCDSInsurance(long insid, String carrier, FCDSEmployee employee) { + this.insid = insid; + this.carrier = carrier; + this.employee = employee; + } + + /** + * Get the insurance ID. + * @return the insurance ID. + */ + public long getInsid() { + return insid; + } + + /** + * Set the insurance ID. + * @param id The insurance ID value. + */ + public void setInsid(long id) { + if (this.insid != 0) + throw new IllegalStateException("Id is already set."); + this.insid = id; + } + + /** + * Get the insurance carrier. + * @return The insurance carrier. + */ + public String getCarrier() { + return carrier; + } + + /** + * Set the insurance carrier. + * @param carrier The insurance carrier. + */ + public void setCarrier(String carrier) { + this.carrier = carrier; + } + + /** + * Get the associated employee. + * @return The employee for this insurance. + */ + public IEmployee getEmployee() { + return employee; + } + + /** + * Set the associated employee. + * @param employee The associated employee. + */ + public void setEmployee(IEmployee employee) { + this.employee = (FCDSEmployee)employee; + } + + /** + * Returns a String representation of a FCDSInsurance object. + * + * @return a String representation of a FCDSInsurance object. + */ + public String toString() { + return "FCInsurance(" + 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(insid); + rc.append(", carrier ").append(carrier); + return rc.toString(); + } + + /** + * Returns true if all the fields of this instance are + * deep equal to the coresponding fields of the other Object. + * @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) { + FCDSInsurance otherIns = (FCDSInsurance)other; + String where = "FCInsurance<" + insid + ">"; + return + helper.equals(insid, otherIns.getInsid(), where + ".insid") & + helper.equals(carrier, otherIns.getCarrier(), where + ".carrier") & + helper.deepEquals(employee, otherIns.getEmployee(), where + ".employee"); + } + + /** + * 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((FCDSInsurance)o); + } + + /** + * Compare two instances. This is a method in Comparator. + */ + public int compare(Object o1, Object o2) { + return compare((FCDSInsurance)o1, (FCDSInsurance)o2); + } + + /** + * Compares this object with the specified Insurance 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 Insurance 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 + * Insurance object. + */ + public int compareTo(FCDSInsurance other) { + return compare(this, other); + } + + /** + * Compares its two IInsurance 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 IInsurance object to be compared. + * @param o2 the second IInsurance 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(FCDSInsurance o1, FCDSInsurance o2) { + return EqualityHelper.compare(o1.getInsid(), o2.getInsid()); + } + + /** + * 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 FCDSInsurance) { + return compareTo((FCDSInsurance)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)insid; + } + + /** + * This class is used to represent the application + * identifier for the Insurance class. + */ + public static class Oid implements Serializable, Comparable + { + /** + * This field represents the application identifier for the + * Insurance class. It must match the field in the + * Insurance class in both name and type. + */ + public long insid; + + /** + * The required public no-args constructor. + */ + public Oid() { } + + /** + * Initialize with an insurance identifier. + * @param insid the insurance ID. + */ + public Oid(long insid) { + this.insid = insid; + } + + public Oid(String s) { insid = Long.parseLong(justTheId(s)); } + + public String toString() { return this.getClass().getName() + ": " + insid;} + + + /** */ + public boolean equals(java.lang.Object obj) { + if( obj==null || !this.getClass().equals(obj.getClass()) ) + return( false ); + Oid o=(Oid) obj; + if( this.insid!=o.insid ) return( false ); + return( true ); + } + + /** */ + public int hashCode() { + return( (int) insid ); + } + + 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( insid < other.insid ) return -1; + if( insid > other.insid ) return 1; + return 0; + } + + } + +} + Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSInsurance.java ------------------------------------------------------------------------------ svn:eol-style = LF Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSMedicalInsurance.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSMedicalInsurance.java?view=auto&rev=557767 ============================================================================== --- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSMedicalInsurance.java (added) +++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSMedicalInsurance.java Thu Jul 19 13:52:29 2007 @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.companyAnnotatedFC; + +import javax.jdo.annotations.*; +import org.apache.jdo.tck.pc.company.IMedicalInsurance; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a dental insurance carrier selection for a + * particular Employee. + */ +@PersistenceCapable +@DatastoreIdentity(strategy=IdGeneratorStrategy.IDENTITY, column="DATASTORE_IDENTITY") +public class FCDSMedicalInsurance extends FCDSInsurance + implements IMedicalInsurance { + + @Column(name="PLANTYPE") + private String planType; // possible values: "PPO", "EPO", "NPO" + + /** This is the JDO-required no-args constructor. The TCK relies on + * this constructor for testing PersistenceManager.newInstance(PCClass). + */ + public FCDSMedicalInsurance() {} + + /** + * Construct a FCDSMedicalInsurance instance. + * + * @param insid The insurance instance identifier. + * @param carrier The insurance carrier. + * @param planType The planType. + */ + public FCDSMedicalInsurance(long insid, String carrier, + String planType) + { + super(insid, carrier); + this.planType = planType; + } + + /** + * Construct a FCDSMedicalInsurance instance. + * + * @param insid The insurance instance identifier. + * @param carrier The insurance carrier. + * @param employee The employee associated with this insurance. + * @param planType The planType. + */ + public FCDSMedicalInsurance(long insid, String carrier, + FCDSEmployee employee, String planType) + { + super(insid, carrier, employee); + this.planType = planType; + } + + /** + * Get the insurance planType. + * @return The insurance planType. + */ + public String getPlanType() { + return planType; + } + + /** + * Set the insurance planType. + * @param planType The insurance planType. + */ + public void setPlanType(String planType) { + this.planType = planType; + } + + /** + * Returns a String representation of a FCDSMedicalInsurance + * object. + * + * @return a String representation of a FCDSMedicalInsurance + * object. + */ + public String toString() { + return "FCMedicalInsurance(" + 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(", planType ").append(planType); + return rc.toString(); + } + + /** + * Returns true if all the fields of this instance are + * deep equal to the coresponding fields of the other Object. + * @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) { + FCDSMedicalInsurance otherIns = (FCDSMedicalInsurance)other; + String where = "FCMedicalInsurance<" + getInsid() + ">"; + return super.deepCompareFields(otherIns, helper) & + helper.equals(planType, otherIns.getPlanType(), where + ".planType"); + } +} + Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSMedicalInsurance.java ------------------------------------------------------------------------------ svn:eol-style = LF Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSPartTimeEmployee.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSPartTimeEmployee.java?view=auto&rev=557767 ============================================================================== --- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSPartTimeEmployee.java (added) +++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSPartTimeEmployee.java Thu Jul 19 13:52:29 2007 @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.companyAnnotatedFC; + +import javax.jdo.annotations.*; + +import java.util.Date; +import org.apache.jdo.tck.pc.company.IAddress; +import org.apache.jdo.tck.pc.company.IPartTimeEmployee; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a part-time employee. + */ +@PersistenceCapable +@Inheritance(strategy=InheritanceStrategy.SUPERCLASS_TABLE) +@DatastoreIdentity(strategy=IdGeneratorStrategy.IDENTITY, column="DATASTORE_IDENTITY") +public class FCDSPartTimeEmployee extends FCDSEmployee implements IPartTimeEmployee { + + @Column(name="WAGE") + private double wage; + + /** This is the JDO-required no-args constructor. The TCK relies on + * this constructor for testing PersistenceManager.newInstance(PCClass). + */ + public FCDSPartTimeEmployee() {} + + /** + * 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 FCDSPartTimeEmployee(long personid, String first, String last, + String middle, Date born, + Date hired, double wage ) { + super(personid, first, last, middle, born, hired); + this.wage = wage; + } + + /** + * 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 addr The person's address. + * @param hired The date the person was hired. + * @param wage The person's wage. + */ + public FCDSPartTimeEmployee(long personid, String first, String last, + String middle, Date born, IAddress addr, + Date hired, double wage ) { + super(personid, first, last, middle, born, (FCDSAddress)addr, hired); + 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 FCDSPartTimeEmployee object. + * + * @return a String representation of a FCDSPartTimeEmployee object. + */ + public String toString() { + return "FCPartTimeEmployee(" + 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 + * FCDSPartTimeEmployee. + * + * @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) { + FCDSPartTimeEmployee otherEmp = (FCDSPartTimeEmployee)other; + String where = "FCPartTimeEmployee<" + getPersonid() + ">"; + return super.deepCompareFields(otherEmp, helper) & + helper.closeEnough(wage, otherEmp.getWage(), where + ".wage"); + } +} Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSPartTimeEmployee.java ------------------------------------------------------------------------------ svn:eol-style = LF Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSPerson.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSPerson.java?view=auto&rev=557767 ============================================================================== --- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSPerson.java (added) +++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSPerson.java Thu Jul 19 13:52:29 2007 @@ -0,0 +1,457 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.companyAnnotatedFC; + +import javax.jdo.annotations.*; + +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.pc.company.IAddress; +import org.apache.jdo.tck.pc.company.IPerson; + +import org.apache.jdo.tck.util.DeepEquality; +import org.apache.jdo.tck.util.EqualityHelper; + +/** + * This class represents a person. + */ +@PersistenceCapable(table="persons") +@Inheritance(strategy=InheritanceStrategy.NEW_TABLE) +@Discriminator(strategy=DiscriminatorStrategy.CLASS_NAME, + column="DISCRIMINATOR", indexed="true") +@DatastoreIdentity(strategy=IdGeneratorStrategy.IDENTITY, + column="DATASTORE_IDENTITY") +public class FCDSPerson + implements IPerson, Serializable, Comparable, Comparator, DeepEquality { + + @Column(name="PERSONID") + private long personid; + @Column(name="FIRSTNAME") + private String firstname; + @Column(name="LASTNAME") + private String lastname; + @Field(defaultFetchGroup="false") + @Column(name="MIDDLENAME", allowsNull="true") + private String middlename; + private Date birthdate; + @Field(persistenceModifier=FieldPersistenceModifier.PERSISTENT) + @Embedded(nullIndicatorColumn="COUNTRY", + fields={ + @Field(name="addrid", columns=@Column(name="ADDRID")), + @Field(name="street", columns=@Column(name="STREET")), + @Field(name="city", columns=@Column(name="CITY")), + @Field(name="state", columns=@Column(name="STATE")), + @Field(name="zipcode", columns=@Column(name="ZIPCODE")), + @Field(name="country", columns=@Column(name="COUNTRY")) + }) + private FCDSAddress address; + + // maps phone number types ("home", "work", "mobile", etc.) + // to phone numbers specified as String + @Field(persistenceModifier=FieldPersistenceModifier.PERSISTENT, + table="employee_phoneno_type") + @Join(column="EMPID") + @Key(types=java.lang.String.class, column="TYPE") + @Value(types=java.lang.String.class, column="PHONENO") + private Map phoneNumbers = new HashMap(); + + protected static SimpleDateFormat formatter = + new SimpleDateFormat("d/MMM/yyyy"); + + /** This is the JDO-required no-args constructor. */ + protected FCDSPerson() {} + + /** + * Construct a FCDSPerson 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 FCDSPerson(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; + } + + /** + * Construct a FCDSPerson 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. + * @param address The person's address. + */ + public FCDSPerson(long personid, String firstname, String lastname, + String middlename, Date birthdate, IAddress address) { + this(personid, firstname, lastname, middlename, birthdate); + this.address = (FCDSAddress)address; + } + + /** + * 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 address. + * @return The address. + */ + public IAddress getAddress() { + return address; + } + + /** + * Set the address. + * @param address The address. + */ + public void setAddress(IAddress address) { + this.address = (FCDSAddress)address; + } + + /** + * 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; + } + + /** + * Get the map of phone numbers as an unmodifiable map. + * @return The map of phone numbers, as an unmodifiable map. + */ + public Map getPhoneNumbers() { + return Collections.unmodifiableMap(phoneNumbers); + } + + /** + * Get the phone number for the specified phone number type. + * @param type The phone number type ("home", "work", "mobile", etc.). + * @return The phone number associated with specified type, or + * null if there was no phone number for the type. + */ + public String getPhoneNumber(String type) { + return (String)phoneNumbers.get(type); + } + + /** + * Associates the specified phone number with the specified type in the + * map of phone numbers of this person. + * @param type The phone number type ("home", "work", "mobile", etc.). + * @param phoneNumber The phone number + * @return The previous phone number associated with specified type, or + * null if there was no phone number for the type. + */ + public String putPhoneNumber(String type, String phoneNumber) { + return (String)phoneNumbers.put(type, phoneNumber); + } + + /** + * Remove a phoneNumber from the map of phone numbers. + * @param type The phone number type ("home", "work", "mobile", etc.). + * @return The previous phone number associated with specified type, or + * null if there was no phone number for the type. + */ + public String removePhoneNumber(String type) { + return (String)phoneNumbers.remove(type); + } + + /** + * Set the phoneNumber map to be in this person. + * @param phoneNumbers The map of phoneNumbers for this person. + */ + public void setPhoneNumbers(Map phoneNumbers) { + // workaround: create a new HashMap, because fostore does not + // support LinkedHashMap + this.phoneNumbers = + (phoneNumbers != null) ? new HashMap(phoneNumbers) : null; + } + + /** + * Returns a String representation of a FCDSPerson object. + * + * @return a string representation of a FCDSPerson object. + */ + public String toString() { + return "FCPerson(" + 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)); + rc.append(", phone ").append(phoneNumbers); + return rc.toString(); + } + + /** + * + * Returns true if all the fields of this instance are + * deep equal to the coresponding fields of the specified FCDSPerson. + * + * @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) { + FCDSPerson otherPerson = (FCDSPerson)other; + String where = "FCPerson<" + 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") & + helper.deepEquals(address, otherPerson.getAddress(), where + ".address") & + helper.deepEquals(phoneNumbers, otherPerson.getPhoneNumbers(), where + ".phoneNumbers"); + } + + /** + * 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((FCDSPerson)o); + } + + /** + * Compare two instances. This is a method in Comparator. + */ + public int compare(Object o1, Object o2) { + return compare((FCDSPerson)o1, (FCDSPerson)o2); + } + + /** + * + * Compares this object with the specified FCDSPerson 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 FCDSPerson 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 FFCDSPerson + * object. + */ + public int compareTo(FCDSPerson 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(FCDSPerson o1, FCDSPerson 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 FCDSPerson) { + return compareTo((FCDSPerson)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; + } + + } + +} Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedFC/FCDSPerson.java ------------------------------------------------------------------------------ svn:eol-style = LF