com.dynamide.db
Class DatasourceHelper

java.lang.Object
  extended by com.dynamide.db.DatasourceHelper
All Implemented Interfaces:
IDatasource, IDatasourceBasic

public class DatasourceHelper
extends java.lang.Object
implements IDatasource


Field Summary
 
Fields inherited from interface com.dynamide.db.IDatasource
AFTER, BEFORE, BEFORE_FIRST, BEGIN, END, ROW_COUNT_NOT_ALLOWED, ROW_INDEX_UNKNOWN
 
Constructor Summary
DatasourceHelper(IDatasourceBasic datasource)
           
 
Method Summary
 void cancel()
           
 void clear()
           
 java.lang.String dumpErrorsHTML()
           
 java.lang.Object get(java.lang.String what)
          Method to work with things like WebMacro, that automatically call Foo.get("bar") when you invoke $foo.bar if foo is of class Foo.
 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;
 IDatasourceBasic getDatasource()
           
 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)
          If you want a String value, try get(String).
 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.
 Property getProperty(java.lang.String propertyName)
          Rather than having a complicated interface to IDatasource, specialized behaviors can be set/retrieved using setProperty/getProperty, for example, "isMultiRowEditable".
 int getRowCount()
          The row count of the current dataset, or IDatasource.ROW_COUNT_NOT_ALLOWED if the operation is not supported.
 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 insertRow(int index)
           
 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.
 void onRowChanged()
          Provides notification that a seek or go operation has occured.
 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 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".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatasourceHelper

public DatasourceHelper(IDatasourceBasic datasource)
Method Detail

getDatasource

public IDatasourceBasic getDatasource()

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
Returns:
A pointer to this.
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()

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

getField

public Field getField(java.lang.String fieldName)
If you want a String value, try get(String).

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)
                     throws java.lang.Exception
Description copied from interface: IDatasource
Method to work with things like WebMacro, that automatically call Foo.get("bar") when you invoke $foo.bar if foo is of class Foo. The Dynamide Session search order should be useful for most implementations: get(String) searches Property objects then Fields.

Specified by:
get in interface IDatasource
Specified by:
get in interface IDatasourceBasic
Throws:
java.lang.Exception

getProperty

public Property getProperty(java.lang.String propertyName)
                     throws java.lang.Exception
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". Most implementations should also just return the Property String value from any calls to IDatasource.get(String).

Specified by:
getProperty in interface IDatasource
Throws:
java.lang.Exception
See Also:
IDatasource.get(String)

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

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.

dumpErrorsHTML

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

setFieldValue

public void setFieldValue(java.lang.String fieldName,
                          java.lang.Object value)
                   throws DatatypeException
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
Throws:
DatatypeException

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

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

clear

public void clear()
Specified by:
clear 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.

seekBegin

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

seekEnd

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

seek

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

Specified by:
seek in interface IDatasource

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.

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

onRowChanged

public void onRowChanged()
Description copied from interface: IDatasource
Provides notification that a seek or go operation has occured.

Specified by:
onRowChanged in interface IDatasource


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