db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matthew Adams" <matthew.ad...@xcalia.com>
Subject RE: Persistent interface specification clarification
Date Thu, 22 Feb 2007 23:24:34 GMT
Here is my writeup for discussion tomorrow, addressing the use of a PC
interface as a field in a PC class.

================ BEGIN PROPOSAL
Metadata requirements for persistence-capable classes that implement or
use persistence-capable interfaces

For persistence-capable classes that implement persistence-capable
interfaces, if the persistence-capable class employs property-level
interception for the persistence-capable interface's property, or if the
persistence-capable class employs field-level interception for the field
that stores the value of the persistence-capable interface's property
and the field's name and type matches the property's name and type, then
no additional metadata is required.  If the persistence-capable class
employs field-level interception for the field that stores the value the
persistence-capable interface's property and the field's name or type
differs from the property's name or type, the "class" element must
include the "implements" element, which for each unmatched property and
field, must include a "property" element whose "name" attribute matches
the persistence-capable interface's property name and whose "field-name"
attribute is the name of the field that stores the value of the
persistence-capable interface's property.

For persistence-capable classes that contain a field or property of a
persistence-capable interface type, no additional metadata is required.

The application is portable if all implementations of the
persistence-capable interface share a common persistence-capable
superclass; if they do not, then the application is not portable.

The inclusion of the "property" element within the "implements" element
is primarily intended to support query filter expressions that traverse
fields of interface types.

Example

Given the following persistence-capable interface

public interface NamedObject {
    // property name is "name", type is "String"
    String getName();
    void setName(String name);
}

the following persistence-capable classes that implement the
persistence-capable interface

public class Company implements NamedObject {
    // field matches type & name of persistent interface's property
    protected String name;
    
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
}

public class Animal implements NamedObject {
    // field matches type but not name of persistent interface's
property
    protected String myName;
    
    public String getName() { return myName; }
    public void setName(String name) { myName = name; }
}

public class Person implements NamedObject {
    protected String firstName;
    protected String lastName;
    
    // value of persistent interface's property is derived
    
    public String getName() { return lastName + ',' + firstName; }

    public void setName(String name) {
        if (name == null) {
            lastName = null;
            firstName = null;
            return;
        }
        int idx = name.indexOf(',');
        if (idx == -1) {
            lastName = name;
            firstName = null;
            return;
        }
        lastName = name.substring(0, idx);
        firstName = name.substring(idx + 1);
    }
}

and the following persistence-capable class that uses a persistent field
whose type is the persistence-capable interface

public class Foo {
    protected NamedObject myNamedObject;
    
    public NamedObject getNamedObject() { return myNamedObject; }
    public void setNamedObject(NamedObject namedObject) { myNamedObject
= namedObject; }
}

the following is the minimal metadata required:

<interface name="NamedObject"/>

<!-- field has same name and type as persistence-capable interface
property -->
<class name="Company"/>

<!-- field has different name than persistence-capable interface
property -->
<class name="Animal">
    <implements name="NamedObject">
        <property name="name" field-name="myName"/>
    </implements>
</class>

<!-- class uses property-level interception (field is ignored by the
implementation) -->
<class name="Person">
    <property name="name"/>
</class>

<class name="Foo"/>

</proposal>
================ END PROPOSAL

-matthew

________________________________

	From: Craig.Russell@Sun.COM [mailto:Craig.Russell@Sun.COM] 
	Sent: Thursday, February 22, 2007 1:18 PM
	To: JDO Expert Group; Apache JDO project; Leschke Scott-QA2775
	Subject: Persistent interface specification clarification
	
	
	There are three scenarios for using persistent interfaces: 

	- as the parameter of the PersistenceManager.newInstance method

	- as the type of a field or property of a persistent interface
or class

	- as the type of a field or property used by a query

	I'd like to discuss the following in tomorrow's conference call.


	The PersistenceManager.newInstance method discusses requirements
if the parameter is a persistent interface, but it's incomplete.

	<spec>
	In order for the newInstance method to be used, the parameter
interface must be completely mapped. For relational implementations, the
interface must be mapped to a table and all persistent properties must
be mapped to columns. Additionally, interfaces that are the targets of
all relationships from persistent properties must also be mapped.
Otherwise, JDOUserException is thrown by the newInstance method.
	</spec>

	I'd like to clarify it a bit:
	<proposed>
	In order for the newInstance method to be used with a persistent
interface, the parameter interface must be completely mapped. That is,
the interface must be declared in metadata using the interface element. 

	Additionally, for relational implementations, 

	o the interface must be mapped to a table; portable applications
will use the table attribute for this purpose

	o all persistent properties must be mapped to columns; portable
applications will use the column attribute of the property element
contained in the interface element

	o interfaces that are of types of relationships declared as
persistent properties of the parameter interface must all be completely
mapped

	If any of the above conditions is not met, JDOUserException is
thrown by the newInstance method.
	</proposed>
	

	Craig Russell

	Architect, Sun Java Enterprise System
http://java.sun.com/products/jdo

	408 276-5638 mailto:Craig.Russell@sun.com

	P.S. A good JDO? O, Gasp!



Mime
View raw message