com.pivotal.gemfirexd.internal.engine.access.index.ContainsUniqueKeyExecutorMessage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snappydata-store-core Show documentation
Show all versions of snappydata-store-core Show documentation
TIBCO ComputeDB store based off Pivotal GemFireXD
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed 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. See accompanying
* LICENSE file.
*/
package com.pivotal.gemfirexd.internal.engine.access.index;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import com.gemstone.gemfire.DataSerializer;
import com.gemstone.gemfire.cache.Operation;
import com.gemstone.gemfire.distributed.internal.DistributionManager;
import com.gemstone.gemfire.internal.cache.LocalRegion;
import com.gemstone.gemfire.internal.cache.RegionEntry;
import com.gemstone.gemfire.internal.cache.TXEntryState;
import com.gemstone.gemfire.internal.cache.TXId;
import com.gemstone.gemfire.internal.cache.TXState;
import com.gemstone.gemfire.internal.cache.TXStateInterface;
import com.gemstone.gemfire.internal.cache.Token;
import com.gemstone.gemfire.internal.cache.TransactionMessage;
import com.gemstone.gemfire.internal.cache.locks.LockingPolicy;
import com.gemstone.gemfire.internal.concurrent.ConcurrentSkipListMap;
import com.gemstone.gemfire.internal.concurrent.FetchFromMap;
import com.gemstone.gemfire.internal.offheap.OffHeapHelper;
import com.gemstone.gemfire.internal.offheap.annotations.Released;
import com.gemstone.gemfire.internal.offheap.annotations.Retained;
import com.pivotal.gemfirexd.internal.engine.GemFireXDQueryObserver;
import com.pivotal.gemfirexd.internal.engine.GemFireXDQueryObserverHolder;
import com.pivotal.gemfirexd.internal.engine.GfxdConstants;
import com.pivotal.gemfirexd.internal.engine.distributed.message.RegionSingleKeyExecutorMessage;
import com.pivotal.gemfirexd.internal.engine.store.CompactCompositeIndexKey;
import com.pivotal.gemfirexd.internal.engine.store.GemFireContainer;
import com.pivotal.gemfirexd.internal.iapi.sql.conn.LanguageConnectionContext;
import com.pivotal.gemfirexd.internal.iapi.types.RowLocation;
import com.pivotal.gemfirexd.internal.impl.sql.execute.xplain.XPLAINUtil;
/**
* Execution function message to perform containsKey() for foreign key on unique
* key columns constraint check.
*
* @author kneeraj
*/
public final class ContainsUniqueKeyExecutorMessage extends
RegionSingleKeyExecutorMessage implements FetchFromMap {
private int[] referenceKeyColumnIndexes;
/**
* the actual skiplist key object as read using the
* {@link FetchFromMap#setMapKey(Object, int)} callback
*/
private transient Object mapKey;
/**
* the skiplist node's version field as read using the
* {@link FetchFromMap#setMapKey(Object, int)} callback
*/
private transient int keyVersion;
/** for deserialization */
public ContainsUniqueKeyExecutorMessage() {
super(true);
}
public ContainsUniqueKeyExecutorMessage(LocalRegion refregion,
int[] refKeyColumnIndexes, Object indexKey, Object routingObject,
TXStateInterface tx, LanguageConnectionContext lcc) {
super(refregion, indexKey, null, routingObject, false, tx,
getTimeStatsSettings(lcc));
this.referenceKeyColumnIndexes = refKeyColumnIndexes;
}
protected ContainsUniqueKeyExecutorMessage(
final ContainsUniqueKeyExecutorMessage other) {
super(other);
this.referenceKeyColumnIndexes = other.referenceKeyColumnIndexes;
}
@Override
public boolean optimizeForWrite() {
return false;
}
@Override
protected ContainsUniqueKeyExecutorMessage clone() {
return new ContainsUniqueKeyExecutorMessage(this);
}
/**
* @see TransactionMessage#canStartRemoteTransaction()
*/
@Override
public final boolean canStartRemoteTransaction() {
return getLockingPolicy().readOnlyCanStartTX();
}
@Override
public boolean isHA() {
return true;
}
public static boolean existsKey(TXStateInterface tx, LocalRegion lr,
int[] referenceKeyColumnIndexes, Object indexKey, Object callbackArg,
FetchFromMap fetch) throws Exception {
boolean containsKey = false;
final GfxdIndexManager idmanager = (GfxdIndexManager) lr.getIndexUpdater();
final List localIndexContainers = idmanager
.getIndexContainers();
if (localIndexContainers != null && !localIndexContainers.isEmpty()) {
for (final GemFireContainer indexContainer : localIndexContainers) {
if (!indexContainer.isLocalIndex() || !indexContainer.isUniqueIndex()) {
continue;
}
final int[] indexKeyPositions = indexContainer.getBaseColumnPositions();
if (indexKeyPositions.length != referenceKeyColumnIndexes.length) {
continue;
}
if (Arrays.equals(indexKeyPositions, referenceKeyColumnIndexes)) {
// need to check the presence of indexkey in this index
final ConcurrentSkipListMap