~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/test/scr016/CallbackTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package com.sleepycat.test;
2
 
import com.sleepycat.db.*;
3
 
 
4
 
public class CallbackTest
5
 
{
6
 
    public static void main(String args[])
7
 
    {
8
 
        try {
9
 
            Db db = new Db(null, 0);
10
 
            db.set_bt_compare(new BtreeCompare());
11
 
            db.open(null, "test.db", "", Db.DB_BTREE, Db.DB_CREATE, 0666);
12
 
            StringDbt[] keys = new StringDbt[10];
13
 
            StringDbt[] datas = new StringDbt[10];
14
 
            for (int i = 0; i<10; i++) {
15
 
                int val = (i * 3) % 10;
16
 
                keys[i] = new StringDbt("key" + val);
17
 
                datas[i] = new StringDbt("data" + val);
18
 
                System.out.println("put " + val);
19
 
                db.put(null, keys[i], datas[i], 0);
20
 
            }
21
 
        }
22
 
        catch (DbException dbe) {
23
 
            System.err.println("FAIL: " + dbe);
24
 
        }
25
 
        catch (java.io.FileNotFoundException fnfe) {
26
 
            System.err.println("FAIL: " + fnfe);
27
 
        }
28
 
 
29
 
    }
30
 
 
31
 
 
32
 
}
33
 
 
34
 
class BtreeCompare
35
 
    implements DbBtreeCompare
36
 
{
37
 
    /* A weird comparator, for example.
38
 
     * In fact, it may not be legal, since it's not monotonically increasing.
39
 
     */
40
 
    public int bt_compare(Db db, Dbt dbt1, Dbt dbt2)
41
 
    {
42
 
        System.out.println("compare function called");
43
 
        byte b1[] = dbt1.get_data();
44
 
        byte b2[] = dbt2.get_data();
45
 
        System.out.println("  " + (new String(b1)) + ", " + (new String(b2)));
46
 
        int len1 = b1.length;
47
 
        int len2 = b2.length;
48
 
        if (len1 != len2)
49
 
            return (len1 < len2) ? 1 : -1;
50
 
        int value = 1;
51
 
        for (int i=0; i<len1; i++) {
52
 
            if (b1[i] != b2[i])
53
 
                return (b1[i] < b2[i]) ? value : -value;
54
 
            value *= -1;
55
 
        }
56
 
        return 0;
57
 
    }
58
 
}
59
 
 
60
 
class StringDbt extends Dbt
61
 
{
62
 
    StringDbt()
63
 
    {
64
 
        set_flags(Db.DB_DBT_MALLOC); // tell Db to allocate on retrieval
65
 
    }
66
 
 
67
 
    StringDbt(String value)
68
 
    {
69
 
        setString(value);
70
 
        set_flags(Db.DB_DBT_MALLOC); // tell Db to allocate on retrieval
71
 
    }
72
 
 
73
 
    void setString(String value)
74
 
    {
75
 
        set_data(value.getBytes());
76
 
        set_size(value.length());
77
 
    }
78
 
 
79
 
    String getString()
80
 
    {
81
 
        return new String(get_data(), 0, get_size());
82
 
    }
83
 
}