Return-Path: Delivered-To: apmail-db-jdo-commits-archive@www.apache.org Received: (qmail 64106 invoked from network); 26 Jan 2010 04:49:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 26 Jan 2010 04:49:48 -0000 Received: (qmail 77493 invoked by uid 500); 26 Jan 2010 04:49:47 -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 77484 invoked by uid 99); 26 Jan 2010 04:49:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Jan 2010 04:49:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Jan 2010 04:49:45 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9634623888BD; Tue, 26 Jan 2010 04:49:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r903076 - in /db/jdo/trunk/tck2/src: conf/ java/org/apache/jdo/tck/api/persistencemanager/getobject/ java/org/apache/jdo/tck/pc/singlefieldidentity/ jdo/applicationidentity/org/apache/jdo/tck/pc/singlefieldidentity/ Date: Tue, 26 Jan 2010 04:49:25 -0000 To: jdo-commits@db.apache.org From: clr@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100126044925.9634623888BD@eris.apache.org> Author: clr Date: Tue Jan 26 04:49:24 2010 New Revision: 903076 URL: http://svn.apache.org/viewvc?rev=903076&view=rev Log: Add tests for single field identity getObjectById exact class Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanager/getobject/GetObjectByIdExactClass.java (with props) db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/Employee.java (with props) db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/FullTimeEmployee.java (with props) db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/PartTimeEmployee.java (with props) db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/Person.java (with props) Modified: db/jdo/trunk/tck2/src/conf/pm.conf db/jdo/trunk/tck2/src/jdo/applicationidentity/org/apache/jdo/tck/pc/singlefieldidentity/package.jdo Modified: db/jdo/trunk/tck2/src/conf/pm.conf URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/conf/pm.conf?rev=903076&r1=903075&r2=903076&view=diff ============================================================================== --- db/jdo/trunk/tck2/src/conf/pm.conf (original) +++ db/jdo/trunk/tck2/src/conf/pm.conf Tue Jan 26 04:49:24 2010 @@ -76,6 +76,7 @@ org.apache.jdo.tck.api.persistencemanager.flags.SetMultithreadedTrue \ org.apache.jdo.tck.api.persistencemanager.flags.SettingFlagsWithTransactionInstance \ org.apache.jdo.tck.api.persistencemanager.getobject.GetObjectById \ +org.apache.jdo.tck.api.persistencemanager.getobject.GetObjectByIdExactClass \ org.apache.jdo.tck.api.persistencemanager.getobject.GetObjectByIdNoValidationInstanceInCache \ org.apache.jdo.tck.api.persistencemanager.getobject.GetObjectByIdNoValidationInstanceInCacheNoStateChange \ org.apache.jdo.tck.api.persistencemanager.getobject.GetObjectByIdNoValidationInstanceNotInCache \ Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanager/getobject/GetObjectByIdExactClass.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanager/getobject/GetObjectByIdExactClass.java?rev=903076&view=auto ============================================================================== --- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanager/getobject/GetObjectByIdExactClass.java (added) +++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanager/getobject/GetObjectByIdExactClass.java Tue Jan 26 04:49:24 2010 @@ -0,0 +1,283 @@ +/* + * 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.api.persistencemanager.getobject; + +import java.util.Date; +import javax.jdo.Transaction; +import javax.jdo.JDOException; + +import javax.jdo.identity.LongIdentity; + +import org.apache.jdo.tck.util.BatchTestRunner; +import org.apache.jdo.tck.api.persistencemanager.PersistenceManagerTest; + +import org.apache.jdo.tck.pc.singlefieldidentity.Person; +import org.apache.jdo.tck.pc.singlefieldidentity.Employee; +import org.apache.jdo.tck.pc.singlefieldidentity.PartTimeEmployee; +import org.apache.jdo.tck.pc.singlefieldidentity.FullTimeEmployee; + +/** + *Title: Get Object By Id + *
+ *Keywords: identity cache + *
+ *Assertion ID: A12.5.6-???. + *
+ *Assertion Description: + If PersistenceManager.getObjectById is called with a value of + false for the second parameter named validate, + and there is not an instance already in the cache with the same JDO identity + as the oid parameter, then this method creates an instance with the specified + JDO identity, and returns it. + * If the class is abstract, throw JDOUserException (we cannot construct + * a hollow instance of an abstract class). + * If the class is actually not correct, an exception with an + * error message will be thrown later if any field other than the identity + * field id accessed. + */ + +public class GetObjectByIdExactClass extends PersistenceManagerTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A12.5.6-??? (GetObjectById) failed: "; + + /** */ + private LongIdentity oid; + + /** */ + private long id; + + /** + * 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(GetObjectByIdExactClass.class); + } + + @Override + public void localSetUp() { + if (!runsWithApplicationIdentity()) { + printNonApplicableIdentityType( + "GetObjectIdExactClass", + APPLICATION_IDENTITY); + return; + } + pm = getPM(); + pm.currentTransaction().begin(); + // create an instance of FullTimeEmployee. + FullTimeEmployee instance = new FullTimeEmployee(); + instance.setPersonid(1000000L); + instance.setFirstname("Full"); + instance.setLastname("Timer"); + instance.setBirthdate(new Date()); + pm.makePersistent(instance); + pm.currentTransaction().commit(); + oid = (LongIdentity)pm.getObjectId(instance); + id = oid.getKey(); + pm.close(); + pm = null; + addTearDownClass(FullTimeEmployee.class); + } + + /** */ + public void testAbstractSuperclassExact() { + if (!runsWithApplicationIdentity()) return; + Transaction tx = null; + try { + pm = getPM(); + pm.currentTransaction().begin(); + // create the oid + Object abstractOid = new LongIdentity(Employee.class, id); + pm.getObjectById(abstractOid, false); + appendMessage(ASSERTION_FAILED + "getObjectById exact " + + "for abstract superclass must fail."); + } catch (JDOException ex) { + // good catch + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + failOnError(); + } + + /** */ + public void testAbstractSuperclassNotExact() { + if (!runsWithApplicationIdentity()) return; + Transaction tx = null; + try { + pm = getPM(); + pm.currentTransaction().begin(); + // create the oid + Object abstractOid = new LongIdentity(Employee.class, id); + Object abstractInstance = pm.getObjectById(abstractOid, true); + if (abstractInstance.getClass() != FullTimeEmployee.class) { + appendMessage(ASSERTION_FAILED + "getObjectById not exact " + + "for abstract superclass returned wrong type " + + abstractInstance.getClass().getName()); + } + } catch (JDOException ex) { + appendMessage(ASSERTION_FAILED + "getObjectById not exact " + + "for abstract superclass threw exception " + + ex.getMessage()); + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + failOnError(); + } + + /** */ + public void testConcreteSuperclassExact() { + if (!runsWithApplicationIdentity()) return; + Transaction tx = null; + Person instance = null; + try { + pm = getPM(); + pm.currentTransaction().begin(); + // create the oid + Object superclassOid = new LongIdentity(Person.class, id); + instance = (Person)pm.getObjectById(superclassOid, false); + if (instance.getClass() != Person.class) { + appendMessage(ASSERTION_FAILED + "getObjectById exact for " + + "concrete superclass should return " + + "Person.class but returned wrong type " + + instance.getClass().getName()); + } + } catch (Exception ex) { + appendMessage(ASSERTION_FAILED + "getObjectById exact for " + + "concrete superclass must succeed before accessing database."); + } + try { + instance.toString(); // accesses non-key fields + appendMessage(ASSERTION_FAILED + "getObjectById exact for " + + "concrete superclass must fail when accessing database."); + } catch (JDOException ex) { + // good catch + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + failOnError(); + } + + /** */ + public void testConcreteSuperclassNotExact() { + if (!runsWithApplicationIdentity()) return; + Transaction tx = null; + try { + pm = getPM(); + pm.currentTransaction().begin(); + // create the oid + Object superclassOid = new LongIdentity(Person.class, id); + Object instance = pm.getObjectById(superclassOid, true); + if (instance.getClass() != FullTimeEmployee.class) { + appendMessage(ASSERTION_FAILED + "getObjectById not exact for " + + "concrete superclass should return FullTimeEmployee " + + "but returned wrong type " + + instance.getClass().getName()); + } + } catch (JDOException ex) { + appendMessage(ASSERTION_FAILED + " getObjectById not exact for " + + "concrete superclass must succeed but threw " + + ex.getMessage()); + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + failOnError(); + } + + /** */ + public void testWrongClass() { + if (!runsWithApplicationIdentity()) return; + Transaction tx = null; + try { + pm = getPM(); + pm.currentTransaction().begin(); + // create the oid + Object wrongOid = new LongIdentity(PartTimeEmployee.class, id); + PartTimeEmployee wrongInstance = + (PartTimeEmployee)pm.getObjectById(wrongOid, false); + wrongInstance.toString(); + appendMessage(ASSERTION_FAILED + " getObjectById exact " + + "for wrong class must throw JDOUserException."); + } catch (JDOException ex) { + // good catch + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + failOnError(); + } + + /** */ + public void testRightClassNotExact() { + if (!runsWithApplicationIdentity()) return; + Transaction tx = null; + try { + pm = getPM(); + pm.currentTransaction().begin(); + // create the oid + Object rightOid = new LongIdentity(FullTimeEmployee.class, id); + FullTimeEmployee rightInstance = + (FullTimeEmployee)pm.getObjectById(rightOid, true); + rightInstance.toString(); + } catch (JDOException ex) { + appendMessage(ASSERTION_FAILED + " getObjectById not exact " + + "for right class must succeed."); + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + failOnError(); + } + + /** */ + public void testRightClassExact() { + if (!runsWithApplicationIdentity()) return; + Transaction tx = null; + try { + pm = getPM(); + pm.currentTransaction().begin(); + // create the oid + Object rightOid = new LongIdentity(FullTimeEmployee.class, id); + FullTimeEmployee rightInstance = + (FullTimeEmployee)pm.getObjectById(rightOid, false); + rightInstance.toString(); + } catch (JDOException ex) { + appendMessage(ASSERTION_FAILED + " getObjectById exact " + + "for right class must succeed."); + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + failOnError(); + } + +} Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanager/getobject/GetObjectByIdExactClass.java ------------------------------------------------------------------------------ svn:eol-style = LF Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/Employee.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/Employee.java?rev=903076&view=auto ============================================================================== --- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/Employee.java (added) +++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/Employee.java Tue Jan 26 04:49:24 2010 @@ -0,0 +1,106 @@ +/* + * 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.singlefieldidentity; + +import java.util.Date; + +/** + * This class represents an employee. + */ +public abstract class Employee extends Person { + + private Date hiredate; + private double weeklyhours; + + /** 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) { + super(personid, firstname, lastname, middlename, birthdate); + 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; + } + + /** + * Return a String representation of a Employee object. + * @return a String representation of a Employee object. + */ + @Override + public String toString() { + return "Employee(" + getFieldRepr() + ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + @Override + protected String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(super.getFieldRepr()); + rc.append(", hired ").append( + hiredate==null ? "null" : formatter.format(hiredate)); + rc.append(", weeklyhours ").append(weeklyhours); + return rc.toString(); + } + +} + Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/Employee.java ------------------------------------------------------------------------------ svn:eol-style = LF Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/FullTimeEmployee.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/FullTimeEmployee.java?rev=903076&view=auto ============================================================================== --- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/FullTimeEmployee.java (added) +++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/FullTimeEmployee.java Tue Jan 26 04:49:24 2010 @@ -0,0 +1,88 @@ +/* + * 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.singlefieldidentity; + +import java.util.Date; + +/** + * This class represents a full-time employee. + */ +public class FullTimeEmployee extends Employee { + + 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, double sal) { + super(personid, first, last, middle, born, 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 FullTimeEmployee object. + * @return a String representation of a FullTimeEmployee object. + */ + @Override + public String toString() { + return "FullTimeEmployee(" + getFieldRepr() + ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + @Override + public String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(super.getFieldRepr()); + rc.append(", $").append(salary); + return rc.toString(); + } + +} Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/FullTimeEmployee.java ------------------------------------------------------------------------------ svn:eol-style = LF Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/PartTimeEmployee.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/PartTimeEmployee.java?rev=903076&view=auto ============================================================================== --- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/PartTimeEmployee.java (added) +++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/PartTimeEmployee.java Tue Jan 26 04:49:24 2010 @@ -0,0 +1,87 @@ +/* + * 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.singlefieldidentity; + +import java.util.Date; + +/** + * This class represents a part-time employee. + */ +public class PartTimeEmployee extends Employee { + 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, double wage ) { + super(personid, first, last, middle, born, 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 PartTimeEmployee object. + * @return a String representation of a PartTimeEmployee object. + */ + @Override + public String toString() { + return "PartTimeEmployee(" + getFieldRepr() + ")"; + } + + /** + * Returns a String representation of the non-relationship fields. + * @return a String representation of the non-relationship fields. + */ + @Override + public String getFieldRepr() { + StringBuffer rc = new StringBuffer(); + rc.append(super.getFieldRepr()); + rc.append(", $" + wage); + return rc.toString(); + } + +} Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/PartTimeEmployee.java ------------------------------------------------------------------------------ svn:eol-style = LF Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/Person.java URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/Person.java?rev=903076&view=auto ============================================================================== --- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/Person.java (added) +++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/Person.java Tue Jan 26 04:49:24 2010 @@ -0,0 +1,167 @@ +/* + * 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.singlefieldidentity; + +import java.io.Serializable; + +import java.text.SimpleDateFormat; + +import java.util.Date; + +/** + * This class represents a person. + */ +public class Person + implements Serializable { + + private long id; + 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 id 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.id = 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.id != 0) + throw new IllegalStateException("Id is already set."); + this.id = id; + } + + /** + * Get the person's id. + * @return The id. + */ + public long getPersonid() { + return id; + } + + /** + * 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. + */ + @Override + 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(id); + rc.append(", ").append(lastname); + rc.append(", ").append(firstname); + rc.append(", born ").append( + birthdate==null ? "null" : formatter.format(birthdate)); + return rc.toString(); + } + +} Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/singlefieldidentity/Person.java ------------------------------------------------------------------------------ svn:eol-style = LF Modified: db/jdo/trunk/tck2/src/jdo/applicationidentity/org/apache/jdo/tck/pc/singlefieldidentity/package.jdo URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/jdo/applicationidentity/org/apache/jdo/tck/pc/singlefieldidentity/package.jdo?rev=903076&r1=903075&r2=903076&view=diff ============================================================================== --- db/jdo/trunk/tck2/src/jdo/applicationidentity/org/apache/jdo/tck/pc/singlefieldidentity/package.jdo (original) +++ db/jdo/trunk/tck2/src/jdo/applicationidentity/org/apache/jdo/tck/pc/singlefieldidentity/package.jdo Tue Jan 26 04:49:24 2010 @@ -82,6 +82,20 @@ + + + + + + + + + + + + +