public final class TypeObjectMap<T> extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
TypeObjectMap.Accessor
An accessor that returns a value from an object.
|
static class |
TypeObjectMap.ClassFactory<T>
A factory that uses reflection to create new instances of the specified
class.
|
static class |
TypeObjectMap.ConvertingFieldHandler
A combined
TypeObjectMap.Accessor and TypeObjectMap.Mutator that provides access to a
specified field using reflection, converting the value to and from the
data type of a specified GPUdb column . |
static class |
TypeObjectMap.ConvertingMethodHandler
A combined
TypeObjectMap.Accessor and TypeObjectMap.Mutator that provides access to a
field via specified get and set methods using reflection, converting the
value to and from the data type of a specified GPUdb column . |
static interface |
TypeObjectMap.Factory<T>
A factory that creates new instances of the specified class.
|
static class |
TypeObjectMap.FieldHandler
A combined
TypeObjectMap.Accessor and TypeObjectMap.Mutator that provides access to a
specified field using reflection. |
static class |
TypeObjectMap.MethodHandler
A combined
TypeObjectMap.Accessor and TypeObjectMap.Mutator that provides access to a
field via specified get and set methods using reflection. |
static interface |
TypeObjectMap.Mutator
A mutator that sets a value in an object.
|
Constructor and Description |
---|
TypeObjectMap(Type type,
Class<T> objectClass,
TypeObjectMap.Factory<T> factory,
List<TypeObjectMap.Accessor> accessors,
List<TypeObjectMap.Mutator> mutators)
Creates a
TypeObjectMap for the specified Type and class. |
Modifier and Type | Method and Description |
---|---|
String |
createType(GPUdb gpudb)
Creates a type in GPUdb based on the metadata in the specified
TypeObjectMap object and returns the type ID for reference. |
static <T> TypeObjectMap<T> |
fromClass(Class<T> objectClass)
Creates a
TypeObjectMap based on the specified class. |
static <T> TypeObjectMap<T> |
fromClass(Class<T> objectClass,
String label,
Map<String,Type.Column> columnOverrides)
Creates a
TypeObjectMap based on the specified class with the
specified type label and overrides. |
static <T> TypeObjectMap<T> |
fromType(Type type,
Class<T> objectClass)
Creates a
TypeObjectMap based on the specified Type and
class. |
static <T> TypeObjectMap<T> |
fromType(Type type,
Class<T> objectClass,
Map<String,String> columnOverrides)
Creates a
TypeObjectMap based on the specified Type and
class with the specified overrides. |
Object |
get(Object o,
int index)
Returns the value of the column at the specified index from the specified
object.
|
Class<?> |
getObjectClass()
Returns the class of the type object map.
|
org.apache.avro.Schema |
getSchema()
Returns the Avro record schema of the type object map.
|
Type |
getType()
Returns the GPUdb
Type of the type object map. |
T |
newInstance()
Creates a new instance of the class specified when the type object map
was created.
|
void |
put(Object o,
int index,
Object value)
Sets the value of the column at the specified index in the specified
object.
|
public TypeObjectMap(Type type, Class<T> objectClass, TypeObjectMap.Factory<T> factory, List<TypeObjectMap.Accessor> accessors, List<TypeObjectMap.Mutator> mutators)
TypeObjectMap
for the specified Type
and class.
The specified factory
must create new instances of the class,
and the specified accessors
and mutators
must get and set
the values in instances of the class corresponding to the columns in the
type (the lists must be in column order and use the data types of the
columns rather than any underlying fields in the class).type
- the typeobjectClass
- the classfactory
- factory that creates instances of the classaccessors
- accessors that get column values from the classmutators
- mutators that set column values in the classpublic static <T> TypeObjectMap<T> fromClass(Class<T> objectClass)
TypeObjectMap
based on the specified class. All public
fields and get/set method pairs with supported data types will be used as
columns and ordered by name.T
- the classobjectClass
- the classIllegalArgumentException
- if the specified class is not publicpublic static <T> TypeObjectMap<T> fromClass(Class<T> objectClass, String label, Map<String,Type.Column> columnOverrides)
TypeObjectMap
based on the specified class with the
specified type label and overrides. By default, all public fields and
get/set method pairs with supported data types will be used as columns
and ordered by name, but column names, data types and properties can be
overridden with entries in the columnOverrides
map. Each entry in
the map must consist of the name of a field in the specified class (or
for method pairs, the name following "get" and "set") as a key, and a
Type.Column
object providing the name, data type, and properties
to use for the corresponding column as a value. To prevent a column from
being created for a field or method pair, use a value of null
.T
- the classobjectClass
- the classlabel
- the type label (null
to use class name)columnOverrides
- the map of overrides (null
for none)IllegalArgumentException
- if the specified class is not publicpublic static <T> TypeObjectMap<T> fromType(Type type, Class<T> objectClass)
TypeObjectMap
based on the specified Type
and
class. Each column in the type is mapped to a public field of the same
name, or in the absence of such a field, a get/set method pair where the
name following "get" and "set" is the same.T
- the classtype
- the typeobjectClass
- the classIllegalArgumentException
- if the specified class is not public,
a column exists in the specified type that has no matching field or
method pair in the class, or a column has a type that is incompatible
with the matching field or method pairpublic static <T> TypeObjectMap<T> fromType(Type type, Class<T> objectClass, Map<String,String> columnOverrides)
TypeObjectMap
based on the specified Type
and
class with the specified overrides. By default, each column is mapped to
a public field of the same name, or in the absence of such a field, a
get/set method pair where the name following "get" and "set" is the same,
but field and method pair names can be overridden with entries in the
columnOverrides
map. Each entry in the map must consist of the
name of a column in the specified type as a key, and the name of the
corresponding field (or for method pairs, the name following "get" and
"set") as a value.T
- the classtype
- the typeobjectClass
- the classcolumnOverrides
- IllegalArgumentException
- if the specified class is not public,
a column exists in the specified type that has no matching field or
method pair in the class, or a column has a type that is incompatible
with the matching field or method pairpublic Class<?> getObjectClass()
public org.apache.avro.Schema getSchema()
public Object get(Object o, int index)
o
- the objectindex
- the column indexpublic void put(Object o, int index, Object value)
o
- the objectindex
- the column indexvalue
- the new value of the columnpublic T newInstance()
public String createType(GPUdb gpudb) throws GPUdbException
TypeObjectMap
object and returns the type ID for reference. If an
identical type already exists in GPUdb, the type ID of the existing type
will be returned and no new type will be created. The specified type
object map will also automatically be added as a
known type
and known type object map
in the specified GPUdb
instance.gpudb
- the GPUdb
instance in which to create the typeGPUdbException
- if an error occurs while creating the typeCopyright © 2019. All rights reserved.