diff --git a/app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java b/app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java
index afe1c66e6b..2455fa6246 100644
--- a/app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java
+++ b/app/server/appsmith-plugins/postgresPlugin/src/test/java/com/external/plugins/PostgresPluginTest.java
@@ -1344,6 +1344,7 @@ public class PostgresPluginTest {
.verifyComplete();
}
+ @Test
public void testReadOnlyMode() {
DatasourceConfiguration dsConfig = createDatasourceConfiguration();
dsConfig.getConnection().setMode(com.appsmith.external.models.Connection.Mode.READ_ONLY);
diff --git a/app/server/appsmith-plugins/redshiftPlugin/pom.xml b/app/server/appsmith-plugins/redshiftPlugin/pom.xml
index 9f58e8b805..bf96f22b7f 100644
--- a/app/server/appsmith-plugins/redshiftPlugin/pom.xml
+++ b/app/server/appsmith-plugins/redshiftPlugin/pom.xml
@@ -39,9 +39,21 @@
com.amazon.redshift
redshift-jdbc42
- 2.1.0.1
+ 2.1.0.9
runtime
+
+ com.zaxxer
+ HikariCP
+ 3.4.5
+
+
+ org.slf4j
+ slf4j-api
+
+
+
+
@@ -51,7 +63,6 @@
1.3
test
-
diff --git a/app/server/appsmith-plugins/redshiftPlugin/src/main/java/com/external/plugins/RedshiftPlugin.java b/app/server/appsmith-plugins/redshiftPlugin/src/main/java/com/external/plugins/RedshiftPlugin.java
index 3fe3352fdb..3ee52a0684 100644
--- a/app/server/appsmith-plugins/redshiftPlugin/src/main/java/com/external/plugins/RedshiftPlugin.java
+++ b/app/server/appsmith-plugins/redshiftPlugin/src/main/java/com/external/plugins/RedshiftPlugin.java
@@ -12,9 +12,10 @@ import com.appsmith.external.models.DatasourceStructure;
import com.appsmith.external.models.DatasourceTestResult;
import com.appsmith.external.models.Endpoint;
import com.appsmith.external.models.RequestParamDTO;
-import com.appsmith.external.models.SSLDetails;
import com.appsmith.external.plugins.BasePlugin;
import com.appsmith.external.plugins.PluginExecutor;
+import com.zaxxer.hikari.HikariDataSource;
+import com.zaxxer.hikari.HikariPoolMXBean;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.ObjectUtils;
@@ -27,7 +28,6 @@ import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;
import java.sql.Connection;
-import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
@@ -42,23 +42,18 @@ import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
import static com.appsmith.external.constants.ActionConstants.ACTION_CONFIGURATION_BODY;
import static com.appsmith.external.helpers.PluginUtils.getColumnsListForJdbcPlugin;
import static com.appsmith.external.helpers.PluginUtils.getIdenticalColumns;
-import static com.appsmith.external.models.Connection.Mode.READ_ONLY;
+import static com.external.utils.RedshiftDatasourceUtils.createConnectionPool;
+import static com.external.utils.RedshiftDatasourceUtils.getConnectionFromConnectionPool;
@Slf4j
public class RedshiftPlugin extends BasePlugin {
- static final String JDBC_DRIVER = "com.amazon.redshift.jdbc.Driver";
- private static final String JDBC_PROTOCOL = "jdbc:redshift://";
- private static final String USER = "user";
- private static final String PASSWORD = "password";
- private static final String SSL = "ssl";
- private static final int VALIDITY_CHECK_TIMEOUT = 5; /* must be positive, otherwise may receive exception */
+ public static final String JDBC_DRIVER = "com.amazon.redshift.jdbc.Driver";
private static final String DATE_COLUMN_TYPE_NAME = "date";
public RedshiftPlugin(PluginWrapper wrapper) {
@@ -66,7 +61,7 @@ public class RedshiftPlugin extends BasePlugin {
}
@Extension
- public static class RedshiftPluginExecutor implements PluginExecutor {
+ public static class RedshiftPluginExecutor implements PluginExecutor {
private final Scheduler scheduler = Schedulers.elastic();
@@ -197,19 +192,8 @@ public class RedshiftPlugin extends BasePlugin {
return row;
}
- /*
- * 1. This method can throw SQLException via connection.isClosed() or connection.isValid(...)
- * 2. StaleConnectionException thrown by this method needs to be propagated to upper layers so that a retry
- * can be triggered.
- */
- private void checkConnectionValidity(Connection connection) throws SQLException {
- if (connection == null || connection.isClosed()) {
- throw new StaleConnectionException();
- }
- }
-
@Override
- public Mono execute(Connection connection,
+ public Mono execute(HikariDataSource connectionPool,
DatasourceConfiguration datasourceConfiguration,
ActionConfiguration actionConfiguration) {
@@ -227,104 +211,139 @@ public class RedshiftPlugin extends BasePlugin {
}
return Mono.fromCallable(() -> {
- /*
- * 1. If there is any issue with checking connection validity then assume that the connection is stale.
- */
+ Connection connection = null;
+ try {
+ connection = getConnectionFromConnectionPool(connectionPool);
+ } catch (SQLException | StaleConnectionException e) {
+ e.printStackTrace();
+
+ /**
+ * When the user configured time limit for the query execution is over, and the query is still
+ * queued in the connectionPool then InterruptedException is thrown as the execution thread is
+ * prepared for termination. This exception is wrapped inside SQLException and hence needs to be
+ * checked via getCause method. This exception does not indicate a Stale connection.
+ */
+ if (e.getCause() != null && e.getCause().getClass().equals(InterruptedException.class)) {
+ return Mono.error(e);
+ }
+
+ // The function can throw either StaleConnectionException or SQLException. The underlying hikari
+ // library throws SQLException in case the pool is closed or there is an issue initializing
+ // the connection pool which can also be translated in our world to StaleConnectionException
+ // and should then trigger the destruction and recreation of the pool.
+ return Mono.error(new StaleConnectionException());
+ }
+
+
+ /**
+ * Keeping this print statement post call to getConnectionFromConnectionPool because it checks for
+ * stale connection pool.
+ */
+ printConnectionPoolStatus(connectionPool, false);
+
+ List