org.apache.ibatis.annotations.Options#org.apache.ibatis.mapping.SqlSource源码实例Demo

下面列出了org.apache.ibatis.annotations.Options#org.apache.ibatis.mapping.SqlSource 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Aooms   文件: RecordDelete.java
@Override
public void process() {
    MappedStatement mappedStatement = MetaObjectAssistant.getMappedStatement(metaObject);
    Object parameterObject = MetaObjectAssistant.getParameterObject(metaObject);
    Record record = (Record) parameterObject;

    String tableName = record.getGeneral(MyBatisConst.TABLE_NAME_PLACEHOLDER);
    String pkName = record.getGeneralOrDefault(MyBatisConst.TABLE_PK_NAME_PLACEHOLDER, AoomsVar.ID);
    Object pkValue = record.get(pkName);

    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(" delete from ");
    stringBuilder.append(tableName); // tableName
    stringBuilder.append(" where "+ pkName +" = #{"+ pkName +"} ");
    String sql = stringBuilder.toString();

   // SqlSource sqlSource = new XMLLanguageDriver().createSqlSource(mappedStatement.getConfiguration(), sql, Map.class);
    Configuration configuration = MetaObjectAssistant.getConfiguration(metaObject);
    SqlSource sqlSource = configuration.getLanguageRegistry().getDefaultDriver().createSqlSource(mappedStatement.getConfiguration(), sql, Map.class);
    BoundSql boundSql = sqlSource.getBoundSql(parameterObject);

    MetaObjectAssistant.setDelegateBoundSql(metaObject,boundSql);
    MetaObjectAssistant.setDelegateParameterHandlerBoundSql(metaObject,boundSql);
}
 
源代码2 项目: taoshop   文件: MybatisSqlInterceptor.java
private MappedStatement newMappedStatement(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 (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());
    builder.resultMaps(ms.getResultMaps());
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());
 
    return builder.build();
}
 
源代码3 项目: mybatis-test   文件: MySqlPagingPlugin.java
@Override
public Object intercept(Invocation invocation) throws Throwable {
    Object[] args = invocation.getArgs();
    RowBounds rb = (RowBounds) args[ROW_BOUNDS_INDEX];
    if (rb == RowBounds.DEFAULT) {
        return invocation.proceed();
    }
    args[ROW_BOUNDS_INDEX] = RowBounds.DEFAULT;

    MappedStatement ms = (MappedStatement) args[MAPPED_STATEMENT_INDEX];
    BoundSql boundSql = ms.getBoundSql(args[PARAMETER_INDEX]);

    System.out.println();
    String sql = boundSql.getSql();
    String limit = String.format("LIMIT %d,%d", rb.getOffset(), rb.getLimit());
    sql = sql + " " + limit;

    SqlSource sqlSource = new StaticSqlSource(ms.getConfiguration(), sql, boundSql.getParameterMappings());

    Field field = MappedStatement.class.getDeclaredField("sqlSource");
    field.setAccessible(true);
    field.set(ms, sqlSource);

    return invocation.proceed();
}
 
源代码4 项目: mybatis   文件: ProviderSqlSource.java
private SqlSource createSqlSource(Object parameterObject) {
  try {
    String sql;
    if (providerTakesParameterObject) {
      sql = (String) providerMethod.invoke(providerType.newInstance(), parameterObject);
    } else {
      sql = (String) providerMethod.invoke(providerType.newInstance());
    }
    Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
    return sqlSourceParser.parse(sql, parameterType, new HashMap<String, Object>());
  } catch (Exception e) {
    throw new BuilderException("Error invoking SqlProvider method ("
        + providerType.getName() + "." + providerMethod.getName()
        + ").  Cause: " + e, e);
  }
}
 
源代码5 项目: platform   文件: MyBatisUtils.java
/**
 * 复制MappedStatement
 *
 * @param ms           {@link MappedStatement}
 * @param newSqlSource {@link SqlSource}
 * @return {@link MappedStatement}
 */
public static 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());
    String[] keyProperties = ms.getKeyProperties();
    builder.keyProperty(keyProperties == null ? null : keyProperties[0]);
    builder.timeout(ms.getTimeout());
    builder.parameterMap(ms.getParameterMap());
    builder.resultMaps(ms.getResultMaps());
    builder.resultSetType(ms.getResultSetType());
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());
    return builder.build();
}
 
源代码6 项目: aaden-pay   文件: PagePluging.java
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();
}
 
源代码7 项目: azeroth   文件: UpdateBuilder.java
/**
 * @param configuration
 * @param entity
 */
public static void build(Configuration configuration, LanguageDriver languageDriver,
                         EntityInfo entity) {
    String[] names = GeneralSqlGenerator.methodDefines.updateName().split(",");
    for (String name : names) {
        String msId = entity.getMapperClass().getName() + "." + name;

        EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());

        String sql = buildUpdateSql(entityMapper, name.endsWith("Selective"));

        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql,
                entity.getEntityClass());

        MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration,
                msId, sqlSource, SqlCommandType.UPDATE);

        MappedStatement statement = statementBuilder.build();

        configuration.addMappedStatement(statement);
    }
}
 
源代码8 项目: azeroth   文件: DeleteBuilder.java
/**
 * @param configuration
 * @param entity
 */
public static void build(Configuration configuration, LanguageDriver languageDriver, EntityInfo entity) {
    String msId = entity.getMapperClass().getName() + "." + GeneralSqlGenerator.methodDefines.deleteName();

    // 从参数对象里提取注解信息
    EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
    // 生成sql
    String sql = buildDeleteSql(entityMapper);

    SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, entity.getEntityClass());

    MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, msId, sqlSource, SqlCommandType.DELETE);

    MappedStatement statement = statementBuilder.build();
    configuration.addMappedStatement(statement);
}
 
源代码9 项目: tsharding   文件: MapperEnhancer.java
protected MappedStatement copyFromMappedStatement(MappedStatement ms,
                                                  SqlSource newSqlSource, String newMsId) {
    MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), newMsId, newSqlSource, ms.getSqlCommandType());
    builder.resource(ms.getResource());
    builder.fetchSize(ms.getFetchSize());
    builder.statementType(ms.getStatementType());
    builder.keyGenerator(ms.getKeyGenerator());
    // setStatementTimeout()
    builder.timeout(ms.getTimeout());
    // setParameterMap()
    builder.parameterMap(ms.getParameterMap());
    // setStatementResultMap()
    List<ResultMap> resultMaps = ms.getResultMaps();
    builder.resultMaps(resultMaps);
    builder.resultSetType(ms.getResultSetType());
    // setStatementCache()
    builder.cache(ms.getCache());
    builder.flushCacheRequired(ms.isFlushCacheRequired());
    builder.useCache(ms.isUseCache());
    return builder.build();
}
 
源代码10 项目: mybaties   文件: DynamicSqlSource.java
@Override
 public BoundSql getBoundSql(Object parameterObject) {
   //生成一个动态上下文
   DynamicContext context = new DynamicContext(configuration, parameterObject);
//这里SqlNode.apply只是将${}这种参数替换掉,并没有替换#{}这种参数
   rootSqlNode.apply(context);
//调用SqlSourceBuilder
   SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);
   Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
//SqlSourceBuilder.parse,注意这里返回的是StaticSqlSource,解析完了就把那些参数都替换成?了,也就是最基本的JDBC的SQL写法
   SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings());
//看似是又去递归调用SqlSource.getBoundSql,其实因为是StaticSqlSource,所以没问题,不是递归调用
   BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
   for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) {
     boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());
   }
   return boundSql;
 }
 
源代码11 项目: mybaties   文件: XMLLanguageDriver.java
@Override
public SqlSource createSqlSource(Configuration configuration, String script, Class<?> parameterType) {
  // issue #3
  if (script.startsWith("<script>")) {
    XPathParser parser = new XPathParser(script, false, configuration.getVariables(), new XMLMapperEntityResolver());
    return createSqlSource(configuration, parser.evalNode("/script"), parameterType);
  } else {
    // issue #127
    script = PropertyParser.parse(script, configuration.getVariables());
    TextSqlNode textSqlNode = new TextSqlNode(script);
    //一种是动态,一种是原始
    if (textSqlNode.isDynamic()) {
      return new DynamicSqlSource(configuration, textSqlNode);
    } else {
      return new RawSqlSource(configuration, script, parameterType);
    }
  }
}
 
源代码12 项目: mybatis   文件: MapperAnnotationBuilder.java
private SqlSource getSqlSourceFromAnnotations(Method method, Class<?> parameterType, LanguageDriver languageDriver) {
  try {
    Class<? extends Annotation> sqlAnnotationType = getSqlAnnotationType(method);
    Class<? extends Annotation> sqlProviderAnnotationType = getSqlProviderAnnotationType(method);
    if (sqlAnnotationType != null) {
      if (sqlProviderAnnotationType != null) {
        throw new BindingException("You cannot supply both a static SQL and SqlProvider to method named " + method.getName());
      }
      Annotation sqlAnnotation = method.getAnnotation(sqlAnnotationType);
      final String[] strings = (String[]) sqlAnnotation.getClass().getMethod("value").invoke(sqlAnnotation);
      return buildSqlSourceFromStrings(strings, parameterType, languageDriver);
    } else if (sqlProviderAnnotationType != null) {
      Annotation sqlProviderAnnotation = method.getAnnotation(sqlProviderAnnotationType);
      return new ProviderSqlSource(assistant.getConfiguration(), sqlProviderAnnotation);
    }
    return null;
  } catch (Exception e) {
    throw new BuilderException("Could not find value method on SQL annotation.  Cause: " + e, e);
  }
}
 
源代码13 项目: mybatis   文件: DynamicSqlSource.java
@Override
 public BoundSql getBoundSql(Object parameterObject) {
   //生成一个动态上下文
   DynamicContext context = new DynamicContext(configuration, parameterObject);
//这里SqlNode.apply只是将${}这种参数替换掉,并没有替换#{}这种参数
   rootSqlNode.apply(context);
//调用SqlSourceBuilder
   SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration);
   Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
//SqlSourceBuilder.parse,注意这里返回的是StaticSqlSource,解析完了就把那些参数都替换成?了,也就是最基本的JDBC的SQL写法
   SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings());
//看似是又去递归调用SqlSource.getBoundSql,其实因为是StaticSqlSource,所以没问题,不是递归调用
   BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
   for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) {
     boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());
   }
   return boundSql;
 }
 
源代码14 项目: mybatis   文件: XMLLanguageDriver.java
@Override
public SqlSource createSqlSource(Configuration configuration, String script, Class<?> parameterType) {
  // issue #3
  if (script.startsWith("<script>")) {
    XPathParser parser = new XPathParser(script, false, configuration.getVariables(), new XMLMapperEntityResolver());
    return createSqlSource(configuration, parser.evalNode("/script"), parameterType);
  } else {
    // issue #127
    script = PropertyParser.parse(script, configuration.getVariables());
    TextSqlNode textSqlNode = new TextSqlNode(script);
    //一种是动态,一种是原始
    if (textSqlNode.isDynamic()) {
      return new DynamicSqlSource(configuration, textSqlNode);
    } else {
      return new RawSqlSource(configuration, script, parameterType);
    }
  }
}
 
源代码15 项目: Aooms   文件: RecordInsert.java
@Override
public void process() {
    MappedStatement mappedStatement = MetaObjectAssistant.getMappedStatement(metaObject);
    Object parameterObject = MetaObjectAssistant.getParameterObject(metaObject);
    Record record = (Record) parameterObject;
    String tableName = record.getGeneral(MyBatisConst.TABLE_NAME_PLACEHOLDER);
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(" insert into ");
    stringBuilder.append(tableName); // tableName
    stringBuilder.append(" ({}) ");
    stringBuilder.append(" values ");
    stringBuilder.append(" ({}) ");

    StringBuilder columns = new StringBuilder();
    StringBuilder values = new StringBuilder();

    int index = 0;
    Iterator<String> keyIterator = record.keySet().iterator();
    while (keyIterator.hasNext()) {
        String key = keyIterator.next();
        if (index > 0) {
            columns.append(",");
            values.append(",");
        }
        columns.append(key);
        values.append("#{").append(key).append("}");
        index++;
    }

    String sql = StrUtil.format(stringBuilder, columns, values);
    Configuration configuration = MetaObjectAssistant.getConfiguration(metaObject);
    SqlSource sqlSource = configuration.getLanguageRegistry().getDefaultDriver().createSqlSource(mappedStatement.getConfiguration(), sql, Map.class);
    BoundSql boundSql = sqlSource.getBoundSql(parameterObject);
    //metaObject.setValue("delegate.boundSql", boundSql);
    //metaObject.setValue("delegate.parameterHandler.boundSql", boundSql);

    MetaObjectAssistant.setDelegateBoundSql(metaObject,boundSql);
    MetaObjectAssistant.setDelegateParameterHandlerBoundSql(metaObject,boundSql);
}
 
源代码16 项目: Aooms   文件: RecordUpdate.java
@Override
public void process() {
    MappedStatement mappedStatement = MetaObjectAssistant.getMappedStatement(metaObject);
    Object parameterObject = MetaObjectAssistant.getParameterObject(metaObject);
    Record record = (Record) parameterObject;

    String tableName = record.getGeneral(MyBatisConst.TABLE_NAME_PLACEHOLDER);
    String pkName = String.valueOf(record.getOrDefault(MyBatisConst.TABLE_PK_NAME_PLACEHOLDER, AoomsVar.ID));
    Object pkValue = record.get(pkName);

    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(" update ");
    stringBuilder.append(tableName); // tableName
    stringBuilder.append(" set {} ");
    stringBuilder.append(" where "+ pkName +" = #{"+ pkName +"} ");

    StringBuilder columns = new StringBuilder();
    int index = 0;
    Iterator<String> keyIterator = record.keySet().iterator();
    while (keyIterator.hasNext()) {
        String key = keyIterator.next();
        if (index > 0) {
            columns.append(",");
        }
        columns.append(key).append(" = ").append("#{").append(key).append("}");
        index++;
    }

    String sql = StrUtil.format(stringBuilder, columns);
    //SqlSource sqlSource = new XMLLanguageDriver().createSqlSource(mappedStatement.getConfiguration(), sql, Map.class);
    Configuration configuration = MetaObjectAssistant.getConfiguration(metaObject);
    SqlSource sqlSource = configuration.getLanguageRegistry().getDefaultDriver().createSqlSource(mappedStatement.getConfiguration(), sql, Map.class);
    BoundSql boundSql = sqlSource.getBoundSql(parameterObject);

    MetaObjectAssistant.setDelegateBoundSql(metaObject,boundSql);
    MetaObjectAssistant.setDelegateParameterHandlerBoundSql(metaObject,boundSql);
}
 
源代码17 项目: mybatis-test   文件: SqlSourceBuilderTest.java
@Test
    public void test() {
//        String sql = "SELECT * FROM Author WHERE name = #{name} AND age = #{age}";
        String sql = "SELECT * FROM Author WHERE age = #{age,javaType=int,jdbcType=NUMERIC}";
        SqlSourceBuilder sqlSourceBuilder = new SqlSourceBuilder(new Configuration());
        SqlSource sqlSource = sqlSourceBuilder.parse(sql, Author.class, new HashMap<>());
        BoundSql boundSql = sqlSource.getBoundSql(new Author());

        System.out.println(String.format("SQL: %s\n", boundSql.getSql()));
        System.out.println(String.format("ParameterMappings: %s", boundSql.getParameterMappings()));
    }
 
源代码18 项目: jig   文件: MyBatisSqlReader.java
private Query getQuery(MappedStatement mappedStatement) throws NoSuchFieldException, IllegalAccessException {
    SqlSource sqlSource = mappedStatement.getSqlSource();

    if (!(sqlSource instanceof DynamicSqlSource)) {
        return new Query(mappedStatement.getBoundSql(null).getSql());
    }

    // 動的クエリ(XMLで組み立てるもの)をエミュレート
    DynamicSqlSource dynamicSqlSource = (DynamicSqlSource) sqlSource;

    Field rootSqlNode = DynamicSqlSource.class.getDeclaredField("rootSqlNode");
    rootSqlNode.setAccessible(true);
    SqlNode sqlNode = (SqlNode) rootSqlNode.get(dynamicSqlSource);


    if (sqlNode instanceof MixedSqlNode) {
        StringBuilder sql = new StringBuilder();
        MixedSqlNode mixedSqlNode = (MixedSqlNode) sqlNode;
        Field contents = mixedSqlNode.getClass().getDeclaredField("contents");
        contents.setAccessible(true);
        List list = (List) contents.get(mixedSqlNode);

        for (Object content : list) {
            if (content instanceof StaticTextSqlNode) {
                StaticTextSqlNode staticTextSqlNode = (StaticTextSqlNode) content;
                Field text = StaticTextSqlNode.class.getDeclaredField("text");
                text.setAccessible(true);
                String textSql = (String) text.get(staticTextSqlNode);
                sql.append(textSql);
            }
        }

        String sqlText = sql.toString().trim();
        LOGGER.debug("動的SQLの組み立てをエミュレートしました。ID={}", mappedStatement.getId());
        LOGGER.debug("組み立てたSQL: [{}]", sqlText);
        return new Query(sqlText);
    }
    return new Query(mappedStatement.getBoundSql(null).getSql());
}
 
源代码19 项目: Roothub   文件: SelectOne.java
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
    SqlMethod selectOne = SqlMethod.SELECT_ONE;
    String sqlScript = String.format(selectOne.getSql(), tableInfo.getSelectColumnSegments(true),
            tableInfo.getTableName(), getWrapperScript());
    SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sqlScript, modelClass);
    return this.addMappedStatement(mapperClass, selectOne.getMethod(), sqlSource, SqlCommandType.SELECT, String.class, null, modelClass, new NoKeyGenerator(), tableInfo.getKeyProperty(), tableInfo.getKeyColumn());
}
 
源代码20 项目: Roothub   文件: DeleteById.java
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
    SqlMethod deleteById = SqlMethod.DELETE_BY_ID;
    String sqlScript = String.format(deleteById.getSql(), tableInfo.getTableName(), tableInfo.getKeyColumn(), "#{id}");
    SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sqlScript, modelClass);
    return this.addMappedStatement(mapperClass, deleteById.getMethod(), sqlSource, SqlCommandType.DELETE, String.class, null, Integer.class, new NoKeyGenerator(), tableInfo.getKeyProperty(), tableInfo.getKeyColumn());
}
 
源代码21 项目: Roothub   文件: Delete.java
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
    SqlMethod delete = SqlMethod.DELETE;
    String sqlScript = String.format(delete.getSql(), tableInfo.getTableName(), getWrapperScript());
    SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sqlScript, modelClass);
    return this.addMappedStatement(mapperClass, delete.getMethod(), sqlSource, SqlCommandType.DELETE, String.class, null, Integer.class, new NoKeyGenerator(), tableInfo.getKeyProperty(), tableInfo.getKeyColumn());
}
 
源代码22 项目: Roothub   文件: Insert.java
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
    SqlMethod insert = SqlMethod.INSERT;
    String sqlScript = String.format(insert.getSql(), tableInfo.getTableName(), tableInfo.getInsertColumnSegments(), tableInfo.getInsertValueSegments());
    SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sqlScript, modelClass);
    return this.addMappedStatement(mapperClass, insert.getMethod(), sqlSource, SqlCommandType.INSERT, String.class, null, Integer.class, new NoKeyGenerator(), tableInfo.getKeyProperty(), tableInfo.getKeyColumn());
}
 
源代码23 项目: Roothub   文件: SelectList.java
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
    SqlMethod selectList = SqlMethod.SELECT_LIST;
    String sqlScript = String.format(selectList.getSql(), tableInfo.getSelectColumnSegments(true),
            tableInfo.getTableName(), getWrapperScript());
    SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sqlScript, modelClass);
    return this.addMappedStatement(mapperClass, selectList.getMethod(), sqlSource, SqlCommandType.SELECT, String.class, null, modelClass, new NoKeyGenerator(), null, tableInfo.getKeyColumn());
}
 
源代码24 项目: Roothub   文件: Update.java
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
    SqlMethod update = SqlMethod.UPDATE;
    String sqlScript = String.format(update.getSql(), tableInfo.getTableName(), tableInfo.getSetSegments(), getWrapperScript());
    SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sqlScript, modelClass);
    return this.addMappedStatement(mapperClass, update.getMethod(), sqlSource, SqlCommandType.UPDATE, String.class, null, Integer.class, new NoKeyGenerator(), tableInfo.getKeyProperty(), tableInfo.getKeyColumn());
}
 
源代码25 项目: Roothub   文件: SelectById.java
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
    SqlMethod selectById = SqlMethod.SELECT_BY_ID;
    String sqlScript = String.format(selectById.getSql(), tableInfo.getSelectColumnSegments(false),
            tableInfo.getTableName(), tableInfo.getKeyColumn(), "#{id}");
    SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sqlScript, modelClass);
    return this.addMappedStatement(mapperClass, selectById.getMethod(), sqlSource, SqlCommandType.SELECT, null, null, modelClass, new NoKeyGenerator(), tableInfo.getKeyProperty(), tableInfo.getKeyColumn());
}
 
源代码26 项目: Roothub   文件: DeleteBatchIds.java
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
    SqlMethod deleteBatchByIds = SqlMethod.DELETE_BATCH_BY_IDS;
    String sqlScript = String.format(deleteBatchByIds.getSql(), tableInfo.getTableName(), tableInfo.getKeyColumn(), getIdsScript());
    SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sqlScript, modelClass);
    return this.addMappedStatement(mapperClass, deleteBatchByIds.getMethod(), sqlSource, SqlCommandType.DELETE, String.class, null, Integer.class, new NoKeyGenerator(), tableInfo.getKeyProperty(), tableInfo.getKeyColumn());
}
 
源代码27 项目: Roothub   文件: SelectCount.java
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
    SqlMethod selectCount = SqlMethod.SELECT_COUNT;
    String sqlScript = String.format(selectCount.getSql(), tableInfo.getTableName(), getNormalSqlSegment());
    SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sqlScript, modelClass);
    return this.addMappedStatement(mapperClass, selectCount.getMethod(), sqlSource, SqlCommandType.SELECT, String.class, null, Integer.class, new NoKeyGenerator(), null, tableInfo.getKeyColumn());
}
 
源代码28 项目: albedo   文件: FindRelationPageLogic.java
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
	String tableNameAlias = StringUtil.lowerCase(modelClass.getSimpleName());
	String sql = SqlInjectorUtil.parseSql(builderAssistant, SqlCustomMethod.FIND_RELATION_PAGE, modelClass, tableInfo,
		sqlWhereEntityWrapper(tableInfo, tableNameAlias));
	SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sql, modelClass);
	return this.addSelectMappedStatementForTable(mapperClass, SqlCustomMethod.FIND_RELATION_PAGE.getMethod(), sqlSource, tableInfo);
}
 
源代码29 项目: albedo   文件: FindRelationListLogic.java
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
	String tableNameAlias = StringUtil.lowerCase(modelClass.getSimpleName());
	String sql = SqlInjectorUtil.parseSql(builderAssistant, SqlCustomMethod.FIND_RELATION_LIST, modelClass, tableInfo,
		sqlWhereEntityWrapper(tableInfo, tableNameAlias));
	SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sql, modelClass);
	return this.addSelectMappedStatementForTable(mapperClass, SqlCustomMethod.FIND_RELATION_LIST.getMethod(), sqlSource, tableInfo);
}
 
源代码30 项目: mybatis   文件: MapperAnnotationBuilder.java
private SqlSource buildSqlSourceFromStrings(String[] strings, Class<?> parameterTypeClass, LanguageDriver languageDriver) {
  final StringBuilder sql = new StringBuilder();
  for (String fragment : strings) {
    sql.append(fragment);
    sql.append(" ");
  }
  return languageDriver.createSqlSource(configuration, sql.toString(), parameterTypeClass);
}