@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.
@Nonnull GenericRecordBuilder newBuilder()
GenericRecordBuilder
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.
@Nonnull GenericRecordBuilder cloneWithBuilder()
GenericRecordBuilder
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();
@Nonnull Set<String> getFieldNames()
@Nonnull FieldType getFieldType(@Nonnull String fieldName)
fieldName
- the name of the fieldIllegalArgumentException
- if the field name does not exist in the class definitionboolean hasField(@Nonnull String fieldName)
fieldName
- the name of the fieldboolean getBoolean(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.byte getByte(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.char getChar(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.double getDouble(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.float getFloat(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.int getInt(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.long getLong(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.short getShort(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable String getString(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable BigDecimal getDecimal(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable LocalTime getTime(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable LocalDate getDate(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable LocalDateTime getTimestamp(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable OffsetDateTime getTimestampWithTimezone(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable GenericRecord getGenericRecord(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable boolean[] getBooleanArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable byte[] getByteArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable char[] getCharArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable double[] getDoubleArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable float[] getFloatArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable int[] getIntArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable long[] getLongArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable short[] getShortArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable String[] getStringArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.@Nullable BigDecimal[] getDecimalArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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(String)
@Nullable LocalTime[] getTimeArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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(String)
@Nullable LocalDate[] getDateArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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(String)
@Nullable LocalDateTime[] getTimestampArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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(String)
@Nullable OffsetDateTime[] getTimestampWithTimezoneArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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(String)
@Nullable GenericRecord[] getGenericRecordArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- 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.Copyright © 2022 Hazelcast, Inc.. All rights reserved.