@Beta 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.getInt("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.cloneWithBuilder()
.setInt("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
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 FieldKind getFieldKind(@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.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 class definition or
the type of the field does not match the one in the class definition.short getInt16(@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 getInt32(@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 getInt64(@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 getFloat32(@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 getFloat64(@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[] getArrayOfBoolean(@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[] 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 class definition or
the type of the field does not match the one in the class definition.@Nullable short[] getArrayOfInt16(@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[] getArrayOfInt32(@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[] getArrayOfInt64(@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[] getArrayOfFloat32(@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[] getArrayOfFloat64(@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[] getArrayOfString(@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[] getArrayOfDecimal(@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[] getArrayOfTime(@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[] getArrayOfDate(@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[] getArrayOfTimestamp(@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[] getArrayOfTimestampWithTimezone(@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[] getArrayOfGenericRecord(@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 getNullableBoolean(@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 getNullableInt8(@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 getNullableInt16(@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 Integer getNullableInt32(@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 getNullableInt64(@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 getNullableFloat32(@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 getNullableFloat64(@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[] getArrayOfNullableBoolean(@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[] getArrayOfNullableInt8(@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[] getArrayOfNullableInt16(@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 Integer[] getArrayOfNullableInt32(@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[] getArrayOfNullableInt64(@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[] getArrayOfNullableFloat32(@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[] getArrayOfNullableFloat64(@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.