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
|
/**
* Copyright © 2005-2012 Akiban Technologies, Inc. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 (only) of the
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* This program may also be available under different license terms. For more
* information, see www.akiban.com or contact licensing@akiban.com.
*/
import com.persistit.Exchange;
import com.persistit.Key;
import com.persistit.Persistit;
public class HelloWorld {
public static void main(String[] args) throws Exception {
Persistit db = new Persistit();
try {
// Read configuration from persistit.properties, allocates
// buffers, opens Volume(s), and performs recovery processing
// if necessary.
//
db.initialize();
//
// Create an Exchange, which is a thread-private facade for
// accessing data in a Persistit Tree. This Exchange will
// access a Tree called "greetings" in a Volume called
// "hwdemo". It will create a new Tree by that name
// if one does not already exist.
//
Exchange dbex = db.getExchange("hwdemo", "greetings", true);
//
// Set up the Value field of the Exchange.
//
dbex.getValue().put("World");
//
// Set up the Key field of the Exchange.
//
dbex.getKey().append("Hello");
//
// Ask Persistit to store this key/value pair into the Tree.
//
dbex.store();
//
// Prepare to traverse all the keys in the Tree (of which there
// is currently only one!) and for each key display its value.
//
dbex.getKey().to(Key.BEFORE);
while (dbex.next()) {
System.out.println(dbex.getKey().reset().decode()
+ " " + dbex.getValue().get());
}
db.releaseExchange(dbex);
} finally {
// Always close Persistit. If the application does not do
// this, Persistit's background threads will keep the JVM from
// terminating.
//
db.close();
}
}
}
|