Class RowValue
- java.lang.Object
-
- com.apama.correlator.memstore.RowValue
-
- All Implemented Interfaces:
java.io.Serializable
public class RowValue extends java.lang.Object implements java.io.Serializable
The value of an entry/row in a distributed store's table.This corresponds to the value of a MemoryStore Row object, i.e. the MemoryStore row without the key.
Note that to maximize efficiency this class uses a fairly low-level interface for getting and setting values, which require specifying fields using a type-specific index value (typedIndex) rather than simply specifying the field number. e.g. if the schema types were [integer, boolean, string] then you'd set the first string value by calling setString(0) not setString(2).
When the schema types for the table are known, it's simplest to use the
RowValueHelper
class to find the type-specific index from the field number before calling the get/set methods. For example:
RowValueHelper helper = new RowValueHelper("string", "integer", "boolean", "float", "string", "decimal");
int i = 0;
RowValue rowValue = helper.createRowValue()
.setString (helper.getTypedIndex(i++), "s1")
.setInteger (helper.getTypedIndex(i++), 200)
.setBoolean (helper.getTypedIndex(i++), true)
.setFloat (helper.getTypedIndex(i++), 300.2)
.setString (helper.getTypedIndex(i++), "s2")
.setDecimal (helper.getTypedIndex(i++), 400.3)
;
System.out.println("The values of the 4th and 5th fields are: "+
rowValue.getFloat(helper.getTypedIndex(3))+" and "+
rowValue.getString(helper.getTypedIndex(4))
);
i = 0;
for (Object v: helper.fieldValues(rowValue))
System.out.println("Got value: "+(i++)+"='"+v+"' ("+v.getClass().getSimpleName()+")");- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RowValue()
Default constructor for creating a new RowValue where the schema is not known.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RowValue
clone()
Clone the values that represent this RowValue into a new RowValue.boolean
equals(java.lang.Object obj)
boolean
getBoolean(int typedIndex)
Get the n'th field of this type.java.lang.Number
getDecimal(int typedIndex)
Get the n'th field of this type.java.util.Map<java.lang.String,java.lang.Object>
getExtraFields()
Get extra non-schema fields.double
getFloat(int typedIndex)
Get the n'th field of this type.long
getInteger(int typedIndex)
Get the n'th field of this type.java.lang.Object
getStoreSpecificObject()
Get a store-specific object.java.lang.String
getString(int typedIndex)
Get the n'th string field.byte[]
getStringBytes(int typedIndex)
Get the n'th string field of this type as a null-terminated array of UTF-8 bytes (which is currently the in-memory storage format for strings).boolean
hasExtraFields()
Get whether there are any extra fields.int
hashCode()
RowValue
setBoolean(int typedIndex, boolean value)
Set the n'th field of this type.void
setBoolean(int typedIndex, int maxSizeHint, boolean v)
Deprecated.void
setDecimal(int typedIndex, int maxSizeHint, java.lang.Number v)
Deprecated.RowValue
setDecimal(int typedIndex, java.lang.Number value)
Set the n'th field of this type.RowValue
setFloat(int typedIndex, double value)
Set the n'th field of this type.void
setFloat(int typedIndex, int maxSizeHint, double v)
Deprecated.void
setInteger(int typedIndex, int maxSizeHint, long v)
Deprecated.RowValue
setInteger(int typedIndex, long value)
Set the n'th field of this type.void
setStoreSpecificObject(java.lang.Object o)
Set a store-specific object.void
setString(int typedIndex, int maxSizeHint, byte[] utf8ByteString)
Deprecated.void
setString(int typedIndex, int maxSizeHint, java.lang.String v)
Deprecated.RowValue
setString(int typedIndex, java.lang.String value)
Set the n'th string field.RowValue
setStringBytes(int typedIndex, byte[] value)
Set the n'th string field from a UTF-8 null-terminated byte array (which is currently the in-memory storage format for strings).java.lang.String
toString()
-
-
-
Constructor Detail
-
RowValue
public RowValue()
Default constructor for creating a new RowValue where the schema is not known.If the schema is known, then use the more efficient
RowValueHelper.createRowValue()
instead.- See Also:
RowValueHelper.createRowValue()
-
-
Method Detail
-
hasExtraFields
public boolean hasExtraFields()
Get whether there are any extra fields. Returns true if there are extra fields (fields outside those defined by the schema) set on this RowValue object (i.e. getExtraFields() returns a non-empty map).- Since:
- 10.1
- See Also:
TableSupportsExtraFields
,getExtraFields()
-
getExtraFields
public java.util.Map<java.lang.String,java.lang.Object> getExtraFields()
Get extra non-schema fields. Some providers support arbitrary named values on each table entry, other than those defined by the schema. Providers that do so should read and write such fields to this map and implement the TableSupportsExtraFields interface. Never returns null; will construct the map if needed.- Since:
- 10.1
- See Also:
TableSupportsExtraFields
-
getStoreSpecificObject
public java.lang.Object getStoreSpecificObject()
Get a store-specific object.- Returns:
- an object that was set by setStoreSpecificObject Get a store-specific object representing the store's view of this entry. This Object is only used by the driver. It is not serialized (it is stored in a transient field), and is not used when comparing RowValue objects for equality, or generating a hashcode. On cloning the RowValue, the same object will be returned in the copy.
- See Also:
setStoreSpecificObject(java.lang.Object)
-
setStoreSpecificObject
public void setStoreSpecificObject(java.lang.Object o)
Set a store-specific object.- Parameters:
o
- an object specific to the driver Set an object specific to the store representing this row. See the notes on getStoreSpecificObject.- See Also:
getStoreSpecificObject()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
clone
public RowValue clone()
Clone the values that represent this RowValue into a new RowValue. Any extra fields are only shallowly copied - i.e. no copy of each value, but a new map of values.- Returns:
- the cloned RowValue
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getString
public final java.lang.String getString(int typedIndex)
Get the n'th string field.- Parameters:
typedIndex
- The type-specific index n, where n is the n'th field of this particular type.- Returns:
- The field value, or the default value "" if the specified index is out of range or there is no value set for it.
-
getStringBytes
public final byte[] getStringBytes(int typedIndex)
Get the n'th string field of this type as a null-terminated array of UTF-8 bytes (which is currently the in-memory storage format for strings).- Parameters:
typedIndex
- The type-specific index n, where n is the n'th field of this particular type.- Returns:
- The field value as null-terminated array of UTF-8 bytes, or a byte array containing a single null byte if the specified index is out of range or there is no value set for it. It is NOT permitted to mutate the returned array.
-
setString
public final RowValue setString(int typedIndex, java.lang.String value)
Set the n'th string field.- Parameters:
typedIndex
- The type-specific index n, where n is the n'th field of this particular type.value
-- Returns:
- This RowValue instance, to facilitate method chaining.
-
setStringBytes
public final RowValue setStringBytes(int typedIndex, byte[] value)
Set the n'th string field from a UTF-8 null-terminated byte array (which is currently the in-memory storage format for strings).- Parameters:
typedIndex
- The type-specific index n, where n is the n'th field of this particular type.value
- The string as a null-terminated UTF-8 string. Ownership passes to the RowValue when this method is called; it is NOT permitted to mutate the array after this point.- Returns:
- This RowValue instance, to facilitate method chaining.
-
setString
@Deprecated public final void setString(int typedIndex, int maxSizeHint, java.lang.String v)
Deprecated.This deprecated method overload will be removed in a future release, please use the alternative overload instead.
-
setString
@Deprecated public final void setString(int typedIndex, int maxSizeHint, byte[] utf8ByteString)
Deprecated.This deprecated method overload will be removed in a future release, please use the alternative overload instead.
-
getInteger
public final long getInteger(int typedIndex)
Get the n'th field of this type.- Parameters:
typedIndex
- The type-specific index n, where n is the n'th field of this particular type.- Returns:
- The field value, or the default value 0 if the specified index is out of range or there is no value set for it.
-
setInteger
public final RowValue setInteger(int typedIndex, long value)
Set the n'th field of this type.- Parameters:
typedIndex
- The type-specific index n, where n is the n'th field of this particular type.value
-- Returns:
- This RowValue instance, to facilitate method chaining.
-
setInteger
@Deprecated public final void setInteger(int typedIndex, int maxSizeHint, long v)
Deprecated.This deprecated method overload will be removed in a future release, please use the alternative overload instead.
-
getFloat
public final double getFloat(int typedIndex)
Get the n'th field of this type.- Parameters:
typedIndex
- The type-specific index n, where n is the n'th field of this particular type.- Returns:
- The field value, or the default value 0.0 if the specified index is out of range or there is no value set for it.
-
setFloat
public final RowValue setFloat(int typedIndex, double value)
Set the n'th field of this type.- Parameters:
typedIndex
- The type-specific index n, where n is the n'th field of this particular type.value
-- Returns:
- This RowValue instance, to facilitate method chaining.
-
setFloat
@Deprecated public final void setFloat(int typedIndex, int maxSizeHint, double v)
Deprecated.This deprecated method overload will be removed in a future release, please use the alternative overload instead.
-
getBoolean
public final boolean getBoolean(int typedIndex)
Get the n'th field of this type.- Parameters:
typedIndex
- The type-specific index n, where n is the n'th field of this particular type.- Returns:
- The field value, or the default value false if the specified index is out of range or there is no value set for it.
-
setBoolean
public final RowValue setBoolean(int typedIndex, boolean value)
Set the n'th field of this type.- Parameters:
typedIndex
- The type-specific index n, where n is the n'th field of this particular type.value
-- Returns:
- This RowValue instance, to facilitate method chaining.
-
setBoolean
@Deprecated public final void setBoolean(int typedIndex, int maxSizeHint, boolean v)
Deprecated.This deprecated method overload will be removed in a future release, please use the alternative overload instead.
-
getDecimal
public final java.lang.Number getDecimal(int typedIndex)
Get the n'th field of this type.- Parameters:
typedIndex
- The type-specific index n, where n is the n'th field of this particular type.- Returns:
- The field value, or the default value 0.0 if the specified index is out of range or there is no value set for it.
-
setDecimal
public final RowValue setDecimal(int typedIndex, java.lang.Number value)
Set the n'th field of this type.- Parameters:
typedIndex
- The type-specific index n, where n is the n'th field of this particular type.value
-- Returns:
- This RowValue instance, to facilitate method chaining.
-
setDecimal
@Deprecated public final void setDecimal(int typedIndex, int maxSizeHint, java.lang.Number v)
Deprecated.This deprecated method overload will be removed in a future release, please use the alternative overload instead.
-
-