db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Bengtson <e...@jpox.org>
Subject Re: Questions regarding persistent interfaces
Date Sat, 20 Jan 2007 11:51:14 GMT
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:



Another model could be:




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

View raw message