本文整理汇总了Java中org.apache.ibatis.mapping.BoundSql.getParameterMappings方法的典型用法代码示例。如果您正苦于以下问题:Java BoundSql.getParameterMappings方法的具体用法?Java BoundSql.getParameterMappings怎么用?Java BoundSql.getParameterMappings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ibatis.mapping.BoundSql
的用法示例。
在下文中一共展示了BoundSql.getParameterMappings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeQueryCount
import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的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;
}
示例2: handleLocallyCachedOutputParameters
import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
private void handleLocallyCachedOutputParameters(MappedStatement ms, CacheKey key, Object parameter, BoundSql boundSql) {
if (ms.getStatementType() == StatementType.CALLABLE) {
final Object cachedParameter = localOutputParameterCache.getObject(key);
if (cachedParameter != null && parameter != null) {
final MetaObject metaCachedParameter = configuration.newMetaObject(cachedParameter);
final MetaObject metaParameter = configuration.newMetaObject(parameter);
for (ParameterMapping parameterMapping : boundSql.getParameterMappings()) {
if (parameterMapping.getMode() != ParameterMode.IN) {
final String parameterName = parameterMapping.getProperty();
final Object cachedValue = metaCachedParameter.getValue(parameterName);
metaParameter.setValue(parameterName, cachedValue);
}
}
}
}
}
示例3: queryCount
import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
private Object queryCount(Invocation invocation, Object[] args, MappedStatement ms, BoundSql boundSql)
throws InvocationTargetException, IllegalAccessException {
MappedStatement countRowStatement = COUNT_MAPPED_STATS.get(ms.getId());
if (countRowStatement == null) {
String countSql = dialect.getCountSql(boundSql.getSql());
BoundSql newBoundSql = new BoundSql(ms.getConfiguration(), countSql, boundSql.getParameterMappings(),
boundSql.getParameterObject());
MetaObject mo = (MetaObject) ReflectionUtils.getFieldValue(boundSql, "metaParameters");
ReflectionUtils.setFieldValue(newBoundSql, "metaParameters", mo);
List<ResultMap> resultMaps = new ArrayList<ResultMap>();
ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), int.class,
EMPTY_RESULTMAPPING).build();
resultMaps.add(resultMap);
countRowStatement = buildMappedStatement(ms, new SqlSourceWrapper(newBoundSql), ms.getId() + "_COUNT",
resultMaps);
}
args[0] = countRowStatement;
args[2] = new RowBounds();
args[3] = null;
return invocation.proceed();
}
示例4: getColumnValue
import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
public static Object getColumnValue(String columnName, ISqlParser iSqlParser, BoundSql boundSql) {
MapperMethod.ParamMap paramMap = (MapperMethod.ParamMap) boundSql.getParameterObject();
List<ColumnValue> cols = iSqlParser.getColumns();
for (int i = 0; i < cols.size(); i++) {
if (Objects.equals(cols.get(i).column, columnName)) {
// if (cols.get(i).value.equals("?")) //TODO
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
String property = parameterMappings.get(i).getProperty();
if (!property.startsWith("_"))
return paramMap.get("param" + (i + 1)); //index start from 1
return parameterMappings.stream()
.filter(p -> p.getProperty().startsWith("__frch_" + columnName))
.map(parameterMapping -> boundSql.getAdditionalParameter(parameterMapping.getProperty()))
.collect(Collectors.toList());
}
}
return null;
}
示例5: executeQueryCount
import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的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.BoundSql; //导入方法依赖的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: processIntercept
import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的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;
}
}
示例8: getNamespaceSql
import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
/**
* 通过命名空间方式获取sql
* @param session
* @param namespace
* @param params
* @return
*/
public static String getNamespaceSql(SqlSession session, String namespace, Object params) {
Configuration configuration = session.getConfiguration();
MappedStatement mappedStatement = configuration.getMappedStatement(namespace);
TypeHandlerRegistry typeHandlerRegistry = mappedStatement.getConfiguration().getTypeHandlerRegistry();
BoundSql boundSql = mappedStatement.getBoundSql(params);
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
String sql = boundSql.getSql();
if (parameterMappings != null) {
for (int i = 0; i < parameterMappings.size(); i++) {
ParameterMapping parameterMapping = parameterMappings.get(i);
if (parameterMapping.getMode() != ParameterMode.OUT) {
Object value;
String propertyName = parameterMapping.getProperty();
if (boundSql.hasAdditionalParameter(propertyName)) {
value = boundSql.getAdditionalParameter(propertyName);
} else if (params == null) {
value = null;
} else if (typeHandlerRegistry.hasTypeHandler(params.getClass())) {
value = params;
} else {
MetaObject metaObject = configuration.newMetaObject(params);
value = metaObject.getValue(propertyName);
}
JdbcType jdbcType = parameterMapping.getJdbcType();
if (value == null && jdbcType == null) jdbcType = configuration.getJdbcTypeForNull();
sql = replaceParameter(sql, value, jdbcType, parameterMapping.getJavaType());
}
}
}
return sql;
}
示例9: copyFromBoundSql
import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的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;
}
示例10: getBoundSql
import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
public BoundSql getBoundSql(Object parameterObject) {
BoundSql boundSql = null;
if (parameterObject instanceof Map && ((Map) parameterObject).containsKey(PROVIDER_OBJECT)) {
boundSql = providerSqlSource.getBoundSql(((Map) parameterObject).get(PROVIDER_OBJECT));
} else {
boundSql = providerSqlSource.getBoundSql(parameterObject);
}
if (count) {
return new BoundSql(configuration, sqlParser.getCountSql(boundSql.getSql()), boundSql.getParameterMappings(), parameterObject);
} else {
return new BoundSql(configuration, sqlParser.getPageSql(boundSql.getSql()), getPageParameterMapping(configuration, boundSql),
parameterObject);
}
}
示例11: copyFromBoundSql
import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
private static BoundSql copyFromBoundSql(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;
}
示例12: createCacheKey
import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
@Override
public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {
if (closed) {
throw new ExecutorException("Executor was closed.");
}
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();
// mimic DefaultParameterHandler logic
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) {
// issue #176
cacheKey.update(configuration.getEnvironment().getId());
}
return cacheKey;
}
示例13: ensureNoOutParams
import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
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.");
}
}
}
}
示例14: copyFromBoundSql
import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
private BoundSql copyFromBoundSql(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;
}
示例15: createCacheKey
import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
@Override
public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {
if (closed) {
throw new ExecutorException("Executor was closed.");
}
CacheKey cacheKey = new CacheKey();
cacheKey.update(ms.getId());
cacheKey.update(Integer.valueOf(rowBounds.getOffset()));
cacheKey.update(Integer.valueOf(rowBounds.getLimit()));
cacheKey.update(boundSql.getSql());
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
TypeHandlerRegistry typeHandlerRegistry = ms.getConfiguration().getTypeHandlerRegistry();
// mimic DefaultParameterHandler logic
for (int i = 0; i < parameterMappings.size(); i++) {
ParameterMapping parameterMapping = parameterMappings.get(i);
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) {
// issue #176
cacheKey.update(configuration.getEnvironment().getId());
}
return cacheKey;
}