com.gemstone.gemfire.pdx.PdxReader Maven / Gradle / Ivy
Show all versions of gemfire-core Show documentation
/*
* 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.gemstone.gemfire.pdx;
import java.util.Date;
/**
* A PdxReader will be passed to {@link PdxSerializable#fromData(PdxReader) fromData} or
* {@link PdxSerializer#fromData(Class, PdxReader) PdxSerializer fromData} by GemFire during deserialization of
* a PDX. The domain class needs to deserialize field members
* using this interface. This interface is implemented by GemFire.
* Each readXXX call will return the field's value. If the serialized
* PDX does not contain the named field then a default value will
* be returned. Standard Java defaults are used. For Objects this is
* null
and for primitives it is 0
or 0.0
.
* You must read fields in the same order they were written by {@link PdxWriter}.
*
The methods on this interface are not thread safe so do not
* call them concurrently, on the same instance, from more than one thread.
*
* @author darrel
* @since 6.6
*/
public interface PdxReader {
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxFieldTypeMismatchException if the named field exists and is not a char
field.
* @throws PdxSerializationException if deserialization of the field fails.
*/
public char readChar(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxFieldTypeMismatchException if the named field exists and is not a boolean
field.
* @throws PdxSerializationException if deserialization of the field fails.
*/
public boolean readBoolean(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxFieldTypeMismatchException if the named field exists and is not a byte
field.
* @throws PdxSerializationException if deserialization of the field fails.
*/
public byte readByte(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxFieldTypeMismatchException if the named field exists and is not a short
field.
* @throws PdxSerializationException if deserialization of the field fails.
*/
public short readShort(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxFieldTypeMismatchException if the named field exists and is not a int
field.
* @throws PdxSerializationException if deserialization of the field fails.
*/
public int readInt(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxFieldTypeMismatchException if the named field exists and is not a long
field.
* @throws PdxSerializationException if deserialization of the field fails.
*/
public long readLong(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxFieldTypeMismatchException if the named field exists and is not a float
field.
* @throws PdxSerializationException if deserialization of the field fails.
*/
public float readFloat(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxFieldTypeMismatchException if the named field exists and is not a double
field.
* @throws PdxSerializationException if deserialization of the field fails.
*/
public double readDouble(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxFieldTypeMismatchException if the named field exists and is not a String
field.
* @throws PdxSerializationException if deserialization of the field fails.
*/
public String readString(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxSerializationException if deserialization of the field fails.
* @throws PdxFieldTypeMismatchException if the named field exists and is not an Object
field.
*/
public Object readObject(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxSerializationException if deserialization of the field fails.
* @throws PdxFieldTypeMismatchException if the named field exists and is not a char[]
field.
*/
public char[] readCharArray(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxSerializationException if deserialization of the field fails.
* @throws PdxFieldTypeMismatchException if the named field exists and is not a boolean[]
field.
*/
public boolean[] readBooleanArray(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxSerializationException if deserialization of the field fails.
* @throws PdxFieldTypeMismatchException if the named field exists and is not a byte[]
field.
*/
public byte[] readByteArray(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxSerializationException if deserialization of the field fails.
* @throws PdxFieldTypeMismatchException if the named field exists and is not a short[]
field.
*/
public short[] readShortArray(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxSerializationException if deserialization of the field fails.
* @throws PdxFieldTypeMismatchException if the named field exists and is not a int[]
field.
*/
public int[] readIntArray(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxSerializationException if deserialization of the field fails.
* @throws PdxFieldTypeMismatchException if the named field exists and is not a long[]
field.
*/
public long[] readLongArray(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxSerializationException if deserialization of the field fails.
* @throws PdxFieldTypeMismatchException if the named field exists and is not a float[]
field.
*/
public float[] readFloatArray(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxSerializationException if deserialization of the field fails.
* @throws PdxFieldTypeMismatchException if the named field exists and is not a double[]
field.
*/
public double[] readDoubleArray(String fieldName) ;
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxSerializationException if deserialization of the field fails.
* @throws PdxFieldTypeMismatchException if the named field exists and is not a String[]
field.
*/
public String[] readStringArray(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxSerializationException if deserialization of the field fails.
* @throws PdxFieldTypeMismatchException if the named field exists and is not a Object[]
field.
*/
public Object[] readObjectArray(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxSerializationException if deserialization of the field fails.
* @throws PdxFieldTypeMismatchException if the named field exists and is not a byte[][]
field.
*/
public byte[][] readArrayOfByteArrays(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxSerializationException if deserialization of the field fails.
* @throws PdxFieldTypeMismatchException if the named field exists and is not a Date
field.
*/
public Date readDate(String fieldName);
/**
* Checks if the named field exists and returns the result.
*
This can be useful when writing code that handles more than one version of
* a PDX class.
* @param fieldName the name of the field to check
* @return true
if the named field exists; otherwise false
*/
public boolean hasField(String fieldName);
/**
* Checks if the named field was {@link PdxWriter#markIdentityField(String) marked} as an identity field.
*
Note that if no fields have been marked then all the fields are used as identity fields even though
* this method will return false
since none of them have been marked.
* @param fieldName the name of the field to check
* @return true
if the named field exists and was marked as an identify field; otherwise false
*/
public boolean isIdentityField(String fieldName);
/**
* Reads the named field and returns its value.
* @param fieldName the name of the field to read
* @return the value of the field if the field exists; otherwise a default value
* @throws PdxSerializationException if deserialization of the field fails.
*/
public Object readField(String fieldName);
/**
* This method returns an object that represents all the unread fields which must be
* passed to {@link PdxWriter#writeUnreadFields(PdxUnreadFields) writeUnreadFields} in the toData code.
*
Note that if {@link com.gemstone.gemfire.cache.CacheFactory#setPdxIgnoreUnreadFields(boolean) setPdxIgnoreUnreadFields}
* or {@link com.gemstone.gemfire.cache.client.ClientCacheFactory#setPdxIgnoreUnreadFields(boolean) client setPdxIgnoreUnreadFields}
* are set to true
then this method will always return an object that has no unread fields.
*
* @return an object that represents the unread fields.
*/
public PdxUnreadFields readUnreadFields();
}