Loading example-common/repository-api/src/main/java/org/apache/shardingsphere/example/common/repository/CommonRepository.java +2 −2 Original line number Diff line number Diff line Loading @@ -39,9 +39,9 @@ public interface CommonRepository<T, P> { /** * insert one entity. * @param entity entity * @return primary key * @return count or primary key */ P insert(T entity); Long insert(T entity); /** * Do delete. Loading example-common/repository-jdbc/src/main/java/org/apache/shardingsphere/example/common/jdbc/repository/CountryRepositoryImpl.java +4 −7 Original line number Diff line number Diff line Loading @@ -68,21 +68,18 @@ public final class CountryRepositoryImpl implements CountryRepository { } @Override public String insert(final Country country) { public Long insert(final Country country) { String sql = "INSERT INTO t_country (code, name, language) VALUES (?, ?, ?)"; int result = 0; try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql)) { preparedStatement.setString(1, country.getCode()); preparedStatement.setString(2, country.getName()); preparedStatement.setString(3, country.getLanguage()); preparedStatement.executeUpdate(); ResultSet rs = connection.createStatement().executeQuery("SELECT @@IDENTITY"); while (rs.next()) { country.setId(rs.getLong("@@IDENTITY")); } result = preparedStatement.executeUpdate(); } catch (final SQLException ignored) { } return country.getCode(); return (long) result; } @Override Loading example-common/repository-mybatis/src/main/java/org/apache/shardingsphere/example/common/mybatis/repository/MybatisCountryRepository.java +0 −3 Original line number Diff line number Diff line Loading @@ -18,11 +18,8 @@ package org.apache.shardingsphere.example.common.mybatis.repository; import org.apache.ibatis.annotations.Mapper; import org.apache.shardingsphere.example.common.entity.Country; import org.apache.shardingsphere.example.common.repository.CountryRepository; @Mapper public interface MybatisCountryRepository extends CountryRepository { Long insertStandard(Country country); } example-common/repository-mybatis/src/main/java/org/apache/shardingsphere/example/common/mybatis/service/SpringCountryServiceImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -95,7 +95,7 @@ public class SpringCountryServiceImpl implements SpringCountryService { currCountry.setCode(l.getCountry()); currCountry.setName(l.getDisplayCountry(l)); currCountry.setLanguage(l.getLanguage()); repository.insertStandard(currCountry); repository.insert(currCountry); result.add(currCountry.getCode()); if (++i == 10) { break; Loading example-common/repository-mybatis/src/main/resources/META-INF/mappers/CountryMapper.xml +2 −2 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ <mapper namespace="org.apache.shardingsphere.example.common.mybatis.repository.MybatisCountryRepository"> <resultMap id="baseResultMap" type="org.apache.shardingsphere.example.common.entity.Country"> <result column="id" property="id" jdbcType="INTEGER"/> <result column="name" property="name" jdbcType="VARCHAR"/> <result column="code" property="code" jdbcType="VARCHAR"/> <result column="name" property="name" jdbcType="VARCHAR"/> <result column="language" property="language" jdbcType="VARCHAR"/> </resultMap> Loading @@ -20,7 +20,7 @@ DROP TABLE IF EXISTS t_country; </update> <insert id="insertStandard" useGeneratedKeys="true" keyProperty="id"> <insert id="insert" useGeneratedKeys="true" keyProperty="id"> INSERT INTO t_country (code, name, language) VALUES (#{code,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{language,jdbcType=VARCHAR}) </insert> Loading Loading
example-common/repository-api/src/main/java/org/apache/shardingsphere/example/common/repository/CommonRepository.java +2 −2 Original line number Diff line number Diff line Loading @@ -39,9 +39,9 @@ public interface CommonRepository<T, P> { /** * insert one entity. * @param entity entity * @return primary key * @return count or primary key */ P insert(T entity); Long insert(T entity); /** * Do delete. Loading
example-common/repository-jdbc/src/main/java/org/apache/shardingsphere/example/common/jdbc/repository/CountryRepositoryImpl.java +4 −7 Original line number Diff line number Diff line Loading @@ -68,21 +68,18 @@ public final class CountryRepositoryImpl implements CountryRepository { } @Override public String insert(final Country country) { public Long insert(final Country country) { String sql = "INSERT INTO t_country (code, name, language) VALUES (?, ?, ?)"; int result = 0; try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql)) { preparedStatement.setString(1, country.getCode()); preparedStatement.setString(2, country.getName()); preparedStatement.setString(3, country.getLanguage()); preparedStatement.executeUpdate(); ResultSet rs = connection.createStatement().executeQuery("SELECT @@IDENTITY"); while (rs.next()) { country.setId(rs.getLong("@@IDENTITY")); } result = preparedStatement.executeUpdate(); } catch (final SQLException ignored) { } return country.getCode(); return (long) result; } @Override Loading
example-common/repository-mybatis/src/main/java/org/apache/shardingsphere/example/common/mybatis/repository/MybatisCountryRepository.java +0 −3 Original line number Diff line number Diff line Loading @@ -18,11 +18,8 @@ package org.apache.shardingsphere.example.common.mybatis.repository; import org.apache.ibatis.annotations.Mapper; import org.apache.shardingsphere.example.common.entity.Country; import org.apache.shardingsphere.example.common.repository.CountryRepository; @Mapper public interface MybatisCountryRepository extends CountryRepository { Long insertStandard(Country country); }
example-common/repository-mybatis/src/main/java/org/apache/shardingsphere/example/common/mybatis/service/SpringCountryServiceImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -95,7 +95,7 @@ public class SpringCountryServiceImpl implements SpringCountryService { currCountry.setCode(l.getCountry()); currCountry.setName(l.getDisplayCountry(l)); currCountry.setLanguage(l.getLanguage()); repository.insertStandard(currCountry); repository.insert(currCountry); result.add(currCountry.getCode()); if (++i == 10) { break; Loading
example-common/repository-mybatis/src/main/resources/META-INF/mappers/CountryMapper.xml +2 −2 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ <mapper namespace="org.apache.shardingsphere.example.common.mybatis.repository.MybatisCountryRepository"> <resultMap id="baseResultMap" type="org.apache.shardingsphere.example.common.entity.Country"> <result column="id" property="id" jdbcType="INTEGER"/> <result column="name" property="name" jdbcType="VARCHAR"/> <result column="code" property="code" jdbcType="VARCHAR"/> <result column="name" property="name" jdbcType="VARCHAR"/> <result column="language" property="language" jdbcType="VARCHAR"/> </resultMap> Loading @@ -20,7 +20,7 @@ DROP TABLE IF EXISTS t_country; </update> <insert id="insertStandard" useGeneratedKeys="true" keyProperty="id"> <insert id="insert" useGeneratedKeys="true" keyProperty="id"> INSERT INTO t_country (code, name, language) VALUES (#{code,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{language,jdbcType=VARCHAR}) </insert> Loading