Package com.gpudb
Class TypeObjectMap<T>
- java.lang.Object
-
- com.gpudb.TypeObjectMap<T>
-
public final class TypeObjectMap<T> extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTypeObjectMap.AccessorAn accessor that returns a value from an object.static classTypeObjectMap.ClassFactory<T>A factory that uses reflection to create new instances of the specified class.static classTypeObjectMap.ConvertingFieldHandlerA combinedTypeObjectMap.AccessorandTypeObjectMap.Mutatorthat provides access to a specified field using reflection, converting the value to and from the data type of a specified GPUdbcolumn.static classTypeObjectMap.ConvertingMethodHandlerA combinedTypeObjectMap.AccessorandTypeObjectMap.Mutatorthat 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 GPUdbcolumn.static interfaceTypeObjectMap.Factory<T>A factory that creates new instances of the specified class.static classTypeObjectMap.FieldHandlerA combinedTypeObjectMap.AccessorandTypeObjectMap.Mutatorthat provides access to a specified field using reflection.static classTypeObjectMap.MethodHandlerA combinedTypeObjectMap.AccessorandTypeObjectMap.Mutatorthat provides access to a field via specified get and set methods using reflection.static interfaceTypeObjectMap.MutatorA mutator that sets a value in an object.
-
Constructor Summary
Constructors Constructor Description TypeObjectMap(Type type, Class<T> objectClass, TypeObjectMap.Factory<T> factory, List<TypeObjectMap.Accessor> accessors, List<TypeObjectMap.Mutator> mutators)Creates aTypeObjectMapfor the specifiedTypeand class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringcreateType(GPUdb gpudb)Creates a type in GPUdb based on the metadata in the specifiedTypeObjectMapobject and returns the type ID for reference.static <T> TypeObjectMap<T>fromClass(Class<T> objectClass)Creates aTypeObjectMapbased on the specified class.static <T> TypeObjectMap<T>fromClass(Class<T> objectClass, String label, Map<String,Type.Column> columnOverrides)Creates aTypeObjectMapbased on the specified class with the specified type label and overrides.static <T> TypeObjectMap<T>fromType(Type type, Class<T> objectClass)Creates aTypeObjectMapbased on the specifiedTypeand class.static <T> TypeObjectMap<T>fromType(Type type, Class<T> objectClass, Map<String,String> columnOverrides)Creates aTypeObjectMapbased on the specifiedTypeand class with the specified overrides.Objectget(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.SchemagetSchema()Returns the Avro record schema of the type object map.TypegetType()Returns the GPUdbTypeof the type object map.TnewInstance()Creates a new instance of the class specified when the type object map was created.voidput(Object o, int index, Object value)Sets the value of the column at the specified index in the specified object.
-
-
-
Constructor Detail
-
TypeObjectMap
public TypeObjectMap(Type type, Class<T> objectClass, TypeObjectMap.Factory<T> factory, List<TypeObjectMap.Accessor> accessors, List<TypeObjectMap.Mutator> mutators)
Creates aTypeObjectMapfor the specifiedTypeand class. The specifiedfactorymust create new instances of the class, and the specifiedaccessorsandmutatorsmust 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).- Parameters:
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 class
-
-
Method Detail
-
fromClass
public static <T> TypeObjectMap<T> fromClass(Class<T> objectClass)
Creates aTypeObjectMapbased 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.- Type Parameters:
T- the class- Parameters:
objectClass- the class- Returns:
- the type object map
- Throws:
IllegalArgumentException- if the specified class is not public
-
fromClass
public static <T> TypeObjectMap<T> fromClass(Class<T> objectClass, String label, Map<String,Type.Column> columnOverrides)
Creates aTypeObjectMapbased 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 thecolumnOverridesmap. 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 aType.Columnobject 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 ofnull.- Type Parameters:
T- the class- Parameters:
objectClass- the classlabel- the type label (nullto use class name)columnOverrides- the map of overrides (nullfor none)- Returns:
- the type object map
- Throws:
IllegalArgumentException- if the specified class is not public
-
fromType
public static <T> TypeObjectMap<T> fromType(Type type, Class<T> objectClass)
Creates aTypeObjectMapbased on the specifiedTypeand 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.- Type Parameters:
T- the class- Parameters:
type- the typeobjectClass- the class- Returns:
- the type object map
- Throws:
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 pair
-
fromType
public static <T> TypeObjectMap<T> fromType(Type type, Class<T> objectClass, Map<String,String> columnOverrides)
Creates aTypeObjectMapbased on the specifiedTypeand 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 thecolumnOverridesmap. 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.- Type Parameters:
T- the class- Parameters:
type- the typeobjectClass- the classcolumnOverrides-- Returns:
- the type object map
- Throws:
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 pair
-
getObjectClass
public Class<?> getObjectClass()
Returns the class of the type object map.- Returns:
- the class
-
getSchema
public org.apache.avro.Schema getSchema()
Returns the Avro record schema of the type object map.- Returns:
- the Avro record schema of the type object map
-
get
public Object get(Object o, int index)
Returns the value of the column at the specified index from the specified object. The object must belong to the class specified when the type object map was created.- Parameters:
o- the objectindex- the column index- Returns:
- the value of the column
-
put
public void put(Object o, int index, Object value)
Sets the value of the column at the specified index in the specified object. The object must belong to the class specified when the type object map was created.- Parameters:
o- the objectindex- the column indexvalue- the new value of the column
-
newInstance
public T newInstance()
Creates a new instance of the class specified when the type object map was created.- Returns:
- the new instance
-
createType
public String createType(GPUdb gpudb) throws GPUdbException
Creates a type in GPUdb based on the metadata in the specifiedTypeObjectMapobject 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 aknown type and known type object mapin the specifiedGPUdbinstance.- Parameters:
gpudb- theGPUdbinstance in which to create the type- Returns:
- the type ID of the type in GPUdb
- Throws:
GPUdbException- if an error occurs while creating the type
-
-