org.apache.jackrabbit.ocm.manager.impl
Class ObjectContentManagerImpl

java.lang.Object
  extended by org.apache.jackrabbit.ocm.manager.impl.ObjectContentManagerImpl
All Implemented Interfaces:
ObjectContentManager

public class ObjectContentManagerImpl
extends Object
implements ObjectContentManager

Default implementation for ObjectContentManager

Author:
Sandro Boehme, Lombart Christophe, Martin Koci, Alexandru Popescu

Field Summary
protected  Mapper mapper
           
protected  ObjectConverter objectConverter
          Object Converter
protected  QueryManager queryManager
          The query manager
protected  ObjectCache requestObjectCache
          Request Cache manager
protected  Session session
          JCR session.
 
Constructor Summary
ObjectContentManagerImpl(Mapper mapper, ObjectConverter converter, QueryManager queryManager, ObjectCache requestObjectCache, Session session)
          Full constructor.
ObjectContentManagerImpl(Session session, InputStream[] xmlMappingFiles)
          Creates a new ObjectContentManager based on a JCR session and some xml mapping files.
ObjectContentManagerImpl(Session session, Mapper mapper)
          Creates a new ObjectContentManager that uses the passed in Mapper, and a Session
ObjectContentManagerImpl(Session session, String[] xmlMappingFiles)
          Creates a new ObjectContentManager based on a JCR session and some xml mapping files.
 
Method Summary
 void addVersionLabel(String path, String versionName, String versionLabel)
          Add a new label to a particular version
protected  void checkIfNodeLocked(String absPath)
          Throws LockedException id node is locked so alter nopde cannot be done
 void checkin(String path)
          Checkin an object
 void checkin(String path, String[] versionLabels)
          Checkin an object and apply some labels to this new version Within a particular object path, a given label may appear a maximum of once
 void checkout(String path)
          Checkout - Create a new version This is only possible if the object is based on mix:versionable node type
 void copy(String srcPath, String destPath)
          Copy an object
 String[] getAllVersionLabels(String path)
          Get all version labels assigned to all versions
 VersionIterator getAllVersions(String path)
          Get all object versions
 Version getBaseVersion(String path)
          Get the lastest object version
protected  Node getNode(String absPath)
           
 Object getObject(Class objectClass, String path)
          Get an object from the JCR repository
 Object getObject(Class objectClass, String path, String versionName)
          Get an object from the JCR repository
 Object getObject(Query query)
          Retrieve an object matching to a query
 Object getObject(String path)
          Get an object from the JCR repository
 Object getObject(String path, String versionName)
          Get an object from the JCR repository
 Object getObjectByUuid(String uuid)
          Get an object from the JCR repository
 Iterator getObjectIterator(Query query)
          Retrieve some objects matching to a query.
 Iterator getObjectIterator(String query, String language)
          Retrieve an objects matching a query specified in a specific query language.
 Collection getObjects(Class objectClass, String path)
          Returns a list of objects of that particular class which are directly under that path.
 Collection getObjects(Query query)
          Retrieve some objects matching to a query
 Collection getObjects(String query, String language)
          Return a list of object matching to a JCR query
 QueryManager getQueryManager()
           
 Version getRootVersion(String path)
          Get the first object version
 Session getSession()
          This method returns the JCR session.
 Version getVersion(String path, String versionName)
          Get a particular version
 String[] getVersionLabels(String path, String versionName)
          Get all version labels assigned to a particular object version
 void insert(Object object)
          Insert an object into the JCR repository
 boolean isLocked(String absPath)
          Is that path locked?
 boolean isPersistent(Class clazz)
          Can this object content manager insert, update, delete, ... that type?
 Lock lock(String absPath, boolean isDeep, boolean isSessionScoped)
          Lock object saved on .
 void logout()
          Close the session
protected  void maybeAddLockToken(String lockToken)
           
 void move(String srcPath, String destPath)
          Move an object
 boolean objectExists(String path)
          Check if an object exists
 void refresh(boolean keepChanges)
          Refresh the underlying jcr session (see the jcr spec)
 void remove(Object object)
          Remove an object from a JCR repository
 void remove(Query query)
          Remove all objects matching to a query
 void remove(String path)
          Remove an object from a JCR repository
 void retrieveAllMappedAttributes(Object object)
          Retrieve all mapped attributes for the given persistent object.
 void retrieveMappedAttribute(Object object, String attributeName)
          Retrieve the specified attribute for the given persistent object. this attribute is either a bean or a collection.
 void save()
          Save all modifications made by the object content manager
 void setMapper(Mapper mapper)
          Sets the Mapper used by this object content manager.
 void setObjectConverter(ObjectConverter objectConverter)
          Sets the ObjectConverter that is used internally by this object content manager.
 void setQueryManager(QueryManager queryManager)
          Sets the QueryManager used by the object content manager.
 void setRequestObjectCache(ObjectCache requestObjectCache)
           
 void unlock(String absPath, String lockToken)
          Unlock object stored on .
 void update(Object object)
          Update an object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

session

protected Session session
JCR session.


mapper

protected Mapper mapper

queryManager

protected QueryManager queryManager
The query manager


objectConverter

protected ObjectConverter objectConverter
Object Converter


requestObjectCache

protected ObjectCache requestObjectCache
Request Cache manager

Constructor Detail

ObjectContentManagerImpl

public ObjectContentManagerImpl(Session session,
                                Mapper mapper)
Creates a new ObjectContentManager that uses the passed in Mapper, and a Session

Parameters:
mapper - the Mapper component
session - The JCR session

ObjectContentManagerImpl

public ObjectContentManagerImpl(Session session,
                                String[] xmlMappingFiles)
Creates a new ObjectContentManager based on a JCR session and some xml mapping files.

Parameters:
session - The JCR session
xmlMappingFiles - the JCR mapping files used mainly to create the Mapper component

ObjectContentManagerImpl

public ObjectContentManagerImpl(Session session,
                                InputStream[] xmlMappingFiles)
Creates a new ObjectContentManager based on a JCR session and some xml mapping files.

Parameters:
session - The JCR session
xmlMappingFiles - the JCR mapping files used mainly to create the Mapper component

ObjectContentManagerImpl

public ObjectContentManagerImpl(Mapper mapper,
                                ObjectConverter converter,
                                QueryManager queryManager,
                                ObjectCache requestObjectCache,
                                Session session)
Full constructor.

Parameters:
mapper - the Mapper component
converter - the ObjectConverter to be used internally
queryManager - the query manager to used
session - The JCR session
Method Detail

setMapper

public void setMapper(Mapper mapper)
Sets the Mapper used by this object content manager.

Parameters:
mapper - mapping solver

setObjectConverter

public void setObjectConverter(ObjectConverter objectConverter)
Sets the ObjectConverter that is used internally by this object content manager.

Parameters:
objectConverter - the internal ObjectConverter

setQueryManager

public void setQueryManager(QueryManager queryManager)
Sets the QueryManager used by the object content manager.

Parameters:
queryManager - a QueryManager

setRequestObjectCache

public void setRequestObjectCache(ObjectCache requestObjectCache)

getObject

public Object getObject(String path)
Description copied from interface: ObjectContentManager
Get an object from the JCR repository

Specified by:
getObject in interface ObjectContentManager
Parameters:
path - the object path
Returns:
the object found or null
Throws:
RepositoryException - if the underlying repository has thrown a javax.jcr.RepositoryException
JcrMappingException - if the mapping for the class is not correct
ObjectContentManagerException - if the object cannot be retrieved from the path
See Also:
ObjectContentManager.getObject(java.lang.Class, java.lang.String)

getObjectByUuid

public Object getObjectByUuid(String uuid)
Description copied from interface: ObjectContentManager
Get an object from the JCR repository

Specified by:
getObjectByUuid in interface ObjectContentManager
Returns:
the object found or null
Throws:
RepositoryException - if the underlying repository has thrown a javax.jcr.RepositoryException
JcrMappingException - if the mapping for the class is not correct
ObjectContentManagerException - if the object cannot be retrieved from the path
See Also:
ObjectContentManager.getObject(java.lang.Class, java.lang.String)

getObject

public Object getObject(String path,
                        String versionName)
Description copied from interface: ObjectContentManager
Get an object from the JCR repository

Specified by:
getObject in interface ObjectContentManager
Parameters:
path - the object path
versionName - The desired object version number
Returns:
the object found or null
See Also:
ObjectContentManager.getObject(java.lang.Class, java.lang.String, java.lang.String)

getObject

public Object getObject(Class objectClass,
                        String path)
Description copied from interface: ObjectContentManager
Get an object from the JCR repository

Specified by:
getObject in interface ObjectContentManager
Parameters:
objectClass - the object class
path - the object path
Returns:
the object found or null
Throws:
RepositoryException - if the underlying repository has thrown a javax.jcr.RepositoryException
JcrMappingException - if the mapping for the class is not correct
ObjectContentManagerException - if the object cannot be retrieved from the path
See Also:
ObjectContentManager.getObject(java.lang.Class, java.lang.String)

getObject

public Object getObject(Class objectClass,
                        String path,
                        String versionName)
Description copied from interface: ObjectContentManager
Get an object from the JCR repository

Specified by:
getObject in interface ObjectContentManager
Parameters:
objectClass - the object class
path - the object path
versionName - The desired object version number
Returns:
the object found or null
See Also:
ObjectContentManager.getObject(java.lang.Class, java.lang.String, java.lang.String)

retrieveAllMappedAttributes

public void retrieveAllMappedAttributes(Object object)
Description copied from interface: ObjectContentManager
Retrieve all mapped attributes for the given persistent object.

Specified by:
retrieveAllMappedAttributes in interface ObjectContentManager
Parameters:
object - The persistent object
See Also:
ObjectContentManager.retrieveAllMappedAttributes(Object)

retrieveMappedAttribute

public void retrieveMappedAttribute(Object object,
                                    String attributeName)
Description copied from interface: ObjectContentManager
Retrieve the specified attribute for the given persistent object. this attribute is either a bean or a collection. This method is usefull if the corresponding descriptor has an autoRetrieve="false"

Specified by:
retrieveMappedAttribute in interface ObjectContentManager
Parameters:
object - The persistent object
attributeName - The name of the attribute to retrieve
See Also:
ObjectContentManager.retrieveMappedAttribute(Object, String)

insert

public void insert(Object object)
Description copied from interface: ObjectContentManager
Insert an object into the JCR repository

Specified by:
insert in interface ObjectContentManager
Parameters:
object - the object to add
See Also:
ObjectContentManager.insert(java.lang.Object)

update

public void update(Object object)
Description copied from interface: ObjectContentManager
Update an object

Specified by:
update in interface ObjectContentManager
Parameters:
object - the object to update
See Also:
ObjectContentManager.update(java.lang.Object)

remove

public void remove(String path)
Description copied from interface: ObjectContentManager
Remove an object from a JCR repository

Specified by:
remove in interface ObjectContentManager
Parameters:
path - the object path
See Also:
ObjectContentManager.remove(java.lang.String)

remove

public void remove(Object object)
Description copied from interface: ObjectContentManager
Remove an object from a JCR repository

Specified by:
remove in interface ObjectContentManager
Parameters:
object - the object to remove
See Also:
ObjectContentManager.remove(java.lang.Object)

remove

public void remove(Query query)
Description copied from interface: ObjectContentManager
Remove all objects matching to a query

Specified by:
remove in interface ObjectContentManager
Parameters:
query - The query used to find the objects to remove
See Also:
ObjectContentManager.remove(org.apache.jackrabbit.ocm.query.Query)

objectExists

public boolean objectExists(String path)
Description copied from interface: ObjectContentManager
Check if an object exists

Specified by:
objectExists in interface ObjectContentManager
Parameters:
path - the object path
Returns:
true if the item exists
See Also:
ObjectContentManager.objectExists(java.lang.String)

isPersistent

public boolean isPersistent(Class clazz)
Description copied from interface: ObjectContentManager
Can this object content manager insert, update, delete, ... that type?

Specified by:
isPersistent in interface ObjectContentManager
Parameters:
clazz - class for question
Returns:
true if the class is persistence
See Also:
ObjectContentManager.isPersistent(java.lang.Class)

getObject

public Object getObject(Query query)
Description copied from interface: ObjectContentManager
Retrieve an object matching to a query

Specified by:
getObject in interface ObjectContentManager
Parameters:
query - The Query object used to seach the object
Returns:
The object found or null
See Also:
ObjectContentManager.getObject(org.apache.jackrabbit.ocm.query.Query)

getObjects

public Collection getObjects(Query query)
Description copied from interface: ObjectContentManager
Retrieve some objects matching to a query

Specified by:
getObjects in interface ObjectContentManager
Parameters:
query - The query used to seach the objects
Returns:
a collection of objects found
See Also:
ObjectContentManager.getObjects(org.apache.jackrabbit.ocm.query.Query)

getObjects

public Collection getObjects(Class objectClass,
                             String path)
                      throws ObjectContentManagerException
Returns a list of objects of that particular class which are directly under that path. This would not return the objects anywhere below the denoted path.

Specified by:
getObjects in interface ObjectContentManager
Parameters:
objectClass -
path -
Returns:
Throws:
ObjectContentManagerException

getObjectIterator

public Iterator getObjectIterator(Query query)
Description copied from interface: ObjectContentManager
Retrieve some objects matching to a query.

Specified by:
getObjectIterator in interface ObjectContentManager
Parameters:
query - The query used to seach the objects
Returns:
an iterator of objects found
See Also:
ObjectContentManager.getObjectIterator(org.apache.jackrabbit.ocm.query.Query)

getObjectIterator

public Iterator getObjectIterator(String query,
                                  String language)
Description copied from interface: ObjectContentManager
Retrieve an objects matching a query specified in a specific query language. This method is expected to call create a Query using the session's QueryManager with the given query exception and language parameters.

If the query statement is syntactically invalid, given the language specified, an InvalidQueryException is thrown. The language must be a string from among those returned by javax.jcr.QueryManager.getSupportedQueryLanguages(); if it is not, then an InvalidQueryException is thrown.

Specified by:
getObjectIterator in interface ObjectContentManager
Parameters:
query - The query to execute to find the objects.
language - The language in which the query is written
Returns:
An iterator of objects instances. Each entry in the iterator represents the mapping of a node returned by the query. If the query returns a node, which may not be mapped, the respective node is ignored.
See Also:
ObjectContentManager.getObjectIterator(String, String)

getObjects

public Collection getObjects(String query,
                             String language)
Description copied from interface: ObjectContentManager
Return a list of object matching to a JCR query

Specified by:
getObjects in interface ObjectContentManager
Parameters:
query - the JCR query
language - the JCR Language ("XPATH" or "SQL").
Returns:

checkin

public void checkin(String path)
Description copied from interface: ObjectContentManager
Checkin an object

Specified by:
checkin in interface ObjectContentManager
Parameters:
path - the object path
See Also:
ObjectContentManager.checkin(java.lang.String)

checkin

public void checkin(String path,
                    String[] versionLabels)
Description copied from interface: ObjectContentManager
Checkin an object and apply some labels to this new version Within a particular object path, a given label may appear a maximum of once

Specified by:
checkin in interface ObjectContentManager
Parameters:
path - The object path
versionLabels - the version labels to apply to the new version
See Also:
ObjectContentManager.checkin(java.lang.String, java.lang.String[])

checkout

public void checkout(String path)
Description copied from interface: ObjectContentManager
Checkout - Create a new version This is only possible if the object is based on mix:versionable node type

Specified by:
checkout in interface ObjectContentManager
Parameters:
path - The object path
See Also:
ObjectContentManager.checkout(java.lang.String)

addVersionLabel

public void addVersionLabel(String path,
                            String versionName,
                            String versionLabel)
Description copied from interface: ObjectContentManager
Add a new label to a particular version

Specified by:
addVersionLabel in interface ObjectContentManager
Parameters:
path - the object path
versionName - the object versio name (1.0, 1.1, ...)
versionLabel - The new label to apply
See Also:
ObjectContentManager.addVersionLabel(java.lang.String, java.lang.String, java.lang.String)

getVersion

public Version getVersion(String path,
                          String versionName)
Description copied from interface: ObjectContentManager
Get a particular version

Specified by:
getVersion in interface ObjectContentManager
Parameters:
path - the object path
versionName - the version name
Returns:
the version found or null
See Also:
ObjectContentManager.getVersion(java.lang.String, java.lang.String)

getVersionLabels

public String[] getVersionLabels(String path,
                                 String versionName)
Description copied from interface: ObjectContentManager
Get all version labels assigned to a particular object version

Specified by:
getVersionLabels in interface ObjectContentManager
Parameters:
path - the object path
versionName - the object version name (1.0, ...)
Returns:
a array of string (version labels)
See Also:
ObjectContentManager.getVersionLabels(java.lang.String, java.lang.String)

getAllVersionLabels

public String[] getAllVersionLabels(String path)
Description copied from interface: ObjectContentManager
Get all version labels assigned to all versions

Specified by:
getAllVersionLabels in interface ObjectContentManager
Parameters:
path - the object path
Returns:
a array of string (version labels)
See Also:
ObjectContentManager.getAllVersionLabels(java.lang.String)

getAllVersions

public VersionIterator getAllVersions(String path)
Description copied from interface: ObjectContentManager
Get all object versions

Specified by:
getAllVersions in interface ObjectContentManager
Parameters:
path - the object path
Returns:
a version iterator
See Also:
ObjectContentManager.getAllVersions(java.lang.String)

getRootVersion

public Version getRootVersion(String path)
Description copied from interface: ObjectContentManager
Get the first object version

Specified by:
getRootVersion in interface ObjectContentManager
Parameters:
path - the object path
Returns:
the first version found
See Also:
ObjectContentManager.getRootVersion(java.lang.String)

getBaseVersion

public Version getBaseVersion(String path)
Description copied from interface: ObjectContentManager
Get the lastest object version

Specified by:
getBaseVersion in interface ObjectContentManager
Parameters:
path - the object path
Returns:
the last version found
See Also:
ObjectContentManager.getBaseVersion(java.lang.String)

lock

public Lock lock(String absPath,
                 boolean isDeep,
                 boolean isSessionScoped)
          throws LockedException
Description copied from interface: ObjectContentManager
Lock object saved on .

Specified by:
lock in interface ObjectContentManager
Parameters:
absPath - path to saved object.
isDeep - is lock deep? See JCR spec: 8.4.3 Shallow and Deep Locks
isSessionScoped - is lock session scoped? See JCR spec: Session-scoped and Open-scoped Locks
Returns:
lock - Wrapper object for a JCR lock
Throws:
LockedException - if path is locked (cannot lock same path again)
See Also:
org.apache.jackrabbit.ocm.manager.ObjectContentManager#lock(java.lang.String, java.lang.Object, boolean, boolean)

unlock

public void unlock(String absPath,
                   String lockToken)
            throws IllegalUnlockException
Description copied from interface: ObjectContentManager
Unlock object stored on .

Specified by:
unlock in interface ObjectContentManager
Parameters:
absPath - path to stored object
lockToken - see JCR spec: 8.4.6 Lock Token; can be null
Throws:
IllegalUnlockException - throws if the current operation does not own the current lock
See Also:
org.apache.jackrabbit.ocm.manager.ObjectContentManager#unlock(java.lang.String, java.lang.Object, java.lang.String)

isLocked

public boolean isLocked(String absPath)
Description copied from interface: ObjectContentManager
Is that path locked?

Specified by:
isLocked in interface ObjectContentManager
Returns:
true if path locked
See Also:
ObjectContentManager.isLocked(java.lang.String)

getQueryManager

public QueryManager getQueryManager()
Specified by:
getQueryManager in interface ObjectContentManager
Returns:
The query manager reference
See Also:
ObjectContentManager.getQueryManager()

checkIfNodeLocked

protected void checkIfNodeLocked(String absPath)
                          throws RepositoryException,
                                 LockedException
Throws LockedException id node is locked so alter nopde cannot be done

Parameters:
absPath - abs path to node
Throws:
RepositoryException
LockedException - if node is locked

maybeAddLockToken

protected void maybeAddLockToken(String lockToken)

getNode

protected Node getNode(String absPath)
                throws PathNotFoundException,
                       RepositoryException
Throws:
PathNotFoundException
RepositoryException

logout

public void logout()
Description copied from interface: ObjectContentManager
Close the session

Specified by:
logout in interface ObjectContentManager
See Also:
ObjectContentManager.logout()

save

public void save()
Description copied from interface: ObjectContentManager
Save all modifications made by the object content manager

Specified by:
save in interface ObjectContentManager
See Also:
ObjectContentManager.save()

getSession

public Session getSession()
Description copied from interface: ObjectContentManager
This method returns the JCR session. The JCR session could be used to make some JCR specific calls.

Specified by:
getSession in interface ObjectContentManager
Returns:
The JCR Session

refresh

public void refresh(boolean keepChanges)
Description copied from interface: ObjectContentManager
Refresh the underlying jcr session (see the jcr spec)

Specified by:
refresh in interface ObjectContentManager

move

public void move(String srcPath,
                 String destPath)
Description copied from interface: ObjectContentManager
Move an object

Specified by:
move in interface ObjectContentManager
Parameters:
srcPath - path of the object to move
destPath - destination path
See Also:
ObjectContentManager.move(java.lang.String, java.lang.String)

copy

public void copy(String srcPath,
                 String destPath)
Description copied from interface: ObjectContentManager
Copy an object

Specified by:
copy in interface ObjectContentManager
Parameters:
srcPath - path of the object to copy
destPath - destination path
See Also:
ObjectContentManager.copy(java.lang.String, java.lang.String)


Copyright © 2004-2008 The Apache Software Foundation. All Rights Reserved.