Interface DFEntityDataProvider
-
public interface DFEntityDataProvider
Data manager for a single entity. It provides CRUD operations, i.e. methods for inserting, querying, updating and deleting data from the managed entity together with some other supplemental methods.Queried data might be cached or might be always obtained directly from a data source. Concrete strategy is up to particular implementations.
If you are interested in data changes, you should register a
DFEntityDataListener
to this object.API Status: Partly stable. This class contains a few methods which can be changed/removed in the future. These methods comments contain TODO info.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
addDFEntityDataListener(DFEntityDataListener listener)
Registers an listener to be notified about data changes in this entity data provider.int
deleteIds(java.util.List<? extends java.lang.Comparable<?>> ids, com.im.commons.progress.DFEnvironmentRW env)
Deletes these IDs.java.lang.String
generateStatistics()
Generates a statistical summary of the information in this entity.java.util.Map<java.lang.Comparable<?>,java.util.Map<java.lang.String,java.lang.Object>>
getData(java.util.List<? extends java.lang.Comparable<?>> ids, com.im.commons.progress.DFEnvironmentRO env)
Deprecated.getData(List, Set, DFEnvironmentRO)
is replacement for this methodjava.util.Map<java.lang.Comparable<?>,java.util.Map<java.lang.String,java.lang.Object>>
getData(java.util.List<? extends java.lang.Comparable<?>> ids, java.util.Set<? extends DFField> fields, com.im.commons.progress.DFEnvironmentRO env)
Fetches data for the specified IDs.DFEntity
getEntity()
Gets the entity which this EDP belongs to.com.im.commons.progress.DFLockable
getLockable()
Gets the lock provider only for this EDP.int
getRowCount(com.im.commons.progress.DFEnvironmentRO env)
Gets the number of rows.DFSchemaDataProvider
getSchemaDataProvider()
Gets parent DFSchemaDataProvider.java.util.Map<java.lang.Comparable<?>,java.util.Map<java.lang.String,java.lang.Object>>
getWrappedData(java.util.List<? extends java.lang.Comparable<?>> ids, com.im.commons.progress.DFEnvironmentRO env)
Fetches data for the specified IDs.java.util.List<DFUpdateInfo>
insert(java.util.List<java.util.Map<java.lang.String,java.lang.Object>> values, java.util.Map<java.lang.String,java.lang.Object> insertOptions, com.im.commons.progress.DFEnvironmentRW env)
Insert multiple new rows with these values.DFUpdateInfo
insert(java.util.Map<java.lang.String,java.lang.Object> values, java.util.Map<java.lang.String,java.lang.Object> insertOptions, com.im.commons.progress.DFEnvironmentRW env)
Inserts a new row with these values.java.util.List<? extends DFRowData>
queryForData(DFTermExpression query, java.util.List<? extends DFField> fields, SortDirective sort, EarlyResultsConsumer consumer, boolean filterOutNulls, com.im.commons.progress.DFEnvironmentRO env)
Deprecated.since 14.8.18 usethe variant without filterOutNulls
, the parameterfilterOutNulls
is ignored since 14.8.18 and the method always behaves as iffilterOutNulls = true
.java.util.List<? extends DFRowData>
queryForData(DFTermExpression query, java.util.List<? extends DFField> fields, SortDirective sort, EarlyResultsConsumer consumer, com.im.commons.progress.DFEnvironmentRO env)
Gets the values of selected fields of the entity that match the specified query.java.util.List<? extends java.lang.Comparable<?>>
queryForIds(DFDataTree dataTree, DFTermExpression query, SortDirective sort, com.im.commons.progress.DFEnvironmentRO env)
java.util.List<? extends java.lang.Comparable<?>>
queryForIds(DFTermExpression query, SortDirective sort, com.im.commons.progress.DFEnvironmentRO env)
Gets the IDs (primary key values) of the entity that match the specified query.java.util.List<? extends java.lang.Comparable<?>>
queryForIds(DFTermExpression query, SortDirective sort, EarlyResultsConsumer consumer, com.im.commons.progress.DFEnvironmentRO env)
Gets the IDs (primary key values) of the entity that match the specified query.java.util.List<? extends java.lang.Object>
queryForValues(DFTermExpression query, DFField selectedField, SortDirective sort, com.im.commons.progress.DFEnvironmentRO env)
Gets the values of selectedField of the entity that match the specified query.void
reloadData()
Reloads data for this EDP.void
removeDFEntityDataListener(DFEntityDataListener listener)
Unregisters an listener to be notified about data changes in this entity data provider.java.util.List<?>
retrieveDistinctValuesForField(DFField field, com.im.commons.progress.DFEnvironmentRO env)
Gets the List of distinct values for this field.java.util.List
retrieveDistinctValuesForField(java.lang.String fieldId)
Deprecated.This method doesn't respect the entity SQL filter parameter, useretrieveDistinctValuesForField(com.im.df.api.ddl.DFField, com.im.commons.progress.DFEnvironmentRO)
java.util.List<? extends java.lang.Comparable<?>>
sortIds(java.util.List<? extends java.lang.Comparable<?>> ids, SortDirective sort, com.im.commons.progress.DFEnvironmentRO env)
Gets these IDs for the entity in sorted order.java.util.Map<DFUpdateDescription,DFUpdateResult>
update(java.util.List<DFUpdateDescription> updateDescriptions, com.im.commons.progress.DFEnvironmentRW env)
java.util.Map<DFUpdateDescription,DFUpdateResult>
update(java.util.List<DFUpdateDescription> updateDescriptions, com.im.commons.progress.DFEnvironmentRW env, boolean fireEvents)
java.util.Map<DFUpdateDescription,DFUpdateResult>
update(java.util.List<DFUpdateDescription> updateDescriptions, DFUndoConfig undoConfig, com.im.commons.progress.DFEnvironmentRW env)
Deprecated.since 20.12.0 useupdate(List, DFEnvironmentRW)
orupdate(List, DFUndoManager, String, DFEnvironmentRW)
if you want to create undo itemjava.util.Map<DFUpdateDescription,DFUpdateResult>
update(java.util.List<DFUpdateDescription> updateDescriptions, DFUndoConfig undoConfig, com.im.commons.progress.DFEnvironmentRW env, boolean fireEvents)
Deprecated.since 20.12.0 useupdate(List, DFEnvironmentRW)
orupdate(List, DFEnvironmentRW, boolean)
if you want to handle (suppress) event firing orupdate(List, DFUndoManager, String, DFEnvironmentRW)
if you want to create undo itemjava.util.Map<DFUpdateDescription,DFUpdateResult>
update(java.util.List<DFUpdateDescription> updateDescriptions, DFUndoManager undoManager, java.lang.String undoMsg, com.im.commons.progress.DFEnvironmentRW env)
Updates the data where certain value match the defined criteria.
-
-
-
Method Detail
-
getLockable
com.im.commons.progress.DFLockable getLockable()
Gets the lock provider only for this EDP. You must lock the EDP before calling data modification methods.- Returns:
- lockable for this EDP.
-
getSchemaDataProvider
DFSchemaDataProvider getSchemaDataProvider()
Gets parent DFSchemaDataProvider.- Returns:
- schema data provider.
-
getEntity
DFEntity getEntity()
Gets the entity which this EDP belongs to.- Returns:
- entity which this EDP belongs to
-
getRowCount
int getRowCount(com.im.commons.progress.DFEnvironmentRO env)
Gets the number of rows.- Parameters:
env
- read only environment- Returns:
- number of rows.
-
queryForIds
java.util.List<? extends java.lang.Comparable<?>> queryForIds(DFTermExpression query, SortDirective sort, com.im.commons.progress.DFEnvironmentRO env)
Gets the IDs (primary key values) of the entity that match the specified query. If interested in early Results from ongoing query, please usequeryForIds(DFTermExpression, SortDirective, EarlyResultsConsumer, DFEnvironmentRO)
- Parameters:
query
- The query. All elements must be present in this entity, for empty query useDFTermExpression.ALL_DATA
constant.sort
- The sort directive describing how returned data should be sortedenv
- environment for reading data- Returns:
- The values of the ID field of the entity that match the query
- Since:
- 15.12.14 throws
QueryExecutionException
when there is something wrong with data retrieval. Before that such problems were only logged and swallowed.
-
queryForIds
java.util.List<? extends java.lang.Comparable<?>> queryForIds(DFTermExpression query, SortDirective sort, EarlyResultsConsumer consumer, com.im.commons.progress.DFEnvironmentRO env)
Gets the IDs (primary key values) of the entity that match the specified query. You can also provide an instance ofEarlyResultsConsumer
which allows you to read partial results already during a query execution.- Parameters:
query
- The query. All elements must be present in this entity, for empty query useDFTermExpression.ALL_DATA
constant.sort
- The sort directive describing how returned data should be sortedconsumer
- Early results consumer provided by caller used by query engine to call back partial results. If it's null then no partial results are reported back.env
- environment for reading data- Returns:
- The values of the ID field of the entity that match the query
- Since:
- 15.12.14 throws
QueryExecutionException
when there is something wrong with data retrieval. Before that such problems were only logged and swallowed.
-
queryForIds
@Deprecated java.util.List<? extends java.lang.Comparable<?>> queryForIds(DFDataTree dataTree, DFTermExpression query, SortDirective sort, com.im.commons.progress.DFEnvironmentRO env)
Deprecated.Gets the IDs (primary key values) of the entity that match the specified query.- Parameters:
dataTree
- The DataTree that allows the different fields to be resolved to formulate the queryquery
- The query. Elements can be from other entities in the DataTree, for empty query useDFTermExpression.ALL_DATA
constant.sort
- The sort directivesenv
- environment for reading data- Returns:
- The values of the ID field of the entity that match the query
-
queryForValues
java.util.List<? extends java.lang.Object> queryForValues(DFTermExpression query, DFField selectedField, SortDirective sort, com.im.commons.progress.DFEnvironmentRO env)
Gets the values of selectedField of the entity that match the specified query.- Parameters:
query
- The query. All elements must be present in this entity, for empty query useDFTermExpression.ALL_DATA
constant.selectedField
- specify field which values are returned (target)sort
- The sort directive describing how returned data should be sortedenv
- environment for reading data- Returns:
- The values of the selectedField field of the entity that match the query
-
queryForData
@Deprecated java.util.List<? extends DFRowData> queryForData(DFTermExpression query, java.util.List<? extends DFField> fields, SortDirective sort, EarlyResultsConsumer consumer, boolean filterOutNulls, com.im.commons.progress.DFEnvironmentRO env)
Deprecated.since 14.8.18 usethe variant without filterOutNulls
, the parameterfilterOutNulls
is ignored since 14.8.18 and the method always behaves as iffilterOutNulls = true
. The only difference usingfilterOutNulls = false
could make was that this method could bring one more row. QueryingWHERE id = NULL
doesn't generally make sense and the previous implementation would return at most one row for all nulls anyway.Gets the values of selected fields of the entity that match the specified query. You can also provide an instance ofEarlyResultsConsumer
which allows you to read partial results already during a query execution.- Parameters:
query
- The query. All elements must be present in this entity, for empty query useDFTermExpression.ALL_DATA
constant.fields
- specify fields which values are returned (target)sort
- The sort directive describing how returned data should be sortedconsumer
- Early results consumer provided by caller used by query engine to call back partial results. If it'snull
then no partial results are reported back.env
- environment for reading datafilterOutNulls
- Whether to filter null ids. This parameter is now ignored and ids are filtered.- Returns:
- The values of the fields of the entity that match the query. Each list item contains data for a single database row. Each row is represented as Map where keys are ids of selected fields and values are real data values.
- See Also:
queryForData(DFTermExpression, List, SortDirective, EarlyResultsConsumer, DFEnvironmentRO)
-
queryForData
java.util.List<? extends DFRowData> queryForData(DFTermExpression query, java.util.List<? extends DFField> fields, SortDirective sort, EarlyResultsConsumer consumer, com.im.commons.progress.DFEnvironmentRO env)
Gets the values of selected fields of the entity that match the specified query. You can also provide an instance ofEarlyResultsConsumer
which allows you to read partial results already during a query execution.- Parameters:
query
- The query. All elements must be present in this entity, for empty query useDFTermExpression.ALL_DATA
constant.fields
- specify fields which values are returned (target)sort
- The sort directive describing how returned data should be sortedconsumer
- Early results consumer provided by caller used by query engine to call back partial results. If it'snull
then no partial results are reported back.env
- environment for reading data- Returns:
- The values of the fields of the entity that match the query. Each list item contains data for a single database row. Each row is represented as Map where keys are ids of selected fields and values are real data values.
-
sortIds
java.util.List<? extends java.lang.Comparable<?>> sortIds(java.util.List<? extends java.lang.Comparable<?>> ids, SortDirective sort, com.im.commons.progress.DFEnvironmentRO env)
Gets these IDs for the entity in sorted order. The implementation can decide if it is faster to leave database to sort them or sort them inside DIF implementation.- Parameters:
ids
- The required IDssort
- The sort directive describing how returned data should be sortedenv
- environment for reading data- Returns:
- The values of the ID field of the entity in sorted order
-
getData
@Deprecated java.util.Map<java.lang.Comparable<?>,java.util.Map<java.lang.String,java.lang.Object>> getData(java.util.List<? extends java.lang.Comparable<?>> ids, com.im.commons.progress.DFEnvironmentRO env)
Deprecated.getData(List, Set, DFEnvironmentRO)
is replacement for this methodFetches data for the specified IDs.- Parameters:
ids
- the IDsenv
- environment for reading data- Returns:
- A map of the data, keyed by the row ID. The values of the first level of
Map
are instances ofMap
again. In these nestedMap
s key is id ofDFField
and value is the read data value. NestedMap
s contain only data for eachDFField
specified infields
parameter.
-
getData
java.util.Map<java.lang.Comparable<?>,java.util.Map<java.lang.String,java.lang.Object>> getData(java.util.List<? extends java.lang.Comparable<?>> ids, java.util.Set<? extends DFField> fields, com.im.commons.progress.DFEnvironmentRO env)
Fetches data for the specified IDs.- Parameters:
ids
- the IDsfields
- set of fields to retrieve the values from. Ifnull
or empty all fields of the entity are retrievedenv
- environment for reading data- Returns:
- A map of the data, keyed by the row ID. The values of the first level of
Map
are instances ofMap
again. In these nestedMap
s key is id ofDFField
and value is the read data value. NestedMap
s contain only data for eachDFField
specified infields
parameter. - Since:
- 5.12
-
getWrappedData
java.util.Map<java.lang.Comparable<?>,java.util.Map<java.lang.String,java.lang.Object>> getWrappedData(java.util.List<? extends java.lang.Comparable<?>> ids, com.im.commons.progress.DFEnvironmentRO env)
Fetches data for the specified IDs. Values which needs time consuming calculation are wrapped toDFWrappedValue
.- Parameters:
ids
- The IDsenv
- environment for reading data- Returns:
- A map of the data, keyed by the row ID. The values of the first level of Map are instances of Map again. In these nested Maps key is DFField's Id and value is the read data value. Nested Maps contain data for each DFField.
-
insert
DFUpdateInfo insert(java.util.Map<java.lang.String,java.lang.Object> values, java.util.Map<java.lang.String,java.lang.Object> insertOptions, com.im.commons.progress.DFEnvironmentRW env)
Inserts a new row with these values.TODO P2 - getInsertOptions methods doesn't exist and currently only usage (in Import) is a hack to API. The architecture and API for insert options should be improved.
- Parameters:
values
- A Map of DFField's Id/value pairsinsertOptions
- Options specific to this type of entity. Can be null.env
- environment for writing data- Returns:
- Update info - id of inserted row and if it's duplicate
-
insert
java.util.List<DFUpdateInfo> insert(java.util.List<java.util.Map<java.lang.String,java.lang.Object>> values, java.util.Map<java.lang.String,java.lang.Object> insertOptions, com.im.commons.progress.DFEnvironmentRW env)
Insert multiple new rows with these values.- Parameters:
values
- list of fieldId/value pairsinsertOptions
- options specific to this type of entity. Can be null.env
- environment for writing data- Returns:
- list of update info
-
deleteIds
int deleteIds(java.util.List<? extends java.lang.Comparable<?>> ids, com.im.commons.progress.DFEnvironmentRW env)
Deletes these IDs.- Parameters:
ids
- The IDs to deleteenv
- environment for writing data- Returns:
- The number of IDs that were deleted. If not known then -1.
-
update
@Deprecated java.util.Map<DFUpdateDescription,DFUpdateResult> update(java.util.List<DFUpdateDescription> updateDescriptions, DFUndoConfig undoConfig, com.im.commons.progress.DFEnvironmentRW env)
Deprecated.since 20.12.0 useupdate(List, DFEnvironmentRW)
orupdate(List, DFUndoManager, String, DFEnvironmentRW)
if you want to create undo item- Parameters:
updateDescriptions
- The list of descriptions what to updateenv
- environment for writing dataundoConfig
- The description if and how to use undo/redo support- Returns:
- The map of results of the update operation. Each provided updateDescription should have its own result in this Map.
-
update
@Deprecated java.util.Map<DFUpdateDescription,DFUpdateResult> update(java.util.List<DFUpdateDescription> updateDescriptions, DFUndoConfig undoConfig, com.im.commons.progress.DFEnvironmentRW env, boolean fireEvents)
Deprecated.since 20.12.0 useupdate(List, DFEnvironmentRW)
orupdate(List, DFEnvironmentRW, boolean)
if you want to handle (suppress) event firing orupdate(List, DFUndoManager, String, DFEnvironmentRW)
if you want to create undo item- Parameters:
updateDescriptions
- The list of descriptions what to updateenv
- environment for writing dataundoConfig
- The description if and how to use undo/redo supportfireEvents
- on true fire events to registeredDFEntityDataListener
- Returns:
- updated data
-
update
java.util.Map<DFUpdateDescription,DFUpdateResult> update(java.util.List<DFUpdateDescription> updateDescriptions, DFUndoManager undoManager, java.lang.String undoMsg, com.im.commons.progress.DFEnvironmentRW env)
Updates the data where certain value match the defined criteria. To recognize if the method was successful you need to checkDFUpdateResult.isSuccessful()
method of each DFUpdateResult.However you can update any number of rows in a single call of this method.you should rather balance it. For example if you want to update 1000000 rows and you will call this method once for each row then the performance won't be good. On the other hand if you call it only once with
List
of 1000000 preparedDFUpdateDescription
s it will require too much memory as whole change must be allocated and is released after operation finishes.It's recommended that you choose some option in the middle of these two extremes. For this reason there is defined a constant which says what is the recommended size of update batch:
DIFUtilities.UPDATE_DESCRIPTORS_RECOMMENDED_LIMIT
. Then the code can look something like (it's simplified - it doesn't solve the returned results):DFEntityDataProvider edp = ....; List<DFUpdateDescription> updateDescriptions = new ArrayList<DFUpdateDescription>(); for (int i = 0; i < rowCount; i++) { updateDescriptions.add(DFUpdateDescription.create(...)); if ((updateDescriptions.size() > DIFUtilities.UPDATE_DESCRIPTORS_RECOMMENDED_LIMIT) || (i == rowCount - 1)) { Map<DFUpdateDescription, DFUpdateResult> result = edp.update(updateDescriptions,...); updateDescriptions.clear(); // check results and possibly break loop if there are any errors? } }
There is a utility which can help with writing this code:
BatchUpdater
.- Parameters:
updateDescriptions
- The list of descriptions what to updateenv
- environment for writing dataundoManager
- undo/redo supportundoMsg
- label of undoable edit- Returns:
- The map of results of the update operation. Each provided updateDescription should have its own result in this Map.
- Since:
- 20.12.0
-
update
java.util.Map<DFUpdateDescription,DFUpdateResult> update(java.util.List<DFUpdateDescription> updateDescriptions, com.im.commons.progress.DFEnvironmentRW env)
- Parameters:
updateDescriptions
- The list of descriptions what to updateenv
- environment for writing data- Returns:
- The map of results of the update operation. Each provided updateDescription should have its own result in this Map.
- Since:
- 20.12.0
- See Also:
update(java.util.List, com.im.df.api.support.DFUndoManager, java.lang.String, com.im.commons.progress.DFEnvironmentRW)
-
update
java.util.Map<DFUpdateDescription,DFUpdateResult> update(java.util.List<DFUpdateDescription> updateDescriptions, com.im.commons.progress.DFEnvironmentRW env, boolean fireEvents)
- Parameters:
updateDescriptions
- The list of descriptions what to updateenv
- environment for writing datafireEvents
- on true fire events to registeredDFEntityDataListener
- Returns:
- The map of results of the update operation.
- Since:
- 20.12.0
- See Also:
update(java.util.List, com.im.df.api.support.DFUndoManager, java.lang.String, com.im.commons.progress.DFEnvironmentRW)
-
reloadData
void reloadData()
Reloads data for this EDP. This method fires event that all data changed. It works currently only for changed data, but not when some row is deleted!!TODO : This method may change in the future (perhaps DFEnvironmentRW will be added as parameter).
-
addDFEntityDataListener
void addDFEntityDataListener(DFEntityDataListener listener)
Registers an listener to be notified about data changes in this entity data provider. Preferred way is to use weak listener to prevent memory leaks.- Parameters:
listener
- listener for data modification
-
removeDFEntityDataListener
void removeDFEntityDataListener(DFEntityDataListener listener)
Unregisters an listener to be notified about data changes in this entity data provider.- Parameters:
listener
- listener for data modification
-
retrieveDistinctValuesForField
@Deprecated java.util.List retrieveDistinctValuesForField(java.lang.String fieldId)
Deprecated.This method doesn't respect the entity SQL filter parameter, useretrieveDistinctValuesForField(com.im.df.api.ddl.DFField, com.im.commons.progress.DFEnvironmentRO)
Gets the List of distinct values for this field.Even though this method doesn't take environment as a parameter, it hits the database and is potentially long running.
To obtain field values which should be used for query, edit or insert use
DFFieldPickListCapability
(since 6.3).- Parameters:
fieldId
- fieldId for query- Returns:
- list of distinct values for field
-
retrieveDistinctValuesForField
java.util.List<?> retrieveDistinctValuesForField(DFField field, com.im.commons.progress.DFEnvironmentRO env)
Gets the List of distinct values for this field.To obtain field values which should be used for query, edit or insert use
DFFieldPickListCapability
(since 6.3).- Parameters:
field
- field whose values should be retrieved, must belong to this entityenv
- the environment- Returns:
- list of distinct values for field
-
generateStatistics
java.lang.String generateStatistics()
Generates a statistical summary of the information in this entity. The returned value is expected to be a human readable string so can be presented in UI.- Returns:
- human readable string with statistical summary of the information this entity.
-
-