com.dynamide.db
Class SimpleDatasource

java.lang.Object
  extended by com.dynamide.DynamideObject
      extended by com.dynamide.db.SimpleDatasource
All Implemented Interfaces:
IDatasource, IDatasourceBasic, IGet
Direct Known Subclasses:
Login, RDBDatasource

public class SimpleDatasource
extends DynamideObject
implements IDatasource

Implements the IDatasource interface as a simple grid; NOTE: Column names default to CASE-INSENSITIVE, unless setCaseInsensitive(false) is called. This class is not backed by any persistent store -- it is just for keeping values in memory.

Test with dynamide/src/shell/tests/test-SimpleDatasource.bs

Here's some notes on the implementation:

 Registered Fields:
    current row:       A      B     C

    rows:              A0     B0    D0
                       A1     B1    C1
                       A2     B2    C2


single row widget:
                  cb.field = "A"        edit.field = "B"        label.field = "C"
                  cb.fieldIndex = ""    edit.fieldIndex = ""    label.fieldIndex = ""

multi row input grid:
                  cb.field = "A"        edit.field = "B"        label.field = "C"
                  cb.fieldIndex = "0"   edit.fieldIndex = "0"   label.fieldIndex = "0"

                  cb.field = "A"        edit.field = "B"        label.field = "C"
                  cb.fieldIndex = "1"   edit.fieldIndex = "1"   label.fieldIndex = "1"

                  cb.field = "A"        edit.field = "B"        label.field = "C"
                  cb.fieldIndex = "2"   edit.fieldIndex = "2"   label.fieldIndex = "2"
  


Nested Class Summary
 class SimpleDatasource.SimpleDatasourceIterator
           
 
Field Summary
protected  StringList m_propertiesTable
           
 
Fields inherited from class com.dynamide.DynamideObject
m_id
 
Fields inherited from interface com.dynamide.db.IDatasource
AFTER, BEFORE, BEFORE_FIRST, BEGIN, END, ROW_COUNT_NOT_ALLOWED, ROW_INDEX_UNKNOWN
 
Constructor Summary
SimpleDatasource()
           
SimpleDatasource(DynamideObject owner)
           
SimpleDatasource(DynamideObject owner, Session session)
           
 
Method Summary
 void addColumn(java.lang.String fieldName, java.lang.Object metadata)
           
 Field addField(java.lang.String fieldName, java.lang.Object value)
           
 Field addField(java.lang.String fieldName, java.lang.Object value, java.lang.Object metadata)
           
 void addRow()
           
 void cancel()
           
 void clear()
          Clear the columns and cached data rows from this object, not necessarily from the underlying back end data -- calls clearColumns() and clearRows().
 void clearColumns()
           
 StringList clearCurrentRow()
           
 void clearRows()
           
 boolean deleteRow()
           
 boolean deleteRow(int index)
           
 int distanceToIndex(int distance)
           
static int distanceToIndex(int distance, int currentRowIndex, int rowCount)
           
 java.lang.String dump()
          Subclasses can override this with something more descriptive, for logging and debugging.
 java.lang.String dump(java.lang.String nl)
           
 java.lang.String dumpErrorsHTML()
           
 java.lang.String dumpRow()
           
static java.lang.String dumpRow(StringList row)
           
static java.lang.String dumpRow(java.lang.String id, java.util.Map row)
           
protected  java.lang.String fixCase(java.lang.String fieldName)
           
 java.lang.Object get(java.lang.String what)
          Subclasses can override this.
 boolean getCaseInsensitive()
           
 java.lang.String getCategoryID()
           
 java.lang.String getColumnNames()
           
 java.util.List getColumnNamesList()
           
 StringList getCurrentRow()
           
 int getCurrentRowIndex()
          The zero-based index of the current row: single-row implementations can always return 0, implementations that don't support row indices should return IDatasource.ROW_INDEX_UNKNOWN;
 IDatasource getDatasourceHelper()
          By default, simply return a reference to "this", since the implementing class is an instance of IDatasource.
 Field getField(java.lang.String fieldName)
          Maintain a list of Field objects; return the live Field when asked by this method.
 Field getField(java.lang.String fieldName, java.lang.String fieldIndex)
          This class can support indexed Fields, by any arbitrary String index, which will for tabular datasets, be the zero-based row index; however the index can be any valid string which could itself be a search specifier that is used by this method.
 java.util.Map getFields()
           
 java.lang.String getID()
          A unique name within the Application for this datasource, it becomes the ID by which Widgets can discover the datasource.
 java.lang.Object getMetadataForColumn(java.lang.String fieldName)
           
protected  StringList getProperties()
           
 Property getProperty(java.lang.String propertyName)
          %% this is funky, since right now all are stored as String name and value. isEvent is just lost, for example.
 StringList getRow(int index)
           
 int getRowCount()
          The row count of the current dataset, or IDatasource.ROW_COUNT_NOT_ALLOWED if the operation is not supported.
 Session getSession()
           
 boolean go(int distance)
          go(0) should go to the first row in the set, if supported, go(-1) should go back a row, if supported, go(1) should go forward a row if supported, go(IDatasource.END) should go to the last row in the set, leaving the last row active, that is, not after the last row, and all unsupported actions should simply be no-ops.
 boolean hasMore()
           
 void insertRow()
           
 boolean insertRow(int index)
           
 boolean isCurrentRow()
           
 boolean isReadOnly()
          Updateable datasets should return false.
 boolean isRowCountAllowed()
          Report if calling getRowCount() will be allowed.
 java.util.Iterator iterator()
          Return an Iterator which knows how to properly iterate over your implementation.
 boolean next()
           
 void onRowChanged()
          Subclasses can override to hook this notification; nothing is done in this class.
 boolean post()
          If isReadOnly() returns false, and the underlying data can be updated, return true.
 void reload()
           
 boolean seek(int zeroBasedIndex)
          Jump to the absolute zero based index.
 boolean seekBegin()
           
 boolean seekEnd()
           
 void setCaseInsensitive(boolean new_value)
           
 void setColumnNames(java.lang.String new_value)
          Pass in a comma separated list of column names, and the columns will be created, without any associated metadata.
protected  void setCurrentRow(StringList newRow)
           
 void setFieldError(java.lang.String fieldName, java.lang.String errorMsg)
           
 void setFieldValue(java.lang.String fieldName, java.lang.Object value)
          The editable Dynamide Widgets can use this to modify the underlying Fields.
 boolean setFieldValue(java.lang.String fieldName, java.lang.Object value, java.lang.String fieldIndex)
          Optional operation: Dynamide Widgets can use this to modify the underlying datasource if the datasource supports indexed Fields.
 void setProperty(java.lang.String name, java.lang.String value)
          Rather than having a complicated interface to IDatasource, specialized behaviors can be set/retrieved using setProperty/getProperty, for example, "isMultiRowEditable".
 void setReadOnly(boolean new_value)
           
 void setSession(Session new_value)
           
 java.lang.String toString()
           
protected  void updateCurrentRowPointers()
           
 
Methods inherited from class com.dynamide.DynamideObject
clearProfiler, dump, dumpHTML, expand, finalize, findParentExpander, findParentPage, findParentSession, findTopParentPage, getDotName, getNextGetter, getObjectID, getOwner, getProfiler, isDebugEnabled, isInfoEnabled, logDebug, logDebug, logDebug, logDebug, logError, logError, logError, logError, logInfo, logInfo, logInfo, logInfo, logWarn, logWarn, logWarn, logWarn, popLogContext, printf, printProfiler, profileEnter, profileLeave, pushLogContext, setDotName, setID, setNextGetter, setObjectID, setOwner, sprintf, useProfiler, walkParents
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_propertiesTable

protected StringList m_propertiesTable
Constructor Detail

SimpleDatasource

public SimpleDatasource(DynamideObject owner)

SimpleDatasource

public SimpleDatasource()

SimpleDatasource

public SimpleDatasource(DynamideObject owner,
                        Session session)
Method Detail

getSession

public Session getSession()

setSession

public void setSession(Session new_value)

getRow

public StringList getRow(int index)

getCurrentRow

public StringList getCurrentRow()

setCurrentRow

protected void setCurrentRow(StringList newRow)

clearCurrentRow

public StringList clearCurrentRow()

getCaseInsensitive

public boolean getCaseInsensitive()

setCaseInsensitive

public void setCaseInsensitive(boolean new_value)

getColumnNames

public java.lang.String getColumnNames()

setColumnNames

public void setColumnNames(java.lang.String new_value)
Pass in a comma separated list of column names, and the columns will be created, without any associated metadata. To set metadata, use addColumn() for each column, which should be called before addRow().


getColumnNamesList

public java.util.List getColumnNamesList()

getMetadataForColumn

public java.lang.Object getMetadataForColumn(java.lang.String fieldName)

getCategoryID

public java.lang.String getCategoryID()
Overrides:
getCategoryID in class DynamideObject

fixCase

protected java.lang.String fixCase(java.lang.String fieldName)

setReadOnly

public void setReadOnly(boolean new_value)

updateCurrentRowPointers

protected void updateCurrentRowPointers()

onRowChanged

public void onRowChanged()
Subclasses can override to hook this notification; nothing is done in this class.

Specified by:
onRowChanged in interface IDatasource

dump

public java.lang.String dump()
Description copied from class: DynamideObject
Subclasses can override this with something more descriptive, for logging and debugging.

Overrides:
dump in class DynamideObject

dump

public java.lang.String dump(java.lang.String nl)

dumpRow

public java.lang.String dumpRow()

dumpRow

public static java.lang.String dumpRow(StringList row)

dumpRow

public static java.lang.String dumpRow(java.lang.String id,
                                       java.util.Map row)

dumpErrorsHTML

public java.lang.String dumpErrorsHTML()
Specified by:
dumpErrorsHTML in interface IDatasource

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

clear

public void clear()
Clear the columns and cached data rows from this object, not necessarily from the underlying back end data -- calls clearColumns() and clearRows().

Specified by:
clear in interface IDatasource

clearColumns

public void clearColumns()

clearRows

public void clearRows()

seekBegin

public boolean seekBegin()
Specified by:
seekBegin in interface IDatasource

seekEnd

public boolean seekEnd()
Specified by:
seekEnd in interface IDatasource

addRow

public void addRow()

insertRow

public void insertRow()

insertRow

public boolean insertRow(int index)
Specified by:
insertRow in interface IDatasource
Parameters:
index - Is one of IDatasource.BEGIN, IDatasource.END, IDatasource.AFTER, IDatasource.BEFORE or is an absolute index the new row will occupy. For examle, if there is one row in the dataset, then insertRow(0) would insert the new row at index 0, before the current row, while insertRow(1) would place the new row at index 1, after the current row. IDatasource.AFTER would place the new row after the current row, regardless of absolute index, and IDatasource.BEFORE would place the row before the current row.
Returns:
false if operation is not supported or raises an error.

deleteRow

public boolean deleteRow()

deleteRow

public boolean deleteRow(int index)

getDatasourceHelper

public IDatasource getDatasourceHelper()
Description copied from interface: IDatasource
By default, simply return a reference to "this", since the implementing class is an instance of IDatasource. This method exists so that IDatasourceBasic implementations can be wrapped in an IDatasource interface.

Specified by:
getDatasourceHelper in interface IDatasource
Specified by:
getDatasourceHelper in interface IDatasourceBasic
See Also:
IDatasourceBasic

iterator

public java.util.Iterator iterator()
Description copied from interface: IDatasourceBasic
Return an Iterator which knows how to properly iterate over your implementation. You can support remove(), or throw an UnsupportedOperationException. Single-row datasource would return an iterator that returned one row, then set hasNext to false. All implementations should provide one row of data, even if this row contains only empty strings for values. For single row datasets, here is a simple implementation, which can be done in an inner class:
  public class MyClass implements IDatasourceBasic{
      public class MyDatasourceIterator implements Iterator {
          private MyClass m_target;
          private int m_iterCount = 0;
          public SessionDatasourceIterator(MyClass target){
              m_target = target;
          }
          public Object next(){
              m_iterCount++;
              return m_target;
          }
          public boolean hasNext(){
              return (m_iterCount < 1);
          }
          public void remove(){
              throw new UnsupportedOperationException();
          }
      }
  }
 

Specified by:
iterator in interface IDatasource
Specified by:
iterator in interface IDatasourceBasic
See Also:
IDatasourceBasic.iterator()

addColumn

public void addColumn(java.lang.String fieldName,
                      java.lang.Object metadata)

addField

public Field addField(java.lang.String fieldName,
                      java.lang.Object value,
                      java.lang.Object metadata)
               throws DatatypeException
Throws:
DatatypeException

addField

public Field addField(java.lang.String fieldName,
                      java.lang.Object value)
               throws DatatypeException
Throws:
DatatypeException

getID

public java.lang.String getID()
Description copied from interface: IDatasource
A unique name within the Application for this datasource, it becomes the ID by which Widgets can discover the datasource.

Specified by:
getID in interface IDatasource
Specified by:
getID in interface IDatasourceBasic
Overrides:
getID in class DynamideObject

getFields

public java.util.Map getFields()
Specified by:
getFields in interface IDatasource
Specified by:
getFields in interface IDatasourceBasic
Returns:
a Map of all the fields owned.

getField

public Field getField(java.lang.String fieldName)
Description copied from interface: IDatasource
Maintain a list of Field objects; return the live Field when asked by this method. IDatasource supports the concept of the "current row", so that getField indexes into a tabular dataset by the fieldName of the column, for the current row. The caller gets different cell values by a) calling next() or some other navigation method, or b) calling getField(fieldName, fieldIndex) if indexed fields are supported.

Specified by:
getField in interface IDatasource
Specified by:
getField in interface IDatasourceBasic

getField

public Field getField(java.lang.String fieldName,
                      java.lang.String fieldIndex)
Description copied from interface: IDatasource
This class can support indexed Fields, by any arbitrary String index, which will for tabular datasets, be the zero-based row index; however the index can be any valid string which could itself be a search specifier that is used by this method.

Specified by:
getField in interface IDatasource

get

public java.lang.Object get(java.lang.String what)
Description copied from class: DynamideObject
Subclasses can override this.

Specified by:
get in interface IDatasource
Specified by:
get in interface IDatasourceBasic
Specified by:
get in interface IGet
Overrides:
get in class DynamideObject

setFieldValue

public void setFieldValue(java.lang.String fieldName,
                          java.lang.Object value)
Description copied from interface: IDatasource
The editable Dynamide Widgets can use this to modify the underlying Fields. If the underlying dataset does not support updates, you may wish to implement this as a no-op.

Specified by:
setFieldValue in interface IDatasource

setFieldValue

public boolean setFieldValue(java.lang.String fieldName,
                             java.lang.Object value,
                             java.lang.String fieldIndex)
Description copied from interface: IDatasource
Optional operation: Dynamide Widgets can use this to modify the underlying datasource if the datasource supports indexed Fields. If the underlying dataset does not support indexed Fields, you can return false from the method.

Specified by:
setFieldValue in interface IDatasource

setFieldError

public void setFieldError(java.lang.String fieldName,
                          java.lang.String errorMsg)

hasMore

public boolean hasMore()

isCurrentRow

public boolean isCurrentRow()

isReadOnly

public boolean isReadOnly()
Description copied from interface: IDatasource
Updateable datasets should return false.

Specified by:
isReadOnly in interface IDatasource

post

public boolean post()
Description copied from interface: IDatasource
If isReadOnly() returns false, and the underlying data can be updated, return true. Otherwise return false.

Specified by:
post in interface IDatasource

cancel

public void cancel()
Specified by:
cancel in interface IDatasource

reload

public void reload()
            throws java.lang.Exception
Specified by:
reload in interface IDatasource
Throws:
java.lang.Exception

next

public boolean next()

seek

public boolean seek(int zeroBasedIndex)
Description copied from interface: IDatasource
Jump to the absolute zero based index.

Specified by:
seek in interface IDatasource

go

public boolean go(int distance)
Description copied from interface: IDatasource
go(0) should go to the first row in the set, if supported, go(-1) should go back a row, if supported, go(1) should go forward a row if supported, go(IDatasource.END) should go to the last row in the set, leaving the last row active, that is, not after the last row, and all unsupported actions should simply be no-ops.

Specified by:
go in interface IDatasource
Returns:
true if navigation to a different row was achieved.

distanceToIndex

public int distanceToIndex(int distance)

distanceToIndex

public static int distanceToIndex(int distance,
                                  int currentRowIndex,
                                  int rowCount)

isRowCountAllowed

public boolean isRowCountAllowed()
Description copied from interface: IDatasource
Report if calling getRowCount() will be allowed. For some datasets it may not be advisable, e.g. for large SQL datasets, to allow getRowCount(), but this method simply tells the caller whether calling getRowCount() will return meaningful data. getRowCount() may return IDatasource.ROW_COUNT_NOT_ALLOWED, but does not throw Exceptions.

Specified by:
isRowCountAllowed in interface IDatasource
Returns:
true if calling getRowCount() is allowed

getRowCount

public int getRowCount()
Description copied from interface: IDatasource
The row count of the current dataset, or IDatasource.ROW_COUNT_NOT_ALLOWED if the operation is not supported. If not supported, be sure to return false from isRowCountAllowed().

Specified by:
getRowCount in interface IDatasource
Returns:
the current row count, or IDatasource.ROW_COUNT_NOT_ALLOWED

getCurrentRowIndex

public int getCurrentRowIndex()
Description copied from interface: IDatasource
The zero-based index of the current row: single-row implementations can always return 0, implementations that don't support row indices should return IDatasource.ROW_INDEX_UNKNOWN;

Specified by:
getCurrentRowIndex in interface IDatasource

getProperties

protected StringList getProperties()

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value)
                 throws DatatypeException
Description copied from interface: IDatasource
Rather than having a complicated interface to IDatasource, specialized behaviors can be set/retrieved using setProperty/getProperty, for example, "isMultiRowEditable".

Specified by:
setProperty in interface IDatasource
Throws:
DatatypeException

getProperty

public Property getProperty(java.lang.String propertyName)
%% this is funky, since right now all are stored as String name and value. isEvent is just lost, for example.

Specified by:
getProperty in interface IDatasource
See Also:
IDatasource.get(String)


Copyright 2001-2013 DYNAMIDE.COM. All Rights Reserved.