Stores & Proxies

Description

Stores can be used to store or proxy data to an external destination or target. They can be linked to single resource classes or they can be shared with a number of resource classes. Resource classes are classes that are storable or are creatable over API endpoints.

Stores are very flexible and can be used with any type of TCP-based external communications, including but not limited to:

  • SOAP
  • REST
  • SQL
  • HTTP
  • LDAP
  • Practically any other TCP-based protocol limited only by available libraries

You can combine any of these to create your own hybrid store or proxy. Your stores can also be used with Appirator’s inbuilt hybrid store, which is a store that combines the internal store with any custom store.

Stores need to support the normal CRUD processes that exist in normal database operations. There’s also an additional search operation that can be supported. If it is not implemented, search will not be available on any resource classes that the store is assigned to unless the custom store is being used with an inbuilt hybrid store in which case the inbuilt search mechanism will be used.

All scripted content in a store must be in the language of the enclosing module. Note that stores cannot be extended by they can be referenced in other stores, so they can be wrapped.

Programmatic Declaration

[com.appirator.core.]reflect.Store
  extends [com.appirator.core.]reflect.ModuleNamed
  extends [com.appirator.core.]Object
  parent [com.appirator.core.]reflect.Module

Properties

name optional (when using Git sync)

The name of the store in its associated module. This is taken from the file name by default if the store is being imported as a file. It can be prefixed with the path name of the file when imported as a file where the path segments are separated with a dot. Similarly, if created object over a REST interface dot notation is permitted. This must be unique within the module.

create

The script used to create the resource at the destination. The object will have been added to the internal store before this script is invoked and it may also be updated after this script successfully runs if something has changed in the object, for example, a property representing the identifier for the object at the destination. This is invoked synchronously with the originating process.

Parameters

context

This is the context of the current process. See Call Context for more information.

object

The resource object being stored. If this store is part of an inbuilt hybrid store, some or all of this object will have been stored in the internal store prior to this script being invoked.

If the destination has created a new identifier for the resource and this store is being used in an internal hybrid store, then the new identifier should be written into the local resource object so it is saved into the internal store and can this be referenced in future operations. This identifier must be a custom property added to the resource class definition in this circumstance.

Similarly if any properties have been returned from the destination that get stored internally, or are returned to the original caller, these should also be written into the resource object, and they are allowed to override any existing properties.

api

This is a global object used to access internal Appirator functionality. See Global API Object for more information.

Returns

Any return value is ignored. If a failure occurred, an appropriate exception should be raised so that the calling process itself can initiate rollback if needed.

read

The script used to read the resource from the destination. This is invoked synchronously with the originating process.

Parameters

context

This is the context of the current process. See Call Context for more information.

object

The resource object being read. If this store is part of an inbuilt hybrid store, some or all of this object will have been read from the internal store. The destination-based identifier assigned during the create will be present on the object in this case. If this store is not part of an internal hybrid store, the object’s $id value (the request id), must be used as the identifier for the destination object.

Once the resource has been read from the destination, this object should be updated with the returned properties. As a result, the destination object properties always override th read from the internal store in the case that the store is used in an internal hybrid store.

api

This is a global object used to access internal Appirator functionality. See Global API Object for more information.

Returns

Any return value is ignored. If a failure occurred, an appropriate exception should be raised so that the calling process itself can initiate rollback if needed.

update

The script used to update the resource at the destination. This is invoked synchronously with the originating process.

Parameters

context

This is the context of the current process. See Call Context for more information.

object

The resource object being stored. If this store is part of an inbuilt hybrid store, some or all of this object will have been stored in the internal store.

If the default resource object $id is not used, there should be a identifier associated with the resource object that was applied when the object was created. This is the custom identifier that was returned from the original create at the destination. This identifier will be present on the object because the object is read from the internal store prior to this script being invoked if this store is part of an internal hybrid store. If this store is not part of an internal hybrid store, then the identifier being used at the destination should be the $id property in the resource (and the originating request).

If any properties have been returned from the destination that get stored internally, or are returned to the original caller, these should be written into the resource object as well.

api

This is a global object used to access internal Appirator functionality. See Global API Object for more information.

Returns

There is no return value. If a failure occurred, an appropriate exception should be raised so that the calling process itself can initiate rollback if needed.

delete

The script used to delete the resource from the destination. The object is removed from the internal store once this script returns without error. This is invoked synchronously with the originating process.

Parameters

context

This is the context of the current process. See Call Context for more information.

object

The resource object being deleted. If this store is part of an inbuilt hybrid store, some or all of this object will have been stored in the internal store.

If the default resource object $id is not used, there should be a identifier associated with the resource object that was applied when the object was created. This is the custom identifier that was returned from the original create at the destination. This identifier will be present on the object because the object is read from the internal store prior to this script being invoked if this store is part of an internal hybrid store. If this store is not part of an internal hybrid store, then the identifier being used at the destination should be the $id property in the resource (and the originating request).

api

This is a global object used to access internal Appirator functionality. See Global API Object for more information.

Returns

There is no return value. If a failure occurred, an appropriate exception should be raised so that the calling process itself can initiate rollback if needed.

search optional

The script used to search resources from the destination. This is invoked synchronously with the originating process. If this script is not implemented and this store is part of an internal hybrid store, the internal store will be used for search. That means that properties not written to the internal store during the create and update operations will not be searchable. If this script is implemented, this search runs instead of the internal search and any results returned are merged with their relevant counterparts in the internal store before the entire result is returned to the caller.

Parameters

context

This is the context of the current process. See Call Context for more information.

params

The list of parameters for the search, these being:

  • term (string) - the search term.
  • page (int) - the page number starting at 1.
  • pageSize (int) - the page size.
  • orderBy (string) - a CSV of property names used to define the order of the objects in the result. Each entry in the CSV has the format: <property-name>[ <direction>]. <property-name> is can be any property in the resource object accepted at the destination. <direction>, when supported at the destination, is optional and if supplied can be one of ASC (ascending) or DESC (descending).
  • fields (string) - a CSV of fields returned in the request if supported at the destination.

api

This is a global object used to access internal Appirator functionality. See Global API Object for more information.

Returns

An object containing the results of the search. This has the same format as a search against Appirator itself, specifically:

  • page (int) - the current page number starting at 1.
  • pageSize (int) - the page size of the results.
  • count (int) - the estimated total count of candidate resource objects in the search result across all pages.
  • data (array) - an array of resource objects returned from the search at the destination. These will be merged with the corresponding objects in the internal store if this store is part of an internal hybrid store. If not, these objects are returned as is back to the caller. The maximum number of entries in this array is pageSize. If there are fewer entries than pageSize that indicates that this is the last page.