use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.
the class GridAbstractTest method createStandaloneBinaryMarshaller.
/**
* Create instance of {@link BinaryMarshaller} suitable for use
* without starting a grid upon given {@link IgniteConfiguration}.
*
* @return Binary marshaller.
* @throws IgniteCheckedException if failed.
*/
protected BinaryMarshaller createStandaloneBinaryMarshaller(IgniteConfiguration cfg) throws IgniteCheckedException {
BinaryMarshaller marsh = new BinaryMarshaller();
BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), cfg, new NullLogger());
marsh.setContext(new MarshallerContextTestImpl());
marsh.setBinaryContext(ctx, cfg);
return marsh;
}
use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.
the class GridTestBinaryMarshaller method createBinaryMarshaller.
/**
* @param log Logger.
*/
private BinaryMarshaller createBinaryMarshaller(IgniteLogger log) throws IgniteCheckedException {
IgniteConfiguration iCfg = new IgniteConfiguration().setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(true)).setClientMode(false).setDiscoverySpi(new TcpDiscoverySpi() {
@Override
public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException {
// No-op.
}
});
BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), iCfg, new NullLogger());
MarshallerContextTestImpl marshCtx = new MarshallerContextTestImpl();
marshCtx.onMarshallerProcessorStarted(new GridTestKernalContext(log, iCfg), null);
BinaryMarshaller marsh = new BinaryMarshaller();
marsh.setContext(marshCtx);
marsh.setBinaryContext(ctx, iCfg);
return marsh;
}
use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.
the class IgniteH2Indexing method executeSelectLocal.
/**
* Queries individual fields (generally used by JDBC drivers).
*
* @param qryId Query id.
* @param qryDesc Query descriptor.
* @param qryParams Query parameters.
* @param select Select.
* @param filter Cache name and key filter.
* @param mvccTracker Query tracker.
* @param cancel Query cancel.
* @param inTx Flag whether the query is executed in transaction.
* @param timeout Timeout.
* @return Query result.
* @throws IgniteCheckedException If failed.
*/
private GridQueryFieldsResult executeSelectLocal(long qryId, QueryDescriptor qryDesc, QueryParameters qryParams, QueryParserResultSelect select, final IndexingQueryFilter filter, MvccQueryTracker mvccTracker, GridQueryCancel cancel, boolean inTx, int timeout) throws IgniteCheckedException {
assert !select.mvccEnabled() || mvccTracker != null;
String qry;
if (select.forUpdate())
qry = inTx ? select.forUpdateQueryTx() : select.forUpdateQueryOutTx();
else
qry = qryDesc.sql();
boolean mvccEnabled = mvccTracker != null;
try {
assert select != null;
if (ctx.security().enabled())
checkSecurity(select.cacheIds());
MvccSnapshot mvccSnapshot = null;
if (mvccEnabled)
mvccSnapshot = mvccTracker.snapshot();
final QueryContext qctx = new QueryContext(0, filter, null, mvccSnapshot, null, true);
return new GridQueryFieldsResultAdapter(select.meta(), null) {
@Override
public GridCloseableIterator<List<?>> iterator() throws IgniteCheckedException {
H2PooledConnection conn = connections().connection(qryDesc.schemaName());
try (TraceSurroundings ignored = MTC.support(ctx.tracing().create(SQL_ITER_OPEN, MTC.span()))) {
H2Utils.setupConnection(conn, qctx, qryDesc.distributedJoins(), qryDesc.enforceJoinOrder(), qryParams.lazy());
PreparedStatement stmt = conn.prepareStatement(qry, H2StatementCache.queryFlags(qryDesc));
// Convert parameters into BinaryObjects.
Marshaller m = ctx.config().getMarshaller();
byte[] paramsBytes = U.marshal(m, qryParams.arguments());
final ClassLoader ldr = U.resolveClassLoader(ctx.config());
Object[] params;
if (m instanceof BinaryMarshaller) {
params = BinaryUtils.rawArrayFromBinary(((BinaryMarshaller) m).binaryMarshaller().unmarshal(paramsBytes, ldr));
} else
params = U.unmarshal(m, paramsBytes, ldr);
H2Utils.bindParameters(stmt, F.asList(params));
H2QueryInfo qryInfo = new H2QueryInfo(H2QueryInfo.QueryType.LOCAL, stmt, qry, ctx.localNodeId(), qryId);
ResultSet rs = executeSqlQueryWithTimer(stmt, conn, qry, timeout, cancel, qryParams.dataPageScanEnabled(), qryInfo);
return new H2FieldsIterator(rs, mvccTracker, conn, qryParams.pageSize(), log, IgniteH2Indexing.this, qryInfo, ctx.tracing());
} catch (IgniteCheckedException | RuntimeException | Error e) {
conn.close();
try {
if (mvccTracker != null)
mvccTracker.onDone();
} catch (Exception e0) {
e.addSuppressed(e0);
}
throw e;
}
}
};
} catch (Exception e) {
GridNearTxLocal tx = null;
if (mvccEnabled && (tx != null || (tx = tx(ctx)) != null))
tx.setRollbackOnly();
throw e;
}
}
use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.
the class IgniteCacheJoinQueryWithAffinityKeyTest method checkPersonAccountsJoin.
/**
* @param cache Cache.
* @param cnts Accounts per person counts.
* @param affKey If {@code true} uses key with affinity key field.
*/
private void checkPersonAccountsJoin(IgniteCache cache, Map<Object, Integer> cnts, boolean affKey) {
String sql1;
if (escape) {
sql1 = "select p.\"name\" from \"Person\" p, \"" + (affKey ? "AccountKeyWithAffinity" : "Account") + "\" a " + "where p._key = a.\"personKey\" and p._key=?";
} else {
sql1 = "select p.name from Person p, " + (affKey ? "AccountKeyWithAffinity" : "Account") + " a " + "where p._key = a.personKey and p._key=?";
}
SqlFieldsQuery qry1 = new SqlFieldsQuery(sql1);
qry1.setDistributedJoins(true);
String sql2;
if (escape) {
sql2 = "select p.\"name\" from \"Person\" p, \"" + (affKey ? "AccountKeyWithAffinity" : "Account") + "\" a " + "where p.\"id\" = a.\"personId\" and p.\"id\"=?";
} else {
sql2 = "select p.name from Person p, " + (affKey ? "AccountKeyWithAffinity" : "Account") + " a " + "where p.id = a.personId and p.id=?";
}
SqlFieldsQuery qry2 = new SqlFieldsQuery(sql2);
qry2.setDistributedJoins(true);
Ignite ignite = (Ignite) cache.unwrap(Ignite.class);
boolean binary = ignite.configuration().getMarshaller() instanceof BinaryMarshaller;
long total = 0;
for (Map.Entry<Object, Integer> e : cnts.entrySet()) {
Object arg = binary ? ignite.binary().toBinary(e.getKey()) : e.getKey();
qry1.setArgs(arg);
List<List<Object>> res = cache.query(qry1).getAll();
assertEquals((int) e.getValue(), res.size());
total += res.size();
qry2.setArgs(((Id) e.getKey()).id());
res = cache.query(qry2).getAll();
assertEquals((int) e.getValue(), res.size());
}
SqlFieldsQuery[] qrys = new SqlFieldsQuery[2];
if (escape) {
qrys[0] = new SqlFieldsQuery("select count(*) " + "from \"Person\" p, \"" + (affKey ? "AccountKeyWithAffinity" : "Account") + "\" a " + "where p.\"id\" = a.\"personId\"");
qrys[1] = new SqlFieldsQuery("select count(*) " + "from \"Person\" p, \"" + (affKey ? "AccountKeyWithAffinity" : "Account") + "\" a " + "where p._key = a.\"personKey\"");
} else {
qrys[0] = new SqlFieldsQuery("select count(*) " + "from Person p, " + (affKey ? "AccountKeyWithAffinity" : "Account") + " a " + "where p.id = a.personId");
qrys[1] = new SqlFieldsQuery("select count(*) " + "from Person p, " + (affKey ? "AccountKeyWithAffinity" : "Account") + " a " + "where p._key = a.personKey");
}
for (SqlFieldsQuery qry : qrys) {
qry.setDistributedJoins(true);
List<List<Object>> res = cache.query(qry).getAll();
assertEquals(1, res.size());
assertEquals(total, res.get(0).get(0));
}
}
use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.
the class IgniteCacheLockPartitionOnAffinityRunAbstractTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
// Enables template with default test configuration
cfg.setCacheConfiguration(F.concat(cfg.getCacheConfiguration(), cacheConfiguration(igniteInstanceName).setName("*")));
((TcpCommunicationSpi) cfg.getCommunicationSpi()).setSharedMemoryPort(-1);
cfg.setMarshaller(new BinaryMarshaller());
// TODO remove key configuration when https://issues.apache.org/jira/browse/IGNITE-5795 is fixed.
cfg.setCacheKeyConfiguration(new CacheKeyConfiguration(Person.Key.class.getName(), "orgId"));
AlwaysFailoverSpi failSpi = new AlwaysFailoverSpi();
failSpi.setMaximumFailoverAttempts(MAX_FAILOVER_ATTEMPTS);
cfg.setFailoverSpi(failSpi);
return cfg;
}
Aggregations