Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,14 @@ private static HikariDataSource createConnectionPool(

addSslOptionsToUrlBuilder(datasourceConfiguration, urlBuilder);

// Add connection mode configuration for READ_ONLY
if (datasourceConfiguration.getConnection() != null
&& datasourceConfiguration.getConnection().getMode()
== com.appsmith.external.models.Connection.Mode.READ_ONLY) {
urlBuilder.append("ApplicationIntent=ReadOnly;");
hikariConfig.setReadOnly(true);
}

hikariConfig.setJdbcUrl(urlBuilder.toString());

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"configProperty": "datasourceConfiguration.connection.mode",
"controlType": "SEGMENTED_CONTROL",
"initialValue": "READ_WRITE",
"tooltipText": "Read-only mode uses ApplicationIntent=ReadOnly. Note: This only enforces read-only connections when using Always On Availability Groups.",
"options": [
{
"label": "Read / Write",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,4 +773,52 @@ public void testGetEndpointIdentifierForRateLimit_HostPresentPortAbsent_ReturnsC
})
.verifyComplete();
}

@Test
public void testReadOnlyConnectionMode() {
DatasourceConfiguration dsConfig = createDatasourceConfiguration(container);

// Set connection mode to READ_ONLY
com.appsmith.external.models.Connection connection = new com.appsmith.external.models.Connection();
connection.setMode(com.appsmith.external.models.Connection.Mode.READ_ONLY);
dsConfig.setConnection(connection);

// Create connection pool
HikariDataSource connectionPool =
mssqlPluginExecutor.datasourceCreate(dsConfig).block();

// Verify the JDBC URL contains ApplicationIntent=ReadOnly
assertNotNull(connectionPool);
String jdbcUrl = connectionPool.getJdbcUrl();
assertTrue(
jdbcUrl.contains("ApplicationIntent=ReadOnly"),
"JDBC URL should contain ApplicationIntent=ReadOnly parameter");

// Cleanup
connectionPool.close();
}

@Test
public void testReadWriteConnectionMode() {
DatasourceConfiguration dsConfig = createDatasourceConfiguration(container);

// Set connection mode to READ_WRITE
com.appsmith.external.models.Connection connection = new com.appsmith.external.models.Connection();
connection.setMode(com.appsmith.external.models.Connection.Mode.READ_WRITE);
dsConfig.setConnection(connection);

// Create connection pool
HikariDataSource connectionPool =
mssqlPluginExecutor.datasourceCreate(dsConfig).block();

// Verify the JDBC URL does NOT contain ApplicationIntent parameter
assertNotNull(connectionPool);
String jdbcUrl = connectionPool.getJdbcUrl();
assertTrue(
!jdbcUrl.contains("ApplicationIntent"),
"JDBC URL should not contain ApplicationIntent parameter for READ_WRITE mode");

// Cleanup
connectionPool.close();
}
}
Loading