You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mc...@apache.org on 2007/10/18 23:36:58 UTC
svn commit: r586149 - in
/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedJPA:
JPAAppPerson.java JPAAppPhoneNumber.java
Author: mcaisse
Date: Thu Oct 18 14:36:57 2007
New Revision: 586149
URL: http://svn.apache.org/viewvc?rev=586149&view=rev
Log:
JDO-543 updated files
Modified:
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedJPA/JPAAppPerson.java
db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedJPA/JPAAppPhoneNumber.java
Modified: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedJPA/JPAAppPerson.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedJPA/JPAAppPerson.java?rev=586149&r1=586148&r2=586149&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedJPA/JPAAppPerson.java (original)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedJPA/JPAAppPerson.java Thu Oct 18 14:36:57 2007
@@ -40,6 +40,7 @@
*/
@Entity
@Table(name="persons")
+@IdClass(org.apache.jdo.tck.pc.companyAnnotatedJPA.JPAAppPerson.Oid.class)
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType=DiscriminatorType.STRING,
name="DISCRIMINATOR")
@@ -74,10 +75,10 @@
})
private JPAAppAddress address;
- @OneToMany
- @MapKey
- private Map<JPAAppPhoneNumber.Oid,
- JPAAppPhoneNumber> phoneNumbers = new HashMap();
+ @OneToMany(mappedBy="person")
+ @MapKey(name="type")
+ private Map<String, JPAAppPhoneNumber> phoneNumbers
+ = new HashMap<String, JPAAppPhoneNumber>();
protected static SimpleDateFormat formatter =
new SimpleDateFormat("d/MMM/yyyy");
@@ -251,8 +252,8 @@
if (pnum != null) {
pnumAsString = pnum.getPhoneNumber(); // old val
}
- pnum = phoneNumbers.put(new JPAAppPhoneNumber.Oid(personid, type),
- new JPAAppPhoneNumber(personid, type, phoneNumber));
+ pnum = phoneNumbers.put(type,
+ new JPAAppPhoneNumber(this, type, phoneNumber));
return pnumAsString;
}
@@ -287,7 +288,7 @@
String key = (String)entry.getKey();
String value = (String)entry.getValue();
JPAAppPhoneNumber newValue =
- new JPAAppPhoneNumber(personid, key, value);
+ new JPAAppPhoneNumber(this, key, value);
retval.put(key, newValue);
}
return retval;
Modified: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedJPA/JPAAppPhoneNumber.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedJPA/JPAAppPhoneNumber.java?rev=586149&r1=586148&r2=586149&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedJPA/JPAAppPhoneNumber.java (original)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/pc/companyAnnotatedJPA/JPAAppPhoneNumber.java Thu Oct 18 14:36:57 2007
@@ -29,13 +29,14 @@
@IdClass(org.apache.jdo.tck.pc.companyAnnotatedJPA.JPAAppPhoneNumber.Oid.class)
@Table(name="employee_phoneno_type")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
-@DiscriminatorColumn(discriminatorType=DiscriminatorType.STRING,
- name="DISCRIMINATOR")
+//@DiscriminatorColumn(discriminatorType=DiscriminatorType.STRING,
+// name="DISCRIMINATOR")
public class JPAAppPhoneNumber implements Serializable {
@Id
- @Column(name="PERSONID")
- private long personid;
+ @ManyToOne
+ @Column(name="EMPID")
+ private JPAAppPerson person;
@Id
@Column(name="TYPE")
private String type;
@@ -49,12 +50,13 @@
* Construct a <code>JPAAppPhoneNumber</code> instance.
*
* @param phonenumid The phone number identifier.
- * @param personid The person id
+ * @param person The person id
* @param type The type of the phone for this number
* @param phoneNumber The phone number
*/
- public JPAAppPhoneNumber(long personid, String type, String phoneNumber) {
- this.personid = personid;
+ public JPAAppPhoneNumber(JPAAppPerson person, String type,
+ String phoneNumber) {
+ this.person = person;
this.type = type;
this.phoneNumber = phoneNumber;
}
@@ -63,18 +65,18 @@
* Set the id associated with this object.
* @param id the id.
*/
- public void setPersonid(long id) {
- if (this.personid != 0)
+ public void setPerson(JPAAppPerson id) {
+ if (this.person != null)
throw new IllegalStateException("Id is already set.");
- this.personid = id;
+ this.person = id;
}
/**
* Get the person's id.
- * @return The personid.
+ * @return The person.
*/
- public long getPersonid() {
- return personid;
+ public JPAAppPerson getPerson() {
+ return person;
}
/**
@@ -125,7 +127,7 @@
*/
protected String getFieldRepr() {
StringBuffer rc = new StringBuffer();
- rc.append(personid);
+ rc.append(person);
rc.append(", ").append(type);
rc.append(", phone ").append(phoneNumber);
return rc.toString();
@@ -142,7 +144,7 @@
* class. It must match a field in the <code>Person</code> class in
* both name and type.
*/
- public long personid;
+ public JPAAppPerson.Oid person;
public String type;
@@ -153,20 +155,20 @@
/**
* Initialize the identifier.
- * @param personid The person identifier.
+ * @param person The person identifier.
*/
- public Oid(long personid, String type) {
- this.personid = personid;
+ public Oid(JPAAppPerson.Oid person, String type) {
+ this.person = person;
this.type = type;
}
public Oid(String s) {
- personid = Long.parseLong(justTheId(s));
+ person = new JPAAppPerson.Oid(justTheOid(s));
type = justTheType(s);
}
public String toString() {
- return this.getClass().getName() + ": " + personid + " + " + type;
+ return this.getClass().getName() + ": " + person + " + " + type;
}
/** */
@@ -174,17 +176,17 @@
if( obj==null ||
!this.getClass().equals(obj.getClass()) ) return( false );
Oid o = (Oid) obj;
- if( this.personid != o.personid ) return( false );
+ if( this.person != o.person ) return( false );
if( this.type != o.type ) return( false );
return( true );
}
/** */
public int hashCode() {
- return( (int) personid + type.hashCode() );
+ return( (int) person.hashCode() + type.hashCode() );
}
- protected static String justTheId(String str) {
+ protected static String justTheOid(String str) {
return str.substring(str.indexOf(':') + 1, str.indexOf('+') - 1);
}
@@ -196,10 +198,12 @@
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 type.compareTo(other.type);
+ int comparison = person.compareTo(other.person);
+ if( comparison != 0 ) {
+ return comparison;
+ } else {
+ return type.compareTo(other.type);
+ }
}
}