Index: project.properties
===================================================================
--- project.properties (revision 898107)
+++ project.properties (working copy)
@@ -18,7 +18,7 @@
maven.compile.target = 1.5
# Java 1.6 only. Comment this out when using Java 1.5
-maven.compile.compilerargs= -proc:none
+#maven.compile.compilerargs= -proc:none
# Manifest seed file
maven.jar.manifest = ${basedir}/../JDO20.MF
Index: src/java/org/apache/jdo/tck/pc/singlefieldidentity/Person.java
===================================================================
--- src/java/org/apache/jdo/tck/pc/singlefieldidentity/Person.java (revision 0)
+++ src/java/org/apache/jdo/tck/pc/singlefieldidentity/Person.java (revision 0)
@@ -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();
+ }
+
+}
Property changes on: src/java/org/apache/jdo/tck/pc/singlefieldidentity/Person.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Index: src/java/org/apache/jdo/tck/pc/singlefieldidentity/Employee.java
===================================================================
--- src/java/org/apache/jdo/tck/pc/singlefieldidentity/Employee.java (revision 0)
+++ src/java/org/apache/jdo/tck/pc/singlefieldidentity/Employee.java (revision 0)
@@ -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();
+ }
+
+}
+
Property changes on: src/java/org/apache/jdo/tck/pc/singlefieldidentity/Employee.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Index: src/java/org/apache/jdo/tck/pc/singlefieldidentity/FullTimeEmployee.java
===================================================================
--- src/java/org/apache/jdo/tck/pc/singlefieldidentity/FullTimeEmployee.java (revision 0)
+++ src/java/org/apache/jdo/tck/pc/singlefieldidentity/FullTimeEmployee.java (revision 0)
@@ -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();
+ }
+
+}
Property changes on: src/java/org/apache/jdo/tck/pc/singlefieldidentity/FullTimeEmployee.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Index: src/java/org/apache/jdo/tck/pc/singlefieldidentity/PartTimeEmployee.java
===================================================================
--- src/java/org/apache/jdo/tck/pc/singlefieldidentity/PartTimeEmployee.java (revision 0)
+++ src/java/org/apache/jdo/tck/pc/singlefieldidentity/PartTimeEmployee.java (revision 0)
@@ -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();
+ }
+
+}
Property changes on: src/java/org/apache/jdo/tck/pc/singlefieldidentity/PartTimeEmployee.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Index: src/java/org/apache/jdo/tck/api/persistencemanager/getobject/GetObjectByIdExactClass.java
===================================================================
--- src/java/org/apache/jdo/tck/api/persistencemanager/getobject/GetObjectByIdExactClass.java (revision 0)
+++ src/java/org/apache/jdo/tck/api/persistencemanager/getobject/GetObjectByIdExactClass.java (revision 0)
@@ -0,0 +1,242 @@
+/*
+ * 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 StupidUserException (we cannot construct
+ * a hollow instance of an abstract class).
+ * If the class is actually not correct, an exception with an
+ * error message might be thrown later.
+ */
+
+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 PartTimeEmployee.
+ 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) {
+ System.out.println("testAbstractSuperclass caught correct JDOUserException: " + ex.getMessage());
+ }
+ 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 instanceof FullTimeEmployee)) {
+ appendMessage(ASSERTION_FAILED + "getObjectById returned wrong type"
+ + abstractInstance.getClass().getName());
+ }
+ } catch (JDOException ex) {
+ appendMessage(ASSERTION_FAILED + "getObjectById not exact for abstract superclass must succeed.");
+ System.out.println("testAbstractSuperclass caught wrong JDOUserException: " + ex.getMessage());
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ failOnError();
+ }
+
+ /** */
+ public void testConcreteSuperclassExact() {
+ if (!runsWithApplicationIdentity()) return;
+ Transaction tx = null;
+ try {
+ pm = getPM();
+ pm.currentTransaction().begin();
+ // create the oid
+ Object superclassOid = new LongIdentity(Person.class, id);
+ Person instance = (Person)pm.getObjectById(superclassOid, false);
+ if (!(instance instanceof FullTimeEmployee)) {
+ appendMessage(ASSERTION_FAILED + "getObjectById returned wrong type "
+ + instance.getClass().getName());
+ }
+ instance.toString();
+ appendMessage(ASSERTION_FAILED + "getObjectById exact for concrete superclass must fail.");
+ } catch (JDOException ex) {
+ System.out.println("testAbstractSuperclass caught correct JDOUserException: " + ex.getMessage());
+ }
+ 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 instanceof FullTimeEmployee)) {
+ appendMessage(ASSERTION_FAILED + "getObjectById returned wrong type "
+ + instance.getClass().getName());
+ }
+ } catch (JDOException ex) {
+ appendMessage(ASSERTION_FAILED + "getObjectById not exact for concrete superclass must succeed.");
+ System.out.println("testAbstractSuperclass caught wrong JDOUserException: " + 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 for wrong class must fail.");
+ } catch (JDOException ex) {
+ // good catch
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ failOnError();
+ }
+
+ /** */
+ public void testRightClass() {
+ 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 for right class must succeed.");
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ failOnError();
+ }
+
+}
Property changes on: src/java/org/apache/jdo/tck/api/persistencemanager/getobject/GetObjectByIdExactClass.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Index: src/java/org/apache/jdo/tck/api/persistencemanagerfactory/Serialize.java
===================================================================
--- src/java/org/apache/jdo/tck/api/persistencemanagerfactory/Serialize.java (revision 0)
+++ src/java/org/apache/jdo/tck/api/persistencemanagerfactory/Serialize.java (revision 0)
@@ -0,0 +1,142 @@
+/*
+ * 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.persistencemanagerfactory;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Date;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.company.Address;
+import org.apache.jdo.tck.pc.company.Company;
+import org.apache.jdo.tck.util.BatchTestRunner;
+import org.apache.jdo.tck.util.EqualityHelper;
+
+/**
+ *Title:ReadOnly property of PersistenceManagerFactory
+ *
+ *Keywords: persistencemanagerfactory
+ *
+ *Assertion IDs:A11.10-1
+ *
+ *Assertion Description:
+ * If the persistence manager factory was created
+ * via the getPersistenceManagerFactory(Map props) method, then
+ * the serializable properties in props must be written to the stream
+ * and upon restoration, used to construct or locate
+ * the persistence manager factory in the new context.
+ */
+
+
+public class Serialize extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion Serializable failed: ";
+
+ /** The company oid */
+ Object oid;
+
+ /** The company */
+ Company referenceCompany;
+
+ /**
+ * 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(FlushThrowsIfReadOnly.class);
+ }
+
+ /**
+ * @see JDO_Test#localSetUp()
+ */
+ protected void localSetUp() {
+ addTearDownClass(Company.class);
+ // make sure the PMF is initialized
+ getPM();
+ pm.currentTransaction().begin();
+ referenceCompany = new Company(1L, "Sun Microsystems", new Date(),
+ new Address(0,"","","","",""));
+ pm.makePersistent(referenceCompany);
+ oid = pm.getObjectId(referenceCompany);
+ pm.currentTransaction().commit();
+ pm.close();
+ }
+
+ /** */
+ public void testMaterializePMFinSameVM() {
+ /** Equality helper */
+ EqualityHelper helper = new EqualityHelper();
+
+ // serialize the PMF to a stream
+ byte[] serializedPMF = serializeObject(pmf);
+
+ // Materialize PMF from stream and read the object
+ PersistenceManagerFactory pmf2;
+ pmf2 = (PersistenceManagerFactory)materializeObject(serializedPMF);
+
+ PersistenceManager pm2;
+ pm2 = pmf2.getPersistenceManager();
+
+ Transaction tx2 = pm2.currentTransaction();
+ tx2.begin();
+ // make sure Company and Company OID are known to this PMF
+ Company newCompany = new Company(100L, "Sun Microsystems", new Date(),
+ new Address(0,"","","","",""));
+ pm2.makePersistent(newCompany);
+ Company comp = (Company)pm2.getObjectById(oid);
+ if (!helper.deepEquals(referenceCompany, comp)) {
+ appendMessage(helper.getUnequalBuffer());
+ }
+ tx2.rollback();
+ pm2.close();
+ pm2 = null;
+ closePMF(pmf2);
+ failOnError();
+ }
+
+ protected byte[] serializeObject(Object o) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(o);
+ return baos.toByteArray();
+ } catch (Throwable t) {
+ throw new RuntimeException("serializeObject threw " + t, t);
+ }
+ }
+
+ protected Object materializeObject(byte[] ba) {
+ ObjectInputStream ois = null;
+ try {
+ ByteArrayInputStream bios = new ByteArrayInputStream(ba);
+ ois = new ObjectInputStream(bios);
+ return ois.readObject();
+ } catch (Throwable t) {
+ throw new RuntimeException("materializeObject threw " + t, t);
+ }
+ }
+}
Property changes on: src/java/org/apache/jdo/tck/api/persistencemanagerfactory/Serialize.java
___________________________________________________________________
Name: svn:eol-style
+ LF
Index: src/jdo/applicationidentity/org/apache/jdo/tck/pc/singlefieldidentity/package.jdo
===================================================================
--- src/jdo/applicationidentity/org/apache/jdo/tck/pc/singlefieldidentity/package.jdo (revision 898107)
+++ src/jdo/applicationidentity/org/apache/jdo/tck/pc/singlefieldidentity/package.jdo (working copy)
@@ -82,6 +82,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: src/orm/applicationidentity/org/apache/jdo/tck/pc/singlefieldidentity/package-standard.orm
===================================================================
--- src/orm/applicationidentity/org/apache/jdo/tck/pc/singlefieldidentity/package-standard.orm (revision 898107)
+++ src/orm/applicationidentity/org/apache/jdo/tck/pc/singlefieldidentity/package-standard.orm (working copy)
@@ -98,5 +98,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+