|
ModeShape Distribution 3.2.0.Final | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.modeshape.jcr.cache.document.DocumentTranslator
public class DocumentTranslator
A utility class that encapsulates all the logic for reading from and writing to Document
instances.
Nested Class Summary | |
---|---|
static class |
DocumentTranslator.ChildReferencesInfo
|
Field Summary | |
---|---|
static String |
BLOCK_SIZE
|
static String |
CACHE_TTL_SECONDS
A constant that can be used by a connector implementation as a supplementary document field, that indicates the maximum number of seconds that particular document should be stored in the workspace cache. |
static String |
CHILDREN
|
static String |
CHILDREN_INFO
|
static String |
COUNT
|
static String |
EMBEDDED_DOCUMENTS
A constant that is used as the name for a nested document in which additional, embedded documents can be placed. |
static String |
EXTERNAL_BINARY_ID_FIELD
|
static String |
FEDERATED_SEGMENTS
|
static String |
KEY
|
static String |
LARGE_VALUE
|
static String |
LAST_BLOCK
|
static String |
LENGTH
|
static String |
LENGTH_FIELD
|
static String |
NAME
|
static String |
NEXT_BLOCK
|
static String |
PARENT
|
static String |
PROPERTIES
|
static String |
QUERYABLE_FIELD
|
static String |
REFERENCE_COUNT
|
static String |
REFERRERS
|
static String |
SHA1
|
static String |
SHA1_FIELD
|
static String |
SOURCE_NAME_FIELD
|
static String |
STRONG
|
static String |
WEAK
|
Constructor Summary | |
---|---|
DocumentTranslator(ExecutionContext context,
DocumentStore documentStore,
long largeStringSize)
|
Method Summary | |
---|---|
protected void |
addFederatedSegment(EditableDocument document,
String documentKey,
String sourceName,
String externalPath,
String alias)
Given an existing document adds a new federated segment with the given alias pointing to the external document located at externalPath |
void |
addPropertyValues(EditableDocument document,
Name propertyName,
boolean isMultiple,
Collection<?> values,
Set<BinaryKey> unusedBinaryKeys)
|
void |
changeChildren(EditableDocument document,
SessionNode.ChangedChildren changedChildren,
ChildReferences appended)
|
void |
changeReferrers(EditableDocument document,
SessionNode.ReferrerChanges changes)
|
protected ChildReference |
childReferenceFrom(Object value)
|
int |
countProperties(Document document)
|
protected boolean |
decrementBinaryReferenceCount(Object fieldValue,
Set<BinaryKey> unusedBinaryKeys)
Decrement the reference count for the binary value. |
EditableDocument |
fromChildReference(ChildReference ref)
|
protected Integer |
getCacheTtlSeconds(Document document)
Returns the value of the CACHE_TTL_SECONDS field, if such a
value exists. |
ChildReferences |
getChildReferences(WorkspaceCache cache,
Document document)
|
ChildReferences |
getChildReferencesFromBlock(Document block)
Reads the children of the given block and returns a ChildReferences instance. |
DocumentTranslator.ChildReferencesInfo |
getChildReferencesInfo(Document document)
|
String |
getKey(Document document)
|
Set<String> |
getMixinTypeNames(Document document)
|
Set<Name> |
getMixinTypes(Document document)
|
NameFactory |
getNameFactory()
|
NodeKey |
getParentKey(Document document,
String primaryWorkspaceKey,
String secondaryWorkspaceKey)
Obtain the preferred key for the parent of this node. |
Set<NodeKey> |
getParentKeys(Document document,
String primaryWorkspaceKey,
String secondaryWorkspaceKey)
|
Name |
getPrimaryType(Document document)
|
String |
getPrimaryTypeName(Document document)
|
void |
getProperties(Document document,
Map<Name,Property> result)
|
Property |
getProperty(Document document,
Name propertyName)
|
Property |
getProperty(Document document,
String propertyName)
|
PropertyFactory |
getPropertyFactory()
|
ReferenceFactory |
getReferenceFactory()
|
Set<NodeKey> |
getReferrers(Document document,
CachedNode.ReferenceType type)
|
ValueFactory<String> |
getStringFactory()
|
ReferenceFactory |
getWeakReferenceFactory()
|
boolean |
hasProperties(Document document)
|
boolean |
hasProperty(Document document,
Name propertyName)
|
protected void |
incrementBinaryReferenceCount(BinaryKey binaryKey,
Set<BinaryKey> unusedBinaryKeys)
Increment the reference count for the stored binary value with the supplied SHA-1 hash. |
protected long |
insertChildren(EditableDocument document,
Map<NodeKey,SessionNode.Insertions> insertionsByBeforeKey,
Set<NodeKey> removals,
Map<NodeKey,Name> newNames)
|
protected boolean |
isFederatedDocument(Document document)
|
boolean |
isLocked(EditableDocument doc)
Checks if the given document is already locked |
protected boolean |
isQueryable(Document document)
|
protected String |
keyForBinaryReferenceDocument(String sha1)
|
protected String |
mergeChildren(NodeKey key,
EditableDocument document,
EditableArray children,
boolean isFirst,
String nextBlock)
Modify the supplied document (with the given key) to merge in all of the children from the next block. |
protected void |
optimizeChildrenBlocks(NodeKey key,
EditableDocument document,
int targetCountPerBlock,
int tolerance)
Note that this method changes the underlying db as well as the given document, so *it must* be called either from a transactional context or it must be followed by a session.save call, otherwise there might be inconsistencies between what a session sees as "persisted" state and the reality. |
protected Property |
propertyFor(Name propertyName,
Object fieldValue)
|
protected void |
removeFederatedSegments(EditableDocument federatedDocument,
Set<String> externalNodeKeys)
|
protected void |
removeFederatedSegments(EditableDocument federatedDocument,
String... externalNodeKeys)
|
Property |
removeProperty(EditableDocument document,
Name propertyName,
Set<BinaryKey> unusedBinaryKeys)
|
void |
removePropertyValues(EditableDocument document,
Name propertyName,
Collection<?> values,
Set<BinaryKey> unusedBinaryKeys)
|
protected Object |
resolveLargeValue(String sha1)
|
protected List<Path.Segment> |
segmentsFrom(List<?> segmentValues)
|
void |
setKey(EditableDocument document,
NodeKey key)
|
void |
setKey(EditableDocument document,
String key)
|
void |
setParents(EditableDocument document,
NodeKey parent,
NodeKey oldParent,
SessionNode.ChangedAdditionalParents additionalParents)
|
void |
setProperty(EditableDocument document,
Property property,
Set<BinaryKey> unusedBinaryKeys)
|
void |
setQueryable(EditableDocument document,
boolean queryable)
Marks the given document as queryable, by setting a flag. |
protected boolean |
splitChildren(NodeKey key,
EditableDocument document,
EditableArray children,
int targetCountPerBlock,
int tolerance,
boolean isFirst,
String nextBlock)
Split the children in the given document (with the given key) into two or more blocks, based upon the specified number of desired children per block and a tolerance. |
Object |
valueFromDocument(Object value)
|
protected Object |
valueToDocument(Object value,
Set<BinaryKey> unusedBinaryKeys)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String SHA1
public static final String EXTERNAL_BINARY_ID_FIELD
public static final String SOURCE_NAME_FIELD
public static final String SHA1_FIELD
public static final String LENGTH
public static final String LENGTH_FIELD
public static final String PARENT
public static final String LARGE_VALUE
public static final String PROPERTIES
public static final String CHILDREN
public static final String CHILDREN_INFO
public static final String FEDERATED_SEGMENTS
public static final String COUNT
public static final String BLOCK_SIZE
public static final String NEXT_BLOCK
public static final String LAST_BLOCK
public static final String NAME
public static final String KEY
public static final String REFERRERS
public static final String WEAK
public static final String STRONG
public static final String REFERENCE_COUNT
public static final String QUERYABLE_FIELD
public static final String EMBEDDED_DOCUMENTS
public static final String CACHE_TTL_SECONDS
Constructor Detail |
---|
public DocumentTranslator(ExecutionContext context, DocumentStore documentStore, long largeStringSize)
Method Detail |
---|
public final ValueFactory<String> getStringFactory()
public final NameFactory getNameFactory()
public final ReferenceFactory getReferenceFactory()
public final ReferenceFactory getWeakReferenceFactory()
public final PropertyFactory getPropertyFactory()
public NodeKey getParentKey(Document document, String primaryWorkspaceKey, String secondaryWorkspaceKey)
key
for the parent of this node. Because a node can be used in more than once place,
it may technically have more than one parent. Therefore, in such cases this method prefers the parent that is in the
primaryWorkspaceKey
and, if there is no such parent, the parent that is in the secondaryWorkspaceKey
.
document
- the document for the node; may not be nullprimaryWorkspaceKey
- the key for the workspace in which the parent should preferably exist; may be nullsecondaryWorkspaceKey
- the key for the workspace in which the parent should exist if not in the primary workspace;
may be null
public Set<NodeKey> getParentKeys(Document document, String primaryWorkspaceKey, String secondaryWorkspaceKey)
public void getProperties(Document document, Map<Name,Property> result)
public int countProperties(Document document)
public boolean hasProperties(Document document)
public boolean hasProperty(Document document, Name propertyName)
public Property getProperty(Document document, String propertyName)
public Property getProperty(Document document, Name propertyName)
public Name getPrimaryType(Document document)
public String getPrimaryTypeName(Document document)
public Set<Name> getMixinTypes(Document document)
public Set<String> getMixinTypeNames(Document document)
protected Property propertyFor(Name propertyName, Object fieldValue)
public void setProperty(EditableDocument document, Property property, Set<BinaryKey> unusedBinaryKeys)
public Property removeProperty(EditableDocument document, Name propertyName, Set<BinaryKey> unusedBinaryKeys)
public void addPropertyValues(EditableDocument document, Name propertyName, boolean isMultiple, Collection<?> values, Set<BinaryKey> unusedBinaryKeys)
public void removePropertyValues(EditableDocument document, Name propertyName, Collection<?> values, Set<BinaryKey> unusedBinaryKeys)
public void setParents(EditableDocument document, NodeKey parent, NodeKey oldParent, SessionNode.ChangedAdditionalParents additionalParents)
public void setKey(EditableDocument document, NodeKey key)
public void setKey(EditableDocument document, String key)
public String getKey(Document document)
public void changeChildren(EditableDocument document, SessionNode.ChangedChildren changedChildren, ChildReferences appended)
protected long insertChildren(EditableDocument document, Map<NodeKey,SessionNode.Insertions> insertionsByBeforeKey, Set<NodeKey> removals, Map<NodeKey,Name> newNames)
public ChildReferences getChildReferences(WorkspaceCache cache, Document document)
public ChildReferences getChildReferencesFromBlock(Document block)
ChildReferences
instance.
block
- a non-null
Document
representing a block of children
non-null
child references instancepublic DocumentTranslator.ChildReferencesInfo getChildReferencesInfo(Document document)
protected ChildReference childReferenceFrom(Object value)
public EditableDocument fromChildReference(ChildReference ref)
public Set<NodeKey> getReferrers(Document document, CachedNode.ReferenceType type)
public void changeReferrers(EditableDocument document, SessionNode.ReferrerChanges changes)
protected Object valueToDocument(Object value, Set<BinaryKey> unusedBinaryKeys)
protected final String keyForBinaryReferenceDocument(String sha1)
protected void incrementBinaryReferenceCount(BinaryKey binaryKey, Set<BinaryKey> unusedBinaryKeys)
binaryKey
- the key for the binary value; never nullunusedBinaryKeys
- the set of binary keys that are considered unused; may be nullprotected boolean decrementBinaryReferenceCount(Object fieldValue, Set<BinaryKey> unusedBinaryKeys)
fieldValue
- the value in the document that may contain a binary value reference; may be nullunusedBinaryKeys
- the set of binary keys that are considered unused; may be null
public Object valueFromDocument(Object value)
protected List<Path.Segment> segmentsFrom(List<?> segmentValues)
protected Object resolveLargeValue(String sha1)
protected void optimizeChildrenBlocks(NodeKey key, EditableDocument document, int targetCountPerBlock, int tolerance)
Note that this method changes the underlying db as well as the given document, so *it must* be called either from a transactional context or it must be followed by a session.save call, otherwise there might be inconsistencies between what a session sees as "persisted" state and the reality.
key
- document
- targetCountPerBlock
- tolerance
- protected boolean splitChildren(NodeKey key, EditableDocument document, EditableArray children, int targetCountPerBlock, int tolerance, boolean isFirst, String nextBlock)
Note this method returns very quickly if the method determines that there is no work to do.
Note that this method changes the underlying db as well as the given document, so *it must* be called either from a transactional context or it must be followed by a session.save call, otherwise there might be inconsistencies between what a session sees as "persisted" state and the reality.
key
- the key for the document whose children are to be split; may not be nulldocument
- the document whose children are to be split; may not be nullchildren
- the children that are to be split; may not be nulltargetCountPerBlock
- the goal for the number of children in each block; must be positivetolerance
- a tolerance that when added to and subtraced from the targetCountPerBlock
gives an acceptable
range for the number of children; must be positive but smaller than targetCountPerBlock
isFirst
- true if the supplied document is the first node document, or false if it is a block documentnextBlock
- the key for the next block of children; may be null if the supplied document is the last document and
there is no next block
protected String mergeChildren(NodeKey key, EditableDocument document, EditableArray children, boolean isFirst, String nextBlock)
Note that this method changes the underlying db as well as the given document, so *it must* be called either from a transactional context or it must be followed by a session.save call, otherwise there might be inconsistencies between what a session sees as "persisted" state and the reality.
key
- the key for the document whose children are to be merged with the next block; may not be nulldocument
- the document to be modified with the next block's children; may not be nullchildren
- the children into which are to be merged the next block's children; may not be nullisFirst
- true if the supplied document is the first node document, or false if it is a block documentnextBlock
- the key for the next block of children; may be null if the supplied document is the last document and
there is no next block
public boolean isLocked(EditableDocument doc)
doc
- the document
protected boolean isFederatedDocument(Document document)
protected void removeFederatedSegments(EditableDocument federatedDocument, Set<String> externalNodeKeys)
protected void removeFederatedSegments(EditableDocument federatedDocument, String... externalNodeKeys)
protected boolean isQueryable(Document document)
public void setQueryable(EditableDocument document, boolean queryable)
document
- a EditableDocument
instance; never nullqueryable
- a boolean which indicates whether the document should be queryable or not.protected void addFederatedSegment(EditableDocument document, String documentKey, String sourceName, String externalPath, String alias)
externalPath
document
- a non-null
EditableDocument
representing the document of a local node to which the
federated segment should be appended.documentKey
- a non-null
String
representing the key of the document. This is passed from the outside
as the document may not have a KEY
property (e.g. root node)sourceName
- a non-null
string, the name of the source where externalPath
will be resolvedexternalPath
- a non-null
string the location in the external source which points to an external nodealias
- an optional string representing the name under which the federated segment will be linked. In effect, this
represents the name of a child reference. If not present, the externalPath
will be used. Note that the name
of the federated segment (either coming from externalPath
or alias
) should not contain the "/"
character. If it does, this will be removed.protected Integer getCacheTtlSeconds(Document document)
CACHE_TTL_SECONDS
field, if such a
value exists.
document
- a non-null
document
null
if such a value doesn't exist.
|
ModeShape Distribution 3.2.0.Final | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |