use of org.h2.mvstore.Cursor in project h2database by h2database.
the class ResultTempTable method find.
private Cursor find(Row row) {
if (index == null) {
// for the case "in(select ...)", the query might
// use an optimization and not create the index
// up front
createIndex();
}
Cursor cursor = index.find(session, row, row);
while (cursor.next()) {
SearchRow found = cursor.getSearchRow();
boolean ok = true;
Database db = session.getDatabase();
for (int i = 0; i < row.getColumnCount(); i++) {
if (!db.areEqual(row.getValue(i), found.getValue(i))) {
ok = false;
break;
}
}
if (ok) {
return cursor;
}
}
return null;
}
use of org.h2.mvstore.Cursor in project h2database by h2database.
the class ResultTempTable method removeRow.
@Override
public int removeRow(Value[] values) {
Row row = convertToRow(values);
Cursor cursor = find(row);
if (cursor != null) {
row = cursor.get();
table.removeRow(session, row);
rowCount--;
}
return rowCount;
}
use of org.h2.mvstore.Cursor in project h2database by h2database.
the class H2Database method openDatabase.
/**
* Open a connection to the given database.
*
* @param path the database file name
* @param factory the cursor factory
* @param flags 0, or a combination of OPEN_READONLY and CREATE_IF_NECESSARY
* @return a connection to this database
*/
public static H2Database openDatabase(String path, H2Database.CursorFactory factory, int flags) {
ConnectionInfo ci = new ConnectionInfo(path);
if ((flags & OPEN_READWRITE) != 0) {
// TODO readonly connections
}
if ((flags & CREATE_IF_NECESSARY) == 0) {
ci.setProperty("IFEXISTS", "TRUE");
}
ci.setProperty("FILE_LOCK", "FS");
Database db = new Database(ci, null);
Session s = db.getSystemSession();
return new H2Database(s, factory);
}
use of org.h2.mvstore.Cursor in project h2database by h2database.
the class H2Database method create.
/**
* Create a new in-memory database.
*
* @param factory the cursor factory
* @return a connection to this database
*/
public static H2Database create(H2Database.CursorFactory factory) {
ConnectionInfo ci = new ConnectionInfo("mem:");
Database db = new Database(ci, null);
Session s = db.getSystemSession();
return new H2Database(s, factory);
}
use of org.h2.mvstore.Cursor in project h2database by h2database.
the class Test method main.
public static void main(String... args) throws Exception {
H2Database db = H2Utils.openOrCreateDatabase("helloWorld.db", MODE_PRIVATE, null);
log("opened ps=" + db.getPageSize());
try {
// db.execSQL("DROP TABLE IF EXISTS test");
// log("dropped");
db.execSQL("CREATE TABLE if not exists test(ID INTEGER PRIMARY KEY, NAME VARCHAR)");
log("created");
for (int j = 0; j < 10; j++) {
Cursor c = db.rawQuery("select * from test", new String[0]);
int count = c.getCount();
for (int i = 0; i < count; i++) {
c.move(1);
c.getInt(0);
c.getString(1);
}
c.close();
}
// log("select " + count);
db.execSQL("delete from test");
log("delete");
db.beginTransaction();
for (int i = 0; i < 1000; i++) {
db.execSQL("INSERT INTO TEST VALUES(?, 'Hello')", new Object[] { i });
}
db.setTransactionSuccessful();
db.endTransaction();
log("inserted");
for (int i = 0; i < 10; i++) {
Cursor c = db.rawQuery("select * from test where id=?", new String[] { "" + i });
int count = c.getCount();
if (count > 0) {
c.move(1);
c.getInt(0);
c.getString(1);
}
c.close();
}
log("select");
} finally {
db.close();
log("closed");
}
}
Aggregations