Search in sources :

Example 1 with EntityMapper

use of com.jeesuite.mybatis.crud.helper.EntityMapper in project jeesuite-libs by vakinge.

the class DeleteBuilder method build.

/**
 * @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);
}
Also used : SqlSource(org.apache.ibatis.mapping.SqlSource) MappedStatement(org.apache.ibatis.mapping.MappedStatement) EntityMapper(com.jeesuite.mybatis.crud.helper.EntityMapper)

Example 2 with EntityMapper

use of com.jeesuite.mybatis.crud.helper.EntityMapper 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)

Example 3 with EntityMapper

use of com.jeesuite.mybatis.crud.helper.EntityMapper in project jeesuite-libs by vakinge.

the class GetByPrimaryKeyBuilder method build.

/**
 * @param configuration
 * @param entity
 */
public static void build(Configuration configuration, LanguageDriver languageDriver, EntityInfo entity) {
    String msId = entity.getMapperClass().getName() + "." + GeneralSqlGenerator.methodDefines.selectName();
    EntityMapper entityMapper = EntityHelper.getEntityMapper(entity.getEntityClass());
    String sql = buildGetByIdSql(entityMapper);
    SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, entity.getEntityClass());
    MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, msId, sqlSource, SqlCommandType.SELECT);
    // 将返回值修改为实体类型
    MappedStatement statement = statementBuilder.build();
    setResultType(configuration, statement, entity.getEntityClass());
    configuration.addMappedStatement(statement);
}
Also used : SqlSource(org.apache.ibatis.mapping.SqlSource) MappedStatement(org.apache.ibatis.mapping.MappedStatement) EntityMapper(com.jeesuite.mybatis.crud.helper.EntityMapper)

Example 4 with EntityMapper

use of com.jeesuite.mybatis.crud.helper.EntityMapper in project jeesuite-libs by vakinge.

the class UpdateBuilder method build.

/**
 * @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);
    }
}
Also used : SqlSource(org.apache.ibatis.mapping.SqlSource) MappedStatement(org.apache.ibatis.mapping.MappedStatement) EntityMapper(com.jeesuite.mybatis.crud.helper.EntityMapper)

Aggregations

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