Show:

MetadataStore Class

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.

    • [serializerFn] optional

      A function that is used to mediate the serialization of instances of this type.

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
  • [shouldOverwrite=false]
)

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

Parameters:

  • dataService DataService

    The DataService to add

  • [shouldOverwrite=false] Boolean optional

    Permit overwrite of existing DataService rather than throw exception

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
)
DataService

Returns the DataService for a specified service name

Parameters:

  • serviceName String

    The service name.

Returns:

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
  • [allowMerge]
)
MetadataStore chainable

Imports a previously exported serialized MetadataStore into this MetadataStore.

Parameters:

  • exportedMetadata String | JSON Object

    A previously exported MetadataStore.

  • [allowMerge] Boolean optional

    Allows custom metadata to be merged into existing metadata types.

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
  • [initFn]
  • [noTrackingFn}
  • noTrackingFn.entity
  • noTrackingFn.entityType
)

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.

  • [initFn] 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. initFn(entity)

    • entity Entity

      The entity being created or materialized.

  • [noTrackingFn} Function

    A function that is executed immediately after a noTracking entity has been created and whose return value will be used in place of the noTracking entity.

  • noTrackingFn.entity Object
  • noTrackingFn.entityType EntityType

    The entityType that the 'entity' parameter would be if we were tracking

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.

setProperties

(
  • config
)

General purpose property set method

Parameters:

  • config Object

    [object]

    • [name] String optional

      A name for the collection of metadata in this store.

    • [serializerFn] optional

      A function that is used to mediate the serialization of instances of this type.

Example:

// assume em1 is an EntityManager containing a number of existing entities.

em1.metadataStore.setProperties( {
    version: "6.1.3",
    serializerFn: function(prop, value) {
    return (prop.isUnmapped) ? undefined : value;
    }
)};

setQ

(
  • q
)

(Re)set Q with a promises implementation suitable for Breeze internal use. Note: This API is likely to change.

Parameters:

  • q Object
    • a "thenable" promises implementation like Q.js with the API that Breeze requires internally.
    • [defer] Function optional

      A function returning a deferred.

    • [resolve] Function optional

      A function returning a resolved promise.

    • [reject] Function optional

      A function returning a rejected promise.

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

Events

metadataFetched

An Event that fires after a MetadataStore has completed fetching metadata from a remote service.

var ms = myEntityManager.metadataStore;
ms.metadataFetched.subscribe(function(args) {
    var metadataStore = args.metadataStore;
    var dataService = args.dataService;
});

});

Event Payload:

  • metadataStore MetadataStore

    The MetadataStore into which the metadata was fetched.

  • dataService DataService

    The DataService that metadata was fetched from.

  • rawMetadata Object

    The raw metadata returned from the service. (It will have already been processed by this point).