Skip to main content
Package com.gpudb

Class TypeObjectMap<T>

java.lang.Object
com.gpudb.TypeObjectMap<T>

public final class TypeObjectMap<T> extends Object
  • Constructor Details

    • TypeObjectMap

      public 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. 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).
      Parameters:
      type - the type
      objectClass - the class
      factory - factory that creates instances of the class
      accessors - accessors that get column values from the class
      mutators - mutators that set column values in the class
  • Method Details

    • fromClass

      public static <T> TypeObjectMap<T> fromClass(Class<T> objectClass)
      Creates a 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.
      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 a 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.
      Type Parameters:
      T - the class
      Parameters:
      objectClass - the class
      label - the type label (null to use class name)
      columnOverrides - the map of overrides (null for 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 a 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.
      Type Parameters:
      T - the class
      Parameters:
      type - the type
      objectClass - 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 a 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.
      Type Parameters:
      T - the class
      Parameters:
      type - the type
      objectClass - the class
      columnOverrides -
      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
    • getType

      public Type getType()
      Returns the GPUdb Type of the type object map.
      Returns:
      the type
    • 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 object
      index - 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 object
      index - the column index
      value - 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 specified 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.
      Parameters:
      gpudb - the GPUdb instance 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