public class MyBatisDataAccessStrategy extends Object implements DataAccessStrategy
DataAccessStrategy implementation based on MyBatis. Each method gets mapped to a statement. The name of the
statement gets constructed as follows: By default, the namespace is based on the class of the entity plus the suffix
"Mapper". This is then followed by the method name separated by a dot. For methods taking a PropertyPath as
argument, the relevant entity is that of the root of the path, and the path itself gets as dot separated String
appended to the statement name. Each statement gets an instance of MyBatisContext, which at least has the
entityType set. For methods taking a PropertyPath the entityType if the context is set to the class of the
leaf type.| Constructor and Description |
|---|
MyBatisDataAccessStrategy(org.apache.ibatis.session.SqlSession sqlSession,
IdentifierProcessing identifierProcessing)
Constructs a
DataAccessStrategy based on MyBatis. |
| Modifier and Type | Method and Description |
|---|---|
<T> void |
acquireLockAll(LockMode lockMode,
Class<T> domainType)
Acquire a lock on all aggregates of the given domain type.
|
<T> void |
acquireLockById(Object id,
LockMode lockMode,
Class<T> domainType)
Acquire a lock on the aggregate specified by id.
|
long |
count(Class<?> domainType)
Counts the rows in the table representing the given domain type.
|
static DataAccessStrategy |
createCombinedAccessStrategy(RelationalMappingContext context,
JdbcConverter converter,
NamedParameterJdbcOperations operations,
org.apache.ibatis.session.SqlSession sqlSession,
Dialect dialect)
Create a
DataAccessStrategy that first checks for queries defined by MyBatis and if it doesn't find one
uses a DefaultDataAccessStrategy |
static DataAccessStrategy |
createCombinedAccessStrategy(RelationalMappingContext context,
JdbcConverter converter,
NamedParameterJdbcOperations operations,
org.apache.ibatis.session.SqlSession sqlSession,
NamespaceStrategy namespaceStrategy,
Dialect dialect)
Create a
DataAccessStrategy that first checks for queries defined by MyBatis and if it doesn't find one
uses a DefaultDataAccessStrategy |
void |
delete(Object id,
Class<?> domainType)
Deletes a single row identified by the id, from the table identified by the domainType.
|
void |
delete(Object rootId,
org.springframework.data.mapping.PersistentPropertyPath<RelationalPersistentProperty> propertyPath)
Deletes all entities reachable via propertyPath from the instance identified by rootId.
|
<T> void |
deleteAll(Class<T> domainType)
Deletes all entities of the given domain type.
|
void |
deleteAll(org.springframework.data.mapping.PersistentPropertyPath<RelationalPersistentProperty> propertyPath)
Deletes all entities reachable via propertyPath from any instance.
|
<T> void |
deleteWithVersion(Object id,
Class<T> domainType,
Number previousVersion)
Deletes a single entity from the database and enforce optimistic record locking using the version property.
|
<T> boolean |
existsById(Object id,
Class<T> domainType)
returns if a row with the given id exists for the given type.
|
<T> Iterable<T> |
findAll(Class<T> domainType)
Loads all entities of the given type.
|
<T> Iterable<T> |
findAll(Class<T> domainType,
org.springframework.data.domain.Pageable pageable)
Loads all entities of the given type, paged and sorted.
|
<T> Iterable<T> |
findAll(Class<T> domainType,
org.springframework.data.domain.Sort sort)
Loads all entities of the given type, sorted.
|
<T> Iterable<T> |
findAllById(Iterable<?> ids,
Class<T> domainType)
Loads all entities that match one of the ids passed as an argument.
|
Iterable<Object> |
findAllByPath(Identifier identifier,
org.springframework.data.mapping.PersistentPropertyPath<? extends RelationalPersistentProperty> path)
Finds all entities reachable via path.
|
<T> T |
findById(Object id,
Class<T> domainType)
Loads a single entity identified by type and id.
|
<T> Object[] |
insert(List<InsertSubject<T>> insertSubjects,
Class<T> domainType,
IdValueSource idValueSource)
Inserts the data of multiple entities.
|
<T> Object |
insert(T instance,
Class<T> domainType,
Identifier identifier)
Inserts the data of a single entity.
|
<T> Object |
insert(T instance,
Class<T> domainType,
Identifier identifier,
IdValueSource idValueSource)
Inserts the data of a single entity.
|
void |
setNamespaceStrategy(NamespaceStrategy namespaceStrategy)
Set a NamespaceStrategy to be used.
|
<S> boolean |
update(S instance,
Class<S> domainType)
Updates the data of a single entity in the database.
|
<S> boolean |
updateWithVersion(S instance,
Class<S> domainType,
Number previousVersion)
Updates the data of a single entity in the database and enforce optimistic record locking using the
previousVersion property. |
public MyBatisDataAccessStrategy(org.apache.ibatis.session.SqlSession sqlSession,
IdentifierProcessing identifierProcessing)
DataAccessStrategy based on MyBatis.
Use a SqlSessionTemplate for SqlSession or a similar implementation tying the session to the proper
transaction. Note that the resulting DataAccessStrategy only handles MyBatis. It does not include the
functionality of the DefaultDataAccessStrategy which one normally still wants. Use
createCombinedAccessStrategy(RelationalMappingContext, JdbcConverter, NamedParameterJdbcOperations, SqlSession, NamespaceStrategy, Dialect)
to create such a DataAccessStrategy.
sqlSession - Must be non null.identifierProcessing - the IdentifierProcessing applied to SqlIdentifier instances in order to
turn them into Stringpublic static DataAccessStrategy createCombinedAccessStrategy(RelationalMappingContext context, JdbcConverter converter, NamedParameterJdbcOperations operations, org.apache.ibatis.session.SqlSession sqlSession, Dialect dialect)
DataAccessStrategy that first checks for queries defined by MyBatis and if it doesn't find one
uses a DefaultDataAccessStrategypublic static DataAccessStrategy createCombinedAccessStrategy(RelationalMappingContext context, JdbcConverter converter, NamedParameterJdbcOperations operations, org.apache.ibatis.session.SqlSession sqlSession, NamespaceStrategy namespaceStrategy, Dialect dialect)
DataAccessStrategy that first checks for queries defined by MyBatis and if it doesn't find one
uses a DefaultDataAccessStrategypublic void setNamespaceStrategy(NamespaceStrategy namespaceStrategy)
namespaceStrategy - Must be non nullpublic <T> Object insert(T instance, Class<T> domainType, Identifier identifier)
DataAccessStrategyinsert in interface DataAccessStrategyT - the type of the instance.instance - the instance to be stored. Must not be null.domainType - the type of the instance. Must not be null.identifier - information about data that needs to be considered for the insert but which is not part of the
entity. Namely references back to a parent entity and key/index columns for entities that are stored in a
Map or List.public <T> Object insert(T instance, Class<T> domainType, Identifier identifier, IdValueSource idValueSource)
DataAccessStrategyinsert in interface DataAccessStrategyT - the type of the instance.instance - the instance to be stored. Must not be null.domainType - the type of the instance. Must not be null.identifier - information about data that needs to be considered for the insert but which is not part of the
entity. Namely references back to a parent entity and key/index columns for entities that are stored in a
Map or List.idValueSource - the IdValueSource for the insert.public <T> Object[] insert(List<InsertSubject<T>> insertSubjects, Class<T> domainType, IdValueSource idValueSource)
DataAccessStrategyinsert in interface DataAccessStrategyT - the type of the instance.insertSubjects - the subjects to be inserted, where each subject contains the instance and its identifier.
Must not be null.domainType - the type of the instance. Must not be null.idValueSource - the IdValueSource for the insert.null.public <S> boolean update(S instance,
Class<S> domainType)
DataAccessStrategyupdate in interface DataAccessStrategyS - the type of the instance to save.instance - the instance to save. Must not be null.domainType - the type of the instance to save. Must not be null.public <S> boolean updateWithVersion(S instance,
Class<S> domainType,
Number previousVersion)
DataAccessStrategypreviousVersion property. Referenced entities don't get handled.
The statement will be of the form : UPDATE … SET … WHERE ID = :id and VERSION_COLUMN = :previousVersion
and throw an optimistic record locking exception if no rows have been updated.
updateWithVersion in interface DataAccessStrategyS - the type of the instance to save.instance - the instance to save. Must not be null.domainType - the type of the instance to save. Must not be null.previousVersion - The previous version assigned to the instance being saved.public void delete(Object id, Class<?> domainType)
DataAccessStrategy
The statement will be of the form : DELETE FROM … WHERE ID = :id and VERSION_COLUMN = :version and throw
an optimistic record locking exception if no rows have been updated.
delete in interface DataAccessStrategyid - the id of the row to be deleted. Must not be null.domainType - the type of entity to be deleted. Implicitly determines the table to operate on. Must not be
null.public <T> void deleteWithVersion(Object id, Class<T> domainType, Number previousVersion)
DataAccessStrategydeleteWithVersion in interface DataAccessStrategyid - the id of the row to be deleted. Must not be null.domainType - the type of entity to be deleted. Implicitly determines the table to operate on. Must not be
null.previousVersion - The previous version assigned to the instance being saved.public void delete(Object rootId, org.springframework.data.mapping.PersistentPropertyPath<RelationalPersistentProperty> propertyPath)
DataAccessStrategydelete in interface DataAccessStrategyrootId - Id of the root object on which the propertyPath is based. Must not be null.propertyPath - Leading from the root object to the entities to be deleted. Must not be null.public <T> void deleteAll(Class<T> domainType)
DataAccessStrategydeleteAll in interface DataAccessStrategyT - type of the domain type.domainType - the domain type for which to delete all entries. Must not be null.public void deleteAll(org.springframework.data.mapping.PersistentPropertyPath<RelationalPersistentProperty> propertyPath)
DataAccessStrategydeleteAll in interface DataAccessStrategypropertyPath - Leading from the root object to the entities to be deleted. Must not be null.public <T> void acquireLockById(Object id, LockMode lockMode, Class<T> domainType)
DataAccessStrategyacquireLockById in interface DataAccessStrategyid - the id of the entity to load. Must not be null.lockMode - the lock mode for select. Must not be null.domainType - the domain type of the entity. Must not be null.public <T> void acquireLockAll(LockMode lockMode, Class<T> domainType)
DataAccessStrategyacquireLockAll in interface DataAccessStrategylockMode - the lock mode for select. Must not be null.domainType - the domain type of the entity. Must not be null.public <T> T findById(Object id, Class<T> domainType)
DataAccessStrategyfindById in interface DataAccessStrategyT - the type of the entity.id - the id of the entity to load. Must not be null.domainType - the domain type of the entity. Must not be null.null.public <T> Iterable<T> findAll(Class<T> domainType)
DataAccessStrategyfindAll in interface DataAccessStrategyT - the type of entities to load.domainType - the type of entities to load. Must not be null.null.public <T> Iterable<T> findAllById(Iterable<?> ids, Class<T> domainType)
DataAccessStrategyfindAllById in interface DataAccessStrategyT - type of entities to load.ids - the Ids of the entities to load. Must not be null.domainType - the type of entities to load. Must not be null.null.public Iterable<Object> findAllByPath(Identifier identifier, org.springframework.data.mapping.PersistentPropertyPath<? extends RelationalPersistentProperty> path)
RelationResolverfindAllByPath in interface DataAccessStrategyfindAllByPath in interface RelationResolveridentifier - the combination of Id, map keys and list indexes that identify the parent of the entity to be
loaded. Must not be null.path - the path from the aggregate root to the entities to be resolved. Must not be null.public <T> boolean existsById(Object id, Class<T> domainType)
DataAccessStrategyexistsById in interface DataAccessStrategyT - the type of the entity.id - the id of the entity for which to check. Must not be null.domainType - the type of the entity to check for. Must not be null.true if a matching row exists, otherwise false.public <T> Iterable<T> findAll(Class<T> domainType, org.springframework.data.domain.Sort sort)
DataAccessStrategyfindAll in interface DataAccessStrategyT - the type of entities to load.domainType - the type of entities to load. Must not be null.sort - the sorting information. Must not be null.null.public <T> Iterable<T> findAll(Class<T> domainType, org.springframework.data.domain.Pageable pageable)
DataAccessStrategyfindAll in interface DataAccessStrategyT - the type of entities to load.domainType - the type of entities to load. Must not be null.pageable - the pagination information. Must not be null.null.public long count(Class<?> domainType)
DataAccessStrategycount in interface DataAccessStrategydomainType - the domain type for which to count the elements. Must not be null.null.Copyright © 2017–2023 Pivotal Software, Inc.. All rights reserved.