コード例 #1
0
 private SqlSource getSqlSource(
     MappedStatement ms, SqlSource sqlSource, Object parameterObject, boolean isCount) {
   if (ms.getSqlSource() instanceof DynamicSqlSource) {
     MetaObject msObject = MetaObjectUtils.forObject(ms);
     SqlNode sqlNode = (SqlNode) msObject.getValue("sqlSource.rootSqlNode");
     MixedSqlNode mixedSqlNode = null;
     if (sqlNode instanceof MixedSqlNode) {
       mixedSqlNode = (MixedSqlNode) sqlNode;
     } else {
       List<SqlNode> contents = new ArrayList<SqlNode>(1);
       contents.add(sqlNode);
       mixedSqlNode = new MixedSqlNode(contents);
     }
     return new CustomerDynamicSqlSource(ms.getConfiguration(), mixedSqlNode, isCount, dialect);
   } else if (sqlSource instanceof ProviderSqlSource) {
     return new CustomerProviderSqlSource(
         ms.getConfiguration(), (ProviderSqlSource) sqlSource, isCount, dialect);
   } else if (!isCount) {
     BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
     return new StaticSqlSource(
         ms.getConfiguration(),
         dialect.generatePageSQL(boundSql.getSql()),
         MybatisUtils.plusTwoParameterToMapping(ms.getConfiguration(), boundSql));
   } else {
     BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
     return new StaticSqlSource(
         ms.getConfiguration(),
         dialect.generateCountSQL(boundSql.getSql()),
         boundSql.getParameterMappings());
   }
 }
コード例 #2
0
 private MappedStatement getMappedStatement(
     MappedStatement ms,
     SqlSource sqlSource,
     Object parameterObject,
     String cacheSuffixKey,
     MappingEnum mappingType) {
   String mappedStatementId = ms.getId() + cacheSuffixKey;
   MappedStatement qs = MybatisUtils.getMappedStatement(ms, mappedStatementId);
   if (qs == null) {
     // 创建一个新的MappedStatement
     SqlSource ss =
         getSqlSource(ms, sqlSource, parameterObject, cacheSuffixKey == Const.CACHE_KEY_COUNT);
     qs = MybatisUtils.createMappedStatement(ms, ss, cacheSuffixKey, mappingType);
     MybatisUtils.addMappedStatement(ms.getConfiguration(), ms);
   }
   return qs;
 }