当前位置:网站首页>Yyds dry inventory executor package (executor function)
Yyds dry inventory executor package (executor function)
2022-06-26 07:36:00 【Grey Wolf_ cxh】
executor package ( Actuator function )
executor The functions provided by each sub package in the package , Ultimately, these functions are provided by Executor Interfaces and their implementation classes jointly provide external services .
Executor The interface can be added based on the following methods , Delete , Change query and transaction processing . in fact ,mybatis All database operations in are implemented by calling these methods .
public interface Executor {
ResultHandler NO_RESULT_HANDLER = null;
// Data update operation , Increase of data 、 Delete 、 Updates can be implemented by this method
int update(MappedStatement ms, Object parameter) throws SQLException;
// Data query operation , The returned result is in the form of a list
<E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey cacheKey, BoundSql boundSql) throws SQLException;
// Data query operation , The returned result is in the form of a list
/**
* Perform query operation
* @param ms Mapping statement objects
* @param parameter Parameter object
* @param rowBounds Page turning restrictions
* @param resultHandler Result processor
* @param <E> Output result type
* @return Query results
* @throws SQLException
*/
<E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException;
// Data query operation , The returned result is in cursor form
<E> Cursor<E> queryCursor(MappedStatement ms, Object parameter, RowBounds rowBounds) throws SQLException;
// Clean cache
List<BatchResult> flushStatements() throws SQLException;
// Commit transaction
void commit(boolean required) throws SQLException;
// Roll back the transaction
void rollback(boolean required) throws SQLException;
// Create cached key values for the current query
CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql);
// Whether the local cache has a specified value
boolean isCached(MappedStatement ms, CacheKey key);
// Clean up the local cache
void clearLocalCache();
// Lazy loading
void deferLoad(MappedStatement ms, MetaObject resultObject, String property, CacheKey key, Class<?> targetType);
// Get transaction
Transaction getTransaction();
// Turn off the actuator
void close(boolean forceRollback);
// Judge whether the actuator is closed
boolean isClosed();
// Set the actuator packing
void setExecutorWrapper(Executor executor);
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
BaseExecutor Is an abstract class , And the template mode is used , It implements some common basic functions of its subclasses , And the operations directly related to the subclass are handled by the subclass .
public abstract class BaseExecutor implements Executor {
private static final Log log = LogFactory.getLog(BaseExecutor.class);
protected Transaction transaction;
protected Executor wrapper;
protected ConcurrentLinkedQueue<DeferredLoad> deferredLoads;
// Result cache of query operation
protected PerpetualCache localCache;
// Callable Output parameter cache of query
protected PerpetualCache localOutputParameterCache;
protected Configuration configuration;
protected int queryStack;
private boolean closed;
/**
* Update database data ,INSERT/UPDATE/DELETE All three operations call this method
* @param ms Mapping statements
* @param parameter Parameter object
* @return Database operation results
* @throws SQLException
*/
@Override
public int update(MappedStatement ms, Object parameter) throws SQLException {
ErrorContext.instance().resource(ms.getResource())
.activity("executing an update").object(ms.getId());
if (closed) {
// The actuator has been closed
throw new ExecutorException("Executor was closed.");
}
// Clean up the local cache
clearLocalCache();
// Return to call the subclass for operation
return doUpdate(ms, parameter);
}
/**
* Perform query operation
* @param ms Mapping statement objects
* @param parameter Parameter object
* @param rowBounds Page turning restrictions
* @param resultHandler Result processor
* @param <E> Output result type
* @return Query results
* @throws SQLException
*/
@Override
public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException {
BoundSql boundSql = ms.getBoundSql(parameter);
// Generate cached keys
CacheKey key = createCacheKey(ms, parameter, rowBounds, boundSql);
return query(ms, parameter, rowBounds, resultHandler, key, boundSql);
}
/**
* Query the data in the database
* @param ms Mapping statements
* @param parameter Parameter object
* @param rowBounds Page turning restrictions
* @param resultHandler Result processor
* @param key The cache keys
* @param boundSql Query statement
* @param <E> Result Type
* @return Result list
* @throws SQLException
*/
@SuppressWarnings("unchecked")
@Override
public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException {
ErrorContext.instance().resource(ms.getResource()).activity("executing a query").object(ms.getId());
if (closed) {
// The actuator has been closed
throw new ExecutorException("Executor was closed.");
}
if (queryStack == 0 && ms.isFlushCacheRequired()) { // New query stack and request to clear cache
// Clear the first level cache
clearLocalCache();
}
List<E> list;
try {
queryStack++;
// Try getting results from the local cache
list = resultHandler == null ? (List<E>) localCache.getObject(key) : null;
if (list != null) {
// There are results in the local cache , For CALLABLE Statements also need to be bound to IN/INOUT Parameter
handleLocallyCachedOutputParameters(ms, key, parameter, boundSql);
} else {
// The local cache has no results , Therefore, you need to query the database
list = queryFromDatabase(ms, parameter, rowBounds, resultHandler, key, boundSql);
}
} finally {
queryStack--;
}
if (queryStack == 0) {
// Processing of lazy loading operation
for (DeferredLoad deferredLoad : deferredLoads) {
deferredLoad.load();
}
deferredLoads.clear();
// If the scope of the local cache is STATEMENT, Clear the local cache immediately
if (configuration.getLocalCacheScope() == LocalCacheScope.STATEMENT) {
clearLocalCache();
}
}
return list;
}
/**
* Generate cached keys for queries
* @param ms Mapping statement objects
* @param parameterObject Parameter object
* @param rowBounds Page turning restrictions
* @param boundSql After parsing SQL sentence
* @return Generated key values
*/
@Override
public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {
if (closed) {
throw new ExecutorException("Executor was closed.");
}
// establish CacheKey, And all query parameters are updated and written in turn
CacheKey cacheKey = new CacheKey();
cacheKey.update(ms.getId());
cacheKey.update(rowBounds.getOffset());
cacheKey.update(rowBounds.getLimit());
cacheKey.update(boundSql.getSql());
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
TypeHandlerRegistry typeHandlerRegistry = ms.getConfiguration().getTypeHandlerRegistry();
for (ParameterMapping parameterMapping : parameterMappings) {
if (parameterMapping.getMode() != ParameterMode.OUT) {
Object value;
String propertyName = parameterMapping.getProperty();
if (boundSql.hasAdditionalParameter(propertyName)) {
value = boundSql.getAdditionalParameter(propertyName);
} else if (parameterObject == null) {
value = null;
} else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
value = parameterObject;
} else {
MetaObject metaObject = configuration.newMetaObject(parameterObject);
value = metaObject.getValue(propertyName);
}
cacheKey.update(value);
}
}
if (configuration.getEnvironment() != null) {
cacheKey.update(configuration.getEnvironment().getId());
}
return cacheKey;
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
BaseExecutor There are four implementation classes :
CloseExecutor : Only those actuators that indicate that they have closed , No other practical functions
SimpleExecutor : One of the simplest actuators
BatchExecutor : Actuators that support batch execution
ReuseExecutor : Support Statement Object reuse executor .
SimpleExecutor,BatchExecutor,ReuseExecutor The choice of these three actuators is in mybatis In the configuration file of , The optional values are defined by session In bag ExecutorType Definition , These three actuators are mainly based on StatementHandler Finish creating Statement object , Binding parameters, etc .
边栏推荐
- systemctl php配置文件
- Redis series - five common data types day1-3
- Sanic based services use celery to complete dynamic modification timing tasks
- 十大证券公司哪个佣金手续费最低,最安全可靠?
- Jemter 压力测试 -可视化工具-【使用篇】
- Junit
- Take you three minutes to get started typescript
- You can command Siri without making a sound! The Chinese team of Cornell University developed the silent language recognition necklace. Chinese and English are OK
- Liquid crystal texture diagram of purple solid mm-tpp-10c methacrylic acid decanoxy tetraphenyl porphyrin and mm-tpp-12c methacrylic acid dodecanoxy tetraphenyl porphyrin - Qi Yue display
- Cloud native integration data warehouse heavy release
猜你喜欢

My colleague asked a question I never thought about. Why did kubernetes' superfluous' launch the static pod concept?

Oracle中计算除法——解决除数为零报错
![[North Asia data recovery] a server data recovery method in which the partitions in the RAID5 array are formatted due to the misoperation of the NTFS file system](/img/4d/01310b489ca6a599a125e849ae4856.jpg)
[North Asia data recovery] a server data recovery method in which the partitions in the RAID5 array are formatted due to the misoperation of the NTFS file system

Kalman filter_ Recursive Processing

How MySQL implements the RC transaction isolation level

The first multi platform webcast of 2021ccf award ceremony pays tribute to the winners! CCF outstanding engineer

B站增量数据湖探索与实践

Solution to the problem of multi application routing using thinkphp6.0

A bold sounding and awesome operation - remake a Netflix

Jemter 壓力測試 -基礎請求-【教學篇】
随机推荐
[UVM practice] Chapter 2: a simple UVM verification platform (3) add various components to the verification platform
[UVM basics] connect of UVM_ Phase execution sequence
JMeter stress test web agent local interface test [teaching]
Nine hours, nine people and nine doors (01 backpack deformation) - Niuke
Junit
Error reported by using two-dimensional array [[]] in thymeleaf: could not parse as expression
Qt基础教程:QString
13. Mismatch simulation of power synthesis for ads usage recording
Is it legal to open an account for compass stock trading software? Is it safe?
Pycharm settings
JS modularization
Jemter 壓力測試 -基礎請求-【教學篇】
Detailed materials of applying for residence permit in non local Beijing
C implementation adds a progress bar display effect to the specified column of the GridView table in devaxpress - code implementation method
Xiaosha's counting (bit operation, Combinatorial Mathematics) - Niuke
Apache inlong graduated as a top-level project with a million billion level data stream processing capability!
Machine learning - Iris Flower classification
Iron / zinc / copper / platinum metal complexes such as 5,10,15,20-tetra (4-hydroxyphenyl) porphyrin (THPP) / (thppfe) / (thppzn) / (thppcu) / (thpppt) - Qiyue R & D
Oracle creates stored procedures with return values and executes SQL calls
Children play games (greed, prefix and) - Niuke winter vacation training camp