HowTo's - Data Management: DataBasket

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 be hard to detect). 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.

Used classes:

Related topics:

ToDo:

  1. Make a new instance of DataBasket or use the relevant of your class. In this case the use is implemented in a SaleProcess so the DataBasket of the process is used by getBasket().
  2. Get the object to be modified. In this case we first get the catalog and then the desired item.
    (the structure of Incorporate a Catalog and Define a simple CatalogItem is used)
  3. Modifiy the item.
  4. If you want to keep the changes, commit the DataBasket by calling basket.commit(). This will force the basket to go through the Commit-Gate and commit the modifications. If you do not want to keep the changes, rollback the DataBasket by calling basket.rollback(). This will force the basket to go through the RollBack-Gate and rollback the modifications.

Example Source Code:

 
    1
        final DataBasket basket = this.getBasket();
			
    2
        // get the catalog from the shop's global list of catalogs
        final Catalog catalog = Shop.getTheShop().getCatalog("SimpleCatalog");
			
        // define the CatalogItemImpl and set to null
        DataBasicCatalogItem item = null;
			
        // get the item with the DataBasket "watching" the action
        try
        {
            item = (DataBasicCatalogItem) catalog.get("item1", basket, true);
        }
			
        // catch the relevant exceptions
        catch(VetoException ve)
        {
            // exception handling here
        }
        catch(NotEditableException nee)
        {
            // exception handling here
        }
        catch(DataBasketConflictException dbce)
        {
            // exception handling here
        }
			
    3
        item.setValue(new IntegerValue(99));
			
    4
	// decide whether to commit or to rollback (doCommit is ot type boolean)
        if(doCommit)
        {
            // commit the changes
            basket.commit();
        }
        else
        {
            // rollback the changes
            basket.rollback();
        }
			 
		

Back to:


Use a DataBasketCondition

Description:
DataBasketConditions are important to display the contents of a DataBasket in a FormSheet (e.g. JDataBasketTable). They could also be used to summ the content's values using public Value sumBasket(DataBasketCondition dbc, BasketEntryValue bev, Value vInit).
The already implemented DataBasketConditionImpl provides all what is needed.

Used classes:

Related topics:

ToDo:

  1. There are three ways to use a DataBasketCondition:
    1. Use the constructor to create an instance of DataBasketConditionImpl.
    2. Use the provided static fields:
      • ALL_CATALOG_ITEMS
      • ALL_STOCK_ITEMS
      • ALL_ENTRIES
    3. Use provided static methods to get the needed instance:
      • allCatalogItemsWithDest(Catalog cDest)
      • allCatalogItemsWithSource(Catalog cSource)
      • allStockItemsWithDest(Stock stDest)
      • allStockItemsWithSource(Stock stSource)
      • specificCatalogItem(CatalogItem ci)
      • specificStockItem(StockItem si)

Example Source Code:

        DataBasketCondition dbc;
        1 a
        dbc = new DataBasketConditionImpl(
                // filters entries of a certain kind
                // (DataBasketKeys.CATALOG_ITEM_MAIN_KEY, DataBasketKeys.STOCK_ITEM_MAIN_KEY)
                (String) mainKey,
			
                // filters Entrys with given name ((StockItem) si).getName()
                (String) secondaryKey,
			
                // filters Entrys from given source (Catalog or Stock)
                (DataBasketEntrySource) dbesSource,
			
                // filters Entrys from given destination (Catalog or Stock)
                (DataBasketEntryDestination) dbedDestination,
			
                // filters only given object (if it is null, all DataBasketEntrys will be checked)
                (Object) value);
			
        1 b
        dbc = DataBasketConditionImpl.ALL_CATALOG_ITEMS;
	1 c
        dbc = DataBasketConditionImpl.allCatalogItemsWithSource(catalog); 
		

Back to:


Create a DataBasketEntryGrouper

Description:
DataBasketEntryGroupers are important to display the contents of a DataBasket in a FormSheet. Every movement creates a new DataBasketEntry. So it could happen, that one CatalogItem for example has created many CatalogItemDataBasketEntrys in the DataBasket.
If you want to display a DataBasket with DBEntrys of StockItems in a CountingStock, the already implemented CountingStockDBEGrouper will be sufficent.
If you don´t want grouping at all, use the NOPDataBasketEntryGrouper.
If you want to implement your own grouping, follow the instructions.

Used classes:

Related topics:

ToDo:

  1. Implement the interface DataBasketEntryGrouper in a class.
  2. Implement the method public boolean canGroup(DataBasketEntry dbe0, DataBasketEntry dbe1).
    Here you have to decide which DataBasketEntrys should be grouped and which not.
  3. Implement the method public DataBasketEntry group(DataBasketEntry dbe0, DataBasketEntry dbe1).
    Here you have to implement how two DataBasketEntrys merge into one Entry.

Example Source Code:

import data.swing.DataBasketEntryGrouper;
import data.DataBasketEntry;
			
1
public class DataDataBasketEntryGrouper implements DataBasketEntryGrouper
{
			
    2
    public boolean canGroup(DataBasketEntry dbe0, DataBasketEntry dbe1)
    {
        // items of same kind (MainKey) and same name (SecondaryKey) can be grouped
        if(dbe0.getMainKey().equals(dbe1.getMainKey()) &&
                dbe0.getSecondaryKey().equals(dbe1.getSecondaryKey()))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
			
    3
    public DataBasketEntry group(DataBasketEntry dbe0, DataBasketEntry dbe1)
    {
        // the first item will be displayed for both
        return dbe0;
    }
			
}
		

Back to:


previous Data Management: CatalogData Management: DataBasket next


Valid HTML 4.01!