
com.hazelcast.query.impl.CachedQueryEntry Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2008-2024, Hazelcast, 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.
*/
package com.hazelcast.query.impl;
import com.hazelcast.internal.serialization.Data;
import com.hazelcast.internal.serialization.InternalSerializationService;
import com.hazelcast.internal.serialization.SerializationService;
import com.hazelcast.map.impl.MapDataSerializerHook;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
import java.io.IOException;
/**
* Entry of the Query.
*
* @param key
* @param value
*/
@SuppressWarnings("removal")
public class CachedQueryEntry extends QueryableEntry implements IdentifiedDataSerializable {
protected Data keyData;
protected Data valueData;
protected K keyObject;
protected V valueObject;
public CachedQueryEntry() {
}
public CachedQueryEntry(SerializationService ss, Object key, Object value) {
init(ss, key, value);
}
public CachedQueryEntry init(SerializationService ss, Object key, Object value) {
this.serializationService = (InternalSerializationService) ss;
return init(key, value);
}
@SuppressWarnings("unchecked")
public CachedQueryEntry init(Object key, Object value) {
if (key == null) {
throw new IllegalArgumentException("keyData cannot be null");
}
if (key instanceof Data data) {
this.keyData = data;
this.keyObject = null;
} else {
this.keyObject = (K) key;
this.keyData = null;
}
if (value instanceof Data data) {
this.valueData = data;
this.valueObject = null;
} else {
this.valueObject = (V) value;
this.valueData = null;
}
return this;
}
@SuppressWarnings("unchecked")
public CachedQueryEntry initWithObjectKeyValue(Object key, Object value) {
this.keyObject = (K) key;
this.keyData = null;
this.valueObject = (V) value;
this.valueData = null;
return this;
}
@Override
public K getKey() {
if (keyObject == null) {
keyObject = serializationService.toObject(keyData);
}
return keyObject;
}
@Override
public Data getKeyData() {
return keyData;
}
@Override
public V getValue() {
if (valueObject == null) {
valueObject = serializationService.toObject(valueData);
}
return valueObject;
}
@Override
public Data getValueData() {
if (valueData == null) {
valueData = serializationService.toData(valueObject);
}
return valueData;
}
@Override
public K getKeyIfPresent() {
return keyObject != null ? keyObject : null;
}
@Override
public Data getKeyDataIfPresent() {
return keyData;
}
@SuppressWarnings("unchecked")
@Override
public V getValueIfPresent() {
if (valueObject != null) {
return valueObject;
}
return null;
}
@Override
public Data getValueDataIfPresent() {
if (valueData != null) {
return valueData;
}
return null;
}
@Override
public V setValue(V value) {
throw new UnsupportedOperationException();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CachedQueryEntry, ?> that = (CachedQueryEntry, ?>) o;
return keyData.equals(that.keyData);
}
@Override
public int hashCode() {
return keyData.hashCode();
}
@Override
public void writeData(ObjectDataOutput out) throws IOException {
out.writeObject(getKey());
out.writeObject(getValue());
}
@Override
public void readData(ObjectDataInput in) throws IOException {
keyObject = in.readObject();
valueObject = in.readObject();
}
@Override
public int getFactoryId() {
return MapDataSerializerHook.F_ID;
}
@Override
public int getClassId() {
// We are intentionally deserializing CachedQueryEntry as LazyMapEntry
// LazyMapEntry is actually a subclass of CacheQueryEntry.
// If this sounds surprising, convoluted or just plain wrong
// then you are not wrong. Please see commit message for reasoning.
return MapDataSerializerHook.LAZY_MAP_ENTRY;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy