Class: PersistenceRegistration

QuickNav

PersistenceRegistration

PersistenceRegistration constructor. This constructor is created when PersistenceManager.register API is envoked. This API is used to add eventlisteners to the registered scope or remove an existing registration object from the PersistenceManager.

Constructor

new PersistenceRegistration(scope, PersistenceManager)

Parameters:
Name Type Description
scope string The URI which should be persisted
PersistenceManager Object

Methods

addEventListener(type, listener)

Add an event listener for how an event will be handled. Currently, the only supported event is the "fetch" event.
Parameters:
Name Type Description
type string A string representing the event type to listen for. Supported value is "fetch" which will trigger the function with a FetchEvent once a fetch occurs.
listener function The object that receives a notification when an event of the specified type occurs
Examples
// Using Default Response Proxy
var ResponseProxy = defaultResponseProxy.getResponseProxy(
   {
      fetchStrategy: fetchStrategies.getCacheFirstStrategy()
});
PersistenceManager.register({scope:'/employee'}).then(function(registration){
   PersistenceRegistration.addEventListener('fetch',ResponseProxy.getFetchEventListener());
});
// Using a custom event listener

//using defaultResponseProxy.getResponseProxy to set up a shreading method
var defaultItemResponseProxy = defaultResponseProxy.getResponseProxy(
  {
    jsonProcessor:
      {
        shredder: simpleJsonShredding.getShredder('item', 'ID'),
        unshredder: simpleJsonShredding.getUnshredder()
      },
    queryHandler: queryHandlers.getSimpleQueryHandler('item', 'limit')
  });
persistenceManager.register({
  scope: '/item'
}).then(function (registration) {
  registration.addEventListener('fetch', function (event) {
    // Using the event's respondWith method, return a new promise
    // that will resolve into the response from the persistence framework
    event.respondWith(new Promise(function (resolve, reject) {
      defaultItemResponseProxy.processRequest(event.request).then(function (response) {
        if (response != null) {
          // Check to see if the response from the cache is stale
          if ((new Date(response.headers.get('x-oracle-jscpt-cache-expiration-date'))).getTime() < (new Date()).getTime()) {
            // handle response
          } else {
            // handle stale response
          }
        }
        resolve(response);
      });
    }));
  })});

unregister() → {Promise.<Boolean>}

Unregisters the registration. Will finish any ongoing operations before it is unregistered.
Returns:
Promise resolves with a boolean indicating whether the scope has been unregistered or not
  • true if successfully unregistered
  • false if unsuccessful
Type
Promise.<Boolean>
Example
PersistenceManager.getRegistration('https://www.oracle.com/location').then(function(registration){
    registration.unregister().then(function(registrationStatus){
     // registrationStatus is boolean based on if it was succuessful or not
   })
})