Class PostgreSQLRDBMSActionStrategy
java.lang.Object
com.kingsrook.qqq.backend.module.rdbms.strategy.BaseRDBMSActionStrategy
com.kingsrook.qqq.backend.module.postgres.strategy.PostgreSQLRDBMSActionStrategy
- All Implemented Interfaces:
RDBMSActionStrategyInterface
PostgreSQL specialization of the default RDBMS/JDBC action strategy.
This class provides PostgreSQL-specific implementations for database operations,
including optimized insert operations using RETURNING clause, proper handling
of temporal data types, and PostgreSQL-specific parameter binding behavior.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.kingsrook.qqq.backend.module.rdbms.strategy.RDBMSActionStrategyInterface
RDBMSActionStrategyInterface.ResultSetProcessor -
Field Summary
FieldsFields inherited from class com.kingsrook.qqq.backend.module.rdbms.strategy.BaseRDBMSActionStrategy
DEFAULT_PAGE_SIZE, PAGE_SIZE, STAT_BATCHES_RAN, STAT_QUERIES_RAN -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbeginConsistentRead(Connection connection, ConsistentReadInput input) PostgreSQL: REPEATABLE READ (READ ONLY, if so requested) - so every table reflects the one snapshot the transaction takes at its first statement.protected voidbindParam(PreparedStatement statement, int index, Double value) Override bindParam for Double to use Types.OTHER for nulls.protected voidbindParam(PreparedStatement statement, int index, Integer value) Override bindParam for Integer to use Types.OTHER for nulls.protected voidbindParam(PreparedStatement statement, int index, Long value) Override bindParam for Long to use Types.OTHER for nulls.protected voidbindParam(PreparedStatement statement, int index, String value) Override bindParam for String to use Types.OTHER for nulls.protected intbindParamObject(PreparedStatement statement, int index, Object value) Override parameter binding for PostgreSQL-specific handling.voidconfigureStatementForLargeResults(Connection connection, PreparedStatement statement) The pgjdbc driver buffers the entire result set in memory unless the connection is in a transaction (autocommit off) and a fetch size is set (it then uses a server-side cursor).executeInsertForGeneratedIds(Connection connection, String sql, List<Object> params, QFieldMetaData primaryKeyField) PostgreSQL uses RETURNING clause for getting generated IDs.getGroupByBucketExpression(GroupBy group, String column, QFieldType sourceType, RDBMSBackendMetaData backend, List<Serializable> params) PostgreSQL date_trunc and width_bucket with an explicitly closed final numeric bin.PostgreSQL uses double quotes for identifier quoting.PostgreSQL requires DEFAULT VALUES when no columns are supplied.intGetter for largeResultFetchSizegetSampledTableExpression(String table, String alias, BigDecimal percent, List<Serializable> params) Block sampling belongs to the main relation, after its alias and before joins.PostgreSQL implements every aggregate extension.jsonMergeAssignment(String column) Merge at the row lock; updates of independent keys cannot overwrite each other.A JSON document is bound as text and explicitly cast to JSONB.jsonPathExpression(String column, JsonPathStorage storage, QFieldType type) Extract JSON scalars using the declared QQQ type.jsonPathPredicate(String column, QFieldMetaData field, QFilterCriteria criterion, List<Serializable> values) Equality and IN use GIN-compatible containment, one document per alternative.voidsetLargeResultFetchSize(int largeResultFetchSize) Setter for largeResultFetchSize (0 disables)booleanPostgreSQL supports SELECT ...Methods inherited from class com.kingsrook.qqq.backend.module.rdbms.strategy.BaseRDBMSActionStrategy
appendCriterionToWhereClause, bindParam, bindParam, bindParam, bindParam, bindParam, bindParam, bindParam, bindParam, bindParamNull, bindParams, executeBatchUpdate, executeStatement, executeUpdate, executeUpdateForRowCount, getAggregateExpression, getBucketTimeZone, getColumnName, getFieldValueFromResultSet, getPageSize, getStatistics, incrementStatistic, isH2, prepareStatementAndBindParams, resetStatistics, setCollectStatistics, setPageSize
-
Field Details
-
DEFAULT_LARGE_RESULT_FETCH_SIZE
public static final int DEFAULT_LARGE_RESULT_FETCH_SIZE- See Also:
-
-
Constructor Details
-
PostgreSQLRDBMSActionStrategy
public PostgreSQLRDBMSActionStrategy()
-
-
Method Details
-
configureStatementForLargeResults
public void configureStatementForLargeResults(Connection connection, PreparedStatement statement) throws SQLException The pgjdbc driver buffers the entire result set in memory unless the connection is in a transaction (autocommit off) and a fetch size is set (it then uses a server-side cursor). So, for queries hinted as potentially large, when we are inside a transaction, set a fetch size. Outside a transaction (autocommit on), a fetch size has no effect, so it is left alone.- Throws:
SQLException
-
setLargeResultFetchSize
public void setLargeResultFetchSize(int largeResultFetchSize) Setter for largeResultFetchSize (0 disables) -
getLargeResultFetchSize
public int getLargeResultFetchSize()Getter for largeResultFetchSize -
getInsertDefaultValuesClause
PostgreSQL requires DEFAULT VALUES when no columns are supplied. -
executeInsertForGeneratedIds
public List<Serializable> executeInsertForGeneratedIds(Connection connection, String sql, List<Object> params, QFieldMetaData primaryKeyField) throws SQLException PostgreSQL uses RETURNING clause for getting generated IDs. This is more efficient than the default JDBC approach.- Specified by:
executeInsertForGeneratedIdsin interfaceRDBMSActionStrategyInterface- Overrides:
executeInsertForGeneratedIdsin classBaseRDBMSActionStrategy- Parameters:
connection- the database connectionsql- the INSERT SQL statementparams- the query parametersprimaryKeyField- the primary key field metadata- Returns:
- list of generated IDs
- Throws:
SQLException- if a database error occurs
-
bindParamObject
protected int bindParamObject(PreparedStatement statement, int index, Object value) throws SQLException Override parameter binding for PostgreSQL-specific handling. PostgreSQL JDBC driver requires explicit handling of temporal types and is stricter about type matching than other databases. For null values, PostgreSQL needs Types.OTHER (not Types.CHAR) so it can infer the correct type from the column definition.- Overrides:
bindParamObjectin classBaseRDBMSActionStrategy- Parameters:
statement- the prepared statementindex- the parameter indexvalue- the parameter value- Returns:
- the number of parameters bound (always 1)
- Throws:
SQLException- if a database error occurs
-
bindParam
Override bindParam for Integer to use Types.OTHER for nulls. This allows PostgreSQL to properly infer types in all contexts.- Overrides:
bindParamin classBaseRDBMSActionStrategy- Parameters:
statement- the prepared statementindex- the parameter indexvalue- the integer value (may be null)- Throws:
SQLException- if a database error occurs
-
bindParam
Override bindParam for Long to use Types.OTHER for nulls. This allows PostgreSQL to properly infer types in all contexts.- Overrides:
bindParamin classBaseRDBMSActionStrategy- Parameters:
statement- the prepared statementindex- the parameter indexvalue- the long value (may be null)- Throws:
SQLException- if a database error occurs
-
bindParam
Override bindParam for Double to use Types.OTHER for nulls. This allows PostgreSQL to properly infer types in all contexts.- Overrides:
bindParamin classBaseRDBMSActionStrategy- Parameters:
statement- the prepared statementindex- the parameter indexvalue- the double value (may be null)- Throws:
SQLException- if a database error occurs
-
bindParam
Override bindParam for String to use Types.OTHER for nulls. This allows PostgreSQL to properly infer types in all contexts.- Overrides:
bindParamin classBaseRDBMSActionStrategy- Parameters:
statement- the prepared statementindex- the parameter indexvalue- the string value (may be null)- Throws:
SQLException- if a database error occurs
-
getIdentifierQuoteString
PostgreSQL uses double quotes for identifier quoting.- Returns:
- double quote string for identifier quoting
-
beginConsistentRead
public ConsistentReadStart beginConsistentRead(Connection connection, ConsistentReadInput input) throws SQLException PostgreSQL: REPEATABLE READ (READ ONLY, if so requested) - so every table reflects the one snapshot the transaction takes at its first statement. For BACKEND scope, the snapshot is exported (pg_export_snapshot), and the id returned, so that other connections (parallel workers, pg_dump --snapshot) can attach to it with SET TRANSACTION SNAPSHOT (via importSnapshotId on the input). The exporting transaction must stay open for as long as others may import. Not done on a hot standby, which can't export snapshots. Caveat: a long-lived snapshot holds back vacuum (xmin), and, on a standby, can be cancelled by recovery conflicts (unless hot_standby_feedback is on).- Specified by:
beginConsistentReadin interfaceRDBMSActionStrategyInterface- Overrides:
beginConsistentReadin classBaseRDBMSActionStrategy- Throws:
SQLException
-
jsonPathExpression
Extract JSON scalars using the declared QQQ type. -
jsonObjectPlaceholder
A JSON document is bound as text and explicitly cast to JSONB. -
jsonMergeAssignment
-
jsonPathPredicate
public String jsonPathPredicate(String column, QFieldMetaData field, QFilterCriteria criterion, List<Serializable> values) Equality and IN use GIN-compatible containment, one document per alternative. -
getSupportedAggregateCapabilities
PostgreSQL implements every aggregate extension.- Specified by:
getSupportedAggregateCapabilitiesin interfaceRDBMSActionStrategyInterface- Overrides:
getSupportedAggregateCapabilitiesin classBaseRDBMSActionStrategy
-
getSampledTableExpression
public String getSampledTableExpression(String table, String alias, BigDecimal percent, List<Serializable> params) Block sampling belongs to the main relation, after its alias and before joins.- Specified by:
getSampledTableExpressionin interfaceRDBMSActionStrategyInterface- Overrides:
getSampledTableExpressionin classBaseRDBMSActionStrategy
-
getGroupByBucketExpression
public String getGroupByBucketExpression(GroupBy group, String column, QFieldType sourceType, RDBMSBackendMetaData backend, List<Serializable> params) PostgreSQL date_trunc and width_bucket with an explicitly closed final numeric bin.- Specified by:
getGroupByBucketExpressionin interfaceRDBMSActionStrategyInterface- Overrides:
getGroupByBucketExpressionin classBaseRDBMSActionStrategy
-
supportsForUpdateSkipLocked
public boolean supportsForUpdateSkipLocked()PostgreSQL supports SELECT ... FOR UPDATE SKIP LOCKED.
-