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.
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.
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/>.
16
import java.util.Iterator;
19
import com.persistit.Exchange;
20
import com.persistit.Persistit;
21
import com.persistit.PersistitMap;
23
public class PersistitMapDemo
25
public static void main(String[] args)
28
// This program uses PersistitMap, an implementation of
29
// java.util.SortedMap to store a copy of the system properties.
30
// Each time you run this program it will compare the current
31
// system properties to those that were stored previously and will
32
// display any differences.
34
// PersistitMap works just like any other Map except that its values
35
// are persistent. (See the API documentation for PersistitMap for
36
// a few other considerations.)
38
Persistit persistit = new Persistit();
41
persistit.initialize();
42
Exchange dbex = new Exchange(persistit, "pmdemo", "properties", true);
44
// Create a PersistitMap over this exchange. The map will be
45
// non-empty if this program has already been run previously.
47
PersistitMap persistitMap = new PersistitMap(dbex);
49
// All Persistit databases below are invoked through the Map
52
if (persistitMap.size() == 0)
54
System.out.println("This is the first time PersistitMapDemo has run");
58
System.out.println("Comparing property values:");
59
for (Iterator iter = System.getProperties().entrySet().iterator();
62
Map.Entry entry = (Map.Entry)iter.next();
63
String name = (String)entry.getKey();
64
String newValue = (String)entry.getValue();
66
String oldValue = (String)persistitMap.remove(name);
70
"New value for " + name + " is '" + newValue + "'");
72
else if (!newValue.equals(oldValue))
75
"Value changed for " + name +
76
" from '" + oldValue + "' to '" + newValue + "'");
81
for (Iterator iter = persistitMap.entrySet().iterator();
84
Map.Entry entry = (Map.Entry)iter.next();
85
String name = (String)entry.getKey();
86
String oldValue = (String)entry.getValue();
89
"Old value for " + name + "='" + oldValue + "' is gone");
92
persistitMap.putAll(System.getProperties());
96
// Always close Persistit. If the application does not do
97
// this, Persistit's background threads will keep the JVM from
b'\\ No newline at end of file'