Search in sources :

Example 1 with Session

use of org.h2.engine.Session in project siena by mandubian.

the class FullText method parseKey.

/**
     * Parse a primary key condition into the primary key columns.
     *
     * @param conn the database connection
     * @param key the primary key condition as a string
     * @return an array containing the column name list and the data list
     */
protected static Object[][] parseKey(Connection conn, String key) {
    ArrayList<String> columns = New.arrayList();
    ArrayList<String> data = New.arrayList();
    JdbcConnection c = (JdbcConnection) conn;
    Session session = (Session) c.getSession();
    Parser p = new Parser(session);
    Expression expr = p.parseExpression(key);
    addColumnData(columns, data, expr);
    Object[] col = new Object[columns.size()];
    columns.toArray(col);
    Object[] dat = new Object[columns.size()];
    data.toArray(dat);
    Object[][] columnData = { col, dat };
    return columnData;
}
Also used : ValueExpression(org.h2.expression.ValueExpression) Expression(org.h2.expression.Expression) JdbcConnection(org.h2.jdbc.JdbcConnection) Session(org.h2.engine.Session) Parser(org.h2.command.Parser)

Example 2 with Session

use of org.h2.engine.Session in project ignite by apache.

the class GridH2Table method commitUserIndex.

/**
     * Promote temporary index to make it usable in queries.
     *
     * @param ses H2 session.
     * @param idxName Index name.
     * @return Temporary index with given name.
     */
private Index commitUserIndex(Session ses, String idxName) {
    lock(true);
    try {
        ensureNotDestroyed();
        Index idx = tmpIdxs.remove(idxName);
        assert idx != null;
        Index cloneIdx = createDuplicateIndexIfNeeded(idx);
        ArrayList<Index> newIdxs = new ArrayList<>(idxs.size() + ((cloneIdx == null) ? 1 : 2));
        newIdxs.addAll(idxs);
        newIdxs.add(idx);
        if (cloneIdx != null)
            newIdxs.add(cloneIdx);
        idxs = newIdxs;
        database.addSchemaObject(ses, idx);
        if (cloneIdx != null)
            database.addSchemaObject(ses, cloneIdx);
        setModified();
        return idx;
    } finally {
        unlock(true);
    }
}
Also used : ArrayList(java.util.ArrayList) Index(org.h2.index.Index) SpatialIndex(org.h2.index.SpatialIndex) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)

Example 3 with Session

use of org.h2.engine.Session in project ignite by apache.

the class GridH2Table method removeIndex.

/**
     * Remove the given index from the list.
     *
     * @param h2Idx the index to remove
     */
public void removeIndex(Session session, Index h2Idx) {
    lock(true);
    try {
        ArrayList<Index> idxs = new ArrayList<>(this.idxs);
        Index targetIdx = (h2Idx instanceof GridH2ProxyIndex) ? ((GridH2ProxyIndex) h2Idx).underlyingIndex() : h2Idx;
        for (int i = pkIndexPos; i < idxs.size(); ) {
            Index idx = idxs.get(i);
            if (idx == targetIdx || (idx instanceof GridH2ProxyIndex && ((GridH2ProxyIndex) idx).underlyingIndex() == targetIdx)) {
                idxs.remove(i);
                if (idx instanceof GridH2ProxyIndex && idx.getSchema().findIndex(session, idx.getName()) != null)
                    database.removeSchemaObject(session, idx);
                continue;
            }
            i++;
        }
        this.idxs = idxs;
    } finally {
        unlock(true);
    }
}
Also used : ArrayList(java.util.ArrayList) Index(org.h2.index.Index) SpatialIndex(org.h2.index.SpatialIndex) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)

Example 4 with Session

use of org.h2.engine.Session in project ignite by apache.

the class GridMergeIndex method getRowCount.

/** {@inheritDoc} */
@Override
public long getRowCount(Session ses) {
    Cursor c = find(ses, null, null);
    long cnt = 0;
    while (c.next()) cnt++;
    return cnt;
}
Also used : Cursor(org.h2.index.Cursor)

Example 5 with Session

use of org.h2.engine.Session in project ignite by apache.

the class IgniteH2Indexing method rebuildIndexesFromHash.

/** {@inheritDoc} */
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
@Override
public void rebuildIndexesFromHash(GridCacheContext cctx, String schemaName, String typeName) throws IgniteCheckedException {
    H2TableDescriptor tbl = tableDescriptor(schemaName, typeName);
    if (tbl == null)
        return;
    assert tbl.table() != null;
    assert tbl.table().rebuildFromHashInProgress();
    H2PkHashIndex hashIdx = tbl.primaryKeyHashIndex();
    Cursor cursor = hashIdx.find((Session) null, null, null);
    while (cursor.next()) {
        CacheDataRow dataRow = (CacheDataRow) cursor.get();
        boolean done = false;
        while (!done) {
            GridCacheEntryEx entry = cctx.cache().entryEx(dataRow.key());
            try {
                synchronized (entry) {
                    // TODO : How to correctly get current value and link here?
                    GridH2Row row = tbl.table().rowDescriptor().createRow(entry.key(), entry.partition(), dataRow.value(), entry.version(), entry.expireTime());
                    row.link(dataRow.link());
                    List<Index> indexes = tbl.table().getAllIndexes();
                    for (int i = 2; i < indexes.size(); i++) {
                        Index idx = indexes.get(i);
                        if (idx instanceof H2TreeIndex)
                            ((H2TreeIndex) idx).put(row);
                    }
                    done = true;
                }
            } catch (GridCacheEntryRemovedException e) {
            // No-op
            }
        }
    }
    tbl.table().markRebuildFromHashInProgress(false);
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridH2Row(org.apache.ignite.internal.processors.query.h2.opt.GridH2Row) Index(org.h2.index.Index) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex) H2PkHashIndex(org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) H2PkHashIndex(org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex) QueryCursor(org.apache.ignite.cache.query.QueryCursor) Cursor(org.h2.index.Cursor) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor)

Aggregations

ArrayList (java.util.ArrayList)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 Cursor (org.h2.index.Cursor)4 Index (org.h2.index.Index)4 SingleRowCursor (org.h2.index.SingleRowCursor)4 H2TreeIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)3 Session (org.h2.engine.Session)3 Node (javax.jcr.Node)2 GridH2Row (org.apache.ignite.internal.processors.query.h2.opt.GridH2Row)2 GridCursor (org.apache.ignite.internal.util.lang.GridCursor)2 SpatialIndex (org.h2.index.SpatialIndex)2 Profiler (org.h2.util.Profiler)2 Test (org.junit.Test)2 SQLException (java.sql.SQLException)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1