SOURCECODE |
How to... use a DataBasket
Description:
The task of this data structure is to backup transactions between framework components. It enables undo actions called RollBack. Remember that DataBaskets can´t undo actions with components which doesn´t belong to the framework. This components have to be restored manually.
To ensure that a framework component is able to be rolled back, the protected getShallowClone()
method of the Item, will have to be overwritten if the Item has additional attributes (Note: Be careful with the clone method, mistakes could hard to be detected). Use the public get(String sKey, DataBasket db, boolean fForEdit)
method implemented in Catalog and Stock to get the Item which is to be modified.
A DataBasket could be displayed like Catalogs and Stocks with the JDataBasketTable, the DefaultCatalogItemDBETableEntryDescriptor, the DefaultCountingStockDBETableEntryDescriptor and the DefaultStoringStockDBETableEntryDescriptor.
(See also: HowTo..create a DataBasketEntryGrouper, HowTo..use a DataBasketCondition, HowTo..create a Table and HowTo..define a new TableLayout)
ToDo's:
- Make a new instance of DataBasket ( ex.:
DataBasket db = new DataBasketImpl();
)
or get the relevant DataBasket (ex.: DataBasket db = salesPoint.getBasket()
).
- Get the Object which is to be modified out of the Stock, Catalog etc.
- Ensure the Object´s
protected getShallowClone()
is making a deep clone with all attributes.
- Modifiy the Object (Change Object´s attributes).
- Decide whether to
- Commit the modification.
- Rollback the modification.
Going through the CommitGate will cause the DataBasket to commit() the modification.
Setting the RollBackGate as next Gate will cause a RollBack on the DataBasket as well. The modification on the Object will have no further consequences.
Uses:
DataBasket DataBasketImpl DataBasketEntry DataBasketEntryImpl
// mainly imports
import data.DataBasket;
import data.ooimpl.DataBasketImpl;
import data.DataBasketConflictException;
import data.NotEditableException;
import data.events.VetoException;
// Main Class
public class RentProcess extends SaleProcess
{
// Main Method
protected void setupMachine()
{
1
// the databasket of this process
final DataBasket dataBasket = getBasket();
// the catalog with the to be modified videos
final Catalog videoCatalog = Shop.getTheShop().getCatalog("Video-Catalog");
2
VideoCassette vc = null;
try
{
// the video is gotten while the DataBasket is "watching"
vc = (VideoCassette) videoCatalog.get("Video 01", dataBasket, true);
}
catch (NotEditableException nee) {
}
catch (VetoException ve) {
}
catch (DataBasketConflictException dbce) {
}
4
// the video is modified
vc.setValue(new QuoteValue(new IntegerValue(2000), new IntegerValue(1500)));
5
boolean youLikeToCommit = false;
if (youLikeToCommit)
6
// commit the modification
// Leaving the process through CommitGate would have the same effect
dataBasket.commit();
else
7
// undo the modification
// Leaving the process through RollbackGate would have the same effect
dataBasket.rollback();
}
}