public interface GenericRecord
IMap
, IQueue
etc.
On remote calls like in the distributed executor service or EntryProcessors, you may need access to the domain object. In case the class of the domain object is not available on the cluster, GenericRecord allows you to read and write the object without the domain class on the classpath. Here is an example with EntryProcessor:
map.executeOnKey(key, (EntryProcessor<Object, Object, Object>) entry -> {
Object value = entry.getValue();
GenericRecord genericRecord = (GenericRecord) value;
int id = genericRecord.getInt32("id");
return null;
});
Another example with EntryProcessor to demonstrate how to read, modify and
set the value back to the map:
map.executeOnKey("key", (EntryProcessor<Object, Object, Object>) entry -> {
GenericRecord genericRecord = (GenericRecord) entry.getValue();
GenericRecord modifiedGenericRecord = genericRecord.newBuilderWithClone()
.setInt32("age", 22)
.build();
entry.setValue(modifiedGenericRecord);
return null;
});
GenericRecord also allows reading 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 objects back
to the cluster without the need to have the domain classes on the classpath.
Currently, this is valid for Portable
and
Compact
serializable
objects.
@Nonnull GenericRecordBuilder newBuilder()
GenericRecordBuilder
allows to create a new object.
This method is a convenience method to get a builder, without creating
the schema/class definition for this type. Here you can see a new object
is constructed from an existing GenericRecord with its schema/class
definition:
GenericRecord newGenericRecord = genericRecord.newBuilder()
.setString("name", "bar")
.setInt32("id", 4)
.build();
See GenericRecordBuilder.portable(ClassDefinition)
to create a
GenericRecord in Portable format with a different class definition and
GenericRecordBuilder.compact(String)
to create a GenericRecord in
Compact format with a different schema.
@Nonnull GenericRecordBuilder newBuilderWithClone()
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"))
.setInt64("id", 4)
.setString("surname", genericRecord.getString("surname"))
.setInt32("age", genericRecord.getInt32("age"))
.build();
`newBuilderWithClone` used as follows:
GenericRecord modifiedGenericRecord = genericRecord.newBuilderWithClone()
.setInt32("id", 4)
.build();
@Nonnull Set<String> getFieldNames()
@Nonnull FieldKind getFieldKind(@Nonnull String fieldName)
If the field with the given name does not exist,
FieldKind.NOT_AVAILABLE
is returned.
This method can be used to check the existence of a field, which can be useful when the class is evolved.
fieldName
- name of the field.boolean getBoolean(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/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.byte getInt8(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.short getInt16(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.int getInt32(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.long getInt64(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.float getFloat32(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.double getFloat64(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable String getString(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable BigDecimal getDecimal(@Nonnull String fieldName)
fieldName
- the name of the fieldBigDecimal
HazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable LocalTime getTime(@Nonnull String fieldName)
fieldName
- the name of the fieldLocalTime
HazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable LocalDate getDate(@Nonnull String fieldName)
fieldName
- the name of the fieldLocalDate
HazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable LocalDateTime getTimestamp(@Nonnull String fieldName)
fieldName
- the name of the fieldLocalDateTime
HazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable OffsetDateTime getTimestampWithTimezone(@Nonnull String fieldName)
fieldName
- the name of the fieldOffsetDateTime
HazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable GenericRecord getGenericRecord(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable boolean[] getArrayOfBoolean(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable char[] getArrayOfChar(@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[] getArrayOfInt8(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable short[] getArrayOfInt16(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable int[] getArrayOfInt32(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable long[] getArrayOfInt64(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable float[] getArrayOfFloat32(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable double[] getArrayOfFloat64(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable String[] getArrayOfString(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable BigDecimal[] getArrayOfDecimal(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.getDecimal(String)
@Nullable LocalTime[] getArrayOfTime(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.getTime(String)
@Nullable LocalDate[] getArrayOfDate(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.getDate(String)
@Nullable LocalDateTime[] getArrayOfTimestamp(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.getTimestamp(String)
@Nullable OffsetDateTime[] getArrayOfTimestampWithTimezone(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.getTimestampWithTimezone(String)
@Nullable GenericRecord[] getArrayOfGenericRecord(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema/class definition or
the type of the field does not
match the one in the schema/class
definition.@Nullable Boolean getNullableBoolean(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema or the type of the
field does not match the one in
the schema.@Nullable Byte getNullableInt8(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema or the type of the
field does not match the one in
the schema.@Nullable Short getNullableInt16(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema or the type of the
field does not match the one in
the schema.@Nullable Integer getNullableInt32(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema or the type of the
field does not match the one in
the schema.@Nullable Long getNullableInt64(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema or the type of the
field does not match the one in
the schema.@Nullable Float getNullableFloat32(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema or the type of the
field does not match the one in
the schema.@Nullable Double getNullableFloat64(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema or the type of the
field does not match the one in
the schema.@Nullable Boolean[] getArrayOfNullableBoolean(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema or the type of the
field does not match the one in
the schema.@Nullable Byte[] getArrayOfNullableInt8(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema or the type of the
field does not match the one in
the schema.@Nullable Short[] getArrayOfNullableInt16(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema or the type of the
field does not match the one in
the schema.@Nullable Integer[] getArrayOfNullableInt32(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema or the type of the
field does not match the one in
the schema.@Nullable Long[] getArrayOfNullableInt64(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema or the type of the
field does not match the one in
the schema.@Nullable Float[] getArrayOfNullableFloat32(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema or the type of the
field does not match the one in
the schema.@Nullable Double[] getArrayOfNullableFloat64(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist
in the schema or the type of the
field does not match the one in
the schema.Copyright © 2024 Hazelcast, Inc.. All rights reserved.