本文整理了Java中org.apache.ibatis.mapping.BoundSql
类的一些代码示例,展示了BoundSql
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BoundSql
类的具体详情如下:
包路径:org.apache.ibatis.mapping.BoundSql
类名称:BoundSql
[英]An actual SQL String got from an SqlSource after having processed any dynamic content. The SQL may have SQL placeholders "?" and an list (ordered) of an parameter mappings with the additional information for each parameter (at least the property name of the input object to read the value from).
Can also have additional parameters that are created by the dynamic language (for loops, bind...).
[中]处理任何动态内容后从SqlSource获取的实际SQL字符串。SQL可能有SQL占位符“?”以及参数映射列表(有序),其中包含每个参数的附加信息(至少是要从中读取值的输入对象的属性名)。
还可以具有由动态语言创建的其他参数(对于循环,绑定…)。
代码示例来源:origin: wuyouzhuguli/FEBS-Shiro
private static String showSql(Configuration configuration, BoundSql boundSql) {
Object parameterObject = boundSql.getParameterObject();
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
String sql = boundSql.getSql().replaceAll("[\\s]+", " ");
if (!CollectionUtils.isEmpty(parameterMappings) && parameterObject != null) {
TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
sql = sql.replaceFirst("\\?", Matcher.quoteReplacement(getParameterValue(parameterObject)));
MetaObject metaObject = configuration.newMetaObject(parameterObject);
for (ParameterMapping parameterMapping : parameterMappings) {
String propertyName = parameterMapping.getProperty();
Object obj = metaObject.getValue(propertyName);
sql = sql.replaceFirst("\\?", Matcher.quoteReplacement(getParameterValue(obj)));
} else if (boundSql.hasAdditionalParameter(propertyName)) {
Object obj = boundSql.getAdditionalParameter(propertyName);
代码示例来源:origin: a466350665/smart
try {
countStmt = connection.prepareStatement(countSql);
BoundSql countBS = new BoundSql(mappedStatement.getConfiguration(), countSql,
boundSql.getParameterMappings(), boundSql.getParameterObject());
setParameters(countStmt, mappedStatement, countBS, boundSql.getParameterObject());
rs = countStmt.executeQuery();
int rowCount = 0;
代码示例来源:origin: pagehelper/Mybatis-PageHelper
BoundSql countBoundSql = new BoundSql(countMs.getConfiguration(), countSql, boundSql.getParameterMappings(), parameter);
countBoundSql.setAdditionalParameter(key, additionalParameters.get(key));
代码示例来源:origin: makersoft/mybatis-shards
private BoundSql buildBoundSql(MappedStatement ms, BoundSql boundSql, String sql) {
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));
}
}
return newBoundSql;
}
代码示例来源:origin: camunda/camunda-bpm-platform
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();
Object value;
String propertyName = parameterMapping.getProperty();
if (boundSql.hasAdditionalParameter(propertyName)) {
value = boundSql.getAdditionalParameter(propertyName);
} else if (parameterObject == null) {
value = null;
value = parameterObject;
} else {
MetaObject metaObject = configuration.newMetaObject(parameterObject);
value = metaObject.getValue(propertyName);
if (configuration.getEnvironment() != null) {
cacheKey.update(configuration.getEnvironment().getId());
代码示例来源:origin: baomidou/mybatis-plus
@Override
@SuppressWarnings("unchecked")
public void setParameters(PreparedStatement ps) {
ErrorContext.instance().activity("setting parameters").object(mappedStatement.getParameterMap().getId());
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
if (parameterMappings != null) {
for (int i = 0; i < parameterMappings.size(); i++) {
Object value;
String propertyName = parameterMapping.getProperty();
if (boundSql.hasAdditionalParameter(propertyName)) { // issue #448 ask first for additional params
value = boundSql.getAdditionalParameter(propertyName);
} else if (parameterObject == null) {
value = null;
value = parameterObject;
} else {
MetaObject metaObject = configuration.newMetaObject(parameterObject);
value = metaObject.getValue(propertyName);
JdbcType jdbcType = parameterMapping.getJdbcType();
if (value == null && jdbcType == null) {
jdbcType = configuration.getJdbcTypeForNull();
代码示例来源:origin: Meituan-Dianping/Zebra
private Object queryLimit(Invocation invocation, Object[] args, MappedStatement ms, BoundSql boundSql, RowBounds rb)
throws InvocationTargetException, IllegalAccessException {
String limitSql = dialect.getLimitSql(boundSql.getSql(), rb.getOffset(), rb.getLimit());
BoundSql newBoundSql = new BoundSql(ms.getConfiguration(), limitSql, boundSql.getParameterMappings(),
boundSql.getParameterObject());
MetaObject mo = (MetaObject) ReflectionUtils.getFieldValue(boundSql, "metaParameters");
ReflectionUtils.setFieldValue(newBoundSql, "metaParameters", mo);
args[0] = buildMappedStatement(ms, new SqlSourceWrapper(newBoundSql), ms.getId() + "_LIMIT",
ms.getResultMaps());
args[2] = new RowBounds();
args[3] = null;
try {
DaoContextHolder.setSqlName(buildDaoName(ms.getId()) + "_LIMIT");
return invocation.proceed();
} finally {
DaoContextHolder.clearSqlName();
}
}
代码示例来源:origin: mybatis-book/book
@SuppressWarnings("rawtypes")
@Override
public Object intercept(Invocation invocation) throws Throwable {
Executor executor = (Executor)invocation.getTarget();
Object[] args = invocation.getArgs();
MappedStatement ms = (MappedStatement)args[0];
Object parameterObject = args[1];
RowBounds rowBounds = (RowBounds)args[2];
ResultHandler resultHandler = (ResultHandler)args[3];
BoundSql boundSql = ms.getBoundSql(parameterObject);
CacheKey pageKey = null, countKey = null;
if(executor instanceof CachingExecutor){
pageKey = ((CachingExecutor)executor).createCacheKey(ms, parameterObject, rowBounds, boundSql);
countKey = ((CachingExecutor)executor).createCacheKey(ms, parameterObject, rowBounds, boundSql);
} else {
pageKey = ((BaseExecutor)executor).createCacheKey(ms, parameterObject, rowBounds, boundSql);
countKey = ((BaseExecutor)executor).createCacheKey(ms, parameterObject, rowBounds, boundSql);
}
countKey.update("Count");
BoundSql countSql = new BoundSql(ms.getConfiguration(), "select count(*) from (" + boundSql.getSql() + ") temp", boundSql.getParameterMappings(), parameterObject);
Object r2 = executor.query(ms, parameterObject, rowBounds, resultHandler, pageKey, boundSql);
MappedStatement countMs = newMappedStatement(ms, Long.class);
Object r1 = executor.query(countMs, parameterObject, rowBounds, resultHandler, countKey, countSql);
System.out.println(r1);
return r2;
}
代码示例来源:origin: baomidou/mybatis-plus
if (!SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) {
return invocation.proceed();
Object paramObj = boundSql.getParameterObject();
String originalSql = boundSql.getSql();
Connection connection = (Connection) invocation.getArgs()[0];
DbType dbType = StringUtils.isNotEmpty(dialectType) ? DbType.getDbType(dialectType)
Configuration configuration = mappedStatement.getConfiguration();
List<ParameterMapping> mappings = new ArrayList<>(boundSql.getParameterMappings());
Map<String, Object> additionalParameters = (Map<String, Object>) metaObject.getValue("delegate.boundSql.additionalParameters");
model.consumers(mappings, configuration, additionalParameters);
代码示例来源:origin: miemiedev/mybatis-paginator
public Object call() throws Exception {
Integer count;
Cache cache = ms.getCache();
if(cache != null && ms.isUseCache() && ms.getConfiguration().isCacheEnabled()){
CacheKey cacheKey = executor.createCacheKey(ms,parameter,new PageBounds(),copyFromBoundSql(ms,boundSql,dialect.getCountSQL(), boundSql.getParameterMappings(), boundSql.getParameterObject()));
count = (Integer)cache.getObject(cacheKey);
if(count == null){
count = SQLHelp.getCount(ms,executor.getTransaction(),parameter,boundSql,dialect);
cache.putObject(cacheKey, count);
}
}else{
count = SQLHelp.getCount(ms,executor.getTransaction(),parameter,boundSql,dialect);
}
return new Paginator(pageBounds.getPage(), pageBounds.getLimit(), count);
}
};
代码示例来源:origin: mybatis-book/book
RowBounds rowBounds = (RowBounds) args[2];
BoundSql boundSql = ms.getBoundSql(parameterObject);
if (dialect.beforeCount(ms.getId(), parameterObject, rowBounds)){
rowBounds,
countKey);
BoundSql countBoundSql = new BoundSql(
ms.getConfiguration(),
countSql,
boundSql.getParameterMappings(),
parameterObject);
countBoundSql.setAdditionalParameter(
key, additionalParameters.get(key));
rowBounds,
pageKey);
BoundSql pageBoundSql = new BoundSql(
ms.getConfiguration(),
pageSql,
boundSql.getParameterMappings(),
parameterObject);
pageBoundSql.setAdditionalParameter(
key, additionalParameters.get(key));
代码示例来源:origin: pagehelper/Mybatis-PageHelper
@Override
public String getCountSql(MappedStatement ms, BoundSql boundSql, Object parameterObject, RowBounds rowBounds, CacheKey countKey) {
return countSqlParser.getSmartCountSql(boundSql.getSql());
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Override
public int executeNonEmptyUpdateStmt(String updateStmt, Object parameter) {
updateStmt = dbSqlSessionFactory.mapStatement(updateStmt);
//if mapped statement is empty, which can happens for some databases, we have no need to execute it
MappedStatement mappedStatement = sqlSession.getConfiguration().getMappedStatement(updateStmt);
if (mappedStatement.getBoundSql(parameter).getSql().isEmpty())
return 0;
return sqlSession.update(updateStmt, parameter);
}
代码示例来源:origin: camunda/camunda-bpm-platform
public BoundSql getBoundSql(Object parameterObject) {
BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
if (parameterMappings == null || parameterMappings.isEmpty()) {
boundSql = new BoundSql(configuration, boundSql.getSql(), parameterMap.getParameterMappings(), parameterObject);
}
// check for nested result maps in parameter mappings (issue #30)
for (ParameterMapping pm : boundSql.getParameterMappings()) {
String rmId = pm.getResultMapId();
if (rmId != null) {
ResultMap rm = configuration.getResultMap(rmId);
if (rm != null) {
hasNestedResultMaps |= rm.hasNestedResultMaps();
}
}
}
return boundSql;
}
代码示例来源:origin: pagehelper/Mybatis-PageHelper
protected void handleParameter(BoundSql boundSql, MappedStatement ms){
if (boundSql.getParameterMappings() != null) {
List<ParameterMapping> newParameterMappings = new ArrayList<ParameterMapping>(boundSql.getParameterMappings());
newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_FIRST, Integer.class).build());
newParameterMappings.add(new ParameterMapping.Builder(ms.getConfiguration(), PAGEPARAMETER_SECOND, Integer.class).build());
MetaObject metaObject = MetaObjectUtil.forObject(boundSql);
metaObject.setValue("parameterMappings", newParameterMappings);
}
}
}
代码示例来源:origin: pagehelper/Mybatis-PageHelper
boolean hasTypeHandler = ms.getConfiguration().getTypeHandlerRegistry().hasTypeHandler(parameterObject.getClass());
MetaObject metaObject = MetaObjectUtil.forObject(parameterObject);
if (boundSql.getParameterMappings() != null && boundSql.getParameterMappings().size() > 0) {
for (ParameterMapping parameterMapping : boundSql.getParameterMappings()) {
String name = parameterMapping.getProperty();
if (!name.equals(PAGEPARAMETER_FIRST)
代码示例来源:origin: camunda/camunda-bpm-platform
@Override
public int doUpdate(MappedStatement ms, Object parameterObject) throws SQLException {
final Configuration configuration = ms.getConfiguration();
final StatementHandler handler = configuration.newStatementHandler(this, ms, parameterObject, RowBounds.DEFAULT, null, null);
final BoundSql boundSql = handler.getBoundSql();
final String sql = boundSql.getSql();
final Statement stmt;
if (sql.equals(currentSql) && ms.equals(currentStatement)) {
int last = statementList.size() - 1;
stmt = statementList.get(last);
applyTransactionTimeout(stmt);
handler.parameterize(stmt);//fix Issues 322
BatchResult batchResult = batchResultList.get(last);
batchResult.addParameterObject(parameterObject);
} else {
Connection connection = getConnection(ms.getStatementLog());
stmt = handler.prepare(connection, transaction.getTimeout());
handler.parameterize(stmt); //fix Issues 322
currentSql = sql;
currentStatement = ms;
statementList.add(stmt);
batchResultList.add(new BatchResult(ms, sql, parameterObject));
}
// handler.parameterize(stmt);
handler.batch(stmt);
return BATCH_UPDATE_RETURN_VALUE;
}
代码示例来源:origin: org.apache.ibatis/ibatis-core
protected void rebindGeneratedKey() {
if (boundSql.getParameterObject() != null) {
String keyStatementName = mappedStatement.getId() + SelectKeyGenerator.SELECT_KEY_SUFFIX;
if (configuration.hasStatement(keyStatementName)) {
MappedStatement keyStatement = configuration.getMappedStatement(keyStatementName);
if (keyStatement != null) {
String keyProperty = keyStatement.getKeyProperty();
MetaObject metaParam = configuration.newMetaObject(boundSql.getParameterObject());
if (keyProperty != null && metaParam.hasSetter(keyProperty) && metaParam.hasGetter(keyProperty)) {
boundSql.setAdditionalParameter(keyProperty, metaParam.getValue(keyProperty));
}
}
}
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Override
public int update(Statement statement) throws SQLException {
String sql = boundSql.getSql();
Object parameterObject = boundSql.getParameterObject();
KeyGenerator keyGenerator = mappedStatement.getKeyGenerator();
int rows;
if (keyGenerator instanceof Jdbc3KeyGenerator) {
statement.execute(sql, Statement.RETURN_GENERATED_KEYS);
rows = statement.getUpdateCount();
keyGenerator.processAfter(executor, mappedStatement, statement, parameterObject);
} else if (keyGenerator instanceof SelectKeyGenerator) {
statement.execute(sql);
rows = statement.getUpdateCount();
keyGenerator.processAfter(executor, mappedStatement, statement, parameterObject);
} else {
statement.execute(sql);
rows = statement.getUpdateCount();
}
return rows;
}
代码示例来源:origin: camunda/camunda-bpm-platform
private void ensureNoOutParams(MappedStatement ms, Object parameter, BoundSql boundSql) {
if (ms.getStatementType() == StatementType.CALLABLE) {
for (ParameterMapping parameterMapping : boundSql.getParameterMappings()) {
if (parameterMapping.getMode() != ParameterMode.IN) {
throw new ExecutorException("Caching stored procedures with OUT params is not supported. Please configure useCache=false in " + ms.getId() + " statement.");
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!