|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectch.elca.el4j.services.persistence.hibernate.dao.extent.DataExtent
public class DataExtent
A DataExtent represents the extent of the graphs of objects to be
loaded in a hibernate query.
Be careful in not mixing up the notion of an extent:
In this context it is referring to the extent of the DOM to be loaded from the underlying
persistent store.
In other contexts like for example OpenJPA the notion can have a different meaning.
Principle:
An Extent represents a part of the DOM that should be loaded together.
It can be used to pool together associated entities in order
to provide performance improvements over standard data fetching.
Specifying the extent when loading entities with Hibernate
allows for tuning of lazy loading and eager fetching behavior.
For details about how to use the "Fetch Type" in order to control whether a field is fetched eagerly or lazily,
see the corresponding reference manual of Java Persistence API
(eg. http://java.sun.com/javaee/5/docs/api/javax/persistence/FetchType.html
)
In a DataExtent we internally distinguish between fields, entities and collections:
Blob
and Clob
are loaded lazy per default.
Since there are different handling policies from different db vendors, be careful when using these types.ch.elca.el4j.apps.refdb.dom.File
.
@OneToOne(fetch = FetchType.LAZY)
Collection
interface should be
added to the extent as collection for a proper fetching at runtime.
public class Employee {
...
public Employee getManager() {...
To be sure that you can access the manager of an employee after retrieving it from the dao, add the manager to
the extent you pass as an extra argument to the dao: dao.findById(id, extent.with("manager"));
ch.elca.el4j.apps.refdb.dao.impl.hibernate.HibernateFileDao
and in
ch.elca.el4j.tests.person.dao.impl.hibernate.HibernatePersonDao
are frozen.
ExtentEntity
to write your code in a convenient way
ExtentEntity.entity(java.lang.Class>)
and
ExtentCollection.collection(java.lang.String, java.lang.Class>)
to create easily new Entities and Collections.
// The Extent Object of type 'Person'
extent = new DataExtent(Person.class);
// Construct a complex graph:
// Person has a List of Teeth, a Tooth has a 'Person' as owner,
// the owner has a list of 'Person' as friends, the friends are again
// the same 'Person'-entity as defined in the beginning.
extent.withSubentities(
collection("teeth",
entity(Tooth.class)
.with("owner")
),
collection("friends", extent.getRootEntity())
);
// Extent of a File
extent = new DataExtent(File.class);
// Create a simple, light extent for an overview over the files
extent.with("name", "lastModified", "fileSize", "mimeType");
dao.getAll(extent);
// Note: there will potentially be loaded more than you specify, if it is defined to be fetched eagerly
// Another extent to see also the file content
extent = new DataExtent(File.class);
extent.with("name", "content", "lastModified", "fileSize", "mimeType");
dao.findById(id, extent);
// Extent in a reference DOM, where references are loaded lazily
extent = new DataExtent(Publication.class);
extent.all(3);
dao.findByName(publicationName, extent);
// Now you have loaded all referenced publications, books, papers, ... to a depth of 3
// Eg. using the parent of the parent is now possible.
for an example
,
Serialized FormField Summary | |
---|---|
static int |
DEFAULT_LOADING_DEPTH
Defines the default loading depth. |
Constructor Summary | |
---|---|
DataExtent(Class<?> c)
Default Creator. |
Method Summary | |
---|---|
DataExtent |
all()
Include all fields, entities and collections of the class. |
DataExtent |
all(int depth)
Include all fields, entities and collections of the class. |
boolean |
equals(Object object)
|
DataExtent |
freeze()
Freeze the extent, meaning that no further changes to it are possible. |
String |
getExtentId()
The id of the data extent. |
ExtentEntity |
getRootEntity()
Root entity of the extent. |
int |
hashCode()
|
DataExtent |
merge(DataExtent other)
Merge two DataExtents. |
String |
toString()
|
DataExtent |
with(String... fields)
Extend the extent by the given fields. |
DataExtent |
without(String... fields)
Exclude fields from the extent. |
DataExtent |
withSubentities(AbstractExtentPart... entities)
Extend the extent by the given sub-entities. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_LOADING_DEPTH
Constructor Detail |
---|
public DataExtent(Class<?> c)
c
- the class of the root entity.Method Detail |
---|
public ExtentEntity getRootEntity()
public String getExtentId()
public DataExtent with(String... fields) throws NoSuchMethodException
fields
- fields to be added.
NoSuchMethodException
public DataExtent withSubentities(AbstractExtentPart... entities) throws NoSuchMethodException
entities
- entities to be added.
NoSuchMethodException
public DataExtent without(String... fields)
fields
- fields to be excluded.
public DataExtent all()
public DataExtent all(int depth)
depth
- Exploration depth
public DataExtent merge(DataExtent other)
other
- the extent to be merged with.
public DataExtent freeze()
public int hashCode()
hashCode
in class Object
public boolean equals(Object object)
equals
in class Object
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |