public class MockObjectBeanPersistenceManager extends Object implements ObjectBeanPersistenceManager
MockObjectBeanPersistenceManager
interface.
This implementation assumes that a content object has 'path' bean property to indicate
from which absolute path the content object is originated.
So, it will use getPath()
method to read the original absolute path to update
or remove the object.
The absolute content paths and objects mapped to the paths are stored in maps.
To store an object to maps, it uses Java Serialization.
Therefore, the object used with this implementation should implement
java.io.Serializable
, public boolean equals(Object object);
and public int hashCode();
properly.
By the way, this mock implementation does not have any knowledge on how to create a new content based on its node type.
Constructor and Description |
---|
MockObjectBeanPersistenceManager() |
Modifier and Type | Method and Description |
---|---|
protected Object |
bytesToObject(byte[] bytes) |
void |
create(String absPath,
String nodeTypeName,
String name) |
void |
create(String absPath,
String nodeTypeName,
String name,
boolean autoCreateFolders) |
String |
createAndReturn(String absPath,
String nodeTypeName,
String name,
boolean autoCreateFolders)
Creates content node(s) with the specified node type at the specified absolute path.
|
Object |
getObject(String absPath)
Get an object from the JCR repository.
|
Object |
getObjectByUuid(String uuid)
Get an object from the JCR repository
|
protected String |
getPathProperty(Object object) |
protected Object |
getSerializedCopy(Object object) |
javax.jcr.Session |
getSession()
This method returns the JCR session.
|
protected String |
getUuidProperty(Object object) |
protected byte[] |
objectToBytes(Object object) |
void |
refresh()
Invokes
Session.refresh(boolean) with false parameter. |
void |
refresh(boolean keepChanges)
Invokes
Session.refresh(boolean) . |
void |
remove(Object content)
Removes the content node which is mapped to the object.
|
void |
save()
Saves all pending changes.
|
void |
setObject(String absPath,
Object object) |
void |
update(Object content)
Updates the content node which is mapped to the object.
|
void |
update(Object content,
ContentNodeBinder customBinder)
Updates the content node which is mapped to the object by the
customContentNodeBinder
provided by client. |
public Object getObject(String absPath) throws ObjectBeanPersistenceException
ObjectBeanManager
path
is the absolute object path and must start with a "/"getObject
in interface ObjectBeanManager
absPath
- the absolute object path.ObjectBeanPersistenceException
public Object getObjectByUuid(String uuid) throws ObjectBeanPersistenceException
ObjectBeanManager
getObjectByUuid
in interface ObjectBeanManager
uuid
- the object uuidObjectBeanPersistenceException
public void setObject(String absPath, Object object) throws ObjectBeanPersistenceException
ObjectBeanPersistenceException
public void create(String absPath, String nodeTypeName, String name) throws ObjectBeanPersistenceException
ObjectBeanPersistenceException
public void create(String absPath, String nodeTypeName, String name, boolean autoCreateFolders) throws ObjectBeanPersistenceException
ObjectBeanPersistenceException
public String createAndReturn(String absPath, String nodeTypeName, String name, boolean autoCreateFolders) throws ObjectBeanPersistenceException
ObjectBeanPersistenceManager
The absolute path could be regarded differently according to physical implementations. For example, an implementation can regard the path as a simple one to create a simple JCR node. On the other hand, a sophisticated implementation can regard the path as an input for a workflow-enabled document/folder path.
If autoCreateFolders
is true, then folders will be automatically created.
createAndReturn
in interface ObjectBeanPersistenceManager
absPath
- the absolute node pathnodeTypeName
- the node type name of the content objectname
- the content node nameautoCreateFolders
- the flag to create foldersObjectBeanPersistenceException
public void update(Object content) throws ObjectBeanPersistenceException
ObjectBeanPersistenceManager
An implementation can provide binding the content object to the physical JCR node(s) and updates.
An implementation can provide automatic content binding, or another requires pre-registered
ContentNodeBinder
map to do real bindings. It probably depends on the functionalities
of underlying repository.
Note: It is recommended as best practice and more semantically correct to always invoke ObjectBeanPersistenceManager.save()
to commit the changes to the repository after successful ObjectBeanPersistenceManager.update(Object)
call.
In the future, the commit or rollback semantics could be more dependent on whether ObjectBeanPersistenceManager.save()
or
ObjectBeanPersistenceManager.refresh()
/ObjectBeanPersistenceManager.refresh(boolean)
is really invoked.
update
in interface ObjectBeanPersistenceManager
ObjectBeanPersistenceException
public void update(Object content, ContentNodeBinder customBinder) throws ObjectBeanPersistenceException
ObjectBeanPersistenceManager
customContentNodeBinder
provided by client.
Unlike ObjectBeanPersistenceManager.update(Object)
, the implementation should not try to do automatic or predefined bindings.
Instead, it should invoke customContentNodeBinder
to do bindings.
Therefore, if a developer wants to customize the bindings, the developer should provide a customContentNodeBinder
.
Note: It is recommended as best practice and more semantically correct to always invoke ObjectBeanPersistenceManager.save()
to commit the changes to the repository after successful ObjectBeanPersistenceManager.update(Object, ContentNodeBinder)
call.
In the future, the commit or rollback semantics could be more dependent on whether ObjectBeanPersistenceManager.save()
or
ObjectBeanPersistenceManager.refresh()
/ObjectBeanPersistenceManager.refresh(boolean)
is really invoked.
update
in interface ObjectBeanPersistenceManager
ObjectBeanPersistenceException
public void remove(Object content) throws ObjectBeanPersistenceException
ObjectBeanPersistenceManager
remove
in interface ObjectBeanPersistenceManager
ObjectBeanPersistenceException
public void save() throws ObjectBeanPersistenceException
ObjectBeanPersistenceManager
save
in interface ObjectBeanPersistenceManager
ObjectBeanPersistenceException
public void refresh() throws ObjectBeanPersistenceException
ObjectBeanPersistenceManager
Session.refresh(boolean)
with false
parameter.refresh
in interface ObjectBeanPersistenceManager
ObjectBeanPersistenceException
public void refresh(boolean keepChanges) throws ObjectBeanPersistenceException
ObjectBeanPersistenceManager
Session.refresh(boolean)
.refresh
in interface ObjectBeanPersistenceManager
ObjectBeanPersistenceException
protected Object getSerializedCopy(Object object) throws ObjectBeanPersistenceException
ObjectBeanPersistenceException
protected byte[] objectToBytes(Object object) throws ObjectBeanPersistenceException
ObjectBeanPersistenceException
protected Object bytesToObject(byte[] bytes) throws ObjectBeanPersistenceException
ObjectBeanPersistenceException
public javax.jcr.Session getSession()
ObjectBeanManager
getSession
in interface ObjectBeanManager
Copyright © 2008–2016 Hippo B.V. (http://www.onehippo.com). All rights reserved.