- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleDb.java
More file actions
Latest commit
84 lines (77 loc) · 3.08 KB
/
Copy pathSimpleDb.java
File metadata and controls
84 lines (77 loc) · 3.08 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
packagesimpledb;
importjava.util.*;
importjava.io.*;
publicclassSimpleDb {
publicstaticvoidmain (Stringargs[])
throwsDbException, TransactionAbortedException, IOException {
// convert a file
if(args[0].equals("convert")) {
try {
if (args.length == 3) {
HeapFileEncoder.convert(newFile(args[1]),
newFile(args[1].replaceAll(".txt", ".dat")),
BufferPool.PAGE_SIZE,
Integer.parseInt(args[2]));
}
elseif (args.length == 4) {
ArrayList<Type> ts = newArrayList<Type>();
String[] typeStringAr = args[3].split(",");
for (Strings: typeStringAr) {
if (s.toLowerCase().equals("int"))
ts.add(Type.INT_TYPE);
elseif (s.toLowerCase().equals("string"))
ts.add(Type.STRING_TYPE);
else {
System.out.println("Unknown type " + s);
return;
}
}
HeapFileEncoder.convert(newFile(args[1]),
newFile(args[1].replaceAll(".txt", ".dat")),
BufferPool.PAGE_SIZE,
Integer.parseInt(args[2]), ts.toArray(newType[0]));
} else {
System.out.println("Unexpected number of arguments to convert ");
}
} catch (IOExceptione) {
thrownewRuntimeException(e);
}
} elseif (args[0].equals("print")) {
FiletableFile = newFile(args[1]);
intcolumns = Integer.parseInt(args[2]);
DbFiletable = Utility.openHeapFile(columns, tableFile);
TransactionIdtid = newTransactionId();
DbFileIteratorit = table.iterator(tid);
if(null == it){
System.out.println("Error: method HeapFile.iterator(TransactionId tid) not yet implemented!");
} else {
it.open();
while (it.hasNext()) {
Tuplet = it.next();
System.out.println(t);
}
it.close();
}
}
elseif (args[0].equals("parser")) {
// Strip the first argument and call the parser
String[] newargs = newString[args.length-1];
for (inti = 1; i < args.length; ++i) {
newargs[i-1] = args[i];
}
try {
//dynamically load Parser -- if it doesn't exist, print error message
Class<?> c = Class.forName("simpledb.Parser");
Class<?> s = String[].class;
java.lang.reflect.Methodm = c.getMethod("main", s);
m.invoke(null, (java.lang.Object)newargs);
} catch (Exceptione) {
System.out.println("Class Parser not found -- perhaps you are trying to run the parser as a part of assignment1?");
}
}
else {
System.err.println("Unknown command: " + args[0]);
System.exit(1);
}
}
}