PostgreSQL

Overview

org.dbunit.ext.postgresql provides PostgreSQL-specific type recognition for dbUnit, covering several PostgreSQL types with no standard JDBC equivalent.

IDataTypeFactory

PostgresqlDataTypeFactory recognizes uuid, interval, inet, geometry, citext, oid, and (via an overridable hook) custom enum types, mapping each to the dedicated classes below; everything else delegates to DefaultDataTypeFactory. Register it via DatabaseConfig.PROPERTY_DATATYPE_FACTORY — see Properties and Connections & Configuration.

IMetadataHandler

Not overridden — the default handler applies.

Connection Preconfiguration Class

None — PostgreSQL has no dedicated IDatabaseConnection subclass. Register PostgresqlDataTypeFactory directly on a plain DatabaseConnection’s `DatabaseConfig:

IDatabaseConnection connection = new DatabaseConnection(jdbcConnection, schema);
connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
        new PostgresqlDataTypeFactory());

Vendor-Specific Types

Type Covers
PostgreSQLOidDataType Large objects (oid), read/written via the driver’s large-object API.
CitextType Case-insensitive text (citext).
IntervalType interval values.
InetType inet (IP address/network) values.
UuidType uuid values.
GeometryType geometry (PostGIS) values, read/written as their string representation.

GenericEnumType

GenericEnumType adapts between PostgreSQL’s native enum types and Strings, using reflection (PGobject.setType()) so dbUnit doesn’t need a compile-time dependency on the PostgreSQL driver’s internal types. PostgreSQL reports a custom enum type generically, so PostgresqlDataTypeFactory cannot recognize one on its own — override isEnumType(String sqlTypeName):

PostgresqlDataTypeFactory factory = new PostgresqlDataTypeFactory() {
    public boolean isEnumType(String sqlTypeName) {
        return "abc_enum".equalsIgnoreCase(sqlTypeName);
    }
};

See the FAQ for more: Are Postgresql enum types supported by dbunit?

Known Quirks

Enum type support requires the isEnumType() override above — see GenericEnumType.