SalesPoint v3.3 API

data.ooimpl
Class DataBasketImpl

java.lang.Object
  extended by data.ooimpl.DataBasketImpl
All Implemented Interfaces:
DataBasket, ListenableDataBasket, Serializable

public class DataBasketImpl
extends Object
implements ListenableDataBasket

Pure Java implementation of the DataBasketImpl.SubDataBasket interface.

This DataBasket implementation can be used together with the Catalog and Stock implementations that come with the framework as well as with any other data container that manages all its internal structure on its own, instead of delegating them, e.g. to a data base. For a data base backing you should use other implementations of Stock, Catalog and DataBasketImpl.SubDataBasket, but these are not yet part of the framework.

Since:
v2.0
Author:
Steffen Zschaler
See Also:
Serialized Form

Nested Class Summary
static class DataBasketImpl.DataBasketImplLogEntry
          A LogEntry that describes an action on a DataBasket.
protected static class DataBasketImpl.SubDataBasket
          Internal helper class used by DataBasketImpl, representing a subbasket of a DataBasket.
 
Field Summary
static int COMMIT_ACTION
          Action constant for log(int, log.Loggable).
static int EXCHANGE_REMOVE_ACTION
          Action constant for log(int, log.Loggable).
static LogEntryFilter LOGENTRYFILTER_COMMIT_ACTIONS
          A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a commit action.
static LogEntryFilter LOGENTRYFILTER_DATABASKETIMPLACTIONS
          A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl.
static LogEntryFilter LOGENTRYFILTER_EXCHANGE_REMOVE_ACTIONS
          A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a exchange_remove action.
static LogEntryFilter LOGENTRYFILTER_NO_DATABASKETIMPLACTIONS
          A LogEntryFilter that will accept only LogEntries that were not produced by a DataBasketImpl.
static LogEntryFilter LOGENTRYFILTER_PUT_ACTIONS
          A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a put action.
static LogEntryFilter LOGENTRYFILTER_ROLLBACK_ACTIONS
          A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a rollback action.
protected  ListenerHelper m_lhListeners
          The listeners currently listening for events from this DataBasket.
protected  Map<String,DataBasketImpl.SubDataBasket> m_mpsdbChildren
          The subbaskets of this DataBasket.
static int PUT_ACTION
          Action constant for log(int, log.Loggable).
static int ROLLBACK_ACTION
          Action constant for log(int, log.Loggable).
 
Fields inherited from interface data.DataBasket
DEFAULTSUBBASKET_NAME, LOG_MODE_ALL, LOG_MODE_COMMITS_ONLY, LOG_MODE_NONE, LOG_MODE_ROLLBACKS_ONLY
 
Constructor Summary
DataBasketImpl()
          Create a new DataBasketImpl.
 
Method Summary
 void addDataBasketListener(DataBasketListener dbl)
          Add a listener that will receive events when the DataBasket's contents change.
protected  void clean()
          Remove any items that have already been handled, but so far have not been removed from the DataBasket.
 void commit()
          Commit the contents of all subbaskets of this DataBasket.
 void commit(DataBasketCondition dbc)
          Commit all items in all subbaskets that do match the given condition.
 void commitCurrentSubBasket()
          Commit the current subbasket's contents.
 void commitSubBasket(String sName)
          Commit all entries in a given subbasket.
 boolean contains(DataBasketCondition dbc)
          Check whether any entries matching a particular condition are contained in the DataBasket.
 void exchange(DataBasketEntry dbeOrg, DataBasketEntry dbeNew)
          Exchange a DataBasketEntry with another.
 void fireDataBasketChanged()
          Fire an event to all listeners listening to this DataBasket.
protected  void fireDBEAdded(DataBasketEntry dbe)
          Fire an event to all listeners listening to this DataBasket.
protected  void fireDBERemoved(DataBasketEntry dbe)
          Fire an event to all listeners listening to this DataBasket.
 DataBasketEntry get(DataBasketCondition dbc)
          Get the first entry in the DataBasket that matches the condition.
protected  Object getChildrenLock()
          Return the monitor used to synchronize access to the list of children.
 Object getDBIMonitor()
          Return the monitor used to synchronize access to the internal data structures of the DataBasket.
 int getLogMode()
          Return the current log mode of the DataBasket.
 Iterator<DataBasketEntry> iterator(DataBasketCondition dbc)
          Iterate all entries in all subbaskets that match the condition.
 void log(int nAction, Loggable la)
          Log the given event wrapped in a LogEntry that describes the action.
 void put(DataBasketEntry dbe)
          Put a DataBasketEntry into the current subbasket.
 void removeDataBasketListener(DataBasketListener dbl)
          Remove a listener that received events when the DataBasket's contents changed.
 void rollback()
          Rollback the contents of all subbaskets of this DataBasket.
 void rollback(DataBasketCondition dbc)
          Rollback all items in all subbaskets that do match the given condition.
 void rollbackCurrentSubBasket()
          Rollback the current subbasket's contents.
 void rollbackSubBasket(String sName)
          Rollback all entries in a given subbasket.
 void setCurrentSubBasket(String sName)
          Set the current subbasket.
 LogContext setLogContext(LogContext lcNew)
          Set the log context for this DataBasket.
 int setLogMode(int nLogMode)
          Set the log mode for this DataBasket.
 Iterator<DataBasketEntry> subBasketIterator(String sName, DataBasketCondition dbc)
          Iterate all entries in a given subbasket that match the given condition.
 Value sumBasket(DataBasketCondition dbc, BasketEntryValue bev, Value vInit)
          Sum up all entries in the DataBasket that match the given condition.
 Value sumCurrentSubBasket(DataBasketCondition dbc, BasketEntryValue bev, Value vInit)
          Sum up all entries in the current subbasket that match the given condition.
 Value sumSubBasket(String sName, DataBasketCondition dbc, BasketEntryValue bev, Value vInit)
          Sum up all entries in a given subbasket that match the given condition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_mpsdbChildren

protected Map<String,DataBasketImpl.SubDataBasket> m_mpsdbChildren
The subbaskets of this DataBasket.


m_lhListeners

protected ListenerHelper m_lhListeners
The listeners currently listening for events from this DataBasket.


PUT_ACTION

public static final int PUT_ACTION
Action constant for log(int, log.Loggable).

See Also:
Constant Field Values

EXCHANGE_REMOVE_ACTION

public static final int EXCHANGE_REMOVE_ACTION
Action constant for log(int, log.Loggable).

See Also:
Constant Field Values

COMMIT_ACTION

public static final int COMMIT_ACTION
Action constant for log(int, log.Loggable).

See Also:
Constant Field Values

ROLLBACK_ACTION

public static final int ROLLBACK_ACTION
Action constant for log(int, log.Loggable).

See Also:
Constant Field Values

LOGENTRYFILTER_DATABASKETIMPLACTIONS

public static final LogEntryFilter LOGENTRYFILTER_DATABASKETIMPLACTIONS
A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl.


LOGENTRYFILTER_NO_DATABASKETIMPLACTIONS

public static final LogEntryFilter LOGENTRYFILTER_NO_DATABASKETIMPLACTIONS
A LogEntryFilter that will accept only LogEntries that were not produced by a DataBasketImpl.


LOGENTRYFILTER_PUT_ACTIONS

public static final LogEntryFilter LOGENTRYFILTER_PUT_ACTIONS
A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a put action.


LOGENTRYFILTER_EXCHANGE_REMOVE_ACTIONS

public static final LogEntryFilter LOGENTRYFILTER_EXCHANGE_REMOVE_ACTIONS
A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a exchange_remove action.


LOGENTRYFILTER_COMMIT_ACTIONS

public static final LogEntryFilter LOGENTRYFILTER_COMMIT_ACTIONS
A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a commit action.


LOGENTRYFILTER_ROLLBACK_ACTIONS

public static final LogEntryFilter LOGENTRYFILTER_ROLLBACK_ACTIONS
A LogEntryFilter that will accept only LogEntries that were produced by a DataBasketImpl and that describe a rollback action.

Constructor Detail

DataBasketImpl

public DataBasketImpl()
Create a new DataBasketImpl.

Method Detail

getChildrenLock

protected final Object getChildrenLock()
Return the monitor used to synchronize access to the list of children.

Override:
Never

rollback

public void rollback()
Rollback the contents of all subbaskets of this DataBasket.

Specified by:
rollback in interface DataBasket
See Also:
DataBasket.commit()
Override:
Never

commit

public void commit()
Commit the contents of all subbaskets of this DataBasket.

Specified by:
commit in interface DataBasket
See Also:
DataBasket.rollback()
Override:
Never

rollback

public void rollback(DataBasketCondition dbc)
Rollback all items in all subbaskets that do match the given condition.

Specified by:
rollback in interface DataBasket
Parameters:
dbc - the condition to be matched. null means rollback unconditionally.
Override:
Never

commit

public void commit(DataBasketCondition dbc)
Commit all items in all subbaskets that do match the given condition.

Specified by:
commit in interface DataBasket
Parameters:
dbc - the condition to be matched. null means commit unconditionally.
Override:
Never

rollbackSubBasket

public void rollbackSubBasket(String sName)
Rollback all entries in a given subbasket.

Specified by:
rollbackSubBasket in interface DataBasket
Parameters:
sName - the name of the subbasket.
See Also:
DataBasket.setCurrentSubBasket(java.lang.String), DataBasket.commitSubBasket(java.lang.String)
Override:
Never

rollbackCurrentSubBasket

public void rollbackCurrentSubBasket()
Rollback the current subbasket's contents.

Specified by:
rollbackCurrentSubBasket in interface DataBasket
See Also:
DataBasket.setCurrentSubBasket(java.lang.String), DataBasket.commitCurrentSubBasket()
Override:
Never

commitSubBasket

public void commitSubBasket(String sName)
Commit all entries in a given subbasket.

Specified by:
commitSubBasket in interface DataBasket
Parameters:
sName - the name of the subbasket.
See Also:
DataBasket.setCurrentSubBasket(java.lang.String), DataBasket.rollbackSubBasket(java.lang.String)
Override:
Never

commitCurrentSubBasket

public void commitCurrentSubBasket()
Commit the current subbasket's contents.

Specified by:
commitCurrentSubBasket in interface DataBasket
See Also:
DataBasket.setCurrentSubBasket(java.lang.String), DataBasket.rollbackCurrentSubBasket()
Override:
Never

setCurrentSubBasket

public void setCurrentSubBasket(String sName)
Set the current subbasket.

Specified by:
setCurrentSubBasket in interface DataBasket
Parameters:
sName - the name of the new current subbasket. If the subbasket does not yet exist, it is created prior to being made the current subbasket.
See Also:
DataBasket.commitSubBasket(java.lang.String), DataBasket.rollbackSubBasket(java.lang.String), DataBasket.commitCurrentSubBasket(), DataBasket.rollbackCurrentSubBasket(), DataBasket.DEFAULTSUBBASKET_NAME
Override:
Never

iterator

public Iterator<DataBasketEntry> iterator(DataBasketCondition dbc)
Iterate all entries in all subbaskets that match the condition.

Specified by:
iterator in interface DataBasket
Parameters:
dbc - the condition to be matched.
Returns:
an iterator that iterates all the entries in the DataBasket that match the condition. The iterator will not support the remove() method.
Override:
Never

subBasketIterator

public Iterator<DataBasketEntry> subBasketIterator(String sName,
                                                   DataBasketCondition dbc)
Iterate all entries in a given subbasket that match the given condition.

Specified by:
subBasketIterator in interface DataBasket
Parameters:
dbc - the condition to be matched.
sName - the name of the SubBasket. A NullPointerException may be thrown if this SubBasket does not exist.
Returns:
an iterator that iterates all the entries in the given subbasket that match the condition. The iterator will not support the remove() method.
Override:
Never

sumBasket

public Value sumBasket(DataBasketCondition dbc,
                       BasketEntryValue bev,
                       Value vInit)
Sum up all entries in the DataBasket that match the given condition.

Specified by:
sumBasket in interface DataBasket
Parameters:
dbc - the condition to be matched.
bev - an object used for determining the value of a DataBasketEntry.
vInit - the value that is to be used for adding up. All adding is performed by calling Value.addAccumulating(data.Value) on this object.
Returns:
the sum in vInit.
Override:
Never

sumSubBasket

public Value sumSubBasket(String sName,
                          DataBasketCondition dbc,
                          BasketEntryValue bev,
                          Value vInit)
Sum up all entries in a given subbasket that match the given condition.

Specified by:
sumSubBasket in interface DataBasket
Parameters:
sName - the name of the subbasket that is to be summed up.
dbc - the condition to be matched.
bev - an object used for determining the value of a DataBasketEntry.
vInit - the value that is to be used for adding up. All adding is performed by calling Value.addAccumulating(data.Value) on this object.
Returns:
the sum in vInit.
Override:
Never

sumCurrentSubBasket

public Value sumCurrentSubBasket(DataBasketCondition dbc,
                                 BasketEntryValue bev,
                                 Value vInit)
Sum up all entries in the current subbasket that match the given condition.

Specified by:
sumCurrentSubBasket in interface DataBasket
Parameters:
dbc - the condition to be matched.
bev - an object used for determining the value of a DataBasketEntry.
vInit - the value that is to be used for adding up. All adding is performed by calling Value.addAccumulating(data.Value) on this object.
Returns:
the sum in vInit.
Override:
Never

put

public void put(DataBasketEntry dbe)
Put a DataBasketEntry into the current subbasket. DataBasketEntries that are to be put into a DataBasketImpl must be instances of, or of subclasses of, DataBasketEntryImpl.

Specified by:
put in interface DataBasket
Parameters:
dbe - the entry to be put in.
Throws:
ClassCastException - if ! (dbe instanceof DataBasketEntryImpl).
Override:
Never

exchange

public void exchange(DataBasketEntry dbeOrg,
                     DataBasketEntry dbeNew)
Exchange a DataBasketEntry with another.

Specified by:
exchange in interface DataBasket
Parameters:
dbeOrg - the original DataBasketEntry, to be replaced.
dbeNew - the replacement.
Override:
Never

get

public DataBasketEntry get(DataBasketCondition dbc)
Get the first entry in the DataBasket that matches the condition.

Specified by:
get in interface DataBasket
Parameters:
dbc - the condition
Returns:
an entry matching the condition, if any.
Override:
Never

contains

public boolean contains(DataBasketCondition dbc)
Check whether any entries matching a particular condition are contained in the DataBasket.

Specified by:
contains in interface DataBasket
Parameters:
dbc - the condition
Returns:
true if an entry that matches the condition could be found.
Override:
Never

setLogContext

public LogContext setLogContext(LogContext lcNew)
Set the log context for this DataBasket.

All operations as defined through setLogMode(int) will be logged using the given log context. If the current log context is null no logging of any kind will occur.

The actual LogEntries written are defined by the DataBasketEntries that participate in the activities that are logged. The DataBasket will wrap those LogEntries into LogEntries that give the type of operation performed.

Specified by:
setLogContext in interface DataBasket
Parameters:
lcNew - the new log context
Returns:
the previous log context, if any.
See Also:
log(int, log.Loggable)
Override:
Never

setLogMode

public int setLogMode(int nLogMode)
Set the log mode for this DataBasket.

The current log mode decides what operations on the DataBasket are being logged. The default value is DataBasket.LOG_MODE_NONE, indicating that no logging occurs. Other possibilities are:

The actual LogEntries written are defined by the DataBasketEntries that participate in the activities that are logged. The DataBasket will wrap those LogEntries into LogEntries that give the type of operation performed.

Specified by:
setLogMode in interface DataBasket
Parameters:
nLogMode - the new log mode.
Returns:
the previous log mode.
See Also:
log(int, log.Loggable)
Override:
Never

getLogMode

public int getLogMode()
Return the current log mode of the DataBasket. For information on the possible values and their meaning, please refer to setLogMode(int).

Specified by:
getLogMode in interface DataBasket
Override:
Never

log

public void log(int nAction,
                Loggable la)
Log the given event wrapped in a LogEntry that describes the action.

If the action needs to be logged in the current log mode, a new DataBasketImpl.DataBasketImplLogEntry is created that wraps the LogEntry produced by the given Loggable. This LogEntry is then logged using the current LogContext.

See Also:
setLogContext(log.LogContext), setLogMode(int)
Override:
Never

getDBIMonitor

public Object getDBIMonitor()
Return the monitor used to synchronize access to the internal data structures of the DataBasket. Whenever a container wants to access a DataBasket implemented in this way, it must first synchronize over the DataBasket's monitor and then synchronize over its own monitor(s).

Override:
Never

clean

protected void clean()
Remove any items that have already been handled, but so far have not been removed from the DataBasket.

This method is usually called by the framework only. It assumes, that it is called from within a synchronized block synchronizing on the monitor returned by getDBIMonitor().

Override:
Never

addDataBasketListener

public void addDataBasketListener(DataBasketListener dbl)
Add a listener that will receive events when the DataBasket's contents change.

Specified by:
addDataBasketListener in interface ListenableDataBasket
Parameters:
dbl - the listener.
Override:
Never

removeDataBasketListener

public void removeDataBasketListener(DataBasketListener dbl)
Remove a listener that received events when the DataBasket's contents changed.

Specified by:
removeDataBasketListener in interface ListenableDataBasket
Parameters:
dbl - the listener.
Override:
Never

fireDataBasketChanged

public void fireDataBasketChanged()
Fire an event to all listeners listening to this DataBasket.

Specified by:
fireDataBasketChanged in interface ListenableDataBasket
Override:
Never

fireDBEAdded

protected void fireDBEAdded(DataBasketEntry dbe)
Fire an event to all listeners listening to this DataBasket.

Override:
Never

fireDBERemoved

protected void fireDBERemoved(DataBasketEntry dbe)
Fire an event to all listeners listening to this DataBasket.

Override:
Never

SalesPoint v3.3 API