本文整理汇总了Java中org.apache.ibatis.mapping.MappedStatement.getConfiguration方法的典型用法代码示例。如果您正苦于以下问题:Java MappedStatement.getConfiguration方法的具体用法?Java MappedStatement.getConfiguration怎么用?Java MappedStatement.getConfiguration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ibatis.mapping.MappedStatement
的用法示例。
在下文中一共展示了MappedStatement.getConfiguration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: intercept
import org.apache.ibatis.mapping.MappedStatement; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
Object object=invocation.getArgs()[0];
if(object instanceof MappedStatement){
MappedStatement statement=(MappedStatement) object;
Configuration config = statement.getConfiguration();
DataSource dataSource= config.getEnvironment().getDataSource();
if(dataSource instanceof DynamicDataSource){
DynamicDataSource dynamicDataSource=((DynamicDataSource)dataSource);
Dialect dialect= dynamicDataSource.getDialect();
if(pageHelpers.containsKey(dialect)){
log.debug("将使用{}的PageHelper....",dialect);
return pageHelpers.get(dialect).intercept(invocation);
}else{
log.debug("将使用默认的PageHelper,dialect=({})的....",this.dialect);
}
}else{
log.debug("将使用默认的PageHelper,dialect=({})的....",this.dialect);
}
}else{
log.debug("将使用默认的PageHelper,dialect=({})的....",this.dialect);
}
return pageHelper.intercept(invocation);
}
示例5: executeQueryCount
import org.apache.ibatis.mapping.MappedStatement; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
private Long executeQueryCount(Executor executor, MappedStatement countMs, Object parameter,
BoundSql boundSql, RowBounds rowBounds,
ResultHandler resultHandler) throws IllegalAccessException,
SQLException {
CacheKey countKey = executor.createCacheKey(countMs, parameter, RowBounds.DEFAULT,
boundSql);
String orignSql = boundSql.getSql().replaceAll(";$", "");
// count sql
String countSql = PageSqlUtils.getCountSql(orignSql);
BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql,
boundSql.getParameterMappings(), parameter);
// 执行 count 查询
Object countResultList = executor.query(countMs, parameter, RowBounds.DEFAULT,
resultHandler, countKey, countBoundSql);
Long count = (Long) ((List) countResultList).get(0);
return count;
}
示例6: getCount
import org.apache.ibatis.mapping.MappedStatement; //导入方法依赖的package包/类
/**
* 查询总纪录数
*
* @param sql
* SQL语句
* @param connection
* 数据库连接
* @param mappedStatement
* mapped
* @param parameterObject
* 参数
* @param boundSql
* boundSql
* @param dialect
* database dialect
* @return 总记录数
* @throws java.sql.SQLException
* sql查询错误
*/
public static int getCount(final String sql, final Connection connection,
final MappedStatement mappedStatement,
final Object parameterObject, final BoundSql boundSql,
Dialect dialect) throws SQLException {
final String count_sql = dialect.getCount(sql);
PreparedStatement countStmt = null;
ResultSet rs = null;
try {
countStmt = connection.prepareStatement(count_sql);
final BoundSql countBS = new BoundSql(
mappedStatement.getConfiguration(), count_sql,
boundSql.getParameterMappings(), parameterObject);
setParameters(countStmt, mappedStatement, countBS, parameterObject);
rs = countStmt.executeQuery();
int count = 0;
if (rs.next()) {
count = rs.getInt(1);
}
return count;
} finally {
if (null != rs) {
rs.close();
}
if (null != countStmt) {
countStmt.close();
}
if (null != connection) {
connection.close();
}
}
}
示例7: MybatisDefaultParameterHandler
import org.apache.ibatis.mapping.MappedStatement; //导入方法依赖的package包/类
public MybatisDefaultParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
super(mappedStatement, processBatch(mappedStatement, parameterObject), boundSql);
this.mappedStatement = mappedStatement;
this.configuration = mappedStatement.getConfiguration();
this.typeHandlerRegistry = mappedStatement.getConfiguration().getTypeHandlerRegistry();
this.parameterObject = parameterObject;
this.boundSql = boundSql;
}
示例8: processIntercept
import org.apache.ibatis.mapping.MappedStatement; //导入方法依赖的package包/类
void processIntercept(final Object[] queryArgs) {
MappedStatement ms = (MappedStatement) queryArgs[MAPPED_STATEMENT_INDEX];
Object parameter = queryArgs[PARAMETER_INDEX];
final RowBounds rowBounds = (RowBounds) queryArgs[ROWBOUNDS_INDEX];
int offset = rowBounds.getOffset();
int limit = rowBounds.getLimit();
if (dialect.supportsLimit() && (offset != RowBounds.NO_ROW_OFFSET || limit != RowBounds.NO_ROW_LIMIT)) {
BoundSql boundSql = ms.getBoundSql(parameter);
String sql = boundSql.getSql().trim();
if (dialect.supportsLimitOffset()) {
sql = dialect.getLimitString(sql, offset, limit);
offset = RowBounds.NO_ROW_OFFSET;
} else {
sql = dialect.getLimitString(sql, 0, limit);
}
limit = RowBounds.NO_ROW_LIMIT;
queryArgs[ROWBOUNDS_INDEX] = new RowBounds(offset, limit);
BoundSql newBoundSql = new BoundSql(ms.getConfiguration(), sql, boundSql.getParameterMappings(),
boundSql.getParameterObject());
for (ParameterMapping mapping : boundSql.getParameterMappings()) {
String prop = mapping.getProperty();
if (boundSql.hasAdditionalParameter(prop)) {
newBoundSql.setAdditionalParameter(prop, boundSql.getAdditionalParameter(prop));
}
}
MappedStatement newMs = copyFromMappedStatement(ms, new BoundSqlSqlSource(newBoundSql));
queryArgs[MAPPED_STATEMENT_INDEX] = newMs;
}
}
示例9: 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();
}
示例10: intercept
import org.apache.ibatis.mapping.MappedStatement; //导入方法依赖的package包/类
public Object intercept(Invocation invocation) throws Throwable {
MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
Object parameter = null;
if (invocation.getArgs().length > 1) {
parameter = invocation.getArgs()[1];
}
String sqlId = mappedStatement.getId();
BoundSql boundSql = mappedStatement.getBoundSql(parameter);
Configuration configuration = mappedStatement.getConfiguration();
Object returnValue = null;
long start = System.currentTimeMillis();
String sql = getSql(configuration, boundSql, sqlId);
System.err.println("========================================================");
System.err.println("https://hpit-bat.github.io/hpit-BAT-home"+"[隐无为]");
System.err.println("========================================================");
System.err.println("执行XML方法:"+sqlId);
System.err.println("执行的完整的sql语句-------------------mysad");
System.err.println(sql);
returnValue = invocation.proceed();
long end = System.currentTimeMillis();
long time = (end - start);
if (time > 1) {
System.err.println("执行的sql语句的时间:"+time+"ms");
}
return returnValue;
}
示例11: DefaultParameterHandler
import org.apache.ibatis.mapping.MappedStatement; //导入方法依赖的package包/类
public DefaultParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
this.mappedStatement = mappedStatement;
this.configuration = mappedStatement.getConfiguration();
this.typeHandlerRegistry = mappedStatement.getConfiguration().getTypeHandlerRegistry();
this.parameterObject = parameterObject;
this.boundSql = boundSql;
}
示例12: copyFromBoundSql
import org.apache.ibatis.mapping.MappedStatement; //导入方法依赖的package包/类
private BoundSql copyFromBoundSql(MappedStatement ms, BoundSql boundSql,
String sql, List<ParameterMapping> parameterMappings,Object parameter) {
BoundSql newBoundSql = new BoundSql(ms.getConfiguration(),sql, parameterMappings, parameter);
for (ParameterMapping mapping : boundSql.getParameterMappings()) {
String prop = mapping.getProperty();
if (boundSql.hasAdditionalParameter(prop)) {
newBoundSql.setAdditionalParameter(prop, boundSql.getAdditionalParameter(prop));
}
}
return newBoundSql;
}
示例13: 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();
}
示例14: 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();
}
示例15: setParameters
import org.apache.ibatis.mapping.MappedStatement; //导入方法依赖的package包/类
/**
* 对SQL参数(?)设值,参考org.apache.ibatis.executor.parameter.
* DefaultParameterHandler
*
* @param ps
* 表示预编译的 SQL 语句的对象。
* @param mappedStatement
* MappedStatement
* @param boundSql
* SQL
* @param parameterObject
* 参数对象
* @throws java.sql.SQLException
* 数据库异常
*/
public static void setParameters(PreparedStatement ps,
MappedStatement mappedStatement, BoundSql boundSql,
Object parameterObject) throws SQLException {
ErrorContext.instance().activity("setting parameters")
.object(mappedStatement.getParameterMap().getId());
List<ParameterMapping> parameterMappings = boundSql
.getParameterMappings();
if (null != parameterMappings) {
Configuration configuration = mappedStatement.getConfiguration();
TypeHandlerRegistry typeHandlerRegistry = configuration
.getTypeHandlerRegistry();
MetaObject metaObject = parameterObject == null ? null
: configuration.newMetaObject(parameterObject);
for (int i = 0; i < parameterMappings.size(); i++) {
ParameterMapping parameterMapping = parameterMappings.get(i);
if (parameterMapping.getMode() != ParameterMode.OUT) {
Object value;
String propertyName = parameterMapping.getProperty();
PropertyTokenizer prop = new PropertyTokenizer(propertyName);
if (null == parameterObject) {
value = null;
} else if (typeHandlerRegistry
.hasTypeHandler(parameterObject.getClass())) {
value = parameterObject;
} else if (boundSql.hasAdditionalParameter(propertyName)) {
value = boundSql.getAdditionalParameter(propertyName);
} else if (propertyName
.startsWith(ForEachSqlNode.ITEM_PREFIX)
&& boundSql.hasAdditionalParameter(prop.getName())) {
value = boundSql.getAdditionalParameter(prop.getName());
if (null != value) {
value = configuration.newMetaObject(value)
.getValue(
propertyName.substring(prop
.getName().length()));
}
} else {
value = metaObject == null ? null : metaObject
.getValue(propertyName);
}
TypeHandler typeHandler = parameterMapping.getTypeHandler();
if (null == typeHandler) {
throw new ExecutorException(
"There was no TypeHandler found for parameter "
+ propertyName + " of statement "
+ mappedStatement.getId());
}
typeHandler.setParameter(ps, i + 1, value,
parameterMapping.getJdbcType());
}
}
}
}