com.cc.framework.ui.model.imp
Class VirtualKeyListDataModel

java.lang.Object
  extended bycom.cc.framework.ui.model.imp.VirtualKeyListDataModel
All Implemented Interfaces:
DataModel, ListDataModel, java.io.Serializable, VirtualDataModel

public abstract class VirtualKeyListDataModel
extends java.lang.Object
implements VirtualDataModel, ListDataModel, java.io.Serializable

List Data Model for Key lists with a very large or unknown number of keys.

Version:
$Revision: 1.7 $
Author:
Harald Schulz
See Also:
Serialized Form

Field Summary
private  int cache
          The List implements a very simple cache mechanism to prevent unnecessary loading
private  java.lang.Object cacheBean
          Cached row bean
private  boolean keepKeys
          This flag directs the list not to flush the keyset cache when a new keyset is loaded.
private  java.util.Vector keyset
          The elements of the currently loaded keyset
private  int keysetIndex
          This is the index of the first key in the keyset.
private  int keysetSize
          This member holds the size of the keyset.
private static long serialVersionUID
          Serial Version UID
private  int size
          The total number of elements.
private  int threshold
          Number of overlapping keys between keysets to reduce page filtering
 
Constructor Summary
VirtualKeyListDataModel()
          Constructor
VirtualKeyListDataModel(int keysetSize, boolean keepKeys)
          Constructor
 
Method Summary
 int capacity()
          Returns the current capacity of this VirtualKeyListDataModel.
 void clear()
          Clears the current list
protected  void clearKeyset()
          Removes all elements from the keyset.
protected abstract  java.util.Collection doFetchKeyset(int startIndex, int keyCount)
          This method reads a keyset into memory
protected abstract  java.lang.Object doFetchRowBean(java.lang.Object key)
          Overwrite this method to load one single row bean
protected  int doFetchSize()
          This method is called to fetch the actual keyset size.
protected  void doSetup()
          This method is called first to do any initialization processing
private  void fetchKeyset(int index)
          This method is called when the next keyset is to be loaded into memory
 java.lang.Object getElementAt(int index)
          Returns the (row) object for the specified index.
 java.lang.Object getElementFromKeyset(int index)
          Returns a Element of the keyset
 int getKeysetIndex()
          Returns the Index of the first element in the keyset
private  java.lang.Object getRowBean(int index)
          Returns the row bean for the given index
 java.lang.String getUniqueKey(int index)
          Returns a unique key for the row which is specified by the index.
private  int mapIndexToKeyset(int index)
          This method maps an absolute index to a relative index in the keyset.
 void setKeysetSize(int i)
          Sets the keyset size to the specified value.
 void setSize(int i)
          Sets the number of total available keys in this list.
 void setThreshold(int i)
          Sets the threshold value.
 int size()
          Returns the number of rows within the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Serial Version UID

See Also:
Constant Field Values

keepKeys

private boolean keepKeys
This flag directs the list not to flush the keyset cache when a new keyset is loaded.


keysetSize

private int keysetSize
This member holds the size of the keyset. It should be larger than the number of displayed rows (but that is not necessary)


threshold

private int threshold
Number of overlapping keys between keysets to reduce page filtering


size

private int size
The total number of elements. -1 when the correct number is unknown


keysetIndex

private int keysetIndex
This is the index of the first key in the keyset.


keyset

private java.util.Vector keyset
The elements of the currently loaded keyset


cache

private int cache
The List implements a very simple cache mechanism to prevent unnecessary loading


cacheBean

private java.lang.Object cacheBean
Cached row bean

Constructor Detail

VirtualKeyListDataModel

public VirtualKeyListDataModel()
Constructor


VirtualKeyListDataModel

public VirtualKeyListDataModel(int keysetSize,
                               boolean keepKeys)
Constructor

Parameters:
keysetSize - The number of keys that should be fetched at a time
keepKeys - Set to true when all keys should be kept in memory. Set to false when only a number of keysetSize keys should be kept in memory (default)
Method Detail

clear

public void clear()
Clears the current list


clearKeyset

protected void clearKeyset()
Removes all elements from the keyset. The current keyset index is not affected.


fetchKeyset

private void fetchKeyset(int index)
                  throws java.lang.Exception
This method is called when the next keyset is to be loaded into memory

Parameters:
index - Start Index
Throws:
java.lang.Exception - Will be thrown in case of an error in the integration layer

doSetup

protected void doSetup()
                throws java.lang.Exception
This method is called first to do any initialization processing

Throws:
java.lang.Exception - Will be thrown in case of an error in the integration layer

doFetchSize

protected int doFetchSize()
                   throws java.lang.Exception
This method is called to fetch the actual keyset size. It's up to the derived class to provide an implementation or not

Returns:
Returns the size of the list or -1
Throws:
java.lang.Exception - Will be thrown in case of an error in the integration layer

doFetchKeyset

protected abstract java.util.Collection doFetchKeyset(int startIndex,
                                                      int keyCount)
                                               throws java.lang.Exception
This method reads a keyset into memory

Parameters:
startIndex - Index of the first key
keyCount - Number of keys to read
Returns:
Returns a collection of keys
Throws:
java.lang.Exception - Will be thrown in case of an error in the integration layer

doFetchRowBean

protected abstract java.lang.Object doFetchRowBean(java.lang.Object key)
                                            throws java.lang.Exception
Overwrite this method to load one single row bean

Parameters:
key - The key
Returns:
row bean
Throws:
java.lang.Exception - An error occurred while loading the row bean

mapIndexToKeyset

private int mapIndexToKeyset(int index)
                      throws java.lang.Exception
This method maps an absolute index to a relative index in the keyset. When the relative index is outside the loaded keyset the missing data will be loaded dynamically to match the required index.

Parameters:
index - the absolute index
Returns:
returns the relative index or -1 when the index could not be matched
Throws:
java.lang.Exception - Will be thrown in case of an error in the integration layer

getElementAt

public java.lang.Object getElementAt(int index)
Description copied from interface: ListDataModel
Returns the (row) object for the specified index. This can be a display object (view helper) whose properties will be accessed within the columns of a List- or TreeControl

Specified by:
getElementAt in interface ListDataModel
Parameters:
index - A zero based index
Returns:
A row object.
See Also:
ListDataModel.getElementAt(int)

getUniqueKey

public java.lang.String getUniqueKey(int index)
Description copied from interface: ListDataModel
Returns a unique key for the row which is specified by the index. This id will be attached in hyperlinks to identify the row/object. This can be a simple row index or a key which correspond to the primary key from the database.

Specified by:
getUniqueKey in interface ListDataModel
Parameters:
index - A zero based index
Returns:
The unique key
See Also:
ListDataModel.getUniqueKey(int)

getRowBean

private java.lang.Object getRowBean(int index)
Returns the row bean for the given index

Parameters:
index - Element index
Returns:
row bean

getElementFromKeyset

public java.lang.Object getElementFromKeyset(int index)
Returns a Element of the keyset

Parameters:
index - Element index in the keyset
Returns:
Key

size

public int size()
Description copied from interface: ListDataModel
Returns the number of rows within the list.

Specified by:
size in interface ListDataModel
Returns:
Number of rows
See Also:
ListDataModel.size()

capacity

public int capacity()
Returns the current capacity of this VirtualKeyListDataModel.

Returns:
the current capacity (the length of its internal data array, kept in the field keyset of this VirtualKeyListDataModel).

setSize

public void setSize(int i)
Sets the number of total available keys in this list.

Parameters:
i - Number of keys or -1 when the number is unknown

getKeysetIndex

public int getKeysetIndex()
Returns the Index of the first element in the keyset

Returns:
Index of the first element in the keyset

setKeysetSize

public void setKeysetSize(int i)
Sets the keyset size to the specified value. It should match the size of a database keyset for optimized data throughput.

Parameters:
i - new keyset size

setThreshold

public void setThreshold(int i)
Sets the threshold value. That is the number of overlapping rows between two adjacent keysets. The threshold reduces page filtering when the user scrolls through the list.

Parameters:
i - new threshold value


Copyright © 2000-2005 SCC Informationssysteme GmbH. All Rights Reserved.