org.modeshape.jcr.cache.document

## Class DocumentTranslator

- java.lang.Object
- - org.modeshape.jcr.cache.document.DocumentTranslator

- All Implemented Interfaces:
    DocumentConstants

      public class DocumentTranslator
      extends Object
      implements DocumentConstants

  A utility class that encapsulates all the logic for reading from and writing to `Document` instances.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `DocumentTranslator.ChildReferencesInfo`

  - ### Field Summary

    - ### Fields inherited from interface org.modeshape.jcr.cache.document.DocumentConstants

      `BLOCK_SIZE, CACHE_TTL_SECONDS, CHILDREN, CHILDREN_INFO, COUNT, EMBEDDED_DOCUMENTS, EXTERNAL_BINARY_ID_FIELD, FEDERATED_SEGMENTS, KEY, LARGE_VALUE, LAST_BLOCK, LENGTH, LENGTH_FIELD, NAME, NEXT_BLOCK, PARENT, PROPERTIES, QUERYABLE_FIELD, REFERENCE_COUNT, REFERENCE_FIELD, REFERRERS, SHA1, SHA1_FIELD, SIMPLE_REFERENCE_FIELD, SOURCE_NAME_FIELD, STRONG, WEAK, WEAK_REFERENCE_FIELD`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DocumentTranslator(ExecutionContext context, DocumentStore documentStore, long largeStringSize)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addFederatedSegment(EditableDocument document, String externalNodeKey, String name)`
    `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 void` | `decrementBinaryReferenceCount(Object fieldValue, Set<BinaryKey> unusedBinaryKeys)` Decrement the reference count for the binary value.
    `EditableDocument` | `fromChildReference(ChildReference ref)`
    `Set<NodeKey>` | `getAdditionalParentKeys(Document document)`
    `protected Integer` | `getCacheTtlSeconds(Document document)` Returns the value of the `DocumentConstants.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.
    `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()`
    `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 Property` | `propertyFor(Name propertyName, Object fieldValue)`
    `protected void` | `removeFederatedSegments(EditableDocument federatedDocument, Set<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.
    `Object` | `valueFromDocument(Object value)`
    `protected Object` | `valueToDocument(Object value, Set<BinaryKey> unusedBinaryKeys)`
    `DocumentTranslator` | `withLargeStringSize(long largeStringSize)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DocumentTranslator

          public DocumentTranslator(ExecutionContext context,
                            DocumentStore documentStore,
                            long largeStringSize)

  - ### Method Detail

    - #### withLargeStringSize

          public DocumentTranslator withLargeStringSize(long largeStringSize)

    - #### getStringFactory

          public final ValueFactory<String> getStringFactory()

    - #### getNameFactory

          public final NameFactory getNameFactory()

    - #### getReferenceFactory

          public final ReferenceFactory getReferenceFactory()

    - #### getPropertyFactory

          public final PropertyFactory getPropertyFactory()

    - #### getParentKey

          public NodeKey getParentKey(Document document,
                             String primaryWorkspaceKey,
                             String secondaryWorkspaceKey)

      Obtain the preferred `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`.
      Parameters:
        `document` - the document for the node; may not be null
        `primaryWorkspaceKey` - the key for the workspace in which the parent should preferably exist; may be null
        `secondaryWorkspaceKey` - the key for the workspace in which the parent should exist if not in the primary workspace; may be null
      Returns:
        the key representing the preferred parent, or null if the document contains no parent reference or if the parent reference(s) do not have the specified workspace keys

    - #### getAdditionalParentKeys

          public Set<NodeKey> getAdditionalParentKeys(Document document)

    - #### getProperties

          public void getProperties(Document document,
                           Map<Name,Property> result)

    - #### countProperties

          public int countProperties(Document document)

    - #### hasProperties

          public boolean hasProperties(Document document)

    - #### hasProperty

          public boolean hasProperty(Document document,
                            Name propertyName)

    - #### getProperty

          public Property getProperty(Document document,
                             String propertyName)

    - #### getProperty

          public Property getProperty(Document document,
                             Name propertyName)

    - #### getPrimaryType

          public Name getPrimaryType(Document document)

    - #### getPrimaryTypeName

          public String getPrimaryTypeName(Document document)

    - #### getMixinTypes

          public Set<Name> getMixinTypes(Document document)

    - #### getMixinTypeNames

          public Set<String> getMixinTypeNames(Document document)

    - #### propertyFor

          protected Property propertyFor(Name propertyName,
                             Object fieldValue)

    - #### setProperty

          public void setProperty(EditableDocument document,
                         Property property,
                         Set<BinaryKey> unusedBinaryKeys)

    - #### removeProperty

          public Property removeProperty(EditableDocument document,
                                Name propertyName,
                                Set<BinaryKey> unusedBinaryKeys)

    - #### addPropertyValues

          public void addPropertyValues(EditableDocument document,
                               Name propertyName,
                               boolean isMultiple,
                               Collection<?> values,
                               Set<BinaryKey> unusedBinaryKeys)

    - #### removePropertyValues

          public void removePropertyValues(EditableDocument document,
                                  Name propertyName,
                                  Collection<?> values,
                                  Set<BinaryKey> unusedBinaryKeys)

    - #### setParents

          public void setParents(EditableDocument document,
                        NodeKey parent,
                        NodeKey oldParent,
                        SessionNode.ChangedAdditionalParents additionalParents)

    - #### setKey

          public void setKey(EditableDocument document,
                    NodeKey key)

    - #### setKey

          public void setKey(EditableDocument document,
                    String key)

    - #### getKey

          public String getKey(Document document)

    - #### changeChildren

          public void changeChildren(EditableDocument document,
                            SessionNode.ChangedChildren changedChildren,
                            ChildReferences appended)

    - #### insertChildren

          protected long insertChildren(EditableDocument document,
                            Map<NodeKey,SessionNode.Insertions> insertionsByBeforeKey,
                            Set<NodeKey> removals,
                            Map<NodeKey,Name> newNames)

    - #### getChildReferences

          public ChildReferences getChildReferences(WorkspaceCache cache,
                                           Document document)

    - #### getChildReferencesFromBlock

          public ChildReferences getChildReferencesFromBlock(Document block)

      Reads the children of the given block and returns a `ChildReferences` instance.
      Parameters:
        `block` - a `non-null` `Document` representing a block of children
      Returns:
        a `non-null` child references instance

    - #### getChildReferencesInfo

          public DocumentTranslator.ChildReferencesInfo getChildReferencesInfo(Document document)

    - #### childReferenceFrom

          protected ChildReference childReferenceFrom(Object value)

    - #### fromChildReference

          public EditableDocument fromChildReference(ChildReference ref)

    - #### getReferrers

          public Set<NodeKey> getReferrers(Document document,
                                  CachedNode.ReferenceType type)

    - #### changeReferrers

          public void changeReferrers(EditableDocument document,
                             SessionNode.ReferrerChanges changes)

    - #### valueToDocument

          protected Object valueToDocument(Object value,
                               Set<BinaryKey> unusedBinaryKeys)

    - #### keyForBinaryReferenceDocument

          protected final String keyForBinaryReferenceDocument(String sha1)

    - #### incrementBinaryReferenceCount

          protected void incrementBinaryReferenceCount(BinaryKey binaryKey,
                                           Set<BinaryKey> unusedBinaryKeys)

      Increment the reference count for the stored binary value with the supplied SHA-1 hash.
      Parameters:
        `binaryKey` - the key for the binary value; never null
        `unusedBinaryKeys` - the set of binary keys that are considered unused; may be null

    - #### decrementBinaryReferenceCount

          protected void decrementBinaryReferenceCount(Object fieldValue,
                                           Set<BinaryKey> unusedBinaryKeys)

      Decrement the reference count for the binary value.
      Parameters:
        `fieldValue` - the value in the document that may contain a binary value reference; may be null
        `unusedBinaryKeys` - the set of binary keys that are considered unused; may be null

    - #### valueFromDocument

          public Object valueFromDocument(Object value)

    - #### segmentsFrom

          protected List<Path.Segment> segmentsFrom(List<?> segmentValues)

    - #### resolveLargeValue

          protected Object resolveLargeValue(String sha1)

    - #### isLocked

          public boolean isLocked(EditableDocument doc)

      Checks if the given document is already locked
      Parameters:
        `doc` - the document
      Returns:
        true if the change was made successfully, or false otherwise

    - #### isFederatedDocument

          protected boolean isFederatedDocument(Document document)

    - #### removeFederatedSegments

          protected void removeFederatedSegments(EditableDocument federatedDocument,
                                     Set<String> externalNodeKeys)

    - #### isQueryable

          protected boolean isQueryable(Document document)

    - #### setQueryable

          public void setQueryable(EditableDocument document,
                          boolean queryable)

      Marks the given document as queryable, by setting a flag.
      Parameters:
        `document` - a `EditableDocument` instance; never null
        `queryable` - a boolean which indicates whether the document should be queryable or not.

    - #### addFederatedSegment

          protected void addFederatedSegment(EditableDocument document,
                                 String externalNodeKey,
                                 String name)

    - #### getCacheTtlSeconds

          protected Integer getCacheTtlSeconds(Document document)

      Returns the value of the `DocumentConstants.CACHE_TTL_SECONDS` field, if such a value exists.
      Parameters:
        `document` - a `non-null` document
      Returns:
        either the value of the above field, or `null` if such a value doesn't exist.

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.