Package org.ofbiz.core.entity
Class GenericDAO
java.lang.Object
org.ofbiz.core.entity.GenericDAO
Generic Entity Data Access Object - Handles persistence for any defined entity.
- Since:
- 1.0
- Version:
- $Revision: 1.1 $
- Author:
- David E. Jones, Andy Zeneski, Chris Maurer, Juergen Donnerstag, Rene Gielen, John Nutting
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DatasourceInfoprotected static Map<String,GenericDAO> protected Stringprotected ModelFieldTypeReaderstatic final Stringstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckDb(Map<String, ? extends ModelEntity> modelEntities, Collection<String> messages, boolean addMissing) intcount(ModelEntity modelEntity, String fieldName, EntityCondition entityCondition, EntityFindOptions findOptions) intdelete(GenericEntity entity) intdeleteAll(List<? extends GenericEntity> dummyPKs) Called dummyPKs because they can be invalid PKs, doing a deleteByAnd instead of a normal deleteintdeleteByAnd(ModelEntity modelEntity, Map<String, ?> fields) intdeleteByCondition(ModelEntity modelEntity, EntityCondition whereCondition) static GenericDAOgetGenericDAO(String helperName) induceModelFromDb(Collection<String> messages) Creates a list of ModelEntity objects based on meta data from the databaseintinsert(GenericEntity entity) voidpartialSelect(GenericEntity entity, Set<String> keys) static voidremoveGenericDAO(String helperName) voidselect(GenericEntity entity) voidselect(GenericEntity entity, Connection connection) selectByAnd(ModelEntity modelEntity, Map<String, ?> fields, List<String> orderBy) selectByCondition(ModelEntity modelEntity, EntityCondition entityCondition, Collection<String> fieldsToSelect, List<String> orderBy) Finds GenericValues by the conditions specified in the EntityCondition object, see the EntityCondition javadoc for more details.selectByCondition(ModelEntity modelEntity, EntityCondition entityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) Finds GenericValues by the conditions specified in the EntityCondition object, see the EntityCondition javadoc for more details.selectByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List<String> orderBy) selectByOr(ModelEntity modelEntity, Map<String, ?> fields, List<String> orderBy) selectListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details.intstoreAll(List<? extends GenericEntity> entities) transform(ModelEntity modelEntity, EntityCondition entityCondition, List<String> orderBy, String lockFieldName, Transformation transformation) Applies the given transformation to any entities matching the given condition, by performing a SELECT followed by an UPDATE.intupdate(GenericEntity entity) Updates the given entity with the given non-PK values.intupdate(GenericEntity entity, EntityConditionParam nonPkCondition) Updates the given entity with the given non-PK values.intupdateAll(GenericEntity entity)
-
Field Details
-
module
-
ORACLE_MAX_LIST_SIZE
public static final int ORACLE_MAX_LIST_SIZE- See Also:
-
MS_SQL_MAX_PARAMETER_COUNT
public static final int MS_SQL_MAX_PARAMETER_COUNT- See Also:
-
POSTGRESQL_MAX_PARAMETER_COUNT
public static final int POSTGRESQL_MAX_PARAMETER_COUNT- See Also:
-
genericDAOs
-
helperName
-
modelFieldTypeReader
-
datasourceInfo
-
-
Constructor Details
-
GenericDAO
-
-
Method Details
-
removeGenericDAO
-
getGenericDAO
-
insert
- Throws:
GenericEntityException
-
updateAll
- Throws:
GenericEntityException
-
update
Updates the given entity with the given non-PK values.- Parameters:
entity- the values to store (except the primary key fields, which are used to identify the row to be updated)- Returns:
- the number of rows updated (always 1)
- Throws:
GenericEntityNotFoundException- if the entity can't be foundGenericEntityException- if some other problem occurred
-
update
public int update(GenericEntity entity, EntityConditionParam nonPkCondition) throws GenericEntityException Updates the given entity with the given non-PK values.- Parameters:
entity- the values to store (except the primary key fields, which are used to identify the row to be updated)nonPkCondition- an optional non-PK condition upon the update- Returns:
- the number of rows updated (always 1)
- Throws:
GenericEntityNotFoundException- if the entity wasn't found by its PK or doesn't meet the non-PK condition, if anyGenericEntityException
-
storeAll
- Throws:
GenericEntityException
-
select
- Throws:
GenericEntityException
-
select
- Throws:
GenericEntityException
-
partialSelect
- Throws:
GenericEntityException
-
selectByAnd
public List<GenericValue> selectByAnd(ModelEntity modelEntity, Map<String, ?> fields, List<String> orderBy) throws GenericEntityException- Throws:
GenericEntityException
-
selectByOr
public List<GenericValue> selectByOr(ModelEntity modelEntity, Map<String, ?> fields, List<String> orderBy) throws GenericEntityException- Throws:
GenericEntityException
-
selectByCondition
public List<GenericValue> selectByCondition(ModelEntity modelEntity, EntityCondition entityCondition, Collection<String> fieldsToSelect, List<String> orderBy) throws GenericEntityException Finds GenericValues by the conditions specified in the EntityCondition object, see the EntityCondition javadoc for more details.- Parameters:
modelEntity- The ModelEntity of the Entity as defined in the entity XML fileentityCondition- The EntityCondition object that specifies how to constrain this queryfieldsToSelect- The fields of the named entity to get from the database; if empty or null all fields will be retreivedorderBy- The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending- Returns:
- List of GenericValue objects representing the result
- Throws:
GenericEntityException
-
selectByCondition
public List<GenericValue> selectByCondition(ModelEntity modelEntity, EntityCondition entityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException Finds GenericValues by the conditions specified in the EntityCondition object, see the EntityCondition javadoc for more details.- Parameters:
modelEntity- The ModelEntity of the Entity as defined in the entity XML fileentityCondition- The EntityCondition object that specifies how to constrain this queryfieldsToSelect- The fields of the named entity to get from the database; if empty or null all fields will be retreivedorderBy- The fields of the named entity to order the query by; optionally add a " ASC" for ascending orfindOptions- if null, the default options will be used " DESC" for descending- Returns:
- List of GenericValue objects representing the result
- Throws:
GenericEntityException
-
selectListIteratorByCondition
public EntityListIterator selectListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details.- Parameters:
modelEntity- The ModelEntity of the Entity as defined in the entity XML filewhereEntityCondition- The EntityCondition object that specifies how to constrain this query before any groupings are done (if this is a view entity with group-by aliases)havingEntityCondition- The EntityCondition object that specifies how to constrain this query after any groupings are done (if this is a view entity with group-by aliases)fieldsToSelect- The fields of the named entity to get from the database; if empty or null all fields will be retreivedorderBy- The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descendingfindOptions- can be null to use the default options- Returns:
- EntityListIterator representing the result of the query: NOTE THAT THIS MUST BE CLOSED WHEN YOU ARE DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BECAUSE IT WILL MAINTAIN A DATABASE CONNECTION.
- Throws:
GenericEntityException
-
selectByMultiRelation
public List<GenericValue> selectByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List<String> orderBy) throws GenericEntityException - Throws:
GenericEntityException
-
delete
- Throws:
GenericEntityException
-
deleteByCondition
public int deleteByCondition(ModelEntity modelEntity, EntityCondition whereCondition) throws GenericEntityException - Throws:
GenericEntityException
-
deleteByAnd
- Throws:
GenericEntityException
-
deleteAll
Called dummyPKs because they can be invalid PKs, doing a deleteByAnd instead of a normal delete- Throws:
GenericEntityException
-
checkDb
public void checkDb(Map<String, ? extends ModelEntity> modelEntities, Collection<String> messages, boolean addMissing) -
induceModelFromDb
Creates a list of ModelEntity objects based on meta data from the database -
count
public int count(ModelEntity modelEntity, String fieldName, EntityCondition entityCondition, EntityFindOptions findOptions) throws GenericEntityException - Throws:
GenericEntityException
-
transform
public List<GenericValue> transform(ModelEntity modelEntity, EntityCondition entityCondition, List<String> orderBy, String lockFieldName, Transformation transformation) throws GenericEntityException Applies the given transformation to any entities matching the given condition, by performing a SELECT followed by an UPDATE. Does NOT do this using "SELECT ... FOR UPDATE" semantics (because of inconsistent and/or missing support for this across database types), and therefore does not guarantee that another transaction has not updated the relevant row(s) between the SELECT and the UPDATE.- Parameters:
modelEntity- the type of entity to transform (required)entityCondition- the condition that selects the entities to transform (null means transform all)orderBy- the order in which the entities should be selected for updating (null means no ordering)lockFieldName- the entity field to use for optimistic locking; the value of this field will be read between the SELECT and the UPDATE to determine whether another process has updated one of the target records in the meantime; if so, the transformation will be reapplied and another UPDATE attemptedtransformation- the transformation to apply (required)- Returns:
- the transformed entities in the order they were selected (never null)
- Throws:
GenericEntityException- Since:
- 1.0.41
-