-
Notifications
You must be signed in to change notification settings - Fork 166
[๐ ์ฌ์ดํด2 - ๋ฏธ์ (๊ธฐ๋ฌผ ํ์ฅ + DB ์ ์ฉ)] ๋ฌ์ ๋ฏธ์ ์ ์ถํฉ๋๋ค. #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
5408b50
tset: Score ๋จ์ ํ
์คํธ ์ถ๊ฐ
soohyun1904 01889ed
feat: Score ๊ฐ์ฒด ์ถ๊ฐ
soohyun1904 da42f3a
feat: PieceName ์ถ๊ฐ
soohyun1904 ecb018e
feat: MoveStrategy ๊ตฌํ์ฒด ์ฑ๊ธํค ์ถ๊ฐ
soohyun1904 87cd305
refactor: Position, Row, Column ์์
soohyun1904 2c46551
test: Direction ๋จ์ ํ
์คํธ ์ถ๊ฐ
soohyun1904 3299b54
feat: Direction ๊ฐ์ฒด ๊ธฐ๋ฅ ์ถ๊ฐ
soohyun1904 7e0b9ae
test: Position, Row, Column ์์ฑ์ ์์ ์ผ๋ก ์ธํ ํ
์คํธ ๋ณ๊ฒฝ
soohyun1904 c62cb1e
test: ๊ถ์ฑ(Palace, Palaces) ๋จ์ ํ
์คํธ ์ถ๊ฐ
soohyun1904 f2ee335
feat: ๊ถ์ฑ(Palace, Palaces) ๊ฐ์ฒด ์ถ๊ฐ
soohyun1904 ad64c77
test: ๊ธฐ๋ฌผ ์์ง์ ๊ถ์ฑ ํ๋จ ํ
์คํธ ์ถ๊ฐ
soohyun1904 14ab1d0
feat: ๊ธฐ๋ฌผ ๊ถ์ฑ ๋ด๋ถ ์์ง์ ์ถ๊ฐ
soohyun1904 8f2aa8e
test: ๊ถ์ฑ ๋ด๋ถ ํ๋จ(false) ํ
์คํธ ์ถ๊ฐ
soohyun1904 2d69e86
refactor: ์ด๋ ์ ๋ต ๊ฐ์ฒด ์์ ์ผ๋ก ์ธํ ๋ณ๊ฒฝ
soohyun1904 ce02030
test: ๊ธฐ๋ฌผ(Piece) ๋จ์ ํ
์คํธ ์ถ๊ฐ
soohyun1904 6123d3b
feat: ๊ธฐ๋ฌผ(Piece) ๊ธฐ๋ฅ ์ถ๊ฐ
soohyun1904 292c307
test: ๋ณด๋(Board) ๋จ์ ํ
์คํธ ์ถ๊ฐ
soohyun1904 19c2224
feat: ๋๋ผ ๋ณ ์ ํ์ธ ๊ธฐ๋ฅ ์ถ๊ฐ
soohyun1904 e26aa53
feat: ์ข
๋ฃ ์ถ๊ฐ
soohyun1904 7043892
chore: .gitignore ์
๋ฐ์ดํธ
soohyun1904 554e7dc
test: Score ๋จ์ ํ
์คํธ ์ถ๊ฐ
soohyun1904 a2b564e
feat: ์ ์(Score) ๋ฐฐ์จ ๊ณฑํ๋ ๊ธฐ๋ฅ ์ถ๊ฐ
soohyun1904 b6bf6fc
test: Board ๋จ์ ํ
์คํธ ์ถ๊ฐ
soohyun1904 c8dd20d
feat: ๋ณด๋(board) ์ ์ ํ๋จ ํ ์นํจ ํ๋จ ๋ก์ง ์ถ๊ฐ
soohyun1904 a760d34
feat: ํญ๋ณต, ๋ฌด์น๋ถ ๊ธฐ๋ฅ ์ถ๊ฐ
soohyun1904 ec2f413
chore: ๋ฐ์ดํฐ๋ฒ ์ด์ค SQL ์์กด์ฑ, properties, sql ์ถ๊ฐ,
soohyun1904 fa07793
feat: ๊ธฐ๋ฌผ(Piece), ๋ง์ ๋ฐฐ์น ํฉํ ๋ฆฌ ํด๋์ค ์ถ๊ฐ
soohyun1904 0716a11
feat: DB ์กฐํ, ์ญ์ , ์ฝ์
์ ์ํ Entity ์ถ๊ฐ
soohyun1904 f34508b
chore: ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฐ๊ฒฐ ์ค์ ๋ฐ SQL ํ๊ฒฝ ๊ตฌ์ถ
soohyun1904 fc618fe
feat: ์ํฐํฐ mapper ์ถ๊ฐ
soohyun1904 bd152a2
feat: ๊ธฐ๋ฌผ, ๊ฒ์ Dao ์ถ๊ฐ
soohyun1904 564cb77
feat: ์ฅ๊ธฐ ์๋น์ค, ๋ฆฌํฌ์งํ ๋ฆฌ ์ถ๊ฐ
soohyun1904 63e91d9
feat: ์ ๋ํฌ ์ปฌ๋ผ ์กฐํฌ ์์ธ์ฒ๋ฆฌ ์ถ๊ฐ
soohyun1904 c736386
refactor: Db, ์๋น์ค ์ถ๊ฐ๋ก ์ธํ ์ ์ฒด์ ์ธ ์์
soohyun1904 38e8eb6
test: ์ฅ๊ธฐ ํ
ใ
กํธ ์ถ์
soohyun1904 2c07af8
refacotor: mapper ๋ฉ์๋ ๋ช
์์ ์ผ๋ก ์์
soohyun1904 c81ae57
feat: ๊ฒ์ ์ด๋ฆ ๊ฒ์ฆ ์ถ๊ฐ
soohyun1904 885234f
refactor: ์ปจํธ๋กค๋ฌ loadGame์์ ์ด๋ฆ ๊ฒ์ฆ ์ญ์
soohyun1904 c0bb5bd
feat: ๊ฒ์ ์ญ์ ๊ธฐ๋ฅ ์ถ๊ฐ
soohyun1904 5fe3ce9
feat: ํธ๋์ญ์
, ์ปค๋ฅ์
ํ ์ถ๊ฐ
soohyun1904 5cd0a6b
test: dao, repository ๋จ์ ํ
์คํธ ์ถ๊ฐ
soohyun1904 7788a7d
refactor: ์์ฑ ์ ์ค๋ณต๋ ์ด๋ฆ ์ฒดํฌ ์ถ๊ฐ
soohyun1904 ae704c3
refactor: ๊ฐ ๊ณ์ธต ๋ณ ๋ฐ์ดํฐ ๋ณํ ์ํ
soohyun1904 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,3 +30,4 @@ out/ | |
|
|
||
| ### VS Code ### | ||
| .vscode/ | ||
| src/main/resources/application.properties | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| -- 1. ๊ฒ์ ํ ์ด๋ธ (๋ฉํ๋ฐ์ดํฐ) | ||
| CREATE TABLE game ( | ||
| id VARCHAR(36) PRIMARY KEY, | ||
| name VARCHAR(50) NOT NULL UNIQUE, | ||
| status VARCHAR(20) NOT NULL, -- PLAYING, CHO_WIN, HAN_WIN, DRAW | ||
| current_turn VARCHAR(10) NOT NULL -- CHO, HAN | ||
| ); | ||
|
|
||
| -- 2. ๊ธฐ๋ฌผ ์ํ ํ ์ด๋ธ (1๋ฒ ํ ์ด๋ธ์ ์ฐธ์กฐ) | ||
| CREATE TABLE piece ( | ||
| id BIGINT AUTO_INCREMENT PRIMARY KEY, | ||
| game_id VARCHAR(36) NOT NULL, -- ์ด๋ค ๊ฒ์ํ์ ์ํด์๋์ง (FK) | ||
| piece_name VARCHAR(20) NOT NULL, -- CHO_SOLDIER, HAN_CHARIOT ๋ฑ | ||
| camp VARCHAR(3) NOT NULL, | ||
| row_index INT NOT NULL, -- Y ์ขํ (0~9) | ||
| column_index INT NOT NULL, -- X ์ขํ (0~8) | ||
|
|
||
|
|
||
| FOREIGN KEY (game_id) REFERENCES game(id) ON DELETE CASCADE | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,58 @@ | ||
| package janggi.config; | ||
|
|
||
| import janggi.controller.JanggiController; | ||
| import janggi.persistence.GameRepositoryImpl; | ||
| import janggi.persistence.dao.GameDao; | ||
| import janggi.persistence.dao.JdbcGameDao; | ||
| import janggi.persistence.dao.JdbcPieceDao; | ||
| import janggi.persistence.dao.PieceDao; | ||
| import janggi.persistence.mapper.GameMapper; | ||
| import janggi.persistence.mapper.PieceMapper; | ||
| import janggi.service.GameRepository; | ||
| import janggi.service.JanggiService; | ||
| import janggi.view.InputView; | ||
| import janggi.view.OutputView; | ||
|
|
||
| public class AppConfig { | ||
| private final ConnectionPool connectionPool = DatabaseConfig.getPool(); | ||
|
|
||
| public JanggiController janggiController() { | ||
| return new JanggiController(new InputView(), new OutputView()); | ||
| return new JanggiController(inputView(), outputView(), janggiService()); | ||
| } | ||
|
|
||
| public InputView inputView() { | ||
| return new InputView(); | ||
| } | ||
|
|
||
| public OutputView outputView() { | ||
| return new OutputView(); | ||
| } | ||
|
|
||
| public JanggiService janggiService() { | ||
| return new JanggiService(gameRepository(), transactionManager()); | ||
| } | ||
|
|
||
| public TransactionManager transactionManager() { | ||
| return new TransactionManager(connectionPool); | ||
| } | ||
|
|
||
| public GameRepository gameRepository() { | ||
| return new GameRepositoryImpl(gameDao(), pieceDao(), gameMapper(), pieceMapper()); | ||
| } | ||
|
|
||
| public GameDao gameDao() { | ||
| return new JdbcGameDao(connectionPool); | ||
| } | ||
|
|
||
| public PieceDao pieceDao() { | ||
| return new JdbcPieceDao(connectionPool); | ||
| } | ||
|
|
||
| public GameMapper gameMapper() { | ||
| return new GameMapper(); | ||
| } | ||
|
|
||
| public PieceMapper pieceMapper() { | ||
| return new PieceMapper(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package janggi.config; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.DriverManager; | ||
| import java.sql.SQLException; | ||
| import java.util.concurrent.ArrayBlockingQueue; | ||
| import java.util.concurrent.BlockingQueue; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| public class ConnectionPool { | ||
| private final BlockingQueue<Connection> pool; | ||
| private final String url; | ||
| private final String username; | ||
| private final String password; | ||
| private final long timeoutMillis; | ||
|
|
||
| private final int poolSize; | ||
|
|
||
| ConnectionPool(String url, String username, String password, int poolSize) { | ||
| this.url = url; | ||
| this.username = username; | ||
| this.password = password; | ||
| this.timeoutMillis = 5000; | ||
| this.poolSize = poolSize; | ||
|
|
||
| this.pool = new ArrayBlockingQueue<>(this.poolSize); | ||
|
|
||
| try { | ||
| for (int i = 0; i < this.poolSize; i++) { | ||
| pool.offer(createConnection()); | ||
| } | ||
| } catch (SQLException e) { | ||
| throw new RuntimeException("์ปค๋ฅ์ ํ ์ด๊ธฐํ ์คํจ", e); | ||
| } | ||
| } | ||
|
|
||
| private Connection createConnection() throws SQLException { | ||
| return DriverManager.getConnection(url, username, password); | ||
| } | ||
|
|
||
| public Connection getConnection() { | ||
| try { | ||
| Connection conn = pool.poll(timeoutMillis, TimeUnit.MILLISECONDS); | ||
| if (conn == null) { | ||
| throw new RuntimeException("์ปค๋ฅ์ ํ๋ ๋๊ธฐ ์๊ฐ ์ด๊ณผ (Timeout)"); | ||
| } | ||
|
|
||
| if (!conn.isValid(1)) { | ||
| try { | ||
| conn.close(); | ||
| } catch (SQLException ignored) {} | ||
| conn = createConnection(); | ||
| } | ||
|
|
||
| return conn; | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| throw new RuntimeException("์ปค๋ฅ์ ๋๊ธฐ ์ค ์ธํฐ๋ฝํธ ๋ฐ์", e); | ||
| } catch (SQLException e) { | ||
| throw new RuntimeException("์ ํจํ์ง ์์ ์ปค๋ฅ์ ์ฌ์ค์ ๋ฐ ๊ฒ์ฆ ์คํจ", e); | ||
| } | ||
| } | ||
|
|
||
| public void release(Connection conn) { | ||
| if (conn != null) { | ||
| try { | ||
| if (!conn.isClosed()) { | ||
| conn.setAutoCommit(true); | ||
| pool.offer(conn); | ||
| } | ||
| } catch (SQLException e) { | ||
| try { | ||
| conn.close(); | ||
| } catch (SQLException ignored) {} | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void shutdown() { | ||
| Connection conn; | ||
| while ((conn = pool.poll()) != null) { | ||
| try { | ||
| conn.close(); | ||
| } catch (SQLException ignored) {} | ||
| } | ||
| } | ||
|
|
||
| public PooledConnection getPooledConnection() { | ||
| return new PooledConnection(getConnection(), this); | ||
| } | ||
|
|
||
| public int getAvailableCount() { | ||
| return pool.size(); | ||
| } | ||
|
|
||
| public int getActiveCount() { | ||
| return poolSize - pool.size(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package janggi.config; | ||
|
|
||
| import java.io.InputStream; | ||
| import java.sql.Connection; | ||
| import java.sql.DriverManager; | ||
| import java.sql.SQLException; | ||
| import java.util.Properties; | ||
|
|
||
| public class DatabaseConfig { | ||
| private static final Properties properties = new Properties(); | ||
| private static final ConnectionPool connectionPool; | ||
|
|
||
| static { | ||
| try (InputStream input = DatabaseConfig.class.getResourceAsStream("/application.properties")) { | ||
| if (input == null) { | ||
| throw new RuntimeException("application.properties ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค."); | ||
| } | ||
| properties.load(input); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException("JDBC ์ด๊ธฐํ ์คํจ", e); | ||
| } | ||
|
|
||
| connectionPool = new ConnectionPool( | ||
| properties.getProperty("db.url"), | ||
| properties.getProperty("db.id"), | ||
| properties.getProperty("db.password"), | ||
| 5 | ||
| ); | ||
| } | ||
|
|
||
| public static void shutdown() { | ||
| connectionPool.shutdown(); | ||
| } | ||
|
|
||
| public static PooledConnection getConnection() { | ||
| return connectionPool.getPooledConnection(); | ||
| } | ||
|
|
||
| public static ConnectionPool getPool() { | ||
| return connectionPool; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package janggi.config; | ||
|
|
||
| import java.sql.Connection; | ||
|
|
||
| public class PooledConnection implements AutoCloseable{ | ||
| private final Connection conn; | ||
| private final ConnectionPool pool; | ||
|
|
||
| PooledConnection(Connection conn, ConnectionPool pool) { | ||
| this.conn = conn; | ||
| this.pool = pool; | ||
| } | ||
|
|
||
| public Connection getConnection() { | ||
| return conn; | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| pool.release(conn); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package janggi.config; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.SQLException; | ||
|
|
||
| @FunctionalInterface | ||
| public interface TransactionCallback<T> { | ||
| T run(Connection conn) throws SQLException; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package janggi.config; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.SQLException; | ||
|
|
||
| public class TransactionManager { | ||
| private final ConnectionPool pool; | ||
|
|
||
| public TransactionManager(ConnectionPool pool) { | ||
| this.pool = pool; | ||
| } | ||
|
|
||
| public <T> T execute(TransactionCallback<T> callback) { | ||
| PooledConnection pooledConn = pool.getPooledConnection(); | ||
| Connection conn = pooledConn.getConnection(); | ||
| try { | ||
| conn.setAutoCommit(false); | ||
| T result = callback.run(conn); | ||
| conn.commit(); | ||
| return result; | ||
| } catch (Exception e) { | ||
| try { conn.rollback(); } catch (SQLException ignored) {} | ||
| throw new RuntimeException("ํธ๋์ญ์ ์คํ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.", e); | ||
| } finally { | ||
| pooledConn.close(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.