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.
Item Index
Methods
Properties
Methods
<ctor> MetadataStore
-
[config]
Constructs a new MetadataStore.
Parameters:
-
[config]Object optionalConfiguration settings .
-
[namingConvention=NamingConvention.defaultInstance]NamingConvention optionalNamingConvention to be used in mapping property names between client and server. Uses the NamingConvention.defaultInstance if not specified.
-
[localQueryComparisonOptions=LocalQueryComparisonOptions.defaultInstance]LocalQueryComparisonOptions optionalThe 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:
-
dataServiceDataServiceThe DataService to add
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:
-
structuralTypeEntityType | ComplexTypeThe EntityType or ComplexType to add
exportMetadata
()
String
Exports this MetadataStore to a serialized string appropriate for local storage. This operation is also called internally when exporting an EntityManager.
Returns:
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]
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:
-
dataServiceDataService | StringEither a DataService or just the name of the DataService to fetch metadata for.
-
[callback]Function optionalFunction called on success.
successFunction([data])-
[data]RawMetadata optional
-
-
[errorCallback]Function optionalFunction called on failure.
failureFunction([error])-
[error]Error optionalAny error that occured wrapped into an Error object.
-
Returns:
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
Returns the DataService for a specified service name
Parameters:
-
serviceNameStringThe 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]
Returns an EntityType or a ComplexType given its name.
Parameters:
-
structuralTypeNameStringEither 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 optionalWhether to throw an error if the specified EntityType is not found.
Returns:
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:
-
resourceNameString
getEntityTypes
()
Array of EntityType | ComplexType
Returns an array containing all of the EntityTypes or ComplexTypes in this MetadataStore.
Returns:
Example:
// assume em1 is a preexisting EntityManager
var allTypes = em1.metadataStore.getEntityTypes();
hasMetadataFor
-
serviceName
Returns whether Metadata has been retrieved for a specified service name.
Parameters:
-
serviceNameStringThe service name.
Returns:
Example:
// Assume em1 is an existing EntityManager.
if (!em1.metadataStore.hasMetadataFor("breeze/NorthwindIBModel"))) {
// do something interesting
}
importMetadata
-
exportedString
Creates a new MetadataStore from a previously exported serialized MetadataStore
Parameters:
-
exportedStringStringA previously exported MetadataStore.
Returns:
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
Imports a previously exported serialized MetadataStore into this MetadataStore.
Parameters:
-
exportedMetadataString | JSON ObjectA previously exported MetadataStore.
Returns:
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:
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:
-
structuralTypeNameStringThe name of the EntityType o0r ComplexType.
-
aCtorFunctionThe constructor for this EntityType or ComplexType; may be null if all you want to do is set the next parameter.
-
[initializationFn]Function optionalA 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)
-
entityEntityThe 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:
-
resourceNameString -
entityTypeOrNameEntityType | StringIf 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:
-
entityCtorFunctionThe constructor for the 'unmapped' type.
-
[interceptor]Function optionalA function
