Unverified Commit 52727bbb authored by zhaojun's avatar zhaojun Committed by GitHub
Browse files

Merge pull request #126 from cherrylzhao/dev

remove id column for t_country table.
parents 157a1aac 477ad5d1
Loading
Loading
Loading
Loading
+1 −11
Original line number Diff line number Diff line
@@ -23,22 +23,12 @@ public class Country implements Serializable {

    private static final long serialVersionUID = 4522167390518926493L;

    private long id;
    
    private String code;

    private String name;

    private String language;

    public long getId() {
        return id;
    }

    public void setId(final long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }
@@ -65,6 +55,6 @@ public class Country implements Serializable {

    @Override
    public String toString() {
        return String.format("id: %s, code: %s, name: %s, language: %s", id, code, name, language);
        return String.format("code: %s, name: %s, language: %s", code, name, language);
    }
}
+4 −5
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public final class CountryRepositoryImpl implements CountryRepository {

    @Override
    public void createTableIfNotExists() {
        String sql = "CREATE TABLE IF NOT EXISTS t_country (id BIGINT NOT NULL AUTO_INCREMENT, code VARCHAR(50), name VARCHAR(50), language VARCHAR(50), PRIMARY KEY (id))";
        String sql = "CREATE TABLE IF NOT EXISTS t_country (code VARCHAR(50), name VARCHAR(50), language VARCHAR(50), PRIMARY KEY (code))";
        try (Connection connection = dataSource.getConnection();
             Statement statement = connection.createStatement()) {
            statement.executeUpdate(sql);
@@ -106,10 +106,9 @@ public final class CountryRepositoryImpl implements CountryRepository {
             ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                Country country = new Country();
                country.setId(resultSet.getLong(1));
                country.setCode(resultSet.getString(2));
                country.setName(resultSet.getString(3));
                country.setLanguage(resultSet.getString(4));
                country.setCode(resultSet.getString(1));
                country.setName(resultSet.getString(2));
                country.setLanguage(resultSet.getString(3));
                result.add(country);
            }
        } catch (final SQLException ignored) {
+9 −5
Original line number Diff line number Diff line
@@ -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 {

@@ -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);
    }
}
+1 −9
Original line number Diff line number Diff line
@@ -18,11 +18,10 @@
package org.apache.shardingsphere.example.common.jpa.entity;

import org.apache.shardingsphere.example.common.entity.Country;
import org.springframework.context.annotation.Primary;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@@ -31,13 +30,6 @@ import javax.persistence.Table;
public class CountryEntity extends Country {

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Override
    public long getId() {
        return super.getId();
    }
    
    @Column(name = "code")
    @Override
    public String getCode() {
+9 −5
Original line number Diff line number Diff line
@@ -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 {
@@ -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);
    }
}
Loading