org.sormula.operation
Class MapSelectOperation<K,R>

java.lang.Object
  extended by org.sormula.operation.SqlOperation<R>
      extended by org.sormula.operation.ScalarSelectOperation<R>
          extended by org.sormula.operation.SelectOperation<R,java.util.Map<K,R>>
              extended by org.sormula.operation.MapSelectOperation<K,R>
Type Parameters:
K - key class type for row
R - Class associated with a row in table
Direct Known Subclasses:
HashMapSelectOperation, LinkedHashMapSelectOperation

public abstract class MapSelectOperation<K,R>
extends SelectOperation<R,java.util.Map<K,R>>

SelectOperation that uses Map for SelectOperation.readAll() results.

Since:
1.0
Author:
Jeff Miller

Constructor Summary
MapSelectOperation(Table<R> table)
          Constructs for a table.
MapSelectOperation(Table<R> table, java.lang.String whereConditionName)
          Constructs for a table and where condition.
 
Method Summary
protected  boolean add(R row)
          Implement to add row to collection created SelectOperation.createReadAllCollection().
 java.lang.reflect.Method getGetKeyMethod()
          Gets the method of class R that obtains key of type K from a row.
 java.lang.String getGetKeyMethodName()
          Return the name of the get key method.
protected  K getKey(R row)
          Gets key for row.
protected  void prepare()
          Creates prepared statement for this operation and invokes SqlOperation.prepareCascades() to prepare statements for any cascade operations.
 void setGetKeyMethod(java.lang.reflect.Method getKeyMethod)
          Sets the get key method.
 void setGetKeyMethodName(java.lang.String getKeyMethodName)
          Sets the get key method.
 
Methods inherited from class org.sormula.operation.SelectOperation
createReadAllCollection, getDefaultReadAllSize, getSelectedRows, readAll, selectAll, selectAll, setDefaultReadAllSize
 
Methods inherited from class org.sormula.operation.ScalarSelectOperation
close, execute, getMaximumRowsRead, getOrderByName, getOrderByTranslator, getResultSet, getRowsReadCount, getSql, initBaseSql, isLazySelectsCascades, isNotifyLazySelects, postRead, postReadCascade, prepareCascades, preRead, preReadCascade, readNext, select, select, setMaximumRowsRead, setOrderBy, setOrderByTranslator, setParameters, setRowParameters
 
Methods inherited from class org.sormula.operation.SqlOperation
cancel, cascade, closeCascades, closeStatement, createTargetField, getBaseSql, getConnection, getCustomSql, getNextParameter, getOperationTime, getParameters, getPreparedSql, getPreparedStatement, getQueryTimeout, getTable, getTargetTable, getTimingId, getWhereConditionName, getWhereTranslator, initOperationTime, isAutoGeneratedKeys, isIncludeIdentityColumns, isReadOnly, isTimings, logTimings, prepareCascades, prepareCheck, prepareColumns, prepareParameters, prepareWhere, setAutoGeneratedKeys, setBaseSql, setCustomSql, setIncludeIdentityColumns, setNextParameter, setQueryTimeout, setReadOnly, setTimingId, setTimings, setWhere, setWhereTranslator, writeColumns, writeParameter, writeParameters, writeWhere
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapSelectOperation

public MapSelectOperation(Table<R> table)
                   throws OperationException
Constructs for a table.

Parameters:
table - select from this table
Throws:
OperationException - if error

MapSelectOperation

public MapSelectOperation(Table<R> table,
                          java.lang.String whereConditionName)
                   throws OperationException
Constructs for a table and where condition.

Parameters:
table - select from this table
whereConditionName - name of where condition to use ("primaryKey" to select by primary key; empty string to select all rows in table)
Throws:
OperationException - if error
Method Detail

getGetKeyMethod

public java.lang.reflect.Method getGetKeyMethod()
Gets the method of class R that obtains key of type K from a row. Used by add(Object) to add a row to the map.

Returns:
method that supplies map key value for a row; default is Object.hashCode()

setGetKeyMethod

public void setGetKeyMethod(java.lang.reflect.Method getKeyMethod)
Sets the get key method. See getGetKeyMethod() for details. The default is Object.hashCode(). Use this method or setGetKeyMethodName(String) to define the get key method or override getKey(Object).

Parameters:
getKeyMethod - row method that gets map key

setGetKeyMethodName

public void setGetKeyMethodName(java.lang.String getKeyMethodName)
                         throws OperationException
Sets the get key method. See getGetKeyMethod() for details. The default is Object.hashCode(). Use this method or setGetKeyMethod(Method)to define the get key method or override getKey(Object).

Parameters:
getKeyMethodName - name of row method to get map key
Throws:
OperationException - if error

getGetKeyMethodName

public java.lang.String getGetKeyMethodName()
Return the name of the get key method.

Returns:
name of row method that gets map key

prepare

protected void prepare()
                throws OperationException
Creates prepared statement for this operation and invokes SqlOperation.prepareCascades() to prepare statements for any cascade operations.

Overrides:
prepare in class SqlOperation<R>
Throws:
OperationException - if error

add

protected boolean add(R row)
               throws OperationException
Implement to add row to collection created SelectOperation.createReadAllCollection().

Specified by:
add in class SelectOperation<R,java.util.Map<K,R>>
Parameters:
row - row to add
Returns:
true if added ok
Throws:
OperationException - if error

getKey

protected K getKey(R row)
            throws OperationException
Gets key for row.

Parameters:
row - row object
Returns:
unique key for row to use as key for map
Throws:
OperationException - if error