Search in sources :

Example 1 with NoKeyGenerator

use of org.apache.ibatis.executor.keygen.NoKeyGenerator in project jeesuite-libs by vakinge.

the class InsertBuilder method build.

/**
 * @param configuration
 * @param entity
 */
public static void build(Configuration configuration, LanguageDriver languageDriver, EntityInfo entity) {
    String[] names = GeneralSqlGenerator.methodDefines.insertName().split(",");
    for (String name : names) {
        String msId = entity.getMapperClass().getName() + "." + name;
        // 从参数对象里提取注解信息
        EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
        // 生成sql
        String sql = buildInsertSql(entityMapper, name.endsWith("Selective"));
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, entity.getEntityClass());
        MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, msId, sqlSource, SqlCommandType.INSERT);
        KeyGenerator keyGenerator = entityMapper.autoId() ? new Jdbc3KeyGenerator() : new NoKeyGenerator();
        // 
        statementBuilder.keyGenerator(keyGenerator).keyProperty(// 
        entityMapper.getIdColumn().getProperty()).keyColumn(entityMapper.getIdColumn().getColumn());
        MappedStatement statement = statementBuilder.build();
        configuration.addMappedStatement(statement);
    }
}
Also used : SqlSource(org.apache.ibatis.mapping.SqlSource) Jdbc3KeyGenerator(org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator) NoKeyGenerator(org.apache.ibatis.executor.keygen.NoKeyGenerator) MappedStatement(org.apache.ibatis.mapping.MappedStatement) NoKeyGenerator(org.apache.ibatis.executor.keygen.NoKeyGenerator) Jdbc3KeyGenerator(org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator) KeyGenerator(org.apache.ibatis.executor.keygen.KeyGenerator) EntityMapper(com.jeesuite.mybatis.crud.helper.EntityMapper)

Aggregations

EntityMapper (com.jeesuite.mybatis.crud.helper.EntityMapper)1 Jdbc3KeyGenerator (org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator)1 KeyGenerator (org.apache.ibatis.executor.keygen.KeyGenerator)1 NoKeyGenerator (org.apache.ibatis.executor.keygen.NoKeyGenerator)1 MappedStatement (org.apache.ibatis.mapping.MappedStatement)1 SqlSource (org.apache.ibatis.mapping.SqlSource)1