Interface GenericRecord
@Beta public interface GenericRecord
IMap
,IQueue
etc.
On remote calls like distributed executor service or EntryProcessors, you may need to access to the domain object. In case class of the domain object is not available on the cluster, GenericRecord allows to access, read and write the objects back without the class of the domain object on the classpath. Here is an read example with EntryProcessor:
map.executeOnKey(key, (EntryProcessorAnother example with EntryProcessor to demonstrate how to read, modify and set back to the map:
map.executeOnKey("key", (EntryProcessor
GenericRecord also allows to read from a cluster without having the classes on the client side.
For Portable
, when PortableFactory
is not provided in the config at the start,
a HazelcastSerializationException
was thrown stating that a factory could not be found. Starting from 4.1,
the objects will be returned as GenericRecord
. This way, the clients can read and write the objects back to
the cluster without needing the classes of the domain objects on the classpath.
Currently this is valid for Portable
objects.
- Since:
- 4.1
-
Method Summary
-
Method Details
-
newBuilder
Creates aGenericRecordBuilder
allows to create a new object. This method is a convenience method to get a builder, without creating the class definition for this type. Here you can see a new object is constructed from an existing GenericRecord with its class definition:GenericRecord newGenericRecord = genericRecord.newBuilder() .setString("name", "bar") .setInt("id", 4).build();
see
GenericRecordBuilder.portable(ClassDefinition)
to create a GenericRecord in Portable format with a different class definition.- Returns:
- an empty generic record builder with same class definition as this one
-
cloneWithBuilder
ReturnedGenericRecordBuilder
can be used to have exact copy and also just to update a couple of fields. By default, it will copy all the fields. So instead of following where only the `id` field is updated,GenericRecord modifiedGenericRecord = genericRecord.newBuilder() .setString("name", genericRecord.getString("name")) .setLong("id", 4) .setString("surname", genericRecord.getString("surname")) .setInt("age", genericRecord.getInt("age")).build();
`cloneWithBuilder` used as follows:GenericRecord modifiedGenericRecord = genericRecord.cloneWithBuilder().setInt("id", 4).build();
- Returns:
- a generic record builder with same class definition as this one and populated with same values.
-
getFieldNames
- Returns:
- set of field names of this GenericRecord
-
getFieldType
- Parameters:
fieldName
- the name of the field- Returns:
- field type for the given field name
- Throws:
IllegalArgumentException
- if the field name does not exist in the class definition
-
hasField
- Parameters:
fieldName
- the name of the field- Returns:
- true if field exists in the definition of the class. Note that returns true even if the field is null.
-
getBoolean
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getByte
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getChar
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getDouble
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getFloat
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getInt
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getLong
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getShort
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getString
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getDecimal
- Parameters:
fieldName
- the name of the field- Returns:
- decimal which is arbitrary precision and scale floating-point number as BigDecimal
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getTime
- Parameters:
fieldName
- the name of the field- Returns:
- time field consisting of hour, minute, seconds and nanos parts as LocalTime
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getDate
- Parameters:
fieldName
- the name of the field- Returns:
- date field consisting of year, month of the year and day of the month as LocalDate
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getTimestamp
- Parameters:
fieldName
- the name of the field- Returns:
- timestamp field consisting of year, month of the year, day of the month, hour, minute, seconds, nanos parts as LocalDateTime
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getTimestampWithTimezone
- Parameters:
fieldName
- the name of the field- Returns:
- timestamp with timezone field consisting of year, month of the year, day of the month, offset seconds, hour, minute, seconds, nanos parts as OffsetDateTime
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getGenericRecord
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getBooleanArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getByteArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getCharArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getDoubleArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getFloatArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getIntArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getLongArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getShortArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getStringArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-
getDecimalArray
- Parameters:
fieldName
- the name of the field- Returns:
- array of Decimal's as BigDecimal[]
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.- See Also:
getDecimal(String)
-
getTimeArray
- Parameters:
fieldName
- the name of the field- Returns:
- array of Time's as LocalTime[]
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.- See Also:
getTime(String)
-
getDateArray
- Parameters:
fieldName
- the name of the field- Returns:
- array of Date's to LocalDate[]
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.- See Also:
getDate(String)
-
getTimestampArray
- Parameters:
fieldName
- the name of the field- Returns:
- array of Timestamp's as LocalDateTime[]
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.- See Also:
getTimestamp(String)
-
getTimestampWithTimezoneArray
- Parameters:
fieldName
- the name of the field- Returns:
- array of TimestampWithTimezone's as OffsetDateTime[]
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.- See Also:
getTimestampWithTimezone(String)
-
getGenericRecordArray
- Parameters:
fieldName
- the name of the field- Returns:
- the value of the field
- Throws:
HazelcastSerializationException
- if the field name does not exist in the class definition or the type of the field does not match the one in the class definition.
-