K
- key class type for rowR
- Class associated with a row in tablepublic abstract class MapSelectOperation<K,R> extends SelectOperation<R,java.util.Map<K,R>>
Constructor and Description |
---|
MapSelectOperation(Table<R> table)
Constructs for a table to use primary key where condition.
|
MapSelectOperation(Table<R> table,
java.lang.String whereConditionName)
Constructs for a table and where condition.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
add(R row)
Implement to add row to collection created
SelectOperation.createReadAllCollection() . |
java.lang.String |
getGetKeyMethodName()
Return the name of the method for the row R that returns the Map key K.
|
protected K |
getKey(R row)
Gets key for row.
|
java.util.function.Function<R,K> |
getKeyFunction()
Gets the function used to obtain the map key from a row.
|
protected void |
prepare()
Creates prepared statement for this operation and invokes
SqlOperation.prepareCascades()
to prepare statements for any cascade operations. |
void |
setGetKeyMethodName(java.lang.String getKeyMethodName)
Sets the method name of row class R that gets key of type K to use in Map.
|
void |
setKeyFunction(java.util.function.Function<R,K> keyFunction)
Sets the function used to obtain the map key from a row.
|
createReadAllCollection, getDefaultReadAllSize, getFetchSize, getResultSetType, getSelectedRows, prepareStatement, readAll, selectAll, selectAll, setDefaultReadAllSize, setFetchSize, setResultSetType, setWhere
addFilter, close, execute, getFilterPredicateMap, getMaximumRowsRead, getOrderByName, getOrderByTranslator, getResultSet, getRowsReadCount, getSql, initBaseSql, isExecuted, isLazySelectsCascades, isNotifyLazySelects, iterator, positionAbsolute, positionRelative, postRead, postReadCascade, prepareCascades, preRead, preReadCascade, readNext, removeFilter, resetRowsReadCount, select, select, setFilterPredicateMap, setMaximumRowsRead, setOrderBy, setOrderByTranslator, setParameters, setRowParameters, updateActiveFilterPredicate
cancel, cascade, closeCascades, closeStatement, createRowField, getBaseSql, getCascadeDepth, getConnection, getCustomSql, getNamedParameterMap, getNextParameter, getOperationTime, getParameter, getParameters, getPreparedSql, getPreparedStatement, getQueryTimeout, getRequiredCascades, getTable, getTargetTable, getTimingId, getWhereAnnotation, getWhereConditionName, getWhereTranslator, initOperationTime, isCached, isCascade, isCascading, isIncludeIdentityColumns, isPrimaryKey, isReadOnly, isRequiredCascade, isTimings, logTimings, prepareCascades, prepareCheck, setBaseSql, setCached, setCascade, setCascadeDepth, setCustomSql, setIncludeIdentityColumns, setNamedParameterMap, setNextParameter, setParameter, setQueryTimeout, setReadOnly, setRequiredCascades, setTimingId, setTimings, setWhereTranslator, writeColumns, writeParameter, writeParameters, writeWhere
public MapSelectOperation(Table<R> table) throws OperationException
SqlOperation
classes.
It is unlikely that you will want to use this constructor without also
changing the where condition since at most one row will be selected. Use
SelectOperation.setWhere(String)
or SqlOperation.setWhereTranslator(org.sormula.translator.AbstractWhereTranslator)
to change the default primary key where condition.
table
- select from this tableOperationException
- if errorpublic MapSelectOperation(Table<R> table, java.lang.String whereConditionName) throws OperationException
table
- select from this tablewhereConditionName
- name of where condition to use ("primaryKey" to select
by primary key; empty string to select all rows in table)OperationException
- if errorpublic void setGetKeyMethodName(java.lang.String getKeyMethodName) throws OperationException
add(Object)
to add a row to the map.
The default is "hashCode".
Override getKey(Object)
to implement alternative ways to form key for Map.
getKeyMethodName
- name of row method to get key for MapOperationException
- if errorsetKeyFunction(Function)
public java.lang.String getGetKeyMethodName()
getKeyFunction()
public java.util.function.Function<R,K> getKeyFunction()
setKeyFunction(Function)
or null if nonepublic void setKeyFunction(java.util.function.Function<R,K> keyFunction)
setGetKeyMethodName(String)
, then the default
is to use Object.hashCode()
.
Examples of use:
MapSelectOperation<SomeKey, SomeRow> operation = ... operation.setKeyFunction(SomeRow::getId); operation.setKeyFunction(r -> r.getId());
keyFunction
- lambda expression that will return map key, K, from a row, Rprotected void prepare() throws OperationException
SqlOperation.prepareCascades()
to prepare statements for any cascade operations.prepare
in class SqlOperation<R>
OperationException
- if errorprotected boolean add(R row) throws OperationException
SelectOperation.createReadAllCollection()
.add
in class SelectOperation<R,java.util.Map<K,R>>
row
- row to addOperationException
- if errorprotected K getKey(R row) throws OperationException
row
- row objectOperationException
- if error