Archived
0

fix: создание таблиц при запуске

This commit is contained in:
2018-09-16 18:15:11 +03:00
parent 384ae13ecf
commit 86f1e1c3d2

View File

@@ -10,6 +10,7 @@ import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.sql.PreparedStatement;
@@ -31,6 +32,11 @@ public class H2PlayerDAO {
@Autowired
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 {
if (player.getName() == null || player.getName().isEmpty()) {
throw new SQLException("Field 'name' is " + (player.getName() == null ? "null" : "empty"));