Using store objects

About this task

As a subclass of the Service class, the JDBCStore class has an externalizer that allows it to define any store object attributes in an external definition file (these attribute values are set automatically when the store object is instantiated). The JDBCStore class inherits all Service attributes; for instance, the name attribute, which will allow the application to request a specific Store service instance in a hierarchy of toolkit contexts.

A store object will usually be instantiated by providing the name of the service to be created to the ServiceExternalizer class. The ServiceExternalizer class then creates an instance of the class (in this case, a store), and sets its attributes to the values read from the services definition file. Alternatively, a store object may be instantiated by requesting this service from the operation context, which will internally run the usual instantiation process if the service has not yet been instantiated in the hierarchy.

After a store service has been instantiated, a name, a tableName, a schema (the database schema where the table is created, if it applies to the DBMS being used) and database connection properties are assigned to the store. After the application has requested the database connection, it sends the store service an open() message to activate the current store object. From this point on, the store service is active and ready to be worked with.

When the application has finished making changes to the STORE table, it can send the close() message to the store service. The name of the table assigned to a store service, the name of the store service, and the database connection properties cannot be changed while the store is active; a close() message needs to be sent before changing these attributes. This may be required when the same store instance should be used to work with different database tables. An application can send the isActive() message at any time to find out the current state of a store object.

While a store object is active, a client can add, retrieve, retrieve for forwarding, update, and delete records. It can commit and roll back either explicitly or by setting the autoCommit attribute to true, in which case every add, update, or delete is followed automatically by a commit.