Index: foundation/eclipselink.extension.oracle.test/build.xml =================================================================== --- foundation/eclipselink.extension.oracle.test/build.xml (revision 3503) +++ foundation/eclipselink.extension.oracle.test/build.xml (working copy) @@ -161,6 +161,12 @@ + + + + + + + org.eclipse.persistence.jpa.PersistenceProvider + org.eclipse.persistence.testing.models.jpa.proxyauthentication.Employee + org.eclipse.persistence.testing.models.jpa.proxyauthentication.PhoneNumber + + + + + + + + + Index: foundation/eclipselink.extension.oracle.test/resource/proxyauthentication/persistence.xml =================================================================== --- foundation/eclipselink.extension.oracle.test/resource/proxyauthentication/persistence.xml (revision 0) +++ foundation/eclipselink.extension.oracle.test/resource/proxyauthentication/persistence.xml (revision 0) @@ -0,0 +1,14 @@ + + + org.eclipse.persistence.jpa.PersistenceProvider + org.eclipse.persistence.testing.models.jpa.proxyauthentication.Employee + org.eclipse.persistence.testing.models.jpa.proxyauthentication.PhoneNumber + + + + + + + + + Index: foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/Employee.java =================================================================== --- foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/Employee.java (revision 0) +++ foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/Employee.java (revision 0) @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 1998, 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 + * which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Oracle - initial API and implementation from Oracle TopLink + ******************************************************************************/ +package org.eclipse.persistence.testing.models.jpa.proxyauthentication; + +import java.io.Serializable; +import java.util.*; +import javax.persistence.*; + +import static javax.persistence.CascadeType.*; +import static javax.persistence.FetchType.*; +import static javax.persistence.GenerationType.*; + +import org.eclipse.persistence.annotations.PrivateOwned; +import org.eclipse.persistence.annotations.Property; + +@Entity +@Table(name="PA_CONN.JPA_PROXY_EMPLOYEE") + +public class Employee implements Serializable { + + private Integer id; + + private String m_lastName; + private String m_firstName; + + public Employee () { + } + + public Employee(String firstName, String lastName){ + this(); + this.m_firstName = firstName; + this.m_lastName = lastName; + } + + @Id + @GeneratedValue(strategy=TABLE, generator="JPA_PROXY_EMPLOYEE_TABLE_GENERATOR") + @TableGenerator( + name="JPA_PROXY_EMPLOYEE_TABLE_GENERATOR", + table="PA_CONN.PROXY_EMPLOYEE_SEQ", + pkColumnName="SEQ_NAME", + valueColumnName="SEQ_COUNT", + pkColumnValue="PROXY_EMPLOYEE_SEQ", + initialValue=5 + ) + + @Column(name="EMP_ID") + public Integer getId() { + return id; + } + + @Column(name="F_NAME") + public String getFirstName() { + return m_firstName; + } + + @Column(name="L_NAME") + public String getLastName() { + return m_lastName; + } + + public void setId(Integer id) { + this.id = id; + } + + public void setFirstName(String name) { + this.m_firstName = name; + } + + public void setLastName(String name) { + this.m_lastName = name; + } +} Index: foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumber.java =================================================================== --- foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumber.java (revision 0) +++ foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumber.java (revision 0) @@ -0,0 +1,127 @@ +/******************************************************************************* + * Copyright (c) 1998, 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 + * which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Oracle - initial API and implementation from Oracle TopLink + ******************************************************************************/ +package org.eclipse.persistence.testing.models.jpa.proxyauthentication; + +import java.io.*; +import java.util.Collection; +import java.util.Vector; + +import javax.persistence.*; +import static javax.persistence.EnumType.STRING; + +import org.eclipse.persistence.annotations.BasicCollection; +import org.eclipse.persistence.annotations.CollectionTable; +import org.eclipse.persistence.annotations.Cache; + +@IdClass(org.eclipse.persistence.testing.models.jpa.proxyauthentication.PhoneNumberPK.class) +@Entity +@Table(name="PA_PROXY.PROXY_PHONENUMBER") +@Cache(shared=false) +public class PhoneNumber implements Serializable { + private String number; + private String type; + private Employee owner; + private Integer id; + private String areaCode; + + public PhoneNumber() { + this("", "###", "#######"); + } + + public PhoneNumber(String type, String theAreaCode, String theNumber) { + this.type = type; + this.areaCode = theAreaCode; + this.number = theNumber; + this.owner = null; + } + + @Id + @Column(name="OWNER_ID", insertable=false, updatable=false) + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + @Column(name="NUMB") + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + + @Id + @Column(name="TYPE") + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Column(name="AREA_CODE") + public String getAreaCode() { + return areaCode; + } + + public void setAreaCode(String areaCode) { + this.areaCode = areaCode; + } + + @ManyToOne + @JoinColumn(name="OWNER_ID", referencedColumnName="EMP_ID") + public Employee getOwner() { + return owner; + } + + public void setOwner(Employee owner) { + this.owner = owner; + } + + /** + * Example: Phone[Work]: (613) 225-8812 + */ + public String toString() { + StringWriter writer = new StringWriter(); + + writer.write("PhoneNumber["); + writer.write(getType()); + writer.write("]: ("); + writer.write(getAreaCode()); + writer.write(") "); + + int numberLength = this.getNumber().length(); + writer.write(getNumber().substring(0, Math.min(3, numberLength))); + if (numberLength > 3) { + writer.write("-"); + writer.write(getNumber().substring(3, Math.min(7, numberLength))); + } + + return writer.toString(); + } + + /** + * Builds the PhoneNumberPK for this class + */ + public PhoneNumberPK buildPK(){ + PhoneNumberPK pk = new PhoneNumberPK(); + pk.setId(this.getOwner().getId()); + pk.setType(this.getType()); + return pk; + } +} Index: foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/EmployeeTableCreator.java =================================================================== --- foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/EmployeeTableCreator.java (revision 0) +++ foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/EmployeeTableCreator.java (revision 0) @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 1998, 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 + * which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Oracle - initial API and implementation from Oracle TopLink + ******************************************************************************/ +package org.eclipse.persistence.testing.models.jpa.proxyauthentication; + +import org.eclipse.persistence.tools.schemaframework.*; + +public class EmployeeTableCreator extends TableCreator { + public EmployeeTableCreator() { + setName("EmployeeTableCreator"); + + addTableDefinition(buildEMPLOYEETable()); + addTableDefinition(buildEMPLOYEE_SEQTable()); + } + + public static TableDefinition buildEMPLOYEETable() { + TableDefinition table = new TableDefinition(); + table.setName("JPA_PROXY_EMPLOYEE"); + + FieldDefinition field = new FieldDefinition(); + field.setName("EMP_ID"); + field.setTypeName("NUMERIC"); + field.setSize(15); + field.setShouldAllowNull(false); + field.setIsPrimaryKey(true); + field.setUnique(false); + field.setIsIdentity(true); + table.addField(field); + + FieldDefinition field1 = new FieldDefinition(); + field1.setName("F_NAME"); + field1.setTypeName("VARCHAR"); + field1.setSize(40); + field1.setShouldAllowNull(true); + field1.setIsPrimaryKey(false); + field1.setUnique(false); + field1.setIsIdentity(false); + table.addField(field1); + + FieldDefinition field2 = new FieldDefinition(); + field2.setName("L_NAME"); + field2.setTypeName("VARCHAR"); + field2.setSize(40); + field2.setShouldAllowNull(true); + field2.setIsPrimaryKey(false); + field2.setUnique(false); + field2.setIsIdentity(false); + table.addField(field2); + + return table; + } + + public static TableDefinition buildEMPLOYEE_SEQTable() { + TableDefinition table = new TableDefinition(); + table.setName("PROXY_EMPLOYEE_SEQ"); + + FieldDefinition fieldSEQ_COUNT = new FieldDefinition(); + fieldSEQ_COUNT.setName("SEQ_COUNT"); + fieldSEQ_COUNT.setTypeName("NUMBER"); + fieldSEQ_COUNT.setSize(15); + fieldSEQ_COUNT.setSubSize(0); + fieldSEQ_COUNT.setIsPrimaryKey(false); + fieldSEQ_COUNT.setIsIdentity(false); + fieldSEQ_COUNT.setUnique(false); + fieldSEQ_COUNT.setShouldAllowNull(false); + table.addField(fieldSEQ_COUNT); + + FieldDefinition fieldSEQ_NAME = new FieldDefinition(); + fieldSEQ_NAME.setName("SEQ_NAME"); + fieldSEQ_NAME.setTypeName("VARCHAR2"); + fieldSEQ_NAME.setSize(80); + fieldSEQ_NAME.setSubSize(0); + fieldSEQ_NAME.setIsPrimaryKey(true); + fieldSEQ_NAME.setIsIdentity(false); + fieldSEQ_NAME.setUnique(false); + fieldSEQ_NAME.setShouldAllowNull(false); + table.addField(fieldSEQ_NAME); + + return table; + } + +} Index: foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumberTableCreator.java =================================================================== --- foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumberTableCreator.java (revision 0) +++ foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumberTableCreator.java (revision 0) @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 1998, 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 + * which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Oracle - initial API and implementation from Oracle TopLink + ******************************************************************************/ +package org.eclipse.persistence.testing.models.jpa.proxyauthentication; + +import org.eclipse.persistence.tools.schemaframework.*; + +public class PhoneNumberTableCreator extends TableCreator { + public PhoneNumberTableCreator() { + setName("PhoneNumberTableCreator"); + + addTableDefinition(buildPHONENUMBERTable()); + } + + public static TableDefinition buildPHONENUMBERTable() { + TableDefinition table = new TableDefinition(); + table.setName("PROXY_PHONENUMBER"); + + // SECTION: FIELD + FieldDefinition field = new FieldDefinition(); + field.setName("OWNER_ID"); + field.setTypeName("NUMERIC"); + field.setSize(15); + field.setShouldAllowNull(false ); + field.setIsPrimaryKey(true ); + field.setUnique(false ); + field.setIsIdentity(false ); + field.setForeignKeyFieldName("JPA_PROXY_EMPLOYEE.EMP_ID"); + table.addField(field); + + // SECTION: FIELD + FieldDefinition field1 = new FieldDefinition(); + field1.setName("TYPE"); + field1.setTypeName("VARCHAR"); + field1.setSize(15); + field1.setShouldAllowNull(false ); + field1.setIsPrimaryKey(true ); + field1.setUnique(false ); + field1.setIsIdentity(false ); + table.addField(field1); + + // SECTION: FIELD + FieldDefinition field2 = new FieldDefinition(); + field2.setName("AREA_CODE"); + field2.setTypeName("VARCHAR"); + field2.setSize(3); + field2.setShouldAllowNull(true ); + field2.setIsPrimaryKey(false ); + field2.setUnique(false ); + field2.setIsIdentity(false ); + table.addField(field2); + + // SECTION: FIELD + FieldDefinition field3 = new FieldDefinition(); + field3.setName("NUMB"); + field3.setTypeName("VARCHAR"); + field3.setSize(8); + field3.setShouldAllowNull(true ); + field3.setIsPrimaryKey(false ); + field3.setUnique(false ); + field3.setIsIdentity(false ); + table.addField(field3); + + return table; + } + + +} Index: foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumberPK.java =================================================================== --- foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumberPK.java (revision 0) +++ foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumberPK.java (revision 0) @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 1998, 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 + * which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Oracle - initial API and implementation from Oracle TopLink + ******************************************************************************/ + + +package org.eclipse.persistence.testing.models.jpa.proxyauthentication; + +public class PhoneNumberPK { + public Integer id; + public String type; + + public PhoneNumberPK() {} + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + /** + * equals: Answer true if the ids are equal + */ + public boolean equals(Object anotherPhoneNumber) { + if (anotherPhoneNumber.getClass() != PhoneNumberPK.class) { + return false; + } + return (getId().equals(((PhoneNumberPK)anotherPhoneNumber).getId())); + } +} \ No newline at end of file Index: foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/Employee.java =================================================================== --- foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/Employee.java (revision 0) +++ foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/Employee.java (revision 0) @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 1998, 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 + * which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Oracle - initial API and implementation from Oracle TopLink + ******************************************************************************/ +package org.eclipse.persistence.testing.models.jpa.proxyauthentication; + +import java.io.Serializable; +import java.util.*; +import javax.persistence.*; + +import static javax.persistence.CascadeType.*; +import static javax.persistence.FetchType.*; +import static javax.persistence.GenerationType.*; + +import org.eclipse.persistence.annotations.PrivateOwned; +import org.eclipse.persistence.annotations.Property; + +@Entity +@Table(name="PA_CONN.JPA_PROXY_EMPLOYEE") + +public class Employee implements Serializable { + + private Integer id; + + private String m_lastName; + private String m_firstName; + + public Employee () { + } + + public Employee(String firstName, String lastName){ + this(); + this.m_firstName = firstName; + this.m_lastName = lastName; + } + + @Id + @GeneratedValue(strategy=TABLE, generator="JPA_PROXY_EMPLOYEE_TABLE_GENERATOR") + @TableGenerator( + name="JPA_PROXY_EMPLOYEE_TABLE_GENERATOR", + table="PA_CONN.PROXY_EMPLOYEE_SEQ", + pkColumnName="SEQ_NAME", + valueColumnName="SEQ_COUNT", + pkColumnValue="PROXY_EMPLOYEE_SEQ", + initialValue=5 + ) + + @Column(name="EMP_ID") + public Integer getId() { + return id; + } + + @Column(name="F_NAME") + public String getFirstName() { + return m_firstName; + } + + @Column(name="L_NAME") + public String getLastName() { + return m_lastName; + } + + public void setId(Integer id) { + this.id = id; + } + + public void setFirstName(String name) { + this.m_firstName = name; + } + + public void setLastName(String name) { + this.m_lastName = name; + } +} Index: foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/EmployeeTableCreator.java =================================================================== --- foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/EmployeeTableCreator.java (revision 0) +++ foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/EmployeeTableCreator.java (revision 0) @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 1998, 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 + * which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Oracle - initial API and implementation from Oracle TopLink + ******************************************************************************/ +package org.eclipse.persistence.testing.models.jpa.proxyauthentication; + +import org.eclipse.persistence.tools.schemaframework.*; + +public class EmployeeTableCreator extends TableCreator { + public EmployeeTableCreator() { + setName("EmployeeTableCreator"); + + addTableDefinition(buildEMPLOYEETable()); + addTableDefinition(buildEMPLOYEE_SEQTable()); + } + + public static TableDefinition buildEMPLOYEETable() { + TableDefinition table = new TableDefinition(); + table.setName("JPA_PROXY_EMPLOYEE"); + + FieldDefinition field = new FieldDefinition(); + field.setName("EMP_ID"); + field.setTypeName("NUMERIC"); + field.setSize(15); + field.setShouldAllowNull(false); + field.setIsPrimaryKey(true); + field.setUnique(false); + field.setIsIdentity(true); + table.addField(field); + + FieldDefinition field1 = new FieldDefinition(); + field1.setName("F_NAME"); + field1.setTypeName("VARCHAR"); + field1.setSize(40); + field1.setShouldAllowNull(true); + field1.setIsPrimaryKey(false); + field1.setUnique(false); + field1.setIsIdentity(false); + table.addField(field1); + + FieldDefinition field2 = new FieldDefinition(); + field2.setName("L_NAME"); + field2.setTypeName("VARCHAR"); + field2.setSize(40); + field2.setShouldAllowNull(true); + field2.setIsPrimaryKey(false); + field2.setUnique(false); + field2.setIsIdentity(false); + table.addField(field2); + + return table; + } + + public static TableDefinition buildEMPLOYEE_SEQTable() { + TableDefinition table = new TableDefinition(); + table.setName("PROXY_EMPLOYEE_SEQ"); + + FieldDefinition fieldSEQ_COUNT = new FieldDefinition(); + fieldSEQ_COUNT.setName("SEQ_COUNT"); + fieldSEQ_COUNT.setTypeName("NUMBER"); + fieldSEQ_COUNT.setSize(15); + fieldSEQ_COUNT.setSubSize(0); + fieldSEQ_COUNT.setIsPrimaryKey(false); + fieldSEQ_COUNT.setIsIdentity(false); + fieldSEQ_COUNT.setUnique(false); + fieldSEQ_COUNT.setShouldAllowNull(false); + table.addField(fieldSEQ_COUNT); + + FieldDefinition fieldSEQ_NAME = new FieldDefinition(); + fieldSEQ_NAME.setName("SEQ_NAME"); + fieldSEQ_NAME.setTypeName("VARCHAR2"); + fieldSEQ_NAME.setSize(80); + fieldSEQ_NAME.setSubSize(0); + fieldSEQ_NAME.setIsPrimaryKey(true); + fieldSEQ_NAME.setIsIdentity(false); + fieldSEQ_NAME.setUnique(false); + fieldSEQ_NAME.setShouldAllowNull(false); + table.addField(fieldSEQ_NAME); + + return table; + } + +} Index: foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumber.java =================================================================== --- foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumber.java (revision 0) +++ foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumber.java (revision 0) @@ -0,0 +1,127 @@ +/******************************************************************************* + * Copyright (c) 1998, 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 + * which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Oracle - initial API and implementation from Oracle TopLink + ******************************************************************************/ +package org.eclipse.persistence.testing.models.jpa.proxyauthentication; + +import java.io.*; +import java.util.Collection; +import java.util.Vector; + +import javax.persistence.*; +import static javax.persistence.EnumType.STRING; + +import org.eclipse.persistence.annotations.BasicCollection; +import org.eclipse.persistence.annotations.CollectionTable; +import org.eclipse.persistence.annotations.Cache; + +@IdClass(org.eclipse.persistence.testing.models.jpa.proxyauthentication.PhoneNumberPK.class) +@Entity +@Table(name="PA_PROXY.PROXY_PHONENUMBER") +@Cache(shared=false) +public class PhoneNumber implements Serializable { + private String number; + private String type; + private Employee owner; + private Integer id; + private String areaCode; + + public PhoneNumber() { + this("", "###", "#######"); + } + + public PhoneNumber(String type, String theAreaCode, String theNumber) { + this.type = type; + this.areaCode = theAreaCode; + this.number = theNumber; + this.owner = null; + } + + @Id + @Column(name="OWNER_ID", insertable=false, updatable=false) + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + @Column(name="NUMB") + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + + @Id + @Column(name="TYPE") + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Column(name="AREA_CODE") + public String getAreaCode() { + return areaCode; + } + + public void setAreaCode(String areaCode) { + this.areaCode = areaCode; + } + + @ManyToOne + @JoinColumn(name="OWNER_ID", referencedColumnName="EMP_ID") + public Employee getOwner() { + return owner; + } + + public void setOwner(Employee owner) { + this.owner = owner; + } + + /** + * Example: Phone[Work]: (613) 225-8812 + */ + public String toString() { + StringWriter writer = new StringWriter(); + + writer.write("PhoneNumber["); + writer.write(getType()); + writer.write("]: ("); + writer.write(getAreaCode()); + writer.write(") "); + + int numberLength = this.getNumber().length(); + writer.write(getNumber().substring(0, Math.min(3, numberLength))); + if (numberLength > 3) { + writer.write("-"); + writer.write(getNumber().substring(3, Math.min(7, numberLength))); + } + + return writer.toString(); + } + + /** + * Builds the PhoneNumberPK for this class + */ + public PhoneNumberPK buildPK(){ + PhoneNumberPK pk = new PhoneNumberPK(); + pk.setId(this.getOwner().getId()); + pk.setType(this.getType()); + return pk; + } +} Index: foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumberPK.java =================================================================== --- foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumberPK.java (revision 0) +++ foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumberPK.java (revision 0) @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 1998, 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 + * which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Oracle - initial API and implementation from Oracle TopLink + ******************************************************************************/ + + +package org.eclipse.persistence.testing.models.jpa.proxyauthentication; + +public class PhoneNumberPK { + public Integer id; + public String type; + + public PhoneNumberPK() {} + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + /** + * equals: Answer true if the ids are equal + */ + public boolean equals(Object anotherPhoneNumber) { + if (anotherPhoneNumber.getClass() != PhoneNumberPK.class) { + return false; + } + return (getId().equals(((PhoneNumberPK)anotherPhoneNumber).getId())); + } +} \ No newline at end of file Index: foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumberTableCreator.java =================================================================== --- foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumberTableCreator.java (revision 0) +++ foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/models/jpa/proxyauthentication/PhoneNumberTableCreator.java (revision 0) @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 1998, 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 + * which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Oracle - initial API and implementation from Oracle TopLink + ******************************************************************************/ +package org.eclipse.persistence.testing.models.jpa.proxyauthentication; + +import org.eclipse.persistence.tools.schemaframework.*; + +public class PhoneNumberTableCreator extends TableCreator { + public PhoneNumberTableCreator() { + setName("PhoneNumberTableCreator"); + + addTableDefinition(buildPHONENUMBERTable()); + } + + public static TableDefinition buildPHONENUMBERTable() { + TableDefinition table = new TableDefinition(); + table.setName("PROXY_PHONENUMBER"); + + // SECTION: FIELD + FieldDefinition field = new FieldDefinition(); + field.setName("OWNER_ID"); + field.setTypeName("NUMERIC"); + field.setSize(15); + field.setShouldAllowNull(false ); + field.setIsPrimaryKey(true ); + field.setUnique(false ); + field.setIsIdentity(false ); + field.setForeignKeyFieldName("JPA_PROXY_EMPLOYEE.EMP_ID"); + table.addField(field); + + // SECTION: FIELD + FieldDefinition field1 = new FieldDefinition(); + field1.setName("TYPE"); + field1.setTypeName("VARCHAR"); + field1.setSize(15); + field1.setShouldAllowNull(false ); + field1.setIsPrimaryKey(true ); + field1.setUnique(false ); + field1.setIsIdentity(false ); + table.addField(field1); + + // SECTION: FIELD + FieldDefinition field2 = new FieldDefinition(); + field2.setName("AREA_CODE"); + field2.setTypeName("VARCHAR"); + field2.setSize(3); + field2.setShouldAllowNull(true ); + field2.setIsPrimaryKey(false ); + field2.setUnique(false ); + field2.setIsIdentity(false ); + table.addField(field2); + + // SECTION: FIELD + FieldDefinition field3 = new FieldDefinition(); + field3.setName("NUMB"); + field3.setTypeName("VARCHAR"); + field3.setSize(8); + field3.setShouldAllowNull(true ); + field3.setIsPrimaryKey(false ); + field3.setUnique(false ); + field3.setIsIdentity(false ); + table.addField(field3); + + return table; + } + + +} Index: foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/jpa/proxyauthentication/ProxyAuthenticationServerTestSuite.java =================================================================== --- foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/jpa/proxyauthentication/ProxyAuthenticationServerTestSuite.java (revision 0) +++ foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/jpa/proxyauthentication/ProxyAuthenticationServerTestSuite.java (revision 0) @@ -0,0 +1,285 @@ +/******************************************************************************* + * Copyright (c) 1998, 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 + * which accompanies this distribution. + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * 05/28/2008-1.0M8 Andrei Ilitchev. + * - New file introduced for bug 224964: Provide support for Proxy Authentication through JPA. + ******************************************************************************/ +package org.eclipse.persistence.testing.tests.jpa.proxyauthentication; + +import java.util.*; +import junit.framework.*; + +import oracle.jdbc.OracleConnection; + +import javax.persistence.EntityManager; +import javax.persistence.Query; + +import org.eclipse.persistence.testing.framework.junit.JUnitTestCase; +import org.eclipse.persistence.testing.models.jpa.proxyauthentication.*; +import org.eclipse.persistence.internal.jpa.EntityManagerImpl; +import org.eclipse.persistence.config.PersistenceUnitProperties; +import org.eclipse.persistence.config.ExclusiveConnectionMode; +/** + * TestSuite to verifying that connectionUser(PA_CONN) and proxyUser(PA_PROXY) are used as expected. + * To run this test suite several users should be setup in the Oracle database, + * to setup Proxy Authentication users in Oracle db, need to execute in sqlPlus or EnterpriseManager + * (sql in the following example uses default names): + 1 - Connect as sysdba + connect sys/password as sysdba + + 2 - Create connectionUser: + create user PA_CONN identified by PA_CONN + grant connect to PA_CONN + grant resource to PA_CONN + + 3 - Create proxyUsers: + create user PA_PROXY identified by PA_PROXY + grant connect to PA_PROXY + grant resource to PA_PROXY + + 4.- Grant proxyUsers connection through connUser + alter user PA_PROXY grant connect through PA_CONN + + 5.- Create JPA_PROXY_EMPLOYEE and PROXY_EMPLOYEE_SEQ tables against PA_CONN user + DROP TABLE JPA_PROXY_EMPLOYEE + CREATE TABLE JPA_PROXY_EMPLOYEE (EMP_ID NUMBER(15) NOT NULL, F_NAME VARCHAR2(40) NULL, L_NAME VARCHAR2(40) NULL, PRIMARY KEY (EMP_ID)) + DROP TABLE PROXY_EMPLOYEE_SEQ + CREATE TABLE PROXY_EMPLOYEE_SEQ (SEQ_NAME VARCHAR2(50) NOT NULL, SEQ_COUNT NUMBER(38) NULL, PRIMARY KEY (SEQ_NAME)) + + 6.- Create PROXY_PHONENUMBER table against PA_PROXY user (you can also create these tables by login as PA_CONN, and execute new PhoneNumberTableCreator().replaceTables(JUnitTestCase.getServerSession()); in testSetup()) + ALTER TABLE PROXY_PHONENUMBER DROP CONSTRAINT FK_PROXY_PHONENUMBER_OWNER_ID + DROP TABLE PROXY_PHONENUMBER + CREATE TABLE PROXY_PHONENUMBER (OWNER_ID NUMBER(15) NOT NULL, TYPE VARCHAR2(15) NOT NULL, AREA_CODE VARCHAR2(3) NULL, NUMB VARCHAR2(8) NULL, PRIMARY KEY (OWNER_ID, TYPE)) + ALTER TABLE PROXY_PHONENUMBER ADD CONSTRAINT FK_PROXY_PHONENUMBER_OWNER_ID FOREIGN KEY (OWNER_ID) REFERENCES JPA_PROXY_EMPLOYEE (EMP_ID) + + 6.- Add object priviledges(ALTER, DELETE, INSERT, REFERENCE, SELECT, UPDATE, INDEX) to JPA_PROXY_EMPLOYEE and PROXY_EMPLOYEE_SEQ for PA_PROXY user + + GRANT ALTER ON PA_CONN.JPA_PROXY_EMPLOYEE TO PA_PROXY; + GRANT DELETE ON PA_CONN.JPA_PROXY_EMPLOYEE TO PA_PROXY; + GRANT INSERT ON PA_CONN.JPA_PROXY_EMPLOYEE TO PA_PROXY; + GRANT REFERENCE ON PA_CONN.JPA_PROXY_EMPLOYEE TO PA_PROXY; + GRANT SELECT ON PA_CONN.JPA_PROXY_EMPLOYEE TO PA_PROXY; + GRANT UPDATE ON PA_CONN.JPA_PROXY_EMPLOYEE TO PA_PROXY; + GRANT INDEX ON PA_CONN.JPA_PROXY_EMPLOYEE TO PA_PROXY; + + GRANT ALTER ON PA_CONN.PROXY_EMPLOYEE_SEQ TO PA_PROXY; + GRANT DELETE ON PA_CONN.PROXY_EMPLOYEE_SEQ TO PA_PROXY; + GRANT INSERT ON PA_CONN.PROXY_EMPLOYEE_SEQ TO PA_PROXY; + GRANT REFERENCE ON PA_CONN.PROXY_EMPLOYEE_SEQ TO PA_PROXY; + GRANT SELECT ON PA_CONN.PROXY_EMPLOYEE_SEQ TO PA_PROXY; + GRANT UPDATE ON PA_CONN.PROXY_EMPLOYEE_SEQ TO PA_PROXY; + GRANT INDEX ON PA_CONN.PROXY_EMPLOYEE_SEQ TO PA_PROXY; + */ +public class ProxyAuthenticationServerTestSuite extends JUnitTestCase { + private static Integer empId = null; + private Employee proxyEmp = null; + private PhoneNumber proxyPhone = null; + private static final String PROXY_PU = "proxyauthentication"; + + public ProxyAuthenticationServerTestSuite(){ + } + + public ProxyAuthenticationServerTestSuite(String name){ + super(name); + } + + public static Test suite() { + TestSuite suite = new TestSuite(); + suite.setName("Proxy Authentication Test Suite"); + + //suite.addTest(new ProxyAuthenticationServerTestSuite("testSetup")); + suite.addTest(new ProxyAuthenticationServerTestSuite("testCreateWithProxy")); + suite.addTest(new ProxyAuthenticationServerTestSuite("testUpdateWithProxy")); + suite.addTest(new ProxyAuthenticationServerTestSuite("testReadDeleteWithProxy")); + suite.addTest(new ProxyAuthenticationServerTestSuite("testCreateWithOutProxy")); + return suite; + } + + public void testSetup() { + //new PhoneNumberTableCreator().replaceTables(JUnitTestCase.getServerSession(PROXY_PU)); + //new EmployeeTableCreator().replaceTables(JUnitTestCase.getServerSession(PROXY_PU)); + //getServerSession(PROXY_PU).executeNonSelectingSQL("update PROXY_EMPLOYEE_SEQ set SEQ_COUNT = 1 where SEQ_NAME='PROXY_EMPLOYEE_SEQ'"); + } + + /** + * Tests creating Entity with proxy setting + */ + public void testCreateWithProxy() throws Exception{ + proxyEmp = new Employee(); + EntityManager em = createEntityManager(PROXY_PU); + try { + startTransaction(em); + proxyEmp.setFirstName("Guy"); + proxyEmp.setLastName("Pelletier"); + em.persist(proxyEmp); + empId = proxyEmp.getId(); + + proxyPhone = new PhoneNumber(); + proxyPhone.setAreaCode("61x"); + proxyPhone.setNumber("823-6262"); + proxyPhone.setOwner(proxyEmp); + proxyPhone.setId(empId); + proxyPhone.setType("Home"); + + em.persist(proxyPhone); + commitTransaction(em); + } catch (Exception ex) { + ex.printStackTrace(); + if (isTransactionActive(em)){ + rollbackTransaction(em); + } + throw ex; + } finally { + closeEntityManager(em); + } + + EntityManager newEm = createEntityManager(PROXY_PU); + try { + startTransaction(newEm); + PhoneNumberPK pk = new PhoneNumberPK(); + pk.setId(empId); + pk.setType("Home"); + PhoneNumber phone = newEm.find(PhoneNumber.class, pk); + Employee emp = newEm.find(Employee.class, empId); + compareObjects(emp, proxyEmp, phone, proxyPhone); + clearCache(PROXY_PU); + compareObjects(emp, proxyEmp, phone, proxyPhone); + commitTransaction(newEm); + } catch (Exception ex) { + ex.printStackTrace(); + if (isTransactionActive(newEm)){ + rollbackTransaction(newEm); + } + throw ex; + } finally { + closeEntityManager(newEm); + } + + } + + /** + * Tests Read and Delete with proxy setting + */ + public void testReadDeleteWithProxy() throws Exception{ + EntityManager em = createEntityManager(PROXY_PU); + Employee readEmp = null; + PhoneNumber readPhone = null; + try { + startTransaction(em); + PhoneNumberPK pk = new PhoneNumberPK(); + pk.setId(empId); + pk.setType("Home"); + readPhone = em.find(PhoneNumber.class, pk); + readEmp = readPhone.getOwner(); + em.remove(readEmp); + em.remove(readPhone); + commitTransaction(em); + } catch (Exception ex) { + ex.printStackTrace(); + if (isTransactionActive(em)){ + rollbackTransaction(em); + } + throw ex; + } finally { + closeEntityManager(em); + } + } + + /** + * Tests Update with proxy setting + */ + public void testUpdateWithProxy() throws Exception{ + EntityManager em = createEntityManager(PROXY_PU); + Query query = em.createQuery("SELECT e FROM PhoneNumber e"); + try { + startTransaction(em); + List phoneNumbers = query.getResultList(); + for (PhoneNumber phoneNumber : phoneNumbers) { + phoneNumber.setAreaCode("613"); + Employee owner = phoneNumber.getOwner(); + } + commitTransaction(em); + } catch (Exception ex) { + ex.printStackTrace(); + if (isTransactionActive(em)){ + rollbackTransaction(em); + } + throw ex; + } finally { + closeEntityManager(em); + } + } + + /** + * Tests create with out proxy setting, it should fail + */ + public void testCreateWithOutProxy() throws Exception{ + Employee employee = new Employee(); + EntityManager em = createEntityManager(PROXY_PU); + try { + beginTransaction(em); + employee.setFirstName("Guy"); + employee.setLastName("Pelletier"); + em.persist(employee); + + PhoneNumber homeNumber = new PhoneNumber(); + homeNumber.setAreaCode("61x"); + homeNumber.setNumber("823-6262"); + homeNumber.setOwner(employee); + homeNumber.setType("Home"); + + em.persist(homeNumber); + empId = employee.getId(); + commitTransaction(em); + } catch (Exception ex) { + if (ex.getMessage().indexOf("java.sql.SQLException: ORA-00942: table or view does not exist") == -1){ + if (isTransactionActive(em)){ + rollbackTransaction(em); + } + ex.printStackTrace(); + fail("it's not the right exception"); + } + } finally { + closeEntityManager(em); + } + } + + /** + * Setup Proxy properties settings to EntityManager through EntityManagerImpl + */ + private void setupProperties(EntityManager em){ + EntityManagerImpl empl = (EntityManagerImpl)em.getDelegate(); + Map newProps = new HashMap(3); + newProps.put(PersistenceUnitProperties.ORACLE_PROXY_TYPE, OracleConnection.PROXYTYPE_USER_NAME); + newProps.put(OracleConnection.PROXY_USER_NAME, "PA_PROXY"); + newProps.put(PersistenceUnitProperties.EXCLUSIVE_CONNECTION_MODE, ExclusiveConnectionMode.Always); + empl.setProperties(newProps); + } + + private void startTransaction(EntityManager em){ + if (!isOnServer()){ + setupProperties(em); + } + beginTransaction(em); + if (isOnServer){ + setupProperties(em); + } + } + + private void compareObjects(Employee readEmp, Employee writtenEmp, PhoneNumber readPhone, PhoneNumber writtenPhone){ + if (!getServerSession(PROXY_PU).compareObjects(readEmp, proxyEmp)) { + fail("Object: " + readEmp + " does not match object that was written: " + proxyEmp + ". See log (on finest) for what did not match."); + } + if (!getServerSession(PROXY_PU).compareObjects(readPhone, writtenPhone)) { + fail("Object: " + readPhone + " does not match object that was written: " + writtenPhone + ". See log (on finest) for what did not match."); + } + } + +} Index: foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/OracleJPATestSuite.java =================================================================== --- foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/OracleJPATestSuite.java (revision 3501) +++ foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/OracleJPATestSuite.java (working copy) @@ -18,6 +18,7 @@ import org.eclipse.persistence.testing.tests.jpa.proxyauthentication.ProxyAuthenticationTestSuite; import org.eclipse.persistence.testing.tests.jpa.structconverter.StructConverterTestSuite; +import org.eclipse.persistence.testing.tests.jpa.proxyauthentication.ProxyAuthenticationServerTestSuite; public class OracleJPATestSuite extends TestSuite{ @@ -27,6 +28,7 @@ fullSuite.addTest(StructConverterTestSuite.suite()); fullSuite.addTest(ProxyAuthenticationTestSuite.suite()); + fullSuite.addTest(ProxyAuthenticationServerTestSuite.suite()); return fullSuite; } Index: jpa/eclipselink.jpa.test/build.properties =================================================================== --- jpa/eclipselink.jpa.test/build.properties (revision 3503) +++ jpa/eclipselink.jpa.test/build.properties (working copy) @@ -47,6 +47,7 @@ eclipselink.struct.converter.model=eclipselink-struct-converter-model eclipselink.customfeatures.model=eclipselink-customfeatures-model +eclipselink.proxyauthentication.model=eclipselink-proxyauthentication-model eclipselink.jpa.oracle=eclipselink-jpa-oracle oracle.extensions.depend.dir=../../../extension.oracle.lib.external oracle.spatial.lib=sdoapi.jar Index: jpa/eclipselink.jpa.test/build.xml =================================================================== --- jpa/eclipselink.jpa.test/build.xml (revision 3536) +++ jpa/eclipselink.jpa.test/build.xml (working copy) @@ -437,6 +437,7 @@ + @@ -1172,6 +1173,7 @@ + @@ -1485,6 +1487,19 @@ + + + + + + + + + + + + +