package jnicli;
import java.lang.reflect.*;
import java.util.*;
/**
* Interface to database using Java native interface.
* This class should be used by applications accessing database locally
*/
public class DatabaseJNI implements Database {
public void open(int accessType, String databaseName, String databasePath, long initSize, int transactionCommitDelay) {
db = jniOpen(accessType, databaseName, databasePath, initSize, transactionCommitDelay);
String table;
classes = new Hashtable();
while ((table = jniNextTable(db)) != null) {
try {
Class c = Class.forName(table);
ClassDescriptor desc = new ClassDescriptor(c);
classes.put(c, desc);
desc.td = jniUpdateTable(db, table, getTableDescriptor(desc));
} catch (ClassNotFoundException x) {
new CliException("Class '" + table + "' not found");
} catch (Exception x) {
new CliException(x.getMessage());
}
}
}
public void close() {
jniClose(db);
classes = null;
}
public Cursor select(Class table, String condition, int flags) {
ClassDescriptor desc = (ClassDescriptor)classes.get(table);
if (desc == null) {
throw new CliException("Table not found: " + table);
}
long result = jniSelect(db, desc.td, condition);
Cursor cursor;
if (remote || (flags & AUTOCOMMIT) != 0) {
cursor = new PrefetchedCursor(this, result, desc);
if ((flags & AUTOCOMMIT) != 0) {
jniCommit(db);
}
} else {
cursor = (flags & FOR_UPDATE) != 0
? (Cursor)new IncrementalCursorForUpdate(this, result, desc)
: (Cursor)new IncrementalCursor(this, result, desc);
}
return cursor;
}
Object unswizzleObject(long cursor, ClassDescriptor desc) {
int[] types = desc.types;
Field[] fields = desc.fields;
try {
Object obj = desc.newInstance();
for (int i = 0; i < types.length; i++) {
Field f = fields[i];
switch (types[i]) {
case TP_BOOL:
f.setBoolean(obj, jniGetByte(cursor) != 0);
continue;
case TP_CHAR:
f.setChar(obj, (char)jniGetShort(cursor));
continue;
case TP_INT1:
f.setByte(obj, jniGetByte(cursor));
continue;
case TP_INT2:
f.setShort(obj, jniGetShort(cursor));
continue;
case TP_INT4:
f.setInt(obj, jniGetInt(cursor));
continue;
case TP_INT8:
f.setLong(obj, jniGetLong(cursor));
continue;
case TP_REAL4:
f.setFloat(obj, Float.intBitsToFloat(jniGetInt(cursor)));
continue;
case TP_REAL8:
f.setDouble(obj, Double.longBitsToDouble(jniGetLong(cursor)));
continue;
case TP_STRING:
f.set(obj, jniGetString(cursor));
continue;
case TP_DATE:
{
long timestamp = jniGetLong(cursor);
f.set(obj, timestamp < 0 ? null : new Date(timestamp));
continue;
}
case TP_BOOL_ARRAY:
f.set(obj, jniGetBoolArray(cursor));
continue;
case TP_CHAR_ARRAY:
f.set(obj, jniGetCharArray(cursor));
continue;
case TP_INT1_ARRAY:
f.set(obj, jniGetByteArray(cursor));
continue;
case TP_INT2_ARRAY:
f.set(obj, jniGetShortArray(cursor));
continue;
case TP_INT4_ARRAY:
f.set(obj, jniGetIntArray(cursor));
continue;
case TP_INT8_ARRAY:
f.set(obj, jniGetLongArray(cursor));
continue;
case TP_REAL4_ARRAY:
f.set(obj, jniGetFloatArray(cursor));
continue;
case TP_REAL8_ARRAY:
f.set(obj, jniGetDoubleArray(cursor));
continue;
case TP_STRING_ARRAY:
f.set(obj, jniGetStringArray(cursor));
continue;
default:
throw new CliException("Invalid field type: " + types[i]);
}
}
return obj;
} catch (Exception x) {
throw new CliException(x.getMessage());
}
}
private long swizzleObject(ClassDescriptor desc, Object obj) {
long buf = jniCreateBuffer();
int[] types = desc.types;
Field[] fields = desc.fields;
try {
for (int i = 0; i < types.length; i++) {
Field f = fields[i];
switch (types[i]) {
case TP_BOOL:
jniSetByte(buf, (byte)(f.getBoolean(obj) ? 1 : 0));
continue;
case TP_CHAR:
jniSetShort(buf, (short)f.getChar(obj));
continue;
case TP_INT1:
jniSetByte(buf, f.getByte(obj));
continue;
case TP_INT2:
jniSetShort(buf, f.getShort(obj));
continue;
case TP_INT4:
jniSetInt(buf, f.getInt(obj));
continue;
case TP_INT8:
jniSetLong(buf, f.getLong(obj));
continue;
case TP_REAL4:
jniSetInt(buf, Float.floatToIntBits(f.getFloat(obj)));
continue;
case TP_REAL8:
jniSetLong(buf, Double.doubleToLongBits(f.getDouble(obj)));
continue;
case TP_STRING:
jniSetString(buf, (String)f.get(obj));
continue;
case TP_DATE:
{
Date d = (Date)f.get(obj);
jniSetLong(buf, d != null ? d.getTime() : -1);
continue;
}
case TP_BOOL_ARRAY:
jniSetBoolArray(buf, (boolean[])f.get(obj));
continue;
case TP_CHAR_ARRAY:
jniSetCharArray(buf, (char[])f.get(obj));
continue;
case TP_INT1_ARRAY:
jniSetByteArray(buf, (byte[])f.get(obj));
continue;
case TP_INT2_ARRAY:
jniSetShortArray(buf, (short[])f.get(obj));
continue;
case TP_INT4_ARRAY:
jniSetIntArray(buf, (int[])f.get(obj));
continue;
case TP_INT8_ARRAY:
jniSetLongArray(buf, (long[])f.get(obj));
continue;
case TP_REAL4_ARRAY:
jniSetFloatArray(buf, (float[])f.get(obj));
continue;
case TP_REAL8_ARRAY:
jniSetDoubleArray(buf, (double[])f.get(obj));
continue;
case TP_STRING_ARRAY:
jniSetStringArray(buf, (String[])f.get(obj)
没有合适的资源?快使用搜索试试~ 我知道了~
内存数据库fastdb
共418个文件
html:148个
cpp:77个
h:71个
需积分: 33 10 下载量 116 浏览量
2009-01-18
19:06:25
上传
评论
收藏 1.15MB ZIP 举报
温馨提示
很精简的内存数据库,速度超级快,接口支持c/C++,有很多例子可以参考
资源推荐
资源详情
资源评论
收起资源包目录
内存数据库fastdb (418个子文件)
.#testperf.cpp.1.1 4KB
makefile.acc 5KB
testperf.bak 4KB
genparse.bat 484B
compile.bat 233B
runtests.bat 230B
make.bat 36B
makefile.bcc 6KB
FastDB.bpg 2KB
clitest.c 11KB
clitest2.c 7KB
testalter.c 5KB
testrect.c 4KB
doxygen.cfg 45KB
CHANGES 41KB
CONTENTS 525B
database.cpp 271KB
subsql.cpp 102KB
localcli.cpp 94KB
bugdb.cpp 80KB
server.cpp 68KB
compiler.cpp 63KB
wince_time.cpp 62KB
class.cpp 60KB
file.cpp 47KB
cli.cpp 42KB
scan.cpp 36KB
scan.cpp 36KB
scan.cpp 36KB
jnicli.cpp 34KB
clidb.cpp 34KB
ttree.cpp 32KB
xml.cpp 31KB
w32sock.cpp 31KB
gram.tab.cpp 29KB
gram.tab.cpp 29KB
gram.tab.cpp 29KB
cursor.cpp 26KB
wwwapi.cpp 24KB
sync.cpp 21KB
unisock.cpp 21KB
rtree.cpp 15KB
testdb.cpp 15KB
hashtab.cpp 13KB
GiST.cpp 12KB
query.cpp 11KB
GiSTnode.cpp 10KB
testjoin.cpp 7KB
testtrav.cpp 7KB
repsock.cpp 7KB
testconc.cpp 7KB
testspat.cpp 5KB
testsync.cpp 5KB
RTnode.cpp 5KB
command.cpp 5KB
command.cpp 5KB
command.cpp 5KB
testindex.cpp 5KB
container.cpp 5KB
testiref.cpp 4KB
guess.cpp 4KB
testperf.cpp 4KB
guess_std.cpp 4KB
guess2.cpp 4KB
cleanupsem.cpp 4KB
testraw.cpp 3KB
testddl.cpp 3KB
cgistub.cpp 3KB
testreplic.cpp 3KB
GiSTfile.cpp 3KB
testfuzzy.cpp 3KB
testleak.cpp 3KB
testharr.cpp 3KB
BTnode.cpp 3KB
RTnode.cpp 3KB
testpar.cpp 3KB
testidx.cpp 3KB
fastdbShim.cpp 2KB
BTentry.cpp 2KB
symtab.cpp 2KB
testfrag.cpp 2KB
testconcur.cpp 2KB
RT.cpp 2KB
RTentry.cpp 2KB
GiSTdb.cpp 2KB
forcerecovery.cpp 2KB
GiSTcursor.cpp 1KB
RTpredicate.cpp 1KB
RTpredicate.cpp 1KB
BTpredicate.cpp 1KB
stdtp.cpp 953B
RTentry.cpp 664B
GiSTpredicate.cpp 571B
FastDbCli.cs 50KB
FastDbFields.cs 32KB
FastDbConnection.cs 18KB
FastDbCommand.cs 14KB
Test.cs 4KB
TestIndex.cs 4KB
AssemblyInfo.cs 2KB
共 418 条
- 1
- 2
- 3
- 4
- 5
资源评论
llikz131
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功