db-jdo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michelle Caisse <Michelle.Cai...@Sun.COM>
Subject [Fwd: Re: Questions regarding persistent interfaces]
Date Thu, 22 Feb 2007 18:10:13 GMT
Hi Scott,

Erik responded to your email, but the response wound up on the wrong 
alias, so I'm forwarding it here.

-- Michelle

-------- Original Message --------
Subject: 	Re: Questions regarding persistent interfaces
Date: 	Sat, 20 Jan 2007 03:51:14 -0800
From: 	Erik Bengtson <erik@jpox.org>
Reply-To: 	jdo-dev@db.apache.org
To: 	Apache JDO project <jdo-dev@db.apache.org>



I have some questions regarding persistent interfaces.

1) If a class implements (in the Java sense via the 'implements'
clause), an interface that is declared persistent-capable in the
metadata, does the corresponding <class> element in the metadata also
required to have a corresponding <implements> element or is the element
implied by the Java structure? I think one would expect this but the
spec doesn't say explicitly.

The Implements attribute allows in declarative form to the JDO implementation
know all the types that implement a certain interface used in a field of a
persistent class. e.g.

Class Person
{
    Thing thing; //persistent field
}

Interface Thing {} //non persistent interface

Class Stuff implements Thing {} //persistent
Class Misc implements Thing {} //persistent

With the implements metadata, the JDO implementation is capable to search for
all Thing kinds, + create the database schema

For example one could have a schema:

PERSON_TABLE
THING_COL (FK)

THING_TABLE
THING_ID
CLASS_NAME (STUFF,MISC)

Another model could be:

PERSON_TABLE
THING_STUFF_COL (FK)
THING_MISC_COL (FK)

STUFF_TABLE
STUFF_ID

MISC_TABLE
MISC_ID

Hopefully Implements is clear now.

Persistent interfaces are used only when you want the JDO implementation to
provide the concrete implementation for you.

You could also have Mixed mode, when you have implementations of Persistent
Interfaces created by the JDO implementation, but also implementations provided
by the user. This has been discussed before, and some of the TCK tests covers
this indirectly.

2) If a class implements a persistent-capable interface, is there a
default mapping between the interface properties and class field names
(i.e. would a property named "modDate" of type java.util.Date map by
default to a field in the implementing class of the same name and type?
If not, why not?

Not to field names, but to getters and setters.

3) Based on the spec, I guessing the answer to this is no but given a
persistent-capable interface, is there a way to specify that
implementation generated instances (i.e. pm.newInstance(interfaceName))
should not be allowed?

You simply do not declare the interface as persistence capable, and for each
implementation of your interface, declare the jdo metadata with the implements
element.




Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message