- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.java
More file actions
Latest commit
62 lines (51 loc) · 1.71 KB
/
Copy pathDatabase.java
File metadata and controls
62 lines (51 loc) · 1.71 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
57
58
59
60
61
62
packagesimpledb;
importjava.io.*;
/** Database is a class that initializes several static
variables used by the database system (the catalog, the buffer pool,
and the log files, in particular.)
<p>
Provides a set of methods that can be used to access these variables
from anywhere.
*/
publicclassDatabase { // 2016 F
privatestaticDatabase_instance = newDatabase();
privatefinalCatalog_catalog;
privateBufferPool_bufferpool;
privatefinalstaticStringLOGFILENAME = "log";
privateLogFile_logfile;
privateDatabase() {
_catalog = newCatalog();
_bufferpool = newBufferPool(BufferPool.DEFAULT_PAGES);
try {
_logfile = newLogFile(newFile(LOGFILENAME));
} catch(IOExceptione) {
_logfile = null;
e.printStackTrace();
System.exit(1);
}
// startControllerThread();
}
/** Return the log file of the static Database instance*/
publicstaticLogFilegetLogFile() {
return_instance._logfile;
}
/** Return the buffer pool of the static Database instance*/
publicstaticBufferPoolgetBufferPool() {
return_instance._bufferpool;
}
/** Return the catalog of the static Database instance*/
publicstaticCataloggetCatalog() {
return_instance._catalog;
}
/** Method used for testing -- create a new instance of the
buffer pool and return it
*/
publicstaticBufferPoolresetBufferPool(intpages) {
_instance._bufferpool = newBufferPool(pages);
return_instance._bufferpool;
}
//reset the database, used for unit tests only.
publicstaticvoidreset() {
_instance = newDatabase();
}
}