org.salespointframework.core.data
Class DataBasketImpl

java.lang.Object
  extended by org.salespointframework.core.data.DataBasketImpl
All Implemented Interfaces:
DatasourceOnChangeListener, DataBasket, ListenableDataBasket, SpAggregate

public class DataBasketImpl
extends java.lang.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
Version:
2.0 14/06/1999
Author:
Steffen Zschaler

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 #org.salespointframework.log.
static int EXCHANGE_REMOVE_ACTION
          Action constant for #org.salespointframework.log.
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.
private  LogContext m_lcLog
          The current org.salespointframework.log context.
protected  ListenerHelper m_lhListeners
          The listeners currently listening for events from this DataBasket.
protected  java.util.Map<java.lang.String,DataBasketImpl.SubDataBasket> m_mpsdbChildren
          The subbaskets of this DataBasket.
private  int m_nLogMode
          The current org.salespointframework.log mode.
private  java.lang.Object m_oChildrenLock
          The monitor used to synchronize access to the list of children.
private  java.lang.Object m_oCurrentLock
          The monitor used to synchronize access to the current subbasket.
private  java.lang.Object m_oLogLock
          The monitor synchronizing access to the org.salespointframework.log related attributes.
private  DataBasketImpl.SubDataBasket m_sdbCurrent
          The current subbasket.
static int PUT_ACTION
          Action constant for #org.salespointframework.log.
static int ROLLBACK_ACTION
          Action constant for #org.salespointframework.log.
 
Fields inherited from interface org.salespointframework.core.data.interfaces.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(java.lang.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 DatasourceOnChange()
          rollback databasket before changing datasource
 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  java.lang.Object getChildrenLock()
          Return the monitor used to synchronize access to the list of children.
private  java.lang.Object getCurrentLock()
          Return the monitor used to synchronize access to the current subbasket.
 java.lang.Object getDBIMonitor()
          Return the monitor used to synchronize access to the internal data structures of the DataBasket.
private  java.lang.Object getLogLock()
          Get the monitor synchronizing access to the org.salespointframework.log related attributes.
 int getLogMode()
          Return the current org.salespointframework.log mode of the DataBasket.
 java.util.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(java.lang.String sName)
          Rollback all entries in a given subbasket.
 void setCurrentSubBasket(java.lang.String sName)
          Set the current subbasket.
 LogContext setLogContext(LogContext lcNew)
          Set the org.salespointframework.log context for this DataBasket.
 int setLogMode(int nLogMode)
          Set the org.salespointframework.log mode for this DataBasket.
 java.util.Iterator<DataBasketEntry> subBasketIterator(java.lang.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(java.lang.String sName, DataBasketCondition dbc, BasketEntryValue bev, Value vInit)
          Sum up all entries in a given subbasket that match the given condition.
 void unsubscribeDatasourceOnChange()
          Unsubscribes from datasource on change events
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_mpsdbChildren

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


m_oChildrenLock

private transient java.lang.Object m_oChildrenLock
The monitor used to synchronize access to the list of children.


m_sdbCurrent

private DataBasketImpl.SubDataBasket m_sdbCurrent
The current subbasket.


m_oCurrentLock

private transient java.lang.Object m_oCurrentLock
The monitor used to synchronize access to the current subbasket.


m_lcLog

private LogContext m_lcLog
The current org.salespointframework.log context.


m_nLogMode

private int m_nLogMode
The current org.salespointframework.log mode.


m_oLogLock

private transient java.lang.Object m_oLogLock
The monitor synchronizing access to the org.salespointframework.log related attributes.


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 #org.salespointframework.log.

See Also:
Constant Field Values

EXCHANGE_REMOVE_ACTION

public static final int EXCHANGE_REMOVE_ACTION
Action constant for #org.salespointframework.log.

See Also:
Constant Field Values

COMMIT_ACTION

public static final int COMMIT_ACTION
Action constant for #org.salespointframework.log.

See Also:
Constant Field Values

ROLLBACK_ACTION

public static final int ROLLBACK_ACTION
Action constant for #org.salespointframework.log.

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 java.lang.Object getChildrenLock()
Return the monitor used to synchronize access to the list of children.


getCurrentLock

private final java.lang.Object getCurrentLock()
Return the monitor used to synchronize access to the current subbasket.


getLogLock

private final java.lang.Object getLogLock()
Get the monitor synchronizing access to the org.salespointframework.log related attributes.


rollback

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

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

commit

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

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

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.

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.

rollbackSubBasket

public void rollbackSubBasket(java.lang.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)

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()

commitSubBasket

public void commitSubBasket(java.lang.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)

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()

setCurrentSubBasket

public void setCurrentSubBasket(java.lang.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

iterator

public java.util.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.

subBasketIterator

public java.util.Iterator<DataBasketEntry> subBasketIterator(java.lang.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.

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(org.salespointframework.core.data.interfaces.Value) on this object.
Returns:
the sum in vInit.

sumSubBasket

public Value sumSubBasket(java.lang.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(org.salespointframework.core.data.interfaces.Value) on this object.
Returns:
the sum in vInit.

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(org.salespointframework.core.data.interfaces.Value) on this object.
Returns:
the sum in vInit.

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:
java.lang.ClassCastException - if ! (dbe instanceof DataBasketEntryImpl).

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.

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.

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.

setLogContext

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

All operations as defined through setLogMode(int) will be logged using the given org.salespointframework.log context. If the current org.salespointframework.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 org.salespointframework.log context
Returns:
the previous org.salespointframework.log context, if any.
See Also:
#org.salespointframework.log

setLogMode

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

The current org.salespointframework.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 org.salespointframework.log mode.
Returns:
the previous org.salespointframework.log mode.
See Also:
#org.salespointframework.log

getLogMode

public int getLogMode()
Return the current org.salespointframework.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

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 org.salespointframework.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(org.salespointframework.core.logging.LogContext), setLogMode(int)

getDBIMonitor

public java.lang.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).


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().


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.

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.

fireDataBasketChanged

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

Specified by:
fireDataBasketChanged in interface ListenableDataBasket

fireDBEAdded

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


fireDBERemoved

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


unsubscribeDatasourceOnChange

public void unsubscribeDatasourceOnChange()
Unsubscribes from datasource on change events


DatasourceOnChange

public void DatasourceOnChange()
rollback databasket before changing datasource

Specified by:
DatasourceOnChange in interface DatasourceOnChangeListener