-
Notifications
You must be signed in to change notification settings - Fork 1
/
Table.java
executable file
·99 lines (90 loc) · 2.64 KB
/
Table.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import org.omg.CORBA.StructMemberHelper;
public class Table implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
ArrayList<String> pagesName = new ArrayList<String>();
transient ArrayList<Page> pages = new ArrayList<Page>();
String currentPage = "0";
String strTableName;
ArrayList<String> indices = new ArrayList<String>();
Hashtable<String, String> htblColNameType;
Hashtable<String, String> htblColNameRefs;
String strKeyColName;
public Table(String strTableName,
Hashtable<String,String> htblColNameType,
Hashtable<String,String>htblColNameRefs,
String strKeyColName) {
this.strKeyColName = strKeyColName;
this.strTableName = strTableName;
this.htblColNameRefs = htblColNameRefs;
this.htblColNameType = htblColNameType;
}
public Table(String tblName){
strTableName = tblName;
}
public Page loadPage(String filename) throws Exception{
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
new File(filename)));
Page p = (Page) ois.readObject();
ois.close();
return p;
}
public void insert(Hashtable<String, String> htblColNameValue)
throws Exception {
updatePages();
Page p = loadPage(currentPage+".ser");
p.insert(htblColNameValue);
}
public void updatePages() throws Exception {
Page p;
if (pages.isEmpty()) {
p = new Page(currentPage, htblColNameType.size());
pagesName.add(currentPage);
pages.add(p);
} else {
p = pages.get(Integer.parseInt(currentPage));
if (p.exceedLimit()) {
currentPage = (Integer.parseInt(currentPage) + 1) + "";
p = new Page(currentPage, htblColNameType.size());
pagesName.add(currentPage);
pages.add(p);
}
}
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
new File(currentPage + ".ser")));
oos.writeObject(p);
oos.close();
}
public ExtensibleHash getUpdatedExtensibleHash(String columnName)throws Exception{
ExtensibleHash h = new ExtensibleHash();
indices.add(columnName);
Enumeration<String> en = htblColNameType.keys();
int count = 0;
int columnNo = 0;
while(!en.hasMoreElements()){
if(en.nextElement().equals(columnName)){
columnNo = htblColNameType.size()-1-count;
}
count++;
}
for(int i = 0; i< pages.size();i++){
Page p=pages.get(i);
for(int j = 0; j<200;j++){
String index = p.tuples[columnNo][j]+","+i+j;
h.insertIndex(index);
}
}
return h;
}
}