本文整理汇总了Java中org.apache.ibatis.mapping.MappedStatement.getId方法的典型用法代码示例。如果您正苦于以下问题:Java MappedStatement.getId方法的具体用法?Java MappedStatement.getId怎么用?Java MappedStatement.getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ibatis.mapping.MappedStatement
的用法示例。
在下文中一共展示了MappedStatement.getId方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: intercept
import org.apache.ibatis.mapping.MappedStatement; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
// TODO Auto-generated method stub
if (invocation.getTarget() instanceof RoutingStatementHandler) {
StatementHandler statementHandler = (RoutingStatementHandler) invocation.getTarget();
MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
MappedStatement mappedStatement = (MappedStatement) metaStatementHandler.getValue("delegate.mappedStatement");
String mapperId = mappedStatement.getId();
String mapperClassName = mapperId.substring(0, mapperId.lastIndexOf("."));
Class<?> mapperClass = Class.forName(mapperClassName);
if (isDaoMapper(mapperClass)&&mapperId.endsWith(".insertUseReturnGeneratedKeys")) {
BaseStatementHandler baseStatementHandler = (BaseStatementHandler) metaStatementHandler.getValue("delegate");
if ("query".equals(invocation.getMethod().getName())) {
return handPreparedStatementHandlerQuery(invocation, baseStatementHandler);
} else if ("prepare".equals(invocation.getMethod().getName())) {
return handPreparedStatementHandlerPrepare(invocation, baseStatementHandler);
}
}
}
return invocation.proceed();
}
示例4: addMappedStatement
import org.apache.ibatis.mapping.MappedStatement; //导入方法依赖的package包/类
public static MappedStatement addMappedStatement(Configuration cfg , MappedStatement ms) {
String msId = ms.getId();
StatementResultLock lock = StatementResultLock.getLock("s#".concat(msId));
lock.lock();
try {
if (cfg.hasStatement(msId)) {
return cfg.getMappedStatement(msId);
}else{
cfg.addMappedStatement(ms);
return ms;
}
} finally {
lock.unlock();
}
}
示例5: 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;
}
示例6: 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();
}
示例7: 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();
}
示例8: intercept
import org.apache.ibatis.mapping.MappedStatement; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
boolean synchronizationActive = TransactionSynchronizationManager.isSynchronizationActive();
if (!synchronizationActive) {
Object[] objects = invocation.getArgs();
MappedStatement mappedStatement = (MappedStatement) objects[0];
String mappedStatementId = mappedStatement.getId();
String dynamicDataSourceGlobal = cacheMap.get(mappedStatementId);
if (dynamicDataSourceGlobal == null) {
//读方法
if (mappedStatement.getSqlCommandType().equals(SqlCommandType.SELECT)) {
if (mappedStatementId.contains(SelectKeyGenerator.SELECT_KEY_SUFFIX)) {
dynamicDataSourceGlobal = MultipleDataSourceHolder.READ;
} else {
BoundSql boundSql = mappedStatement.getSqlSource().getBoundSql(objects[1]);
String sql = boundSql.getSql().toLowerCase(Locale.CHINA).replaceAll("[\\t\\n\\r]", " ");
if (sql.matches(REGEX)) {
dynamicDataSourceGlobal = MultipleDataSourceHolder.WRITE;
} else {
dynamicDataSourceGlobal = MultipleDataSourceHolder.READ;
}
}
} else {
dynamicDataSourceGlobal = MultipleDataSourceHolder.WRITE;
}
logger.warn("设置方法[{}] use [{}] Strategy, SqlCommandType [{}]..", mappedStatementId, dynamicDataSourceGlobal, mappedStatement.getSqlCommandType().name());
cacheMap.put(mappedStatementId, dynamicDataSourceGlobal);
}
MultipleDataSourceHolder.setDataSource(dynamicDataSourceGlobal);
}
return invocation.proceed();
}
示例9: 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());
}
}
}
}
示例10: 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;
}
}
示例11: getQueryIdsMappedStatementForUpdateCache
import org.apache.ibatis.mapping.MappedStatement; //导入方法依赖的package包/类
private MappedStatement getQueryIdsMappedStatementForUpdateCache(MappedStatement mt,
EntityInfo entityInfo) {
String msId = mt.getId() + QUERY_IDS_SUFFIX;
MappedStatement statement = null;
Configuration configuration = mt.getConfiguration();
try {
statement = configuration.getMappedStatement(msId);
if (statement != null) { return statement; }
} catch (Exception e) {
}
synchronized (configuration) {
if (configuration.hasStatement(msId)) { return configuration.getMappedStatement(msId); }
String sql = entityInfo.getMapperSqls().get(mt.getId());
if (StringUtils.isNotBlank(sql)) {
if (!sql.toLowerCase().contains(entityInfo.getTableName().toLowerCase())) {
return null;
}
sql = "select " + entityInfo.getIdColumn() + " from " + entityInfo.getTableName()
+ " WHERE " + sql.split(WHERE_REGEX)[1];
sql = String.format(SqlTemplate.SCRIPT_TEMAPLATE, sql);
} else {
sql = PARSE_SQL_ERROR_DEFAULT;
}
SqlSource sqlSource = configuration.getDefaultScriptingLanguageInstance()
.createSqlSource(configuration, sql, Object.class);
MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration,
msId, sqlSource, SqlCommandType.SELECT);
statementBuilder.resource(mt.getResource());
statementBuilder.fetchSize(mt.getFetchSize());
statementBuilder.statementType(mt.getStatementType());
statementBuilder.parameterMap(mt.getParameterMap());
statement = statementBuilder.build();
List<ResultMap> resultMaps = new ArrayList<ResultMap>();
String id = msId + "-Inline";
ResultMap.Builder builder = new ResultMap.Builder(configuration, id,
entityInfo.getIdType(), new ArrayList<ResultMapping>(), true);
resultMaps.add(builder.build());
MetaObject metaObject = SystemMetaObject.forObject(statement);
metaObject.setValue("resultMaps", Collections.unmodifiableList(resultMaps));
configuration.addMappedStatement(statement);
return statement;
}
}