Part 1 - Part 2 - Part 3 - Part 4 - Part 5
Part five will introduce some more advanced topics when creating prevalent applications and provide some pointers as to Preclipse's other functionalities.
Managing deeper business object hierarchies
We have shown you how to create a simple Prevayler-based application, which only contained a one-level hierarchy of BOs: The prevalent system itself (DVDStorage) and some objects inside it (DVDs). However, more complex applications will probably have deeper hierarchies.
When working with Preclipse, you will always create new business objects inside existing ones; in many cases this will add one level to the hierarchy. Preclipse fully supports multi-level hierarchies, as it will always create the methods for adding, changing and removing the BOs inside their parent BO. For example, when creating a list of Actor objects inside the DVD, methods for adding, changing and removing Actors will be created inside DVD:
DVDStorage | ||
--> DVD | ||
--> Actor |
The change and delete transactions created by Preclipse, however, will only contain the ID field of the current object. That is, if you create a 'change' transaction for an Actor, the ActorCreateTransaction will only contain the ID of the Actor (and the fields to be changed). This is important because the executeAndQuery and executeOn methods of Prevayler's transaction Interface always contain the prevalent root system:
public Object executeAndQuery(Object prevalentSystem, Date executionTime) throws Exception { DVD changeDVD = ((DVDStorage)prevalentSystem).getDVD(id); |
So far, this was not a problem as the DVD were directly contained within DVDStorage. However, when changing Actors, for example, you need to retrieve the DVD first in order to reach the Actor object:
public Object executeAndQuery(Object prevalentSystem, Date executionTime) throws Exception { DVD changeDVD = ((DVDStorage)prevalentSystem).getDVD(dvd_id); Actor changeActor = changeDVD.getActor(actor_id); // Change some stuff |
You'll need to provide these additional IDs yourself, as Preclipse does not add them to the constructors of the transactions.
Single (Business) Objects
Preclipse provides functionality for adding single business objects instead of complete lists. Note that you don't need IDs in this case, as there is only one object present; simply ignore the ID field when creating transactions for such BOs.
Other functionality
Besides Code Generation, Preclipse also provides insight into transactionLog and snapshot files. When running DVDStorage, those files will be created in the /data/ folder of the Eclipse project. Hit "Refresh" in the context menu of /data/ to make them visible inside the Eclipse IDE. A double click on those files will open up the Preclipse file viewer. For example, the following screen shot shows the snapshot file of a DVDStorage instance with a few DVDs:
Preclipse also comes with a code analyser, which will spot common mistakes when implementing prevalent applications. The analyser is implemented as a builder, which can be activated in the project properties:
You need to provide the package containing your BOs in order for the analyser to work properly.
Additionally, Preclipse provides some tools which come in quite handy when developing prevalent applications. Those can be reached via the project's context menu:
We hope you enjoyed this little tour of Preclipse and wish you all the best when implementing Prevayler-based applications.
The Preclipse team