use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class RecordViewImpl method marshalKeys.
/**
* Marshal key-records.
*
* @param recs Records collection.
* @return Binary rows collection.
*/
private Collection<BinaryRow> marshalKeys(@NotNull Collection<R> recs) {
final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
List<BinaryRow> rows = new ArrayList<>(recs.size());
try {
for (R rec : recs) {
final BinaryRow row = marsh.marshalKey(Objects.requireNonNull(rec));
rows.add(row);
}
return rows;
} catch (MarshallerException e) {
throw new IgniteException(e);
}
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class RecordViewImpl method replaceAsync.
/**
* {@inheritDoc}
*/
@Override
@NotNull
public CompletableFuture<Boolean> replaceAsync(@Nullable Transaction tx, @NotNull R oldRec, @NotNull R newRec) {
BinaryRow oldRow = marshal(Objects.requireNonNull(oldRec));
BinaryRow newRow = marshal(Objects.requireNonNull(newRec));
return tbl.replace(oldRow, newRow, (InternalTransaction) tx);
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class RecordViewImpl method marshal.
/**
* Marshal records.
*
* @param recs Records collection.
* @return Binary rows collection.
*/
private Collection<BinaryRow> marshal(@NotNull Collection<R> recs) {
final RecordMarshaller<R> marsh = marshaller(schemaReg.lastSchemaVersion());
List<BinaryRow> rows = new ArrayList<>(recs.size());
try {
for (R rec : recs) {
final BinaryRow row = marsh.marshal(Objects.requireNonNull(rec));
rows.add(row);
}
return rows;
} catch (MarshallerException e) {
throw new IgniteException(e);
}
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class RecordViewImpl method unmarshal.
/**
* Unmarshal value object from given binary row.
*
* @param binaryRow Binary row.
* @return Value object.
*/
private R unmarshal(BinaryRow binaryRow) {
if (binaryRow == null || !binaryRow.hasValue()) {
return null;
}
Row row = schemaReg.resolve(binaryRow);
RecordMarshaller<R> marshaller = marshaller(row.schemaVersion());
try {
return marshaller.unmarshal(row);
} catch (MarshallerException e) {
throw new IgniteException(e);
}
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class PartitionListener method handleScanRetrieveBatchCommand.
/**
* Handler for the {@link ScanRetrieveBatchCommand}.
*
* @param clo Command closure.
* @param cmd Command.
*/
private void handleScanRetrieveBatchCommand(CommandClosure<ScanRetrieveBatchCommand> clo, ScanRetrieveBatchCommand cmd) {
CursorMeta cursorDesc = cursors.get(cmd.scanId());
if (cursorDesc == null) {
clo.result(new NoSuchElementException(format("Cursor with id={} is not found on server side.", cmd.scanId())));
return;
}
AtomicInteger internalBatchCounter = cursorDesc.batchCounter();
if (internalBatchCounter.getAndSet(clo.command().batchCounter()) != clo.command().batchCounter() - 1) {
throw new IllegalStateException("Counters from received scan command and handled scan command in partition listener are inconsistent");
}
List<BinaryRow> res = new ArrayList<>();
try {
for (int i = 0; i < cmd.itemsToRetrieveCount() && cursorDesc.cursor().hasNext(); i++) {
res.add(cursorDesc.cursor().next());
}
} catch (NoSuchElementException e) {
clo.result(e);
}
clo.result(new MultiRowsResponse(res));
}
Aggregations