fix: создание таблиц при запуске
This commit is contained in:
@@ -10,6 +10,7 @@ import org.springframework.jdbc.support.GeneratedKeyHolder;
|
|||||||
import org.springframework.jdbc.support.KeyHolder;
|
import org.springframework.jdbc.support.KeyHolder;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@@ -31,6 +32,11 @@ public class H2PlayerDAO {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() throws IOException {
|
||||||
|
jdbcTemplate.execute(IOUtils.resourceToString("/sqls/create_tables.sql", StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
private void checkPlayer(H2Player player) throws SQLException {
|
private void checkPlayer(H2Player player) throws SQLException {
|
||||||
if (player.getName() == null || player.getName().isEmpty()) {
|
if (player.getName() == null || player.getName().isEmpty()) {
|
||||||
throw new SQLException("Field 'name' is " + (player.getName() == null ? "null" : "empty"));
|
throw new SQLException("Field 'name' is " + (player.getName() == null ? "null" : "empty"));
|
||||||
|
|||||||
Reference in New Issue
Block a user