• R/O
  • SSH
  • HTTPS

senna-java: Commit


Commit MetaInfo

Revision3 (tree)
Time2008-12-18 16:42:54
Authormir

Log Message

imported new classes for Senna DB API - based on rev1277.

Change Summary

Incremental Difference

--- trunk/src/java/senna/SennaObject.java (revision 0)
+++ trunk/src/java/senna/SennaObject.java (revision 3)
@@ -0,0 +1,118 @@
1+/*
2+ * Copyright(C) 2008 Tetsuro IKEDA <ikdttr@gmail.com>
3+ *
4+ * This library is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * This library is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with this library; if not, write to the Free Software
16+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+ */
18+
19+package senna;
20+
21+/**
22+ * Wrapper for sen_obj
23+ */
24+public abstract class SennaObject {
25+ /**
26+ * call sen_obj_remove().
27+ *
28+ * @param path
29+ * @throws SennaException
30+ */
31+ public native void remove(String path) throws SennaException;
32+
33+ /**
34+ * call sen_obj_rename().
35+ *
36+ * @param old_path
37+ * @param new_path
38+ * @throws SennaException
39+ */
40+ public native void rename(String old_path, String new_path) throws SennaException;
41+
42+ /**
43+ * call sen_obj_close().
44+ *
45+ * @throws SennaException
46+ */
47+ public native void close() throws SennaException;
48+
49+ /**
50+ * call sen_obj_path().
51+ *
52+ * @return path
53+ * @throws SennaException
54+ */
55+ public native String getPath() throws SennaException;
56+
57+ /**
58+ * call sen_obj_name().
59+ *
60+ * @return name
61+ * @throws SennaException
62+ */
63+ public native String getName() throws SennaException;
64+
65+ /**
66+ * call sen_obj_expire().
67+ *
68+ * @param threshold
69+ * @throws SennaException
70+ */
71+ public native void expire(int threshold) throws SennaException;
72+
73+ /**
74+ * call sen_obj_check().
75+ *
76+ * @return status
77+ * @throws SennaException
78+ */
79+ public native int check() throws SennaException;
80+
81+ /**
82+ * call sen_obj_lock().
83+ *
84+ * @param timeout
85+ * @throws SennaException
86+ */
87+ public native void lock(int timeout) throws SennaException;
88+
89+ /**
90+ * call sen_obj_unlock().
91+ *
92+ * @throws SennaException
93+ */
94+ public native void unlock() throws SennaException;
95+
96+ /**
97+ * call sen_obj_clear_lock().
98+ *
99+ * @throws SennaException
100+ */
101+ public native void clearLock() throws SennaException;
102+
103+ /**
104+ * call sen_obj_is_locked().
105+ *
106+ * @return true if object is locked
107+ * @throws SennaException
108+ */
109+ public native boolean isLocked() throws SennaException;
110+
111+ /**
112+ * call sen_obj_space().
113+ *
114+ * @return space
115+ * @throws SennaException
116+ */
117+ public native Space getSpace() throws SennaException;
118+}
--- trunk/src/java/senna/Space.java (revision 0)
+++ trunk/src/java/senna/Space.java (revision 3)
@@ -0,0 +1,97 @@
1+/*
2+ * Copyright(C) 2008 Tetsuro IKEDA <ikdttr@gmail.com>
3+ *
4+ * This library is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * This library is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with this library; if not, write to the Free Software
16+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+ */
18+
19+package senna;
20+
21+/**
22+ * Wrapper for Space
23+ */
24+public class Space extends SennaObject {
25+ /**
26+ * call sen_space_create().
27+ *
28+ * @param ctx
29+ * SenaContext
30+ * @param path
31+ * path
32+ * @return created space
33+ * @throws SennaException
34+ */
35+ public static native Space create(SennaContext ctx, String path) throws SennaException;
36+
37+ /**
38+ * call sen_space_create().
39+ *
40+ * @param ctx
41+ * SennaContext
42+ * @param path
43+ * path
44+ * @param encoding
45+ * default encoding for this space
46+ * @return created space
47+ * @throws SennaException
48+ */
49+ public static native Space create(SennaContext ctx, String path, int encoding)
50+ throws SennaException;
51+
52+ /* for create() */
53+ private Space() {
54+ }
55+
56+ /**
57+ * call sen_space_open().
58+ *
59+ * @param ctx
60+ * SennaContext
61+ * @param path
62+ * path
63+ * @param encoding
64+ * default encoding for this space
65+ * @return opened space
66+ * @throws SennaException
67+ */
68+ private native Space open(SennaContext ctx, String path, int encoding)
69+ throws SennaException;
70+
71+ /**
72+ * creates new object with sen_space_open().
73+ *
74+ * @param ctx SennaContext
75+ * @param path path
76+ * @throws SennaException
77+ */
78+ public Space(SennaContext ctx, String path) throws SennaException {
79+ open(ctx, path, Senna.SEN_ENC_DEFAULT);
80+ }
81+
82+ /**
83+ * creates new object with sen_space_open().
84+ *
85+ * @param ctx
86+ * SennaContext
87+ * @param path
88+ * path
89+ * @param encoding
90+ * default encoding
91+ * @throws SennaException
92+ */
93+ public Space(SennaContext ctx, String path, int encoding) throws SennaException {
94+ open(ctx, path, encoding);
95+ }
96+
97+}
--- trunk/src/java/senna/Column.java (revision 0)
+++ trunk/src/java/senna/Column.java (revision 3)
@@ -0,0 +1,85 @@
1+/*
2+ * Copyright(C) 2008 Tetsuro IKEDA <ikdttr@gmail.com>
3+ *
4+ * This library is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * This library is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with this library; if not, write to the Free Software
16+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+ */
18+
19+package senna;
20+
21+/**
22+ * Wrapper for Column
23+ */
24+public class Column extends SennaObject {
25+ /**
26+ * call sen_column_create().
27+ *
28+ * @param ctx SennaContext
29+ * @param table table
30+ * @param name name
31+ * @param path path
32+ * @param flags flags
33+ * @return created column
34+ * @throws SennaException
35+ */
36+ public static native Column create(SennaContext ctx, Table table, String name,
37+ String path, int flags) throws SennaException;
38+
39+ /**
40+ * call sen_column_open().
41+ *
42+ * @param ctx SennaContext
43+ * @param name name
44+ * @param flags flags
45+ * @param type type
46+ * @return created column
47+ * @throws SennaException
48+ */
49+ private native Column open(SennaContext ctx, Table table, String name,
50+ String path, Type type) throws SennaException;
51+
52+ /**
53+ * creates new object with sen_column_open().
54+ *
55+ * @param ctx
56+ * @param table
57+ * @param name
58+ * @param path
59+ * @throws SennaException
60+ */
61+ public Column(SennaContext ctx, Table table, String name, String path,
62+ Type type) throws SennaException {
63+ open(ctx, table, name, path, type);
64+ }
65+
66+ /**
67+ * call sen_column_index_update().
68+ *
69+ * @param sen_id
70+ * @param section
71+ * @param old_value
72+ * @param new_value
73+ * @throws SennaException
74+ */
75+ public native void indexUpdate(int sen_id, int section, String old_value,
76+ String new_value) throws SennaException;
77+
78+ /**
79+ * call sen_column_table().
80+ *
81+ * @return table
82+ * @throws SennaException
83+ */
84+ public native Table getTable() throws SennaException;
85+}
--- trunk/src/java/senna/Cursor.java (revision 0)
+++ trunk/src/java/senna/Cursor.java (revision 3)
@@ -0,0 +1,94 @@
1+/*
2+ * Copyright(C) 2008 Tetsuro IKEDA <ikdttr@gmail.com>
3+ *
4+ * This library is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * This library is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with this library; if not, write to the Free Software
16+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+ */
18+
19+package senna;
20+
21+/**
22+ * Wrapper for Cursor
23+ */
24+public class Cursor {
25+ /**
26+ * call sent_table_cursor_open().
27+ *
28+ * @param table table
29+ * @param min minimum value of key condition
30+ * @param max maximum value of key condition
31+ * @return opened cursor
32+ * @throws SennaException
33+ */
34+ private native Cursor open(Table table, String min, String max) throws SennaException;
35+
36+ /**
37+ * create new object with sen_table_cursor_open().
38+ *
39+ * @param table table
40+ * @param min minimum value of key condition
41+ * @param max maximum value of key condition
42+ * @throws SennaException
43+ */
44+ public Cursor(Table table, String min, String max) throws SennaException {
45+ open(table, min, max);
46+ }
47+
48+ /**
49+ * call sen_table_cursor_close().
50+ *
51+ * @throws SennaException
52+ */
53+ public native void close() throws SennaException;
54+
55+ /**
56+ * call sen_table_cursor_next().
57+ *
58+ * @return sen_id
59+ * @throws SennaException
60+ */
61+ public native int next() throws SennaException;
62+
63+ /**
64+ * call sen_table_cursor_get_key().
65+ *
66+ * @return key
67+ * @throws SennaException
68+ */
69+ public native String getKey() throws SennaException;
70+
71+ /**
72+ * call sen_table_cursor_get_value().
73+ *
74+ * @return value
75+ * @throws SennaException
76+ */
77+ public native String getValue() throws SennaException;
78+
79+ /**
80+ * call sen_table_cursor_set_value().
81+ *
82+ * @param value
83+ * @param type
84+ * @throws SennaException
85+ */
86+ public native void setValue(String value, int type) throws SennaException;
87+
88+ /**
89+ * call sen_table_cursor_delete().
90+ *
91+ * @throws SennaException
92+ */
93+ public native void delete() throws SennaException;
94+}
--- trunk/src/java/senna/Type.java (revision 0)
+++ trunk/src/java/senna/Type.java (revision 3)
@@ -0,0 +1,37 @@
1+/*
2+ * Copyright(C) 2008 Tetsuro IKEDA <ikdttr@gmail.com>
3+ *
4+ * This library is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * This library is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with this library; if not, write to the Free Software
16+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+ */
18+
19+package senna;
20+
21+/**
22+ * Wrapper for Type
23+ */
24+public class Type extends SennaObject {
25+ /**
26+ * call sen_type_create().
27+ *
28+ * @param ctx SennaContext
29+ * @param name name
30+ * @param flags flags
31+ * @param size size
32+ * @return created type
33+ * @throws SennaException
34+ */
35+ public static native Type create(SennaContext ctx, String name,
36+ int flags, int size) throws SennaException;
37+}
--- trunk/src/java/senna/Table.java (revision 0)
+++ trunk/src/java/senna/Table.java (revision 3)
@@ -0,0 +1,169 @@
1+/*
2+ * Copyright(C) 2008 Tetsuro IKEDA <ikdttr@gmail.com>
3+ *
4+ * This library is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * This library is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with this library; if not, write to the Free Software
16+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+ */
18+
19+package senna;
20+
21+/**
22+ * Wrapper for Table
23+ */
24+public class Table extends SennaObject {
25+ /**
26+ * call sen_table_create().
27+ *
28+ * @param ctx SennaContext
29+ * @param name name
30+ * @param path path
31+ * @param flags flasgs
32+ * @param encoding encoding
33+ */
34+ public static native Type create(SennaContext ctx, String name, String path,
35+ int flags, Type key_type, int encoding)
36+ throws SennaException;
37+
38+ /* for open() */
39+ private Table() {
40+ }
41+
42+ /**
43+ * call sen_table_open().
44+ *
45+ * @param ctx SennaContext
46+ * @param name name
47+ * @param path path
48+ * @return opened table
49+ * @throws SennaException
50+ */
51+ private native Table open(SennaContext ctx, String name, String path) throws SennaException;
52+
53+ /**
54+ * creates new object with sen_table_open().
55+ *
56+ * @param ctx SennaContext
57+ * @param name name
58+ * @param path path
59+ * @throws SennaException
60+ */
61+ public Table(SennaContext ctx, String name, String path) throws SennaException {
62+ open(ctx, name, path);
63+ }
64+
65+ /**
66+ * call sen_table_lookup().
67+ *
68+ * @param key key
69+ * @param flags flags
70+ * @return matched record's sen_id
71+ * @throws SennaException
72+ */
73+ public native int lookup(String key, int flags) throws SennaException;
74+
75+ /**
76+ * call sen_table_add().
77+ *
78+ * @return created record's sen_id
79+ * @throws SennaException
80+ */
81+ public native int add() throws SennaException;
82+
83+ /**
84+ * call sen_table_get_key().
85+ *
86+ * @param sen_id sen_id
87+ * @return key
88+ * @throws SennaException
89+ */
90+ public native String getKey(int sen_id) throws SennaException;
91+
92+ /**
93+ * call sen_table_delete().
94+ *
95+ * @param key key
96+ * @throws SennaException
97+ */
98+ public native void delete(String key) throws SennaException;
99+
100+ /**
101+ * call sen_table_delete_by_id().
102+ *
103+ * @param sen_id sen_id
104+ * @throws SennaException
105+ */
106+ public native void deleteByID(int sen_id) throws SennaException;
107+
108+ /**
109+ * call sen_table_truncate().
110+ *
111+ * @throws SennaException
112+ */
113+ public native void truncate() throws SennaException;
114+
115+ /**
116+ * call sen_table_sort().
117+ *
118+ * @param limit
119+ * @param option
120+ * @return result
121+ * @throws SennaException
122+ */
123+ public native Table sort(int limit, int option) throws SennaException;
124+
125+ /**
126+ * call sen_table_group().
127+ *
128+ * @param keys
129+ * @return result
130+ * @throws SennaException
131+ */
132+ public native Table group(String keys[]) throws SennaException;
133+
134+ /**
135+ * call sen_table_setoperation().
136+ *
137+ * @param table
138+ * @param operation
139+ * @return result
140+ * @throws SennaException
141+ */
142+ public native Table setoperation(Table table, int operation) throws SennaException;
143+
144+ /**
145+ * call sen_table_difference().
146+ *
147+ * @param table
148+ * @return array size is 2. 1st object is from this table, 2nd object is from param.
149+ * @throws SennaException
150+ */
151+ public native Table[] difference(Table table) throws SennaException;
152+
153+ /**
154+ * call sen_table_column().
155+ *
156+ * @param name
157+ * @return matched column
158+ * @throws SennaException
159+ */
160+ public native Column getColumn(String name) throws SennaException;
161+
162+ /**
163+ * call sen_table_size().
164+ *
165+ * @return number of record in this table
166+ * @throws SennaException
167+ */
168+ public native int size() throws SennaException;
169+}
--- trunk/src/java/senna/SennaContext.java (revision 0)
+++ trunk/src/java/senna/SennaContext.java (revision 3)
@@ -0,0 +1,131 @@
1+/*
2+ * Copyright(C) 2008 Tetsuro IKEDA <ikdttr@gmail.com>
3+ *
4+ * This library is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * This library is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with this library; if not, write to the Free Software
16+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+ */
18+
19+package senna;
20+
21+/**
22+ * Wrapper for sen_ctx
23+ */
24+public class SennaContext {
25+ /* C pointer to sen_ctx */
26+ private int sen_ctx_ptr;
27+
28+ /* C pointer to space */
29+ private int space_ptr;
30+
31+ /**
32+ * call sen_ctx_init().
33+ *
34+ * @throws SennaException
35+ */
36+ private native void init(int flags, int encoding) throws SennaException;
37+
38+ /**
39+ * call sen_ctx_fin().
40+ *
41+ * @throws SennaException
42+ */
43+ private native void fin() throws SennaException;
44+
45+ /**
46+ * call sen_ctx_fin().
47+ *
48+ * @throws SennaException
49+ */
50+ protected void finalize() throws SennaException {
51+ fin();
52+ }
53+
54+ /**
55+ * <pre>
56+ * call sen_ctx_init() with below values.
57+ * flags: SEN_CTX_USE_DB
58+ * encoding: SEN_ENC_DEFAULT
59+ * </pre>
60+ *
61+ * @throws SennaException
62+ */
63+ public SennaContext() throws SennaException {
64+ init(Senna.SEN_CTX_USE_DB, Senna.SEN_ENC_DEFAULT);
65+ }
66+
67+ /**
68+ * <pre>
69+ * call sen_ctx_init() with below values.
70+ * flags: SEN_CTX_USE_DB
71+ * </pre>
72+ *
73+ * @param encoding
74+ * default encoding for this context
75+ * @throws SennaException
76+ */
77+ public SennaContext(int encoding) throws SennaException {
78+ init(Senna.SEN_CTX_USE_DB, encoding);
79+ }
80+
81+ /**
82+ * call sen_ctx_init().
83+ *
84+ * @param flags
85+ * context flags
86+ * @param encoding
87+ * default encoding for this context
88+ * @throws SennaException
89+ */
90+ public SennaContext(int flags, int encoding) throws SennaException {
91+ init(flags, encoding);
92+ }
93+
94+ /**
95+ * call sen_ctx_use().
96+ *
97+ * @param space
98+ * space
99+ * @throws SennaException
100+ */
101+ public native void use(Space space) throws SennaException;
102+
103+ /**
104+ * call sen_ctx_space().
105+ *
106+ * @return current space
107+ * @throws SennaException
108+ */
109+ public native Space getSpace() throws SennaException;
110+
111+ /**
112+ * call sen_ctx_lookup().
113+ *
114+ * @param name
115+ * object name
116+ * @return matched senna object
117+ * @throws SennaException
118+ */
119+ public native SennaObject lookup(String name) throws SennaException;
120+
121+ /**
122+ * call sen_ctx_get().
123+ *
124+ * @param sen_id sen_id
125+ * @return matched senna object
126+ * @throws SennaException
127+ */
128+ public native SennaObject get(int sen_id) throws SennaException;
129+
130+
131+}
Show on old repository browser