Convert local variable to field
Instead of instantiating the variable every time the method is called,
do it once in the constructor.
Change-Id: I524ef5a3a5fb47c6f82be4f167900ec868279c34
diff --git a/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLClient.java b/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLClient.java
index d0e5d94..e950dcd 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLClient.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/eventslog/sql/SQLClient.java
@@ -47,6 +47,8 @@
class SQLClient {
private static final Logger log = LoggerFactory.getLogger(SQLClient.class);
private final Gson gson;
+ private final boolean isPostgresql;
+
private BasicDataSource ds;
SQLClient(String storeUrl, String urlOptions) {
@@ -59,6 +61,7 @@
ds.setValidationQueryTimeout(5);
gson = new GsonBuilder().registerTypeAdapter(Supplier.class, new SupplierSerializer()).create();
+ isPostgresql = storeUrl.contains("postgresql");
}
/**
@@ -106,9 +109,8 @@
* @throws SQLException If there was a problem with the database
*/
void createDBIfNotCreated() throws SQLException {
- boolean postgresql = ds.getUrl().contains("postgresql");
- execute(SQLTable.createTableQuery(postgresql));
- execute(SQLTable.createIndexes(postgresql));
+ execute(SQLTable.createTableQuery(isPostgresql));
+ execute(SQLTable.createIndexes(isPostgresql));
}
/**