Loading example-common/repository-jdbc/src/main/java/org/apache/shardingsphere/example/common/jdbc/service/CountryServiceImpl.java +9 −5 Original line number Diff line number Diff line Loading @@ -22,8 +22,10 @@ import org.apache.shardingsphere.example.common.repository.CountryRepository; import org.apache.shardingsphere.example.common.service.CommonService; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Set; public class CountryServiceImpl implements CommonService { Loading Loading @@ -79,19 +81,21 @@ public class CountryServiceImpl implements CommonService { private List<String> insertData() { System.out.println("---------------------------- Insert Data ----------------------------"); List<String> result = new ArrayList<>(); Set<String> result = new LinkedHashSet<>(); for (Locale each : Locale.getAvailableLocales()) { final String country = each.getCountry(); if (country == null || "".equals(country)) { if (result.contains(each.getCountry()) || each.getCountry().isEmpty()) { continue; } if (result.size() >= 20) { break; } result.add(each.getCountry()); Country entity = new Country(); entity.setName(each.getDisplayCountry(each)); entity.setLanguage(each.getLanguage()); entity.setCode(each.getCountry()); countryRepository.insert(entity); result.add(entity.getCode()); } return result; return new ArrayList<>(result); } } example-common/repository-jpa/src/main/java/org/apache/shardingsphere/example/common/jpa/service/JPACountryServiceImpl.java +9 −5 Original line number Diff line number Diff line Loading @@ -23,8 +23,10 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Set; @Service public class JPACountryServiceImpl implements JPACountryService { Loading Loading @@ -75,19 +77,21 @@ public class JPACountryServiceImpl implements JPACountryService { private List<String> insertData() { System.out.println("---------------------------- Insert Data ----------------------------"); List<String> result = new ArrayList<>(); Set<String> result = new LinkedHashSet<>(); for (Locale each : Locale.getAvailableLocales()) { final String country = each.getCountry(); if (country == null || "".equals(country)) { if (result.contains(each.getCountry()) || each.getCountry().isEmpty()) { continue; } if (result.size() >= 10) { break; } result.add(each.getCountry()); CountryEntity entity = new CountryEntity(); entity.setName(each.getDisplayCountry(each)); entity.setLanguage(each.getLanguage()); entity.setCode(each.getCountry()); countryRepository.insert(entity); result.add(entity.getCode()); } return result; return new ArrayList<>(result); } } example-common/repository-mybatis/src/main/java/org/apache/shardingsphere/example/common/mybatis/service/SpringCountryServiceImpl.java +11 −8 Original line number Diff line number Diff line Loading @@ -25,8 +25,10 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Set; @Service public class SpringCountryServiceImpl implements SpringCountryService { Loading Loading @@ -82,20 +84,21 @@ public class SpringCountryServiceImpl implements SpringCountryService { private List<String> insertData() { System.out.println("---------------------------- Insert Data ----------------------------"); MybatisCountryRepository repository = (MybatisCountryRepository) countryRepository; List<String> result = new ArrayList<>(); Set<String> result = new LinkedHashSet<>(); for (Locale each : Locale.getAvailableLocales()) { final String country = each.getCountry(); if (null == country || "".equals(country)) { if (result.contains(each.getCountry()) || each.getCountry().isEmpty()) { continue; } if (result.size() >= 10) { break; } result.add(each.getCountry()); Country entity = new Country(); entity.setCode(each.getCountry()); entity.setName(each.getDisplayCountry(each)); entity.setLanguage(each.getLanguage()); repository.insert(entity); result.add(entity.getCode()); entity.setCode(each.getCountry()); countryRepository.insert(entity); } return result; return new ArrayList<>(result); } } Loading
example-common/repository-jdbc/src/main/java/org/apache/shardingsphere/example/common/jdbc/service/CountryServiceImpl.java +9 −5 Original line number Diff line number Diff line Loading @@ -22,8 +22,10 @@ import org.apache.shardingsphere.example.common.repository.CountryRepository; import org.apache.shardingsphere.example.common.service.CommonService; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Set; public class CountryServiceImpl implements CommonService { Loading Loading @@ -79,19 +81,21 @@ public class CountryServiceImpl implements CommonService { private List<String> insertData() { System.out.println("---------------------------- Insert Data ----------------------------"); List<String> result = new ArrayList<>(); Set<String> result = new LinkedHashSet<>(); for (Locale each : Locale.getAvailableLocales()) { final String country = each.getCountry(); if (country == null || "".equals(country)) { if (result.contains(each.getCountry()) || each.getCountry().isEmpty()) { continue; } if (result.size() >= 20) { break; } result.add(each.getCountry()); Country entity = new Country(); entity.setName(each.getDisplayCountry(each)); entity.setLanguage(each.getLanguage()); entity.setCode(each.getCountry()); countryRepository.insert(entity); result.add(entity.getCode()); } return result; return new ArrayList<>(result); } }
example-common/repository-jpa/src/main/java/org/apache/shardingsphere/example/common/jpa/service/JPACountryServiceImpl.java +9 −5 Original line number Diff line number Diff line Loading @@ -23,8 +23,10 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Set; @Service public class JPACountryServiceImpl implements JPACountryService { Loading Loading @@ -75,19 +77,21 @@ public class JPACountryServiceImpl implements JPACountryService { private List<String> insertData() { System.out.println("---------------------------- Insert Data ----------------------------"); List<String> result = new ArrayList<>(); Set<String> result = new LinkedHashSet<>(); for (Locale each : Locale.getAvailableLocales()) { final String country = each.getCountry(); if (country == null || "".equals(country)) { if (result.contains(each.getCountry()) || each.getCountry().isEmpty()) { continue; } if (result.size() >= 10) { break; } result.add(each.getCountry()); CountryEntity entity = new CountryEntity(); entity.setName(each.getDisplayCountry(each)); entity.setLanguage(each.getLanguage()); entity.setCode(each.getCountry()); countryRepository.insert(entity); result.add(entity.getCode()); } return result; return new ArrayList<>(result); } }
example-common/repository-mybatis/src/main/java/org/apache/shardingsphere/example/common/mybatis/service/SpringCountryServiceImpl.java +11 −8 Original line number Diff line number Diff line Loading @@ -25,8 +25,10 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Set; @Service public class SpringCountryServiceImpl implements SpringCountryService { Loading Loading @@ -82,20 +84,21 @@ public class SpringCountryServiceImpl implements SpringCountryService { private List<String> insertData() { System.out.println("---------------------------- Insert Data ----------------------------"); MybatisCountryRepository repository = (MybatisCountryRepository) countryRepository; List<String> result = new ArrayList<>(); Set<String> result = new LinkedHashSet<>(); for (Locale each : Locale.getAvailableLocales()) { final String country = each.getCountry(); if (null == country || "".equals(country)) { if (result.contains(each.getCountry()) || each.getCountry().isEmpty()) { continue; } if (result.size() >= 10) { break; } result.add(each.getCountry()); Country entity = new Country(); entity.setCode(each.getCountry()); entity.setName(each.getDisplayCountry(each)); entity.setLanguage(each.getLanguage()); repository.insert(entity); result.add(entity.getCode()); entity.setCode(each.getCountry()); countryRepository.insert(entity); } return result; return new ArrayList<>(result); } }