This repository has been archived by the owner on Aug 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menu.java
98 lines (92 loc) · 2.66 KB
/
Menu.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
import com.sleepycat.db.DatabaseException;
public class Menu{
Scan scan;
public Menu(){
this.printHeader();
scan = Scan.getInstance();
this.makeSelection();
}
public void printHeader(){
System.out.println("======================================");
System.out.println("|\tGeneric File Database");
System.out.println("======================================");
System.out.println("|Options:");
System.out.println("|\t1) Create and populate a database");
System.out.println("|\t2) Retrieve records with a given key");
System.out.println("|\t3) Retrieve records with a given data");
System.out.println("|\t4) Retrieve records with a given range of key values");
System.out.println("|\t5) Destroy the database");
System.out.println("|\t6) Quit");
System.out.println("======================================");
}
public void makeSelection(){
DataBase db;
int option = this.select();
switch(option){
case 1 :
db = DataBase.getInstance();
db.initDataBase();
printHeader();
makeSelection();
break;
case 2 :
System.out.println("Option 2 executed");
KeyRetrieve kr = new KeyRetrieve();
if(Pref.getDbType() == 3){
try{
kr.getIndexFileRecord(false, null);
db = DataBase.getInstance();
if(db.getIndexTree() == null)
db.initDataBase();
}catch(DatabaseException dbe){
dbe.printStackTrace();
}
}
else{
kr.getRecords(false, null);
}
printHeader();
makeSelection();
break;
case 3:
System.out.println("Option 3 executed");
DataRetrieve dr = new DataRetrieve();
dr.getRecords(false, null);
printHeader();
makeSelection();
break;
case 4:
System.out.println("Option 4 executed");
RangeSearch rs = new RangeSearch();
rs.execute(false, null, null);
printHeader();
makeSelection();
break;
case 5:
System.out.println("Option 5 executed");
DataBase.getInstance().close(false);
this.printHeader();
this.makeSelection();
break;
case 6:
//TODO ensure that DataBase.getInstance() does not open create database when unwanted
System.out.println("Exiting data base");
DataBase.getInstance().close(true);
System.exit(-1);
break;
default:
System.out.println("invalid option selected");
this.makeSelection();
}
}
public int select(){
int selection = -1;
try{
selection = scan.getInt();
}catch(Exception e){
System.out.println("Menu selection failed! Check output console");
e.printStackTrace();
}
return selection;
}
}