Class: Metadata

util.Metadata(entity, type)

The Metadata instance tracks the state of an object and checks if the object state was changed since last
load/update. The metadata keeps therefore the state of:

  • in which state the object currently is
  • which db managed the instance
  • the metadata of the object (id, version, bucket)
  • which is the owning object (root object) of an embedded object

util.Metadata#get(object) can be used on any managed object to retrieve the metadata of the root object

Constructor

new Metadata(entity, type)

Parameters:
Name Type Description
entity binding.Entity
type metamodel.ManagedType
Source:

Extends

Members

(static) Type :number

Type:
  • number
Properties:
Name Type Description
UNAVAILABLE number
PERSISTENT number
DIRTY number
Source:

acl :Acl

Type:
Source:

(readonly) bucket :string

Type:
  • string
Source:

db :EntityManager

Type:
Source:

db

Source:

id :string

Type:
  • string
Source:

(readonly) isAttached :boolean

Indicates if this object already belongs to an db
true if this object belongs already to an db otherwise false

Type:
  • boolean
Source:

(readonly) isAvailable :boolean

Indicates if this object is represents a db object, but was not loaded up to now

Type:
  • boolean
Source:

(readonly) isDirty :boolean

Indicates that this object was modified and the object was not written back to the db

Type:
  • boolean
Source:

(readonly) isPersistent :boolean

Indicates if this object represents the state of the db and was not modified in any manner

Type:
  • boolean
Source:

isReady :boolean

Indicates if there is currently no exclusive operation executed
true If no exclusive lock is hold

Type:
  • boolean
Inherited From:
Source:

key

Source:

(readonly) key :string

Type:
  • string
Source:

type :metamodel.ManagedType

Type:
Source:

version :number

Type:
  • number
Source:

Methods

(static) create(type, object) → {*}

Creates a metadata instance for the given type and object instance

Parameters:
Name Type Description
type metamodel.ManagedType

The type of the object

object *

The object instance of the type

Source:
Returns:

The created metadata for the object

Type
*

(static) get(managed) → {util.Metadata}

Returns the metadata of the managed object

Parameters:
Name Type Description
managed binding.Managed
Source:
Returns:
Type
util.Metadata

enable(newStateTrackingState) → {void}

Enable/Disable state change tracking of this object

Parameters:
Name Type Description
newStateTrackingState boolean

The new change tracking state

Source:
Returns:
Type
void

getJson(optionsopt) → {json}

Converts the object to an JSON-Object

Parameters:
Name Type Attributes Default Description
options Object | boolean <optional>
false

to json options by default excludes the metadata

Properties
Name Type Attributes Default Description
excludeMetadata boolean <optional>
false

Excludes the metadata form the serialized json

depth number <optional>
0

Includes up to depth referenced objects into the serialized json

persisting boolean <optional>
false

indicates if the current state will be persisted.
Used to update the internal change tracking state of collections and mark the object persistent if its true

Deprecated:
  • Yes
Source:
Returns:

JSON-Object

Type
json

readAccess() → {void}

Signals that the object will be accessed by a read

Ensures that the object was loaded already.

Source:
Returns:
Type
void

ready(doneCallbackopt, failCallbackopt) → {Promise.<this>}

Waits on the previously requested operation and calls the doneCallback if the operation is fulfilled

Parameters:
Name Type Attributes Description
doneCallback util.Lockable~doneCallback <optional>

The callback which will be invoked when the previously
operations on this object is completed.

failCallback util.Lockable~failCallback <optional>

When the lock can't be released caused by a none
recoverable error

Inherited From:
Source:
Returns:

A promise which completes successfully, when the previously requested
operation completes

Type
Promise.<this>

setDirty() → {void}

Indicates the the object is modified by the user

Source:
Returns:
Type
void

setJson(json, optionsopt) → {void}

Sets the object content from json

Parameters:
Name Type Attributes Default Description
json json

The updated json content

options Object <optional>

The options used to apply the json

Properties
Name Type Attributes Default Description
persisting boolean <optional>
false

indicates if the current state will be persisted.
Used to update the internal change tracking state of collections and mark the object persistent or dirty afterwards

onlyMetadata boolean false}

Indicates if only the metadata should be updated

{options.updateMetadataOnly boolean false}

Indicates if only the metadata should be updated

Deprecated:
  • Yes
Source:
Returns:
Type
void

setPersistent() → {void}

Indicates that the associated object is not stale

An object is stale if it correlates the database state and is not modified by the user.

Source:
Returns:
Type
void

setRemoved() → {void}

Indicates the the object is removed

Source:
Returns:
Type
void

setUnavailable() → {void}

Indicates that the associated object isn't available

Source:
Returns:
Type
void

(protected) withLock(callback, criticalopt) → {Promise.<T>}

Try to aquire an exclusive lock and executes the given callback.

Parameters:
Name Type Attributes Default Description
callback util.Lockable~callback

The exclusive operation to execute

critical boolean <optional>
false

Indicates if the operation is critical. If the operation is critical and the
operation fails, then the lock will not be released

Inherited From:
  • util.Lockable#withLock<T>
Source:
Throws:

If the lock can't be aquired

Type
Error
Returns:

A promise

Type
Promise.<T>

writeAccess() → {void}

Signals that the object will be accessed by a write

Ensures that the object was loaded already and marks the object as dirty.

Source:
Returns:
Type
void