Commit 5af5e42b authored by cherrylzhao's avatar cherrylzhao
Browse files

revise country table id, name, code => id, code, name

parent 4a6247d5
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -25,10 +25,10 @@ public class Country implements Serializable {

    private long id;
    
    private String name;

    private String code;

    private String name;

    private String language;

    public long getId() {
@@ -65,6 +65,6 @@ public class Country implements Serializable {

    @Override
    public String toString() {
        return String.format("id: %s, name: %s, code: %s, language: %s", id, name, code, language);
        return String.format("id: %s, code: %s, name: %s, language: %s", id, code, name, language);
    }
}
+7 −7
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;

public class CountryRepositoryImpl implements CountryRepository {
public final class CountryRepositoryImpl implements CountryRepository {

    private final DataSource dataSource;

@@ -39,7 +39,7 @@ public class CountryRepositoryImpl implements CountryRepository {

    @Override
    public void createTableIfNotExists() {
        String sql = "CREATE TABLE IF NOT EXISTS t_country (id BIGINT NOT NULL AUTO_INCREMENT, name VARCHAR(50),code VARCHAR(50), language VARCHAR(50), PRIMARY KEY (id))";
        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))";
        try (Connection connection = dataSource.getConnection();
             Statement statement = connection.createStatement()) {
            statement.executeUpdate(sql);
@@ -69,11 +69,11 @@ public class CountryRepositoryImpl implements CountryRepository {

    @Override
    public String insert(final Country country) {
        String sql = "INSERT INTO t_country (name, code, language) VALUES (?, ?, ?)";
        String sql = "INSERT INTO t_country (code, name, language) VALUES (?, ?, ?)";
        try (Connection connection = dataSource.getConnection();
             PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
            preparedStatement.setString(1, country.getName());
            preparedStatement.setString(2, country.getCode());
            preparedStatement.setString(1, country.getCode());
            preparedStatement.setString(2, country.getName());
            preparedStatement.setString(3, country.getLanguage());
            preparedStatement.executeUpdate();
            ResultSet rs = connection.createStatement().executeQuery("SELECT @@IDENTITY");
@@ -110,8 +110,8 @@ public class CountryRepositoryImpl implements CountryRepository {
            while (resultSet.next()) {
                Country country = new Country();
                country.setId(resultSet.getLong(1));
                country.setName(resultSet.getString(2));
                country.setCode(resultSet.getString(3));
                country.setCode(resultSet.getString(2));
                country.setName(resultSet.getString(3));
                country.setLanguage(resultSet.getString(4));
                result.add(country);
            }
+6 −6
Original line number Diff line number Diff line
@@ -38,18 +38,18 @@ public class CountryEntity extends Country {
        return super.getId();
    }
    
    @Column(name = "name")
    @Override
    public String getName() {
        return super.getName();
    }

    @Column(name = "code")
    @Override
    public String getCode() {
        return super.getCode();
    }

    @Column(name = "name")
    @Override
    public String getName() {
        return super.getName();
    }

    @Column(name = "language")
    @Override
    public String getLanguage() {
+1 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ public class CountryRepositoryImpl implements CountryRepository {
    }

    @Override
    @SuppressWarnings("unchecked")
    public List<Country> selectAll() {
        return (List<Country>) entityManager.createQuery("SELECT o FROM CountryEntity o").getResultList();
    }
+1 −1
Original line number Diff line number Diff line
@@ -92,9 +92,9 @@ public class SpringCountryServiceImpl implements SpringCountryService {
                continue;
            }
            Country currCountry = new Country();
            currCountry.setCode(l.getCountry());
            currCountry.setName(l.getDisplayCountry(l));
            currCountry.setLanguage(l.getLanguage());
            currCountry.setCode(l.getCountry());
            repository.insertStandard(currCountry);
            result.add(currCountry.getCode());
            if (++i == 10) {
Loading