Module store

Store instances represent the underlying database, providing functionality for defining entities, manipulating and querying data.

Class Store

Instance Methods

Static Methods


Store (connectionPool)

Creates a new Store instance

Parameters

ConnectionPool connectionPool The connection pool to use

Returns

A new Store instance

See


Store.initConnectionPool (props)

Inititalizes the connection pool and returns it

Parameters

Object props The pool/connection properties to use

Returns

Object The initialized connection pool

See


Store.prototype.abortTransaction ()

Aborts (i.e. rolls back) the transaction bound to the current thread and closes it.


Store.prototype.all (type)

Retrieves all instances of the given type from the database

Parameters

String type The type

Returns

Array An array containing all instances of the given type

Store.prototype.beginTransaction ()

Starts a new transaction. Note that the transaction is bound to the thread, so any SQL query issued during an open transaction is using the same database connection.

Returns

Transaction The newly opened transaction

Store.prototype.close ()

Closes all open connections to the database and clears all caches.


Store.prototype.commitTransaction ()

Commits the transaction bound to the current thread and closes it.


Store.prototype.defineEntity (type, mapping)

Defines an entity within this store. This method returns a constructor function for creating new instances of this entity. All entity constructors created by this method are registered within this store and can be retrieved later on using getEntityConstructor(type).

Parameters

String type The name of the entity constructor
Object mapping The database mapping object, defining the ID column and all (optionally mapped) properties of entity instances.

Returns

Function The entity constructor function

See


Store.prototype.getConnection ()

Returns a database connection object.

Returns

java.sql.Connection A database connection object

Store.prototype.getEntityConstructor (type)

Returns the registered entity constructor for the given type.

Parameters

String type The name of the registered entity

Returns

Function The entity constructor function

Store.prototype.getTransaction ()

Returns the current transaction, or null if none has been opened.

Returns

Transaction The current transaction

Store.prototype.hasTransaction ()

Returns true if there is a transaction bound to the current thread.

Returns

Boolean True if a transaction is bound to the current thread

Store.prototype.query (queryStr, nparams)

Returns the result of the given query

Parameters

String queryStr The query string
Object nparams Optional object containing the named parameters referenced in the query

Returns

Array The result of the query

Store.prototype.setEntityCache (cache)

Sets the cache passed as argument as entity data cache of this store

Parameters

Cache cache The entity cache to use

Store.prototype.setQueryCache (cache)

Sets the cache passed as argument as query cache of this store

Parameters

Cache cache The query cache to use

Store.prototype.sqlQuery (queryStr, params)

Returns the result of the given raw SQL query

Parameters

String queryStr The SQL query string
Array params Optional array containing parameter values referenced in the query

Returns

Array An array of objects containing the query results