Class PostgresSupport
- All Implemented Interfaces:
DatabaseSupport
- Direct Known Subclasses:
CockroachDBSupport
DatabaseSupport.
On top of the cross-database defaults, this registers generators for the PostgreSQL
types the JDBC driver surfaces as JDBCType.OTHER, JDBCType.ARRAY,
JDBCType.SQLXML, and JDBCType.BIT, dispatching on the driver-reported
type name:
uuid,json,jsonb,inet,cidr,macaddr,macaddr8,interval,varbit(all reported asOTHER)_text,_int2,_int4,_int8arrays (reported asARRAY)xml(reported asSQLXML)bit/bit(n)andboolean(both reported asBIT, distinguished by type name)
Because CockroachDB speaks the PostgreSQL wire protocol through the same JDBC driver,
CockroachDBSupport extends this class and inherits all of the above.
Connection requirement: these extension types are generated as their
text representations and bound as strings. PostgreSQL will not implicitly cast
character varying to uuid, jsonb, inet, bit, etc.,
so the JDBC connection must be opened with stringtype=unspecified (e.g.
jdbc:postgresql://host/db?stringtype=unspecified) for the server to infer each
column's type. Standard column types do not require this.
- Since:
- 1.0.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturnsreWriteBatchedInserts, the PostgreSQL JDBC driver parameter that rewrites a batch of single-rowINSERTs into one multi-row statement.protected voidconfigure(Map<JDBCType, GeneratorFactory> registry) Hook for subclasses to add or replace generator factories for specific JDBC types.disableConstraints(Connection connection, Database database) Setssession_replication_role = replicaon the connection, which stops user and foreign-key triggers (including referential-integrity checks) from firing for the session.voidenableConstraints(Connection connection, Database database, BulkLoadHandle handle) Restoressession_replication_role = origin, re-enabling trigger and foreign-key firing for the session before the connection is returned to the pool.readConstraints(Connection connection, String schema, String table) Reads the value constraints (CHECK constraints and enum/domain allowed values) for a table's columns, so the fill engine can generate values that satisfy them (issue #479).booleanPostgreSQL supports unordered bulk loading by suppressing foreign-key trigger firing for the session viaSET session_replication_role = replica.Methods inherited from class AbstractDatabaseSupport
getDataGenerator
-
Constructor Details
-
PostgresSupport
public PostgresSupport()Creates a PostgreSQL support instance.
-
-
Method Details
-
batchRewriteUrlParameter
ReturnsreWriteBatchedInserts, the PostgreSQL JDBC driver parameter that rewrites a batch of single-rowINSERTs into one multi-row statement. Enabling it (e.g.jdbc:postgresql://host/db?reWriteBatchedInserts=true) drastically cuts the number of round trips and is often the single biggest fill speedup; Bloviate logs a one-time recommendation when a fill connection's URL does not set it.- Returns:
- the
reWriteBatchedInsertsparameter name - Since:
- 2.10.0
-
readConstraints
public Map<String, ColumnConstraint> readConstraints(Connection connection, String schema, String table) Description copied from interface:DatabaseSupportReads the value constraints (CHECK constraints and enum/domain allowed values) for a table's columns, so the fill engine can generate values that satisfy them (issue #479). The default returns an empty map (no constraint awareness); database-specific implementations override it with vendor catalog queries.Constraint reading is best-effort and must never fail a fill: an implementation that cannot read the catalog should log and return what it has.
- Parameters:
connection- an open connection to query the catalog withschema- the table's schema (may be null for the default schema)table- the table name- Returns:
- constraints keyed by lower-cased column name; empty when none are found or supported
-
supportsBulkLoad
public boolean supportsBulkLoad()PostgreSQL supports unordered bulk loading by suppressing foreign-key trigger firing for the session viaSET session_replication_role = replica.- Returns:
true- Since:
- 2.17.0
-
disableConstraints
public BulkLoadHandle disableConstraints(Connection connection, Database database) throws SQLException Setssession_replication_role = replicaon the connection, which stops user and foreign-key triggers (including referential-integrity checks) from firing for the session. This is the cheapest bulk-load mechanism — no catalog churn and nothing to rebuild — but it requires a superuser (orrds_superuser) role. A privilege failure is reported as aBulkLoadUnsupportedExceptionso the engine can fall back to the ordered path.- Parameters:
connection- an open connection whose session role is changeddatabase- the database metadata (unused by this mechanism)- Returns:
- a handle recording that
session_replication_rolewas changed - Throws:
BulkLoadUnsupportedException- if the role lacks privilege to change the settingSQLException- if the statement otherwise fails
-
enableConstraints
public void enableConstraints(Connection connection, Database database, BulkLoadHandle handle) throws SQLException Restoressession_replication_role = origin, re-enabling trigger and foreign-key firing for the session before the connection is returned to the pool.- Parameters:
connection- the same connection passed todisableConstraints(Connection, Database)database- the database metadata (unused by this mechanism)handle- the handle returned bydisableConstraints(Connection, Database)- Throws:
SQLException- if the statement fails
-
configure
Description copied from class:AbstractDatabaseSupportHook for subclasses to add or replace generator factories for specific JDBC types. The supplied registry already holds the cross-database defaults; subclasses with no customizations need not override this method. Implementations must not retain a reference to the map beyond the call.- Overrides:
configurein classAbstractDatabaseSupport- Parameters:
registry- the mutable registry to customize, keyed byJDBCType
-