-
Notifications
You must be signed in to change notification settings - Fork 1
/
db_api_doc.txt
95 lines (62 loc) · 2.6 KB
/
db_api_doc.txt
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
// ***************************************************
// the following is the documentation on using the
// database interface api
//
// The goal of the api is to simplify accesses to the database
//
// This point of the interface is to encompass the data
// representation of a queries results into different classes.
//
// A template file to implement your own query is included
// "template_DbTable_implementer.txt"
// Copy the contents of the file to create a new class for your
// query and follow the steps inside to customize it appropriately
// ***************************************************
// ***************************************************
// this import must be in the file where this is used
import javax.faces.bean.ManagedProperty
// ***************************************************
// ***************************************************
// this code must appear in your own class declaration where it is used
@ManagedProperty(value="#{dbConnection}")
private DbConnector db;
// must provide the setter method
// don't actually call this yourself
public void setdb(DbConnector db) {
this.db = db;
}
// ***************************************************
// ***************************************************
// This is an example of using the interface To Read from the table
// in this example Course_package is a class that represents
// a query and the data it will return
Course_package cp = new Course_package();
// now pass in the parameters for WHERE to call read
cp = (Course_package) db.readTable(cp, "cpid = " + cpid + " AND page = " + page, Course_package.class);
// the queries will usually return more than one result
// so you must loop through them
//
// continue reading even if you know your query returns one result
while (cp.next() != null){
// this call to cp.next must be called first
//
// even if you know your query returns one result
// you must still call next() at least once
cp = (Course_package) cp.next();
// after that call you can read all the values from one entry
String something = cp.media_type;
}
// ***************************************************
// ***************************************************
// This is an example of using the interface To Write
// test insert
Course_package ins = new Course_package();
// note that no id is given because the database sets this automaticly
// so the underliying query should not try to write its own
ins.cpid = 1;
ins.media_type = "YOUTUBE";
ins.page = 7;
ins.source = "nmI9H5gT8wQ";
ins.location = "FULL";
db.writeTable(ins);
// ***************************************************