-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database.java
62 lines (51 loc) · 1.71 KB
/
Database.java
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
package simpledb;
import java.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.
*/
public class Database { // 2016 F
private static Database _instance = new Database();
private final Catalog _catalog;
private BufferPool _bufferpool;
private final static String LOGFILENAME = "log";
private LogFile _logfile;
private Database() {
_catalog = new Catalog();
_bufferpool = new BufferPool(BufferPool.DEFAULT_PAGES);
try {
_logfile = new LogFile(new File(LOGFILENAME));
} catch(IOException e) {
_logfile = null;
e.printStackTrace();
System.exit(1);
}
// startControllerThread();
}
/** Return the log file of the static Database instance*/
public static LogFile getLogFile() {
return _instance._logfile;
}
/** Return the buffer pool of the static Database instance*/
public static BufferPool getBufferPool() {
return _instance._bufferpool;
}
/** Return the catalog of the static Database instance*/
public static Catalog getCatalog() {
return _instance._catalog;
}
/** Method used for testing -- create a new instance of the
buffer pool and return it
*/
public static BufferPool resetBufferPool(int pages) {
_instance._bufferpool = new BufferPool(pages);
return _instance._bufferpool;
}
//reset the database, used for unit tests only.
public static void reset() {
_instance = new Database();
}
}