com.holonplatform.datastore.mongo.core.document

## Interface DocumentIdResolver

-     public interface DocumentIdResolver

  Resolver to detect a suitable `Path` type `Property` within a `PropertySet` which can act as document identifier property.
  Since:
    5.2.0

- - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T> T` | `decode(org.bson.types.ObjectId id, Class<? extends T> type)` Decode given `ObjectId` using given type.
    `org.bson.types.ObjectId` | `encode(Object documentId)` Encode given document id as an `ObjectId`.
    `static DocumentIdResolver` | `getDefault()` Get the default `DocumentIdResolver` implementation.
    `boolean` | `isValidDocumentIdType(com.holonplatform.core.property.Property<?> property)` Checks if the type of given property is a valid document id type.
    `Optional<com.holonplatform.core.Path<?>>` | `resolveDocumentIdPath(com.holonplatform.core.property.PropertySet<?> propertySet)` Try to resolve the `Path` within given `PropertySet` which can act as document identifier path property.
    `Optional<com.holonplatform.core.property.Property<?>>` | `resolveDocumentIdProperty(com.holonplatform.core.property.PropertySet<?> propertySet)` Try to resolve the `Property` within given `PropertySet` which can act as document identifier property.

- - ### Method Detail

    - #### resolveDocumentIdProperty

          Optional<com.holonplatform.core.property.Property<?>> resolveDocumentIdProperty(com.holonplatform.core.property.PropertySet<?> propertySet)
                                                                                   throws InvalidDocumentIdentifierException

      Try to resolve the `Property` within given `PropertySet` which can act as document identifier property.
      Parameters:
        `propertySet` - The property set (not null)
      Returns:
        The document identifier property, if available
      Throws:
        `InvalidDocumentIdentifierException` - If an error occurred during document identifier property resolution

    - #### resolveDocumentIdPath

          Optional<com.holonplatform.core.Path<?>> resolveDocumentIdPath(com.holonplatform.core.property.PropertySet<?> propertySet)
                                                                  throws InvalidDocumentIdentifierException

      Try to resolve the `Path` within given `PropertySet` which can act as document identifier path property.
      Parameters:
        `propertySet` - The property set (not null)
      Returns:
        The document identifier path, if available
      Throws:
        `InvalidDocumentIdentifierException` - If an error occurred during document identifier property resolution

    - #### encode

          org.bson.types.ObjectId encode(Object documentId)
                                  throws InvalidDocumentIdentifierException

      Encode given document id as an `ObjectId`.
      Parameters:
        `documentId` - The document id to encode
      Returns:
        The encoded `ObjectId`, `null` if given document id was `null`
      Throws:
        `InvalidDocumentIdentifierException` - If the given document id is not encodable

    - #### decode

          <T> T decode(org.bson.types.ObjectId id,
                       Class<? extends T> type)
                throws InvalidDocumentIdentifierException

      Decode given `ObjectId` using given type.
      Type Parameters:
        `T` - Expected value type
      Parameters:
        `id` - The id to decode
        `type` - The decoding type (not null)
      Returns:
        The decoded document id, `null` if given id was `null`
      Throws:
        `InvalidDocumentIdentifierException` - If the given type is not decodable

    - #### isValidDocumentIdType

          boolean isValidDocumentIdType(com.holonplatform.core.property.Property<?> property)

      Checks if the type of given property is a valid document id type.
      Parameters:
        `property` - Property to check
      Returns:
        `true` if the type of given property is a valid document id typ, `false` otherwise

    - #### getDefault

          static DocumentIdResolver getDefault()

      Get the default `DocumentIdResolver` implementation.

      The admitted identifier property types are: `String`, `BigInteger` and `ObjectId`.

      The default `DocumentIdResolver` implementation looks for a `Path` type `Property` with the `_id` path name, first of all in the identifier property set, if available (see `PropertySet.getIdentifiers()`), or in the overall property set.

      If more than one property with the `_id` path name is found, or if the identifier property type is not admitted, an `InvalidDocumentIdentifierException` is thrown.

      Returns:
        The default `DocumentIdResolver` implementation

Copyright © 2019 The Holon Platform. All rights reserved.