Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ignite.internal.table;
import static org.apache.ignite.internal.lang.IgniteExceptionMapperUtil.convertToPublicFuture;
import static org.apache.ignite.internal.util.CompletableFutures.trueCompletedFuture;
import static org.apache.ignite.internal.util.ViewUtils.checkKeysForNulls;
import static org.apache.ignite.internal.util.ViewUtils.sync;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Flow;
import java.util.concurrent.Flow.Publisher;
import java.util.function.Function;
import org.apache.ignite.internal.lang.IgniteBiTuple;
import org.apache.ignite.internal.marshaller.MarshallersProvider;
import org.apache.ignite.internal.replicator.TablePartitionId;
import org.apache.ignite.internal.schema.BinaryRow;
import org.apache.ignite.internal.schema.BinaryRowEx;
import org.apache.ignite.internal.schema.SchemaDescriptor;
import org.apache.ignite.internal.schema.SchemaRegistry;
import org.apache.ignite.internal.schema.row.Row;
import org.apache.ignite.internal.streamer.StreamerBatchSender;
import org.apache.ignite.internal.table.criteria.SqlRowProjection;
import org.apache.ignite.internal.table.distributed.schema.SchemaVersions;
import org.apache.ignite.internal.thread.PublicApiThreading;
import org.apache.ignite.internal.tx.InternalTransaction;
import org.apache.ignite.internal.util.IgniteUtils;
import org.apache.ignite.lang.MarshallerException;
import org.apache.ignite.lang.NullableValue;
import org.apache.ignite.sql.IgniteSql;
import org.apache.ignite.sql.ResultSetMetadata;
import org.apache.ignite.sql.SqlRow;
import org.apache.ignite.table.DataStreamerItem;
import org.apache.ignite.table.DataStreamerOptions;
import org.apache.ignite.table.KeyValueView;
import org.apache.ignite.table.ReceiverDescriptor;
import org.apache.ignite.table.Tuple;
import org.apache.ignite.tx.Transaction;
import org.jetbrains.annotations.Nullable;
/**
* Key-value view implementation for binary user-object representation.
*
*
NB: Binary view doesn't allow null tuples. Methods return either a tuple that represents the value, or {@code null} if no value
* exists for the given key.
*/
public class KeyValueBinaryViewImpl extends AbstractTableView> implements KeyValueView {
private final TupleMarshallerCache marshallerCache;
/**
* The constructor.
*
* @param tbl Table storage.
* @param schemaReg Schema registry.
* @param schemaVersions Schema versions access.
* @param sql Ignite SQL facade.
* @param marshallers Marshallers provider.
*/
public KeyValueBinaryViewImpl(
InternalTable tbl,
SchemaRegistry schemaReg,
SchemaVersions schemaVersions,
IgniteSql sql,
MarshallersProvider marshallers
) {
super(tbl, schemaVersions, schemaReg, sql, marshallers);
marshallerCache = new TupleMarshallerCache(schemaReg);
}
/** {@inheritDoc} */
@Override
public Tuple get(@Nullable Transaction tx, Tuple key) {
return sync(getAsync(tx, key));
}
/** {@inheritDoc} */
@Override
public CompletableFuture getAsync(@Nullable Transaction tx, Tuple key) {
Objects.requireNonNull(key, "key");
return doOperation(tx, (schemaVersion) -> {
Row keyRow = marshal(key, null, schemaVersion);
return tbl.get(keyRow, (InternalTransaction) tx).thenApply(row -> unmarshalValue(row, schemaVersion));
});
}
/** {@inheritDoc} */
@Override
public NullableValue getNullable(@Nullable Transaction tx, Tuple key) {
return sync(getNullableAsync(tx, key));
}
/** {@inheritDoc} */
@Override
public CompletableFuture> getNullableAsync(@Nullable Transaction tx, Tuple key) {
// This method implemented for consistency and has the same semantics as regular get().
// NullableValue.get() will never return null and there is no ambiguity between value absence and null result.
return getAsync(tx, key).thenApply(r -> r == null ? null : NullableValue.of(r));
}
/** {@inheritDoc} */
@Override
public Tuple getOrDefault(@Nullable Transaction tx, Tuple key, Tuple defaultValue) {
return sync(getOrDefaultAsync(tx, key, defaultValue));
}
/** {@inheritDoc} */
@Override
public CompletableFuture getOrDefaultAsync(@Nullable Transaction tx, Tuple key, Tuple defaultValue) {
Objects.requireNonNull(key, "key");
return doOperation(tx, (schemaVersion) -> {
BinaryRowEx keyRow = marshal(key, null, schemaVersion);
return tbl.get(keyRow, (InternalTransaction) tx)
.thenApply(r -> IgniteUtils.nonNullOrElse(unmarshalValue(r, schemaVersion), defaultValue));
});
}
/** {@inheritDoc} */
@Override
public Map getAll(@Nullable Transaction tx, Collection keys) {
return sync(getAllAsync(tx, keys));
}
/** {@inheritDoc} */
@Override
public CompletableFuture