Show:

MetadataStore Class

Module: breeze

An instance of the MetadataStore contains all of the metadata about a collection of EntityType's. MetadataStores may be shared across EntityManager's. If an EntityManager is created without an explicit MetadataStore, the MetadataStore from the MetadataStore.defaultInstance property will be used.

Methods

<ctor> MetadataStore

(
  • [config]
)

Constructs a new MetadataStore.

Parameters:

  • [config] Object optional

    Configuration settings .

    • [namingConvention=NamingConvention.defaultInstance] NamingConvention optional

      NamingConvention to be used in mapping property names between client and server. Uses the NamingConvention.defaultInstance if not specified.

    • [localQueryComparisonOptions=LocalQueryComparisonOptions.defaultInstance] LocalQueryComparisonOptions optional

      The LocalQueryComparisonOptions to be used when performing "local queries" in order to match the semantics of queries against a remote service.

Example:

var ms = new MetadataStore();

The store can then be associated with an EntityManager

var entityManager = new EntityManager( {
    serviceName: "breeze/NorthwindIBModel", 
    metadataStore: ms 
});

or for an existing EntityManager

// Assume em1 is an existing EntityManager
em1.setProperties( { metadataStore: ms });

addDataService

(
  • dataService
)

Adds a DataService to this MetadataStore. If a DataService with the same serviceName is already in the MetadataStore an exception will be thrown.

Parameters:

addEntityType

(
  • structuralType
)

Adds an EntityType to this MetadataStore. No additional properties may be added to the EntityType after its has been added to the MetadataStore.

Parameters:

exportMetadata

() String

Exports this MetadataStore to a serialized string appropriate for local storage. This operation is also called internally when exporting an EntityManager.

Returns:

String: A serialized version of this MetadataStore that may be stored locally and later restored.

Example:

// assume ms is a previously created MetadataStore
var metadataAsString = ms.exportMetadata();
window.localStorage.setItem("metadata", metadataAsString);
// and later, usually in a different session imported
var metadataFromStorage = window.localStorage.getItem("metadata");
var newMetadataStore = new MetadataStore();
newMetadataStore.importMetadata(metadataFromStorage);

fetchMetadata

(
  • dataService
  • [callback]
  • [errorCallback]
)
Promise async

Fetches the metadata for a specified 'service'. This method is automatically called internally by an EntityManager before its first query against a new service.

Parameters:

  • dataService DataService | String

    Either a DataService or just the name of the DataService to fetch metadata for.

  • [callback] Function optional

    Function called on success.

    successFunction([data])
    
    • [data] RawMetadata optional
  • [errorCallback] Function optional

    Function called on failure.

    failureFunction([error])
    
    • [error] Error optional

      Any error that occured wrapped into an Error object.

Returns:

Promise: Promise

Example:

Usually you will not actually process the results of a fetchMetadata call directly, but will instead ask for the metadata from the EntityManager after the fetchMetadata call returns.

var ms = new MetadataStore();
// or more commonly
// var ms = anEntityManager.metadataStore;
ms.fetchMetadata("breeze/NorthwindIBModel")
.then(function(rawMetadata) {
    // do something with the metadata
}
.fail(function(exception) {
    // handle exception here
};

getDataService

(
  • serviceName
)
Boolean

Returns the DataService for a specified service name

Parameters:

  • serviceName String

    The service name.

Returns:

Boolean:

Example:

// Assume em1 is an existing EntityManager.
var ds = em1.metadataStore.getDataService("breeze/NorthwindIBModel");
var adapterName = ds.adapterName; // may be null

getEntityType

(
  • structuralTypeName
  • [okIfNotFound=false]
)
EntityType | ComplexType

Returns an EntityType or a ComplexType given its name.

Parameters:

  • structuralTypeName String

    Either the fully qualified name or a short name may be used. If a short name is specified and multiple types share that same short name an exception will be thrown.

  • [okIfNotFound=false] Boolean optional

    Whether to throw an error if the specified EntityType is not found.

Returns:

EntityType | ComplexType: The EntityType. ComplexType or 'undefined' if not not found.

Example:

// assume em1 is a preexisting EntityManager
var odType = em1.metadataStore.getEntityType("OrderDetail");

or to throw an error if the type is not found

var badType = em1.metadataStore.getEntityType("Foo", false);
// badType will not get set and an exception will be thrown.

getEntityTypeNameForResourceName

(
  • resourceName
)

Returns a fully qualified entityTypeName for a specified resource name. The reverse of this operation can be obtained via the EntityType 'defaultResourceName' property

Parameters:

  • resourceName String

getEntityTypes

() Array of EntityType | ComplexType

Returns an array containing all of the EntityTypes or ComplexTypes in this MetadataStore.

Returns:

Array of EntityType | ComplexType:

Example:

// assume em1 is a preexisting EntityManager
var allTypes = em1.metadataStore.getEntityTypes();

hasMetadataFor

(
  • serviceName
)
Boolean

Returns whether Metadata has been retrieved for a specified service name.

Parameters:

  • serviceName String

    The service name.

Returns:

Boolean:

Example:

// Assume em1 is an existing EntityManager.
if (!em1.metadataStore.hasMetadataFor("breeze/NorthwindIBModel"))) {
    // do something interesting
}

importMetadata

(
  • exportedString
)
MetadataStore static

Creates a new MetadataStore from a previously exported serialized MetadataStore

Parameters:

  • exportedString String

    A previously exported MetadataStore.

Returns:

MetadataStore: A new MetadataStore.

Example:

// assume ms is a previously created MetadataStore
var metadataAsString = ms.exportMetadata();
window.localStorage.setItem("metadata", metadataAsString);
// and later, usually in a different session
var metadataFromStorage = window.localStorage.getItem("metadata");
var newMetadataStore = MetadataStore.importMetadata(metadataFromStorage);

importMetadata

(
  • exportedMetadata
)
MetadataStore chainable

Imports a previously exported serialized MetadataStore into this MetadataStore.

Parameters:

  • exportedMetadata String | JSON Object

    A previously exported MetadataStore.

Returns:

MetadataStore: This MetadataStore.

Example:

// assume ms is a previously created MetadataStore
var metadataAsString = ms.exportMetadata();
window.localStorage.setItem("metadata", metadataAsString);
// and later, usually in a different session
var metadataFromStorage = window.localStorage.getItem("metadata");
var newMetadataStore = new MetadataStore();
newMetadataStore.importMetadata(metadataFromStorage);

isEmpty

() Boolean

Returns whether this MetadataStore contains any metadata yet.

Returns:

Boolean:

Example:

// assume em1 is a preexisting EntityManager;
if (em1.metadataStore.isEmpty()) {
    // do something interesting
}

registerEntityTypeCtor

(
  • structuralTypeName
  • aCtor
  • [initializationFn]
)

Provides a mechanism to register a 'custom' constructor to be used when creating new instances of the specified entity type. If this call is not made, a default constructor is created for the entity as needed. This call may be made before or after the corresponding EntityType has been discovered via Metadata discovery.

Parameters:

  • structuralTypeName String

    The name of the EntityType o0r ComplexType.

  • aCtor Function

    The constructor for this EntityType or ComplexType; may be null if all you want to do is set the next parameter.

  • [initializationFn] Function optional

    A function or the name of a function on the entity that is to be executed immediately after the entity has been created and populated with any initial values.

    initializationFn(entity)

    • entity Entity

      The entity being created or materialized.

Example:

var Customer = function () {
    this.miscData = "asdf";
};
Customer.prototype.doFoo() {
    ...
}
// assume em1 is a preexisting EntityManager;
em1.metadataStore.registerEntityTypeCtor("Customer", Customer);
// any queries or EntityType.create calls from this point on will call the Customer constructor
// registered above.

setEntityTypeForResourceName

(
  • resourceName
  • entityTypeOrName
)

Associates a resourceName with an entityType.

This method is only needed in those cases where multiple resources return the same entityType. In this case Metadata discovery will only determine a single resource name for each entityType.

Parameters:

  • resourceName String
  • entityTypeOrName EntityType | String

    If passing a string either the fully qualified name or a short name may be used. If a short name is specified and multiple types share that same short name an exception will be thrown. If the entityType has not yet been discovered then a fully qualified name must be used.

trackUnmappedType

(
  • entityCtor
  • [interceptor]
)

Used to register a constructor for an EntityType that is not known via standard Metadata discovery; i.e. an unmapped type.

Parameters:

  • entityCtor Function

    The constructor for the 'unmapped' type.

  • [interceptor] Function optional

    A function

Properties

namingConvention

NamingConvention

The NamingConvention associated with this MetadataStore.

readOnly