Updated files and created compose.yml for internal database usage
This commit is contained in:
19
docker/compose.yml
Normal file
19
docker/compose.yml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
version: "3.9"
|
||||||
|
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: mysql:8.0
|
||||||
|
container_name: mysql-db
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: root
|
||||||
|
MYSQL_DATABASE: sql7810540&
|
||||||
|
MYSQL_USER: sql7810540&
|
||||||
|
MYSQL_PASSWORD: mXdJCFtDZz
|
||||||
|
ports:
|
||||||
|
- "3306:3306"
|
||||||
|
volumes:
|
||||||
|
- mysql_data:/var/lib/mysql
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
mysql_data:
|
||||||
5
resources/sql/createWorkerTable.sql
Normal file
5
resources/sql/createWorkerTable.sql
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
CREATE TABLE Worker (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
workerid INT,
|
||||||
|
name VARCHAR(255) NOT NULL
|
||||||
|
);
|
||||||
1
resources/sql/insertWorkerTable.sql
Normal file
1
resources/sql/insertWorkerTable.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
INSERT INTO Worker (workerid, name) VALUES (?, ?)
|
||||||
@@ -3,15 +3,50 @@ package hhn.temp.project.provider;
|
|||||||
import hhn.temp.project.Task;
|
import hhn.temp.project.Task;
|
||||||
import hhn.temp.project.Worker;
|
import hhn.temp.project.Worker;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class SimpleDatabaseManager implements DatabaseManager {
|
public class SimpleDatabaseManager implements DatabaseManager {
|
||||||
|
|
||||||
|
private final static Path INSERT_TASK = Path.of("./src/main/resources/sql/InsertTaskTable.sql");
|
||||||
|
private final static Path DELETE_TASK = Path.of("./src/main/resources/sql/DeleteTaskTable.sql");
|
||||||
|
private final static Path SELECT_TASK = Path.of("./src/main/resources/sql/SelectTaskTable.sql");
|
||||||
|
private final static Path UPDATE_TASK = Path.of("./src/main/resources/sql/UpdateTaskTable.sql");
|
||||||
|
|
||||||
private boolean connected = false;
|
private boolean connected = false;
|
||||||
private Map<Integer, Task> temporaryTaskList = new HashMap();
|
private Map<Integer, Task> temporaryTaskList = new HashMap();
|
||||||
private Map<Integer, Worker> temporaryWorkerList = new HashMap<>();
|
private Map<Integer, Worker> temporaryWorkerList = new HashMap<>();
|
||||||
|
|
||||||
|
public enum QueryMode {
|
||||||
|
INSERT,
|
||||||
|
SELECT,
|
||||||
|
UPDATE,
|
||||||
|
DELETE
|
||||||
|
}
|
||||||
|
|
||||||
|
public String loadFile(QueryMode queryMode) throws IOException, URISyntaxException {
|
||||||
|
switch (queryMode) {
|
||||||
|
case INSERT -> {
|
||||||
|
return Files.readString(INSERT_TASK);
|
||||||
|
}
|
||||||
|
case SELECT -> {
|
||||||
|
|
||||||
|
}
|
||||||
|
case DELETE -> {
|
||||||
|
|
||||||
|
}
|
||||||
|
case UPDATE -> {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveTask(Task task) throws SQLException {
|
public void saveTask(Task task) throws SQLException {
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -16,7 +17,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class DatabaseGoodCasesTest {
|
public class DatabaseGoodCasesTest {
|
||||||
|
|
||||||
private DatabaseManager databaseManager;
|
private SimpleDatabaseManager databaseManager;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() throws SQLException {
|
public void setup() throws SQLException {
|
||||||
@@ -83,4 +84,9 @@ public class DatabaseGoodCasesTest {
|
|||||||
assertEquals(0, databaseManager.getTotalNumberOfTasks());
|
assertEquals(0, databaseManager.getTotalNumberOfTasks());
|
||||||
assertEquals(0, databaseManager.getTotalNumberOfWorkers());
|
assertEquals(0, databaseManager.getTotalNumberOfWorkers());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRandom() throws IOException, URISyntaxException {
|
||||||
|
System.out.println(databaseManager.loadFile(SimpleDatabaseManager.QueryMode.INSERT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user