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());
}
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());
}
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;
}
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();
}
}
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;
}
Aggregations