ObjectExtender User's Guide and Reference

Creating, retrieving, deleting instances

Creating business objects. There are a number of ways to create persistence instances. The first is to create a persistent instance with the create protocol on the home collection.

Before this can be done, a data store and non-read-only transaction must have been activated. There is one data store for each map that has had services generated from it and the map provides the layer between the model domain objects and the persistent back end.

Having created an object with the create protocol, it can be modified and/or deleted in the transaction in which it was created or within a transaction that is nested from the transaction in which it was created. If any attempt is made to access the object in a transaction other than these, a VapVersionNotFound exception will be raised.

Before persisting the object (which will happen when the TopLevelTransaction is committed) the key must have been supplied to the object. The key is the set of attribute and association roles that were specified as the object identifier (OID) in the Model Browser. For example, if the object has a key of name, the following protocol would be sufficient:

Another way of creating an object with a specific key is with the createFromKey method on the home collection:

The code generation services will create a helper method that has a specific create method that has one parameter for each OID element.

Retrieving business objects. Instances of business objects can be retrieved by creating an instance of the appropriate key class and asking a home collection to find the corresponding instance.

      DepartmentHome singleton findByPrimaryKey: (DepartmentKey with: 'CIS')
 
 

Asking for all instances. All instances of a persistent class can be retrieved by sending a message to the home collection for the business object. This will always execute a query against the database to retrieve a Vector of business object instances. This method returns all instances that exist in the database, not the instances that exist only in the image.

Deleting business objects. Send the remove() message to primary objects to delete them, and secondaryRemove() for deleting cascaded objects.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]