Skip to content

Commit 5ef4f15

Browse files
committed
PLUGIN-1823: Create object only once.
1 parent 1eba47c commit 5ef4f15

File tree

24 files changed

+120
-24
lines changed

24 files changed

+120
-24
lines changed

cloudsql-mysql-plugin/src/main/java/io/cdap/plugin/cloudsql/mysql/CloudSQLMySQLConnector.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class CloudSQLMySQLConnector extends AbstractDBSpecificConnector<MysqlDBR
5353

5454
public static final String NAME = CloudSQLMySQLConstants.PLUGIN_NAME;
5555
private final CloudSQLMySQLConnectorConfig config;
56+
private CloudSQLMySQLErrorDetailsProvider cloudSQLMySQLErrorDetailsProvider;
5657

5758
public CloudSQLMySQLConnector(CloudSQLMySQLConnectorConfig config) {
5859
super(config);
@@ -111,6 +112,9 @@ protected void setConnectorSpec(ConnectorSpecRequest request, DBConnectorPath pa
111112

112113
@Override
113114
protected CloudSQLMySQLErrorDetailsProvider getErrorDetailsProvider() {
114-
return new CloudSQLMySQLErrorDetailsProvider();
115+
if (cloudSQLMySQLErrorDetailsProvider == null) {
116+
cloudSQLMySQLErrorDetailsProvider = new CloudSQLMySQLErrorDetailsProvider();
117+
}
118+
return cloudSQLMySQLErrorDetailsProvider;
115119
}
116120
}

cloudsql-mysql-plugin/src/main/java/io/cdap/plugin/cloudsql/mysql/CloudSQLMySQLSink.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class CloudSQLMySQLSink extends AbstractDBSink<CloudSQLMySQLSink.CloudSQL
5959

6060
private final CloudSQLMySQLSinkConfig cloudsqlMysqlSinkConfig;
6161
private static final Character ESCAPE_CHAR = '`';
62+
private CloudSQLMySQLErrorDetailsProvider cloudSQLMySQLErrorDetailsProvider;
6263

6364
public CloudSQLMySQLSink(CloudSQLMySQLSinkConfig cloudsqlMysqlSinkConfig) {
6465
super(cloudsqlMysqlSinkConfig);
@@ -111,7 +112,10 @@ protected String getErrorDetailsProviderClassName() {
111112

112113
@Override
113114
protected CloudSQLMySQLErrorDetailsProvider getErrorDetailsProvider() {
114-
return new CloudSQLMySQLErrorDetailsProvider();
115+
if (cloudSQLMySQLErrorDetailsProvider == null) {
116+
cloudSQLMySQLErrorDetailsProvider = new CloudSQLMySQLErrorDetailsProvider();
117+
}
118+
return cloudSQLMySQLErrorDetailsProvider;
115119
}
116120

117121
@Override

cloudsql-mysql-plugin/src/main/java/io/cdap/plugin/cloudsql/mysql/CloudSQLMySQLSource.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
public class CloudSQLMySQLSource extends AbstractDBSource<CloudSQLMySQLSource.CloudSQLMySQLSourceConfig> {
5656

5757
private final CloudSQLMySQLSourceConfig cloudsqlMysqlSourceConfig;
58+
private CloudSQLMySQLErrorDetailsProvider cloudSQLMySQLErrorDetailsProvider;
5859

5960
public CloudSQLMySQLSource(CloudSQLMySQLSourceConfig cloudsqlMysqlSourceConfig) {
6061
super(cloudsqlMysqlSourceConfig);
@@ -140,7 +141,10 @@ protected String getErrorDetailsProviderClassName() {
140141

141142
@Override
142143
protected CloudSQLMySQLErrorDetailsProvider getErrorDetailsProvider() {
143-
return new CloudSQLMySQLErrorDetailsProvider();
144+
if (cloudSQLMySQLErrorDetailsProvider == null) {
145+
cloudSQLMySQLErrorDetailsProvider = new CloudSQLMySQLErrorDetailsProvider();
146+
}
147+
return cloudSQLMySQLErrorDetailsProvider;
144148
}
145149

146150
/** CloudSQL MySQL source config. */

cloudsql-postgresql-plugin/src/main/java/io/cdap/plugin/cloudsql/postgres/CloudSQLPostgreSQLConnector.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
public class CloudSQLPostgreSQLConnector extends AbstractDBSpecificConnector<PostgresDBRecord> {
5353
public static final String NAME = CloudSQLPostgreSQLConstants.PLUGIN_NAME;
5454
private final CloudSQLPostgreSQLConnectorConfig config;
55+
private CloudSQLPostgreSQLErrorDetailsProvider cloudSQLPostgreSQLErrorDetailsProvider;
5556

5657
public CloudSQLPostgreSQLConnector(CloudSQLPostgreSQLConnectorConfig config) {
5758
super(config);
@@ -121,6 +122,9 @@ protected void setConnectorSpec(ConnectorSpecRequest request, DBConnectorPath pa
121122

122123
@Override
123124
protected CloudSQLPostgreSQLErrorDetailsProvider getErrorDetailsProvider() {
124-
return new CloudSQLPostgreSQLErrorDetailsProvider();
125+
if (cloudSQLPostgreSQLErrorDetailsProvider == null) {
126+
cloudSQLPostgreSQLErrorDetailsProvider = new CloudSQLPostgreSQLErrorDetailsProvider();
127+
}
128+
return cloudSQLPostgreSQLErrorDetailsProvider;
125129
}
126130
}

cloudsql-postgresql-plugin/src/main/java/io/cdap/plugin/cloudsql/postgres/CloudSQLPostgreSQLSink.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class CloudSQLPostgreSQLSink extends AbstractDBSink<CloudSQLPostgreSQLSin
6666
private static final Character ESCAPE_CHAR = '"';
6767

6868
private final CloudSQLPostgreSQLSinkConfig cloudsqlPostgresqlSinkConfig;
69+
private CloudSQLPostgreSQLErrorDetailsProvider cloudSQLPostgreSQLErrorDetailsProvider;
6970

7071
public CloudSQLPostgreSQLSink(CloudSQLPostgreSQLSinkConfig cloudsqlPostgresqlSinkConfig) {
7172
super(cloudsqlPostgresqlSinkConfig);
@@ -155,7 +156,10 @@ protected String getErrorDetailsProviderClassName() {
155156

156157
@Override
157158
protected CloudSQLPostgreSQLErrorDetailsProvider getErrorDetailsProvider() {
158-
return new CloudSQLPostgreSQLErrorDetailsProvider();
159+
if (cloudSQLPostgreSQLErrorDetailsProvider == null) {
160+
cloudSQLPostgreSQLErrorDetailsProvider = new CloudSQLPostgreSQLErrorDetailsProvider();
161+
}
162+
return cloudSQLPostgreSQLErrorDetailsProvider;
159163
}
160164

161165
@Override

cloudsql-postgresql-plugin/src/main/java/io/cdap/plugin/cloudsql/postgres/CloudSQLPostgreSQLSource.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class CloudSQLPostgreSQLSource
5555
extends AbstractDBSource<CloudSQLPostgreSQLSource.CloudSQLPostgreSQLSourceConfig> {
5656

5757
private final CloudSQLPostgreSQLSourceConfig cloudsqlPostgresqlSourceConfig;
58+
private CloudSQLPostgreSQLErrorDetailsProvider cloudSQLPostgreSQLErrorDetailsProvider;
5859

5960
public CloudSQLPostgreSQLSource(CloudSQLPostgreSQLSourceConfig cloudsqlPostgresqlSourceConfig) {
6061
super(cloudsqlPostgresqlSourceConfig);
@@ -99,7 +100,10 @@ protected String getErrorDetailsProviderClassName() {
99100

100101
@Override
101102
protected CloudSQLPostgreSQLErrorDetailsProvider getErrorDetailsProvider() {
102-
return new CloudSQLPostgreSQLErrorDetailsProvider();
103+
if (cloudSQLPostgreSQLErrorDetailsProvider == null) {
104+
cloudSQLPostgreSQLErrorDetailsProvider = new CloudSQLPostgreSQLErrorDetailsProvider();
105+
}
106+
return cloudSQLPostgreSQLErrorDetailsProvider;
103107
}
104108

105109
@Override

database-commons/src/main/java/io/cdap/plugin/db/action/AbstractDBArgumentSetter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class AbstractDBArgumentSetter extends Action {
4545
private static final String JDBC_PLUGIN_ID = "driver";
4646
private final ArgumentSetterConfig config;
4747
private final RetryPolicy<?> retryPolicy;
48+
private DBErrorDetailsProvider dbErrorDetailsProvider;
4849

4950
public AbstractDBArgumentSetter(ArgumentSetterConfig config) {
5051
this.config = config;
@@ -172,6 +173,9 @@ protected String getExternalDocumentationLink() {
172173
* @return DBErrorDetailsProvider instance
173174
*/
174175
protected DBErrorDetailsProvider getErrorDetailsProvider() {
175-
return new DBErrorDetailsProvider();
176+
if (dbErrorDetailsProvider == null) {
177+
dbErrorDetailsProvider = new DBErrorDetailsProvider();
178+
}
179+
return dbErrorDetailsProvider;
176180
}
177181
}

database-commons/src/main/java/io/cdap/plugin/db/action/DBRun.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class DBRun {
3838
private final Class<? extends Driver> driverClass;
3939
private boolean enableAutoCommit;
4040
private final RetryPolicy<?> retryPolicy;
41+
private DBErrorDetailsProvider dbErrorDetailsProvider;
4142

4243
public DBRun(QueryConfig config, Class<? extends Driver> driverClass, Boolean enableAutocommit) {
4344
this.config = config;
@@ -55,7 +56,10 @@ public DBRun(QueryConfig config, Class<? extends Driver> driverClass, Boolean en
5556
* @return DBErrorDetailsProvider instance
5657
*/
5758
protected DBErrorDetailsProvider getErrorDetailsProvider() {
58-
return new DBErrorDetailsProvider();
59+
if (dbErrorDetailsProvider == null) {
60+
dbErrorDetailsProvider = new DBErrorDetailsProvider();
61+
}
62+
return dbErrorDetailsProvider;
5963
}
6064

6165
/**

database-commons/src/main/java/io/cdap/plugin/db/sink/AbstractDBSink.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public abstract class AbstractDBSink<T extends PluginConfig & DatabaseSinkConfig
9898
private ConnectionConfigAccessor configAccessor;
9999
private Configuration configuration;
100100
private final RetryPolicy<?> retryPolicy;
101+
private DBErrorDetailsProvider dbErrorDetailsProvider;
101102

102103
public AbstractDBSink(T dbSinkConfig) {
103104
super(new ReferencePluginConfig(dbSinkConfig.getReferenceName()));
@@ -188,7 +189,10 @@ protected String getErrorDetailsProviderClassName() {
188189
* @return DBErrorDetailsProvider instance
189190
*/
190191
protected DBErrorDetailsProvider getErrorDetailsProvider() {
191-
return new DBErrorDetailsProvider();
192+
if (dbErrorDetailsProvider == null) {
193+
dbErrorDetailsProvider = new DBErrorDetailsProvider();
194+
}
195+
return dbErrorDetailsProvider;
192196
}
193197

194198
/**

database-commons/src/main/java/io/cdap/plugin/db/source/AbstractDBSource.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public abstract class AbstractDBSource<T extends PluginConfig & DatabaseSourceCo
8888
Pattern.CASE_INSENSITIVE);
8989
private final RetryPolicy<?> retryPolicy;
9090

91+
private DBErrorDetailsProvider dbErrorDetailsProvider;
9192
protected final T sourceConfig;
9293
protected Class<? extends Driver> driverClass;
9394

@@ -235,7 +236,10 @@ protected String getErrorDetailsProviderClassName() {
235236
* @return DBErrorDetailsProvider instance
236237
*/
237238
protected DBErrorDetailsProvider getErrorDetailsProvider() {
238-
return new DBErrorDetailsProvider();
239+
if (dbErrorDetailsProvider == null) {
240+
dbErrorDetailsProvider = new DBErrorDetailsProvider();
241+
}
242+
return dbErrorDetailsProvider;
239243
}
240244

241245
private DriverCleanup loadPluginClassAndGetDriver(Class<? extends Driver> driverClass)

0 commit comments

Comments
 (0)