Class SqlStructGenerator

All Implemented Interfaces:
DataGenerator<Struct>

public class SqlStructGenerator extends AbstractDataGenerator<Struct>
Generator for SQL STRUCT (structured / user-defined type) columns.

generate() intentionally returns null. A Struct cannot be synthesized in memory: the only portable way to create one is Connection.createStruct(typeName, attributes), which requires a live Connection, the SQL type name, and one correctly typed value per attribute. The generate() contract exposes none of these, and the JDBC drivers this library targets (PostgreSQL, MySQL, CockroachDB) do not implement createStruct — it throws SQLFeatureNotSupportedException. Returning null lets nullable STRUCT columns fill; a non-nullable one will fail at insert.

get(ResultSet, int) reads an existing Struct normally, so round-tripping a value already present in a ResultSet works.

  • Method Details

    • generate

      public Struct generate()
      Generates a random value of type T.

      Always returns null; see the class documentation for why a Struct cannot be generated.

      Returns:
      a generated value, may be null if the generator supports nullable columns
    • generateAsString

      public String generateAsString()
      Description copied from interface: DataGenerator
      Generates a value and returns its string representation.
      Specified by:
      generateAsString in interface DataGenerator<Struct>
      Overrides:
      generateAsString in class AbstractDataGenerator<Struct>
      Returns:
      the string representation of a generated value
    • get

      public Struct get(ResultSet resultSet, int columnIndex) throws SQLException
      Description copied from interface: DataGenerator
      Retrieves a value from a ResultSet column.
      Parameters:
      resultSet - the result set to read from
      columnIndex - the 1-based column index
      Returns:
      the value from the result set, properly cast to type T
      Throws:
      SQLException - if the database operation fails