~tjoneslo/akiban-persistit/header-check-files-update

« back to all changes in this revision

Viewing changes to examples/HelloWorld/HelloWorld.java

  • Committer: Padraig O'Sullivan
  • Date: 2011-02-01 16:48:36 UTC
  • mfrom: (125.1.12 learning)
  • Revision ID: osullivan.padraig@gmail.com-20110201164836-mtdbk9d0rgcxpwye
Merge Padraig.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011 Akiban Technologies Inc.
 
3
 * This program is free software: you can redistribute it and/or modify
 
4
 * it under the terms of the GNU Affero General Public License, version 3,
 
5
 * as published by the Free Software Foundation.
 
6
 *
 
7
 * This program is distributed in the hope that it will be useful,
 
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
10
 * GNU Affero General Public License for more details.
 
11
 *
 
12
 * You should have received a copy of the GNU Affero General Public License
 
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 
14
 */
 
15
 
 
16
import com.persistit.Persistit;
 
17
import com.persistit.Exchange;
 
18
import com.persistit.Key;
 
19
 
 
20
public class HelloWorld
 
21
{
 
22
    public static void main(String[] args)
 
23
    throws Exception 
 
24
    {
 
25
        Persistit persistit = new Persistit();
 
26
        try
 
27
        {
 
28
            // Reads configuration from persistit.properties, allocates
 
29
            // buffers, opens Volume(s), and performs recovery processing
 
30
            // if necessary.
 
31
            //
 
32
            persistit.initialize();
 
33
            //
 
34
            // Creates an Exchange, which is a thread-private facade for
 
35
            // accessing data in a Persistit Tree. This Exchange will 
 
36
            // access a Tree called "greetings" in a Volume called 
 
37
            // "hwdemo". It will create a new Tree by that name 
 
38
            // if one does not already exist.
 
39
            //
 
40
            Exchange dbex = new Exchange(persistit, "hwdemo", "greetings", true);
 
41
            //
 
42
            // Set up the Value field of the Exchange.
 
43
            //
 
44
            dbex.getValue().put("World");
 
45
            //
 
46
            // Set up the Key field of the Exchange.
 
47
            //
 
48
            dbex.getKey().append("Hello");
 
49
            //
 
50
            // Ask Persistit to put this key/value pair into the Tree.  
 
51
            // Until this point, the changes to the Exchange are local 
 
52
            // to this thread.
 
53
            //
 
54
            dbex.store();
 
55
            //
 
56
            // Prepare to traverse all the keys in the Tree (of which there 
 
57
            // is currently only one!) and for each key display its value.
 
58
            //
 
59
            dbex.getKey().to(Key.BEFORE);
 
60
            while (dbex.next())
 
61
            {
 
62
                System.out.println(
 
63
                    dbex.getKey().indexTo(0).decode() + " " +
 
64
                    dbex.getValue().get());
 
65
            }
 
66
        }
 
67
        finally
 
68
        {
 
69
            // Always close Persistit. If the application does not do 
 
70
            // this, Persistit's background threads will keep the JVM from
 
71
            // terminating.
 
72
            //
 
73
            persistit.close();
 
74
        }
 
75
    }
 
76
}
 
 
b'\\ No newline at end of file'