Search in sources :

Example 46 with SqlFieldsQuery

use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.

the class JdbcUpdateStatementSelfTest method testExecuteUpdate.

/**
 */
@Test
public void testExecuteUpdate() throws SQLException {
    conn.createStatement().executeUpdate("update Person set firstName = 'Jack' where " + "cast(substring(_key, 2, 1) as int) % 2 = 0");
    assertEquals(Arrays.asList(F.asList("John"), F.asList("Jack"), F.asList("Mike")), jcache(0).query(new SqlFieldsQuery("select firstName from Person order by _key")).getAll());
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Test(org.junit.Test)

Example 47 with SqlFieldsQuery

use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.

the class JdbcUpdateStatementSelfTest method testExecute.

/**
 */
@Test
public void testExecute() throws SQLException {
    conn.createStatement().execute("update Person set firstName = 'Jack' where " + "cast(substring(_key, 2, 1) as int) % 2 = 0");
    assertEquals(Arrays.asList(F.asList("John"), F.asList("Jack"), F.asList("Mike")), jcache(0).query(new SqlFieldsQuery("select firstName from Person order by _key")).getAll());
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Test(org.junit.Test)

Example 48 with SqlFieldsQuery

use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.

the class JdbcConnection method prepareStatement.

/**
 * {@inheritDoc}
 */
@Override
public PreparedStatement prepareStatement(String sql, int resSetType, int resSetConcurrency, int resSetHoldability) throws SQLException {
    ensureNotClosed();
    if (resSetType != TYPE_FORWARD_ONLY)
        throw new SQLFeatureNotSupportedException("Invalid result set type (only forward is supported.)");
    if (resSetConcurrency != CONCUR_READ_ONLY)
        throw new SQLFeatureNotSupportedException("Invalid concurrency (updates are not supported).");
    if (!txAllowed && resSetHoldability != HOLD_CURSORS_OVER_COMMIT)
        throw new SQLFeatureNotSupportedException("Invalid holdability (transactions are not supported).");
    JdbcPreparedStatement stmt;
    if (!stream)
        stmt = new JdbcPreparedStatement(this, sql);
    else {
        GridQueryIndexing idx = ignite().context().query().getIndexing();
        if (!idx.isStreamableInsertStatement(schemaName(), new SqlFieldsQuery(sql)))
            throw new IgniteSQLException("Streaming mode supports only INSERT commands without subqueries.", IgniteQueryErrorCode.UNSUPPORTED_OPERATION).toJdbcException();
        IgniteDataStreamer streamer = ignite().dataStreamer(cacheName);
        streamer.autoFlushFrequency(streamFlushTimeout);
        streamer.allowOverwrite(streamAllowOverwrite);
        if (streamNodeBufSize > 0)
            streamer.perNodeBufferSize(streamNodeBufSize);
        if (streamNodeParOps > 0)
            streamer.perNodeParallelOperations(streamNodeParOps);
        stmt = new JdbcStreamedPreparedStatement(this, sql, streamer);
    }
    statements.add(stmt);
    return stmt;
}
Also used : IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) GridQueryIndexing(org.apache.ignite.internal.processors.query.GridQueryIndexing) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Example 49 with SqlFieldsQuery

use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.

the class JdbcPreparedStatement method getMetadata0.

/**
 * Fetches metadata of the result set is returned when specified query gets executed.
 *
 * @return metadata describing result set or {@code null} if query is not a SELECT operation.
 */
@Nullable
private ResultSetMetaData getMetadata0() throws SQLException {
    SqlFieldsQuery qry = new SqlFieldsQuery(sql);
    setupQuery(qry);
    try {
        List<GridQueryFieldMetadata> meta = conn.ignite().context().query().getIndexing().resultMetaData(conn.schemaName(), qry);
        if (meta == null)
            return null;
        return new JdbcResultSetMetadata(meta);
    } catch (IgniteSQLException ex) {
        throw ex.toJdbcException();
    }
}
Also used : IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) GridQueryFieldMetadata(org.apache.ignite.internal.processors.query.GridQueryFieldMetadata) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) Nullable(org.jetbrains.annotations.Nullable)

Example 50 with SqlFieldsQuery

use of org.apache.ignite.cache.query.SqlFieldsQuery in project ignite by apache.

the class PlatformCache method readFieldsQuery.

/**
 * Reads fields query.
 *
 * @param reader Binary reader.
 * @return Query.
 */
private Query readFieldsQuery(BinaryRawReaderEx reader) {
    boolean loc = reader.readBoolean();
    String sql = reader.readString();
    final int pageSize = reader.readInt();
    Object[] args = readQueryArgs(reader);
    boolean distrJoins = reader.readBoolean();
    boolean enforceJoinOrder = reader.readBoolean();
    boolean lazy = reader.readBoolean();
    int timeout = reader.readInt();
    boolean replicated = reader.readBoolean();
    boolean collocated = reader.readBoolean();
    String schema = reader.readString();
    int[] partitions = reader.readIntArray();
    int updateBatchSize = reader.readInt();
    SqlFieldsQuery qry = QueryUtils.withQueryTimeout(new SqlFieldsQuery(sql), timeout, TimeUnit.MILLISECONDS).setPageSize(pageSize).setArgs(args).setLocal(loc).setDistributedJoins(distrJoins).setEnforceJoinOrder(enforceJoinOrder).setLazy(lazy).setReplicatedOnly(replicated).setCollocated(collocated).setSchema(schema).setPartitions(partitions).setUpdateBatchSize(updateBatchSize);
    return qry;
}
Also used : SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

Aggregations

SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)679 Test (org.junit.Test)388 List (java.util.List)373 Ignite (org.apache.ignite.Ignite)170 ArrayList (java.util.ArrayList)136 IgniteCache (org.apache.ignite.IgniteCache)123 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)115 AbstractIndexingCommonTest (org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest)94 IgniteEx (org.apache.ignite.internal.IgniteEx)90 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)83 Transaction (org.apache.ignite.transactions.Transaction)80 CacheException (javax.cache.CacheException)67 Random (java.util.Random)55 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)53 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)52 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)45 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)41 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)32 HashMap (java.util.HashMap)31 Cache (javax.cache.Cache)31