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
- <ctor> MetadataStore
- addDataService
- addEntityType
- exportMetadata
- fetchMetadata
- getDataService
- getEntityType
- getEntityTypeNameForResourceName
- getEntityTypes
- hasMetadataFor
- importMetadata static
- importMetadata
- isEmpty
- registerEntityTypeCtor
- setEntityTypeForResourceName
- setProperties
- setQ
- trackUnmappedType
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.
-
[serializerFn]
optionalA 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
DataServiceThe DataService to add
-
[shouldOverwrite=false]
Boolean optionalPermit 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:
-
structuralType
EntityType | 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:
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]
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 | 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:
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
Returns the DataService for a specified service name
Parameters:
-
serviceName
StringThe 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:
-
structuralTypeName
StringEither 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:
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:
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:
-
serviceName
StringThe 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:
-
exportedString
StringA previously exported MetadataStore.
Returns:
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]
Imports a previously exported serialized MetadataStore into this MetadataStore.
Parameters:
-
exportedMetadata
String | JSON ObjectA previously exported MetadataStore.
-
[allowMerge]
Boolean optionalAllows custom metadata to be merged into existing metadata types.
Returns:
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:
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
StringThe name of the EntityType o0r ComplexType.
-
aCtor
FunctionThe constructor for this EntityType or ComplexType; may be null if all you want to do is set the next parameter.
-
[initFn]
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. initFn(entity)
-
entity
EntityThe entity being created or materialized.
-
-
[noTrackingFn}
FunctionA 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
EntityTypeThe 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 | 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.
setProperties
-
config
General purpose property set method
Parameters:
-
config
Object[object]
-
[name]
String optionalA name for the collection of metadata in this store.
-
[serializerFn]
optionalA 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
Parameters:
-
q
Object- a "thenable" promises implementation like Q.js with the API that Breeze requires internally.
-
[defer]
Function optionalA function returning a deferred.
-
[resolve]
Function optionalA function returning a resolved promise.
-
[reject]
Function optionalA 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
FunctionThe constructor for the 'unmapped' type.
-
[interceptor]
Function optionalA function