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));
continue;
default:
throw new CliException("Invalid field type: " + types[i]);
}
}
} catch (Exception x)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共408个文件
html:142个
cpp:73个
h:70个
FastDb是高效的内存数据库系统,具备实时能力及便利的C++接口。FastDB不支持client-server架构因而所有使用FastDB的应用程序必须运行在同一主机上。FastDB针对应用程序通过控制读访问模式作了优化。
资源推荐
资源详情
资源评论
收起资源包目录
fastdb-3.31.tar.gz_MEMCACHED_fastdb_内存数据库 (408个子文件)
makefile.acc 4KB
genparse.bat 458B
compile.bat 222B
runtests.bat 210B
make.bat 36B
makefile.bcc 6KB
FastDB.bpg 2KB
clitest.c 10KB
clitest2.c 7KB
testalter.c 4KB
testrect.c 4KB
doxygen.cfg 44KB
CHANGES 33KB
JniTestIndex.class 3KB
JniTestIndex$Record.class 482B
CONTENTS 515B
database.cpp 240KB
subsql.cpp 120KB
localcli.cpp 83KB
bugdb.cpp 78KB
compiler.cpp 60KB
wince_time.cpp 60KB
class.cpp 57KB
server.cpp 53KB
file.cpp 40KB
cli.cpp 40KB
scan.cpp 35KB
scan.cpp 35KB
scan.cpp 35KB
clidb.cpp 33KB
jnicli.cpp 33KB
ttree.cpp 31KB
w32sock.cpp 29KB
gram.tab.cpp 28KB
gram.tab.cpp 28KB
gram.tab.cpp 28KB
cursor.cpp 24KB
wwwapi.cpp 23KB
sync.cpp 18KB
unisock.cpp 17KB
rtree.cpp 14KB
testdb.cpp 14KB
GiST.cpp 11KB
query.cpp 10KB
hashtab.cpp 10KB
GiSTnode.cpp 9KB
testjoin.cpp 7KB
testtrav.cpp 7KB
repsock.cpp 6KB
testconc.cpp 6KB
testspat.cpp 5KB
testsync.cpp 5KB
RTnode.cpp 5KB
command.cpp 5KB
command.cpp 5KB
command.cpp 5KB
container.cpp 4KB
testiref.cpp 4KB
testperf.cpp 4KB
guess.cpp 4KB
testindex.cpp 4KB
guess_std.cpp 4KB
guess2.cpp 4KB
testraw.cpp 3KB
cgistub.cpp 3KB
testddl.cpp 3KB
testfuzzy.cpp 3KB
GiSTfile.cpp 3KB
testleak.cpp 3KB
testharr.cpp 3KB
BTnode.cpp 3KB
RTnode.cpp 3KB
testpar.cpp 2KB
testidx.cpp 2KB
cleanupsem.cpp 2KB
BTentry.cpp 2KB
symtab.cpp 2KB
testconcur.cpp 2KB
RT.cpp 2KB
RTentry.cpp 2KB
GiSTdb.cpp 1KB
forcerecovery.cpp 1KB
GiSTcursor.cpp 1KB
RTpredicate.cpp 1KB
RTpredicate.cpp 1KB
BTpredicate.cpp 984B
stdtp.cpp 675B
RTentry.cpp 638B
GiSTpredicate.cpp 547B
FastDbCli.cs 48KB
FastDbFields.cs 32KB
FastDbConnection.cs 18KB
FastDbCommand.cs 14KB
Test.cs 4KB
TestIndex.cs 4KB
AssemblyInfo.cs 2KB
FastDbNet.csproj 4KB
Test2.csproj 4KB
Test1.csproj 4KB
doxygen.css 5KB
共 408 条
- 1
- 2
- 3
- 4
- 5
资源评论
周楷雯
- 粉丝: 78
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功