Search in sources :

Example 21 with Cursor

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;
}
Also used : Database(org.h2.engine.Database) Cursor(org.h2.index.Cursor)

Example 22 with Cursor

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;
}
Also used : Cursor(org.h2.index.Cursor)

Example 23 with Cursor

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);
}
Also used : Database(org.h2.engine.Database) ConnectionInfo(org.h2.engine.ConnectionInfo) Session(org.h2.engine.Session)

Example 24 with Cursor

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);
}
Also used : Database(org.h2.engine.Database) ConnectionInfo(org.h2.engine.ConnectionInfo) Session(org.h2.engine.Session)

Example 25 with Cursor

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");
    }
}
Also used : Cursor(android.database.Cursor) H2Database(org.h2.android.H2Database)

Aggregations

Cursor (org.h2.index.Cursor)24 Value (org.h2.value.Value)20 Index (org.h2.index.Index)11 Row (org.h2.result.Row)11 SearchRow (org.h2.result.SearchRow)11 ArrayList (java.util.ArrayList)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 Constraint (org.h2.constraint.Constraint)5 SingleRowCursor (org.h2.index.SingleRowCursor)5 Column (org.h2.table.Column)5 Session (org.h2.engine.Session)4 MultiVersionIndex (org.h2.index.MultiVersionIndex)4 IndexColumn (org.h2.table.IndexColumn)4 H2PkHashIndex (org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex)3 GridH2Row (org.apache.ignite.internal.processors.query.h2.opt.GridH2Row)3 Database (org.h2.engine.Database)3 ValueLong (org.h2.value.ValueLong)3 PreparedStatement (java.sql.PreparedStatement)2 BitSet (java.util.BitSet)2 UUID (java.util.UUID)2