Skip to content

Commit

Permalink
Merge pull request #1083 from aoganezo/main
Browse files Browse the repository at this point in the history
Allow preparedStatementThreshold to be 0 to disable the cache.
  • Loading branch information
daneshk authored Nov 11, 2024
2 parents e92eab5 + 1bdc496 commit b95a9d8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
4 changes: 3 additions & 1 deletion ballerina/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ type ClientConfiguration record {|
# + cachedMetadataFieldSize - The maximum size (in megabytes) of fields to be cached per connection.
# A value of 0 disables the cache
# + preparedStatementThreshold - The number of `PreparedStatement` executions required before switching
# over to use server-side prepared statements
# over to use server-side prepared statements. A value of 0 disables the cache.
# + preparedStatementCacheQueries - The number of queries that are cached in each connection
# A value of 0 for preparedStatementThreshold disables the cache.
# + preparedStatementCacheSize - The maximum size (in mebibytes) of the prepared queries
# A value of 0 for preparedStatementThreshold disables the cache.
# + cancelSignalTimeout - Time (in seconds) by which the cancel command is sent out of band over its own connection
# so that the cancel message itself can get stuck. The default value is 10 seconds
# + keepAliveTcpProbe - Enable or disable the TCP keep-alive probe
Expand Down
8 changes: 4 additions & 4 deletions ballerina/tests/connection-init-test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ function testWithOptions2() returns error? {
rowFetchSize: 0,
cachedMetadataFieldsCount: 0,
cachedMetadataFieldSize: 0,
preparedStatementThreshold: 0,
preparedStatementCacheQueries: 0,
preparedStatementCacheSize: 0,
preparedStatementThreshold: -1,
preparedStatementCacheQueries: -1,
preparedStatementCacheSize: -1,
cancelSignalTimeout: 0,
keepAliveTcpProbe: false
};
Expand Down Expand Up @@ -240,7 +240,7 @@ function testWithConnectionParams3() returns error? {
rowFetchSize: 20,
cachedMetadataFieldsCount: 65536,
cachedMetadataFieldSize: 5,
preparedStatementThreshold: 5,
preparedStatementThreshold: 0,
preparedStatementCacheQueries: 256,
preparedStatementCacheSize: 5,
cancelSignalTimeout: 10,
Expand Down
3 changes: 1 addition & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added

### Changed
- [Allow prepareThreshold, preparedStatementCacheQueries and preparedStatementCacheSizeMiB to pass 0 values](https://github.com/ballerina-platform/ballerina-standard-library/issues/7345)

## [1.10.0] - 2023-06-30

Expand Down
4 changes: 3 additions & 1 deletion docs/spec/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ public isolated function init(string host = "localhost", string? username = "pos
# + cachedMetadataFieldSize - The maximum size (in megabytes) of fields to be cached per connection.
# A value of 0 disables the cache
# + preparedStatementThreshold - The number of `PreparedStatement` executions required before switching
# over to use server-side prepared statements
# over to use server-side prepared statements. A value of 0 disables the cache.
# + preparedStatementCacheQueries - The number of queries that are cached in each connection
# A value of 0 for preparedStatementThreshold disables the cache.
# + preparedStatementCacheSize - The maximum size (in mebibytes) of the prepared queries
# A value of 0 for preparedStatementThreshold disables the cache.
# + cancelSignalTimeout - Time (in seconds) by which the cancel command is sent out of band over its own connection
# so that the cancel message itself can get stuck. The default value is 10 seconds
# + keepAliveTcpProbe - Enable or disable the TCP keep-alive probe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ public static BMap generateOptionsMap(BMap postgresqlOptions) {
if (postgresqlOptions.containsKey(Constants.Options.PREPARE_THRESHOLD)) {
long preparedStatementThreshold = getIntegerValue(postgresqlOptions.
getIntValue(Constants.Options.PREPARE_THRESHOLD));
if (preparedStatementThreshold > 0) {
if (preparedStatementThreshold >= 0) {
options.put(Constants.DatabaseProps.PREPARE_THRESHOLD, preparedStatementThreshold);
}
}
if (postgresqlOptions.containsKey(Constants.Options.PREPARED_STATEMENT_CACHE_QUERIES)) {
long preparedStatementCacheQueries = getIntegerValue(postgresqlOptions
.getIntValue(Constants.Options.PREPARED_STATEMENT_CACHE_QUERIES));
if (preparedStatementCacheQueries > 0) {
if (preparedStatementCacheQueries >= 0) {
options.put(Constants.DatabaseProps.PREPARED_STATEMENT_CACHE_QUERIES,
preparedStatementCacheQueries);
}
}
if (postgresqlOptions.containsKey(Constants.Options.PREPARED_STATEMENT_CACHE_QUERIES)) {
long preparedStatementCacheSize = getIntegerValue(postgresqlOptions
.getIntValue(Constants.Options.PREPARED_STATEMENT_CACHE_SIZE_MIB));
if (preparedStatementCacheSize > 0) {
if (preparedStatementCacheSize >= 0) {
options.put(Constants.DatabaseProps.PREPARED_STATEMENT_CACHE_SIZE_MIB, preparedStatementCacheSize);
}
}
Expand Down

0 comments on commit b95a9d8

Please sign in to comment.