Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
51 lines (37 loc) · 1.48 KB
/
Copy pathMain.java
File metadata and controls
51 lines (37 loc) · 1.48 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
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String[] args) {
Database db = new Database();
List<String> fields = Arrays.asList("id", "name", "address");
List<String> types = Arrays.asList("LONG", "STRING", "STRING");
List<String> pKeys = Arrays.asList("id");
Table people = db.createTable("people", fields, types, pKeys);
Row r1 = new Row();
r1.setLong("id", 1L);
r1.setString("name", "Alice");
r1.setString("address", "123 Main St");
people.insert(r1);
Row r2 = new Row();
r2.setLong("id", 2L);
r2.setString("name", "Bob");
r2.setString("address", "456 Oak Ave");
people.insert(r2);
people.printAll();
System.out.println("\nLooking up id=1:");
Row found = people.getByLongKey("id", 1L);
System.out.println(" Found: " + found);
System.out.println("\nUpdating address for id=1:");
people.updateField("id", 1L, "address", "789 Elm Rd");
people.printAll();
System.out.println("\nDeleting id=2:");
people.deleteByLongKey("id", 2L);
people.printAll();
System.out.println("\nSelecting 'people' table from db:");
Table same = db.selectTable("people");
System.out.println(" Table name: " + same.getTableName()
+ ", rows: " + same.size());
db.deleteTable("people");
db.listTables();
}
}