Search in sources :

Example 1 with Call

use of org.h2.command.dml.Call in project ignite by apache.

the class GridH2AbstractKeyValueRow method syncValue.

/**
     * @param waitTime Time to await for value unswap.
     * @return Synchronized value.
     */
protected synchronized Value syncValue(long waitTime) {
    Value v = peekValue(VAL_COL);
    while (v == null && waitTime > 0) {
        // This call must be quite rare, so performance is not a concern.
        long start = System.nanoTime();
        try {
            // Wait for value arrival to allow other threads to make a progress.
            wait(waitTime);
        } catch (InterruptedException e) {
            throw new IgniteInterruptedException(e);
        }
        long t = System.nanoTime() - start;
        if (t > 0)
            waitTime -= TimeUnit.NANOSECONDS.toMillis(t);
        v = peekValue(VAL_COL);
    }
    return v;
}
Also used : Value(org.h2.value.Value) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException)

Example 2 with Call

use of org.h2.command.dml.Call in project frostwire by frostwire.

the class FullTextLucene2 method getIndexPath.

/**
 * Get the path of the Lucene index for this database.
 *
 * @param conn the database connection
 * @return the path
 */
protected static String getIndexPath(Connection conn) throws SQLException {
    Statement stat = conn.createStatement();
    ResultSet rs = stat.executeQuery("CALL DATABASE_PATH()");
    rs.next();
    String path = rs.getString(1);
    if (path == null) {
        throw throwException("Fulltext search for in-memory databases is not supported.");
    }
    int index = path.lastIndexOf(':');
    // position 1 means a windows drive letter is used, ignore that
    if (index > 1) {
        path = path.substring(index + 1);
    }
    rs.close();
    return path;
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet)

Example 3 with Call

use of org.h2.command.dml.Call in project ignite by apache.

the class IgniteH2Indexing method querySqlFields.

/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "StringEquality", "unchecked" })
@Override
public List<FieldsQueryCursor<List<?>>> querySqlFields(String schemaName, SqlFieldsQuery qry, @Nullable SqlClientContext cliCtx, boolean keepBinary, boolean failOnMultipleStmts, GridQueryCancel cancel) {
    List<FieldsQueryCursor<List<?>>> res = tryQueryDistributedSqlFieldsNative(schemaName, qry.getSql(), cliCtx);
    if (res != null)
        return res;
    {
        // First, let's check if we already have a two-step query for this statement...
        H2TwoStepCachedQueryKey cachedQryKey = new H2TwoStepCachedQueryKey(schemaName, qry.getSql(), qry.isCollocated(), qry.isDistributedJoins(), qry.isEnforceJoinOrder(), qry.isLocal());
        H2TwoStepCachedQuery cachedQry;
        if ((cachedQry = twoStepCache.get(cachedQryKey)) != null) {
            checkQueryType(qry, true);
            GridCacheTwoStepQuery twoStepQry = cachedQry.query().copy();
            List<GridQueryFieldMetadata> meta = cachedQry.meta();
            res = Collections.singletonList(doRunDistributedQuery(schemaName, qry, twoStepQry, meta, keepBinary, cancel));
            if (!twoStepQry.explain())
                twoStepCache.putIfAbsent(cachedQryKey, new H2TwoStepCachedQuery(meta, twoStepQry.copy()));
            return res;
        }
    }
    {
        // Second, let's check if we already have a parsed statement...
        PreparedStatement cachedStmt;
        if ((cachedStmt = cachedStatement(connectionForSchema(schemaName), qry.getSql())) != null) {
            Prepared prepared = GridSqlQueryParser.prepared(cachedStmt);
            // We may use this cached statement only for local queries and non queries.
            if (qry.isLocal() || !prepared.isQuery())
                return (List<FieldsQueryCursor<List<?>>>) doRunPrepared(schemaName, prepared, qry, null, null, keepBinary, cancel);
        }
    }
    res = new ArrayList<>(1);
    int firstArg = 0;
    String remainingSql = qry.getSql();
    while (remainingSql != null) {
        ParsingResult parseRes = parseAndSplit(schemaName, remainingSql != qry.getSql() ? cloneFieldsQuery(qry).setSql(remainingSql) : qry, firstArg);
        // Let's avoid second reflection getter call by returning Prepared object too
        Prepared prepared = parseRes.prepared();
        GridCacheTwoStepQuery twoStepQry = parseRes.twoStepQuery();
        List<GridQueryFieldMetadata> meta = parseRes.meta();
        SqlFieldsQuery newQry = parseRes.newQuery();
        remainingSql = parseRes.remainingSql();
        if (remainingSql != null && failOnMultipleStmts)
            throw new IgniteSQLException("Multiple statements queries are not supported");
        firstArg += prepared.getParameters().size();
        res.addAll(doRunPrepared(schemaName, prepared, newQry, twoStepQry, meta, keepBinary, cancel));
        if (parseRes.twoStepQuery() != null && parseRes.twoStepQueryKey() != null && !parseRes.twoStepQuery().explain())
            twoStepCache.putIfAbsent(parseRes.twoStepQueryKey(), new H2TwoStepCachedQuery(meta, twoStepQry.copy()));
    }
    return res;
}
Also used : FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) Prepared(org.h2.command.Prepared) GridCacheTwoStepQuery(org.apache.ignite.internal.processors.cache.query.GridCacheTwoStepQuery) GridQueryFieldMetadata(org.apache.ignite.internal.processors.query.GridQueryFieldMetadata) PreparedStatement(java.sql.PreparedStatement) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with Call

use of org.h2.command.dml.Call in project ignite by apache.

the class GridH2Table method removeChildrenAndResources.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Override
public void removeChildrenAndResources(Session ses) {
    lock(true);
    try {
        super.removeChildrenAndResources(ses);
        // Clear all user indexes registered in schema.
        while (idxs.size() > sysIdxsCnt) {
            Index idx = idxs.get(sysIdxsCnt);
            if (idx.getName() != null && idx.getSchema().findIndex(ses, idx.getName()) == idx) {
                // This call implicitly removes both idx and its proxy, if any, from idxs.
                database.removeSchemaObject(ses, idx);
                // We have to call destroy here if we are who has removed this index from the table.
                if (idx instanceof GridH2IndexBase)
                    ((GridH2IndexBase) idx).destroy(rmIndex);
            }
        }
        if (SysProperties.CHECK) {
            for (SchemaObject obj : database.getAllSchemaObjects(DbObject.INDEX)) {
                Index idx = (Index) obj;
                if (idx.getTable() == this)
                    DbException.throwInternalError("index not dropped: " + idx.getName());
            }
        }
        database.removeMeta(ses, getId());
        invalidate();
    } finally {
        unlock(true);
    }
}
Also used : SchemaObject(org.h2.schema.SchemaObject) Index(org.h2.index.Index) SpatialIndex(org.h2.index.SpatialIndex) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)

Example 5 with Call

use of org.h2.command.dml.Call in project ignite by apache.

the class H2DynamicTableSelfTest method testIndexNameConflictCheckDiscovery.

/**
 * Tests index name conflict check in discovery thread.
 * @throws Exception if failed.
 */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void testIndexNameConflictCheckDiscovery() throws Exception {
    execute(grid(0), "CREATE TABLE \"Person\" (id int primary key, name varchar)");
    execute(grid(0), "CREATE INDEX \"idx\" ON \"Person\" (\"name\")");
    GridTestUtils.assertThrows(null, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            QueryEntity e = new QueryEntity();
            e.setTableName("City");
            e.setKeyFields(Collections.singleton("name"));
            e.setFields(new LinkedHashMap<>(Collections.singletonMap("name", String.class.getName())));
            e.setIndexes(Collections.singleton(new QueryIndex("name").setName("idx")));
            e.setKeyType("CityKey");
            e.setValueType("City");
            queryProcessor(client()).dynamicTableCreate("PUBLIC", e, CacheMode.PARTITIONED.name(), null, null, null, null, CacheAtomicityMode.ATOMIC, null, 10, false);
            return null;
        }
    }, SchemaOperationException.class, "Index already exists: idx");
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) BinaryObject(org.apache.ignite.binary.BinaryObject) QueryEntity(org.apache.ignite.cache.QueryEntity) IgniteException(org.apache.ignite.IgniteException) SQLException(java.sql.SQLException) CacheException(javax.cache.CacheException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) JdbcSQLException(org.h2.jdbc.JdbcSQLException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Task (org.h2.util.Task)69 Connection (java.sql.Connection)68 Statement (java.sql.Statement)64 PreparedStatement (java.sql.PreparedStatement)60 ResultSet (java.sql.ResultSet)48 SQLException (java.sql.SQLException)42 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)24 SimpleResultSet (org.h2.tools.SimpleResultSet)24 MVStore (org.h2.mvstore.MVStore)20 Random (java.util.Random)19 JdbcConnection (org.h2.jdbc.JdbcConnection)19 CallableStatement (java.sql.CallableStatement)14 DbException (org.h2.message.DbException)13 IOException (java.io.IOException)10 JdbcSQLException (org.h2.jdbc.JdbcSQLException)7 ArrayList (java.util.ArrayList)6 Expression (org.h2.expression.Expression)6 ValueString (org.h2.value.ValueString)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 OutputStream (java.io.OutputStream)4