本文整理匯總了Java中org.apache.ibatis.mapping.MappedStatement.getSqlCommandType方法的典型用法代碼示例。如果您正苦於以下問題:Java MappedStatement.getSqlCommandType方法的具體用法?Java MappedStatement.getSqlCommandType怎麽用?Java MappedStatement.getSqlCommandType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.ibatis.mapping.MappedStatement
的用法示例。
在下文中一共展示了MappedStatement.getSqlCommandType方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: intercept
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
public Object intercept(Invocation invocation) throws Throwable {
/**
* 處理 DELETE UPDATE 語句
*/
MappedStatement ms = (MappedStatement) invocation.getArgs()[0];
if (ms.getSqlCommandType() == SqlCommandType.DELETE || ms.getSqlCommandType() == SqlCommandType.UPDATE) {
Executor executor = (Executor) invocation.getTarget();
Configuration configuration = ms.getConfiguration();
Object parameter = invocation.getArgs()[1];
BoundSql boundSql = ms.getBoundSql(parameter);
Connection connection = executor.getTransaction().getConnection();
String databaseVersion = connection.getMetaData().getDatabaseProductVersion();
if (GlobalConfigUtils.getDbType(configuration).equals(DBType.MYSQL)
&& VersionUtils.compare(minMySQLVersion, databaseVersion)) {
logger.warn("Warn: Your mysql version needs to be greater than '5.6.3' to execute of Sql Explain!");
return invocation.proceed();
}
/**
* 執行 SQL 分析
*/
sqlExplain(configuration, ms, boundSql, connection, parameter);
}
return invocation.proceed();
}
示例2: copyFromMappedStatement
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
private MappedStatement copyFromMappedStatement(MappedStatement ms,
SqlSource newSqlSource) {
MappedStatement.Builder builder = new MappedStatement.Builder(
ms.getConfiguration(), ms.getId(), newSqlSource,
ms.getSqlCommandType());
builder.resource(ms.getResource());
builder.fetchSize(ms.getFetchSize());
builder.statementType(ms.getStatementType());
builder.keyGenerator(ms.getKeyGenerator());
if (null != ms.getKeyProperties()) {
for (String keyProperty : ms.getKeyProperties()) {
builder.keyProperty(keyProperty);
}
}
builder.timeout(ms.getTimeout());
builder.parameterMap(ms.getParameterMap());
builder.resultMaps(ms.getResultMaps());
builder.cache(ms.getCache());
return builder.build();
}
示例3: copyFromMappedStatement
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
private MappedStatement copyFromMappedStatement(MappedStatement ms, SqlSource newSqlSource) {
Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), newSqlSource,
ms.getSqlCommandType());
builder.resource(ms.getResource());
builder.fetchSize(ms.getFetchSize());
builder.statementType(ms.getStatementType());
builder.keyGenerator(ms.getKeyGenerator());
// builder.keyProperty((ms.getKeyProperty()));
builder.keyProperty(arrayToStr(ms.getKeyProperties()));
// setStatementTimeout()
builder.timeout(ms.getTimeout());
// setStatementResultMap()
builder.parameterMap(ms.getParameterMap());
// setStatementResultMap()
builder.resultMaps(ms.getResultMaps());
builder.resultSetType(ms.getResultSetType());
// setStatementCache()
builder.cache(ms.getCache());
builder.flushCacheRequired(ms.isFlushCacheRequired());
builder.useCache(ms.isUseCache());
return builder.build();
}
示例4: setupCommandType
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
/**
* 設置當前的參數的類型信息
*/
private void setupCommandType() {
MappedStatement ms = config.getMappedStatement(commandName);
type = ms.getSqlCommandType();
if (type != SqlCommandType.SELECT) {
throw new BindingException("Unsupport execution method for: "
+ commandName);
}
}
示例5: populateKeys
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
/**
* <p>
* 自定義元對象填充控製器
* </p>
*
* @param metaObjectHandler 元數據填充處理器
* @param tableInfo 數據庫表反射信息
* @param ms MappedStatement
* @param parameterObject 插入數據庫對象
* @return Object
*/
protected static Object populateKeys(MetaObjectHandler metaObjectHandler, TableInfo tableInfo,
MappedStatement ms, Object parameterObject) {
if (null == tableInfo || StringUtils.isEmpty(tableInfo.getKeyProperty()) || null == tableInfo.getIdType()) {
/* 不處理 */
return parameterObject;
}
/* 自定義元對象填充控製器 */
MetaObject metaObject = ms.getConfiguration().newMetaObject(parameterObject);
if (ms.getSqlCommandType() == SqlCommandType.INSERT) {
if (IdType.ID_WORKER.equals(tableInfo.getIdType()) || IdType.UUID.equals(tableInfo.getIdType())) {
Object idValue = metaObject.getValue(tableInfo.getKeyProperty());
/* 自定義 ID */
if (StringUtils.checkValNull(idValue)) {
if (IdType.ID_WORKER.equals(tableInfo.getIdType())) {
metaObject.setValue(tableInfo.getKeyProperty(), IdWorker.getId());
} else if (IdType.UUID.equals(tableInfo.getIdType())) {
metaObject.setValue(tableInfo.getKeyProperty(), IdWorker.get32UUID());
}
}
}
// 插入填充
if (metaObjectHandler.openInsertFill()) {
metaObjectHandler.insertFill(metaObject);
}
} else if (ms.getSqlCommandType() == SqlCommandType.UPDATE && metaObjectHandler.openUpdateFill()) {
// 更新填充
metaObjectHandler.updateFill(metaObject);
}
return metaObject.getOriginalObject();
}
示例6: createCountMappedStatement
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
private MappedStatement createCountMappedStatement(MappedStatement ms, String newMsId) {
MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), newMsId, ms.getSqlSource(), ms.getSqlCommandType());
builder.resource(ms.getResource());
builder.fetchSize(ms.getFetchSize());
builder.statementType(ms.getStatementType());
builder.keyGenerator(ms.getKeyGenerator());
if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
StringBuilder keyProperties = new StringBuilder();
for (String keyProperty : ms.getKeyProperties()) {
keyProperties.append(keyProperty).append(",");
}
keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
builder.keyProperty(keyProperties.toString());
}
builder.timeout(ms.getTimeout());
builder.parameterMap(ms.getParameterMap());
//count查詢返回值int
List<ResultMap> resultMaps = new ArrayList<ResultMap>();
ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), Long.class, new ArrayList<ResultMapping>(0)).build();
resultMaps.add(resultMap);
builder.resultMaps(resultMaps);
builder.resultSetType(ms.getResultSetType());
builder.cache(ms.getCache());
builder.flushCacheRequired(ms.isFlushCacheRequired());
builder.useCache(ms.isUseCache());
return builder.build();
}
示例7: copyFromMappedStatement
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
private MappedStatement copyFromMappedStatement(MappedStatement ms,SqlSource newSqlSource) {
Builder builder = new Builder(ms.getConfiguration(),ms.getId(),newSqlSource,ms.getSqlCommandType());
builder.resource(ms.getResource());
builder.fetchSize(ms.getFetchSize());
builder.statementType(ms.getStatementType());
builder.keyGenerator(ms.getKeyGenerator());
if(ms.getKeyProperties() != null && ms.getKeyProperties().length !=0){
StringBuffer keyProperties = new StringBuffer();
for(String keyProperty : ms.getKeyProperties()){
keyProperties.append(keyProperty).append(",");
}
keyProperties.delete(keyProperties.length()-1, keyProperties.length());
builder.keyProperty(keyProperties.toString());
}
//setStatementTimeout()
builder.timeout(ms.getTimeout());
//setStatementResultMap()
builder.parameterMap(ms.getParameterMap());
//setStatementResultMap()
builder.resultMaps(ms.getResultMaps());
builder.resultSetType(ms.getResultSetType());
//setStatementCache()
builder.cache(ms.getCache());
builder.flushCacheRequired(ms.isFlushCacheRequired());
builder.useCache(ms.isUseCache());
return builder.build();
}
示例8: copyFromMappedStatement
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
private MappedStatement copyFromMappedStatement(MappedStatement ms, SqlSource newSqlSource)
{
Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), newSqlSource, ms.getSqlCommandType());
builder.resource(ms.getResource());
builder.fetchSize(ms.getFetchSize());
builder.statementType(ms.getStatementType());
builder.keyGenerator(ms.getKeyGenerator());
String[] arr = ms.getKeyProperties();
if(arr != null && arr.length > 0)
{
StringBuilder sb = new StringBuilder();
for(String s : arr)
{
sb.append(",").append(s);
}
if(sb.length() > 0)
{
sb.delete(0, 1);
}
builder.keyProperty(sb.toString());
}
// setStatementTimeout()
builder.timeout(ms.getTimeout());
// setStatementResultMap()
builder.parameterMap(ms.getParameterMap());
// setStatementResultMap()
builder.resultMaps(ms.getResultMaps());
builder.resultSetType(ms.getResultSetType());
// setStatementCache()
builder.cache(ms.getCache());
builder.flushCacheRequired(ms.isFlushCacheRequired());
builder.useCache(ms.isUseCache());
return builder.build();
}
示例9: getCountMappedStatement
import org.apache.ibatis.mapping.MappedStatement; //導入方法依賴的package包/類
/**
* 新建count查詢的MappedStatement
*
* @param ms
* @return
*/
public MappedStatement getCountMappedStatement(MappedStatement ms) {
String newMsId = ms.getId() + PAGE_COUNT_SUFFIX;
MappedStatement statement = null;
Configuration configuration = ms.getConfiguration();
try {
statement = configuration.getMappedStatement(newMsId);
if (statement != null) { return statement; }
} catch (Exception e) {
}
synchronized (configuration) {
if (configuration.hasStatement(newMsId)) { return configuration.getMappedStatement(newMsId); }
MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(),
newMsId, ms.getSqlSource(), ms.getSqlCommandType());
builder.resource(ms.getResource());
builder.fetchSize(ms.getFetchSize());
builder.statementType(ms.getStatementType());
builder.keyGenerator(ms.getKeyGenerator());
if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
StringBuilder keyProperties = new StringBuilder();
for (String keyProperty : ms.getKeyProperties()) {
keyProperties.append(keyProperty).append(",");
}
keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
builder.keyProperty(keyProperties.toString());
}
builder.timeout(ms.getTimeout());
builder.parameterMap(ms.getParameterMap());
//count查詢返回值int
List<ResultMap> resultMaps = new ArrayList<ResultMap>();
String id = newMsId + "-Inline";
ResultMap resultMap = new ResultMap.Builder(configuration, id, Long.class,
new ArrayList<ResultMapping>(0)).build();
resultMaps.add(resultMap);
builder.resultMaps(resultMaps);
builder.resultSetType(ms.getResultSetType());
builder.cache(ms.getCache());
builder.flushCacheRequired(ms.isFlushCacheRequired());
builder.useCache(ms.isUseCache());
statement = builder.build();
configuration.addMappedStatement(statement);
return statement;
}
}