Repository navigation
Expand file tree
/
Copy pathDatabasePersistenceLog.java
More file actions
56 lines (44 loc) · 1.77 KB
/
Copy pathDatabasePersistenceLog.java
File metadata and controls
56 lines (44 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.List;
public class DatabasePersistenceLog {
private String dbName;
private Path filePath;
public DatabasePersistenceLog(String dbName) throws IOException {
this.dbName = dbName;
this.filePath = Path.of("data", dbName + ".dblog");
Files.createDirectories(filePath.getParent());
Files.deleteIfExists(filePath);
Files.createFile(filePath);
}
private void appendLine(String line) throws IOException {
Files.writeString(filePath, line + System.lineSeparator(), StandardOpenOption.APPEND);
}
public void logDbCreate() throws IOException {
appendLine("db create " + dbName);
appendLine("db select " + dbName);
}
public void logTableCreate(String tableName, List<String> fieldArgs) throws IOException {
appendLine("table create " + tableName + " " + String.join(" ", fieldArgs));
}
public void logTableSelect(String tableName) throws IOException {
appendLine("table select " + tableName);
}
public void logTableDelete(String tableName) throws IOException {
appendLine("table delete " + tableName);
}
public void logRowCreate(List<String> fieldValueArgs) throws IOException {
appendLine("row create " + String.join(" ", fieldValueArgs));
}
public void logRowUpdate(List<String> updateArgs) throws IOException {
appendLine("row update " + String.join(" ", updateArgs));
}
public void logRowDelete(List<String> deleteArgs) throws IOException {
appendLine("row delete " + String.join(" ", deleteArgs));
}
public String getFilePath() {
return filePath.toString();
}
}