From 605b3eb0c6cef6e90d393a5a057ede460d2c15f6 Mon Sep 17 00:00:00 2001 From: Alex Bogdanovski Date: Fri, 27 Nov 2020 12:45:32 +0200 Subject: [PATCH] moved listeners registration code to static block --- .../com/erudika/para/persistence/H2DAO.java | 31 +++++++++---------- .../com/erudika/para/persistence/SqlDAO.java | 31 +++++++++---------- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/erudika/para/persistence/H2DAO.java b/src/main/java/com/erudika/para/persistence/H2DAO.java index 3c0ab38..dd520e9 100644 --- a/src/main/java/com/erudika/para/persistence/H2DAO.java +++ b/src/main/java/com/erudika/para/persistence/H2DAO.java @@ -17,8 +17,6 @@ */ package com.erudika.para.persistence; -import com.erudika.para.AppCreatedListener; -import com.erudika.para.AppDeletedListener; import com.erudika.para.core.App; import com.erudika.para.core.ParaObject; import com.erudika.para.utils.Config; @@ -41,29 +39,28 @@ public class H2DAO implements DAO { private static final Logger logger = LoggerFactory.getLogger(H2DAO.class); - /** - * Default constructor. - */ - public H2DAO() { - if (getClass().getSimpleName().equals(Config.getConfigParam("dao", ""))) { + static { + if (H2DAO.class.getSimpleName().equals(Config.getConfigParam("dao", ""))) { // set up automatic table creation and deletion - App.addAppCreatedListener(new AppCreatedListener() { - public void onAppCreated(App app) { - if (app != null) { - H2Utils.createTable(app.getAppIdentifier()); - } + App.addAppCreatedListener((App app) -> { + if (app != null) { + H2Utils.createTable(app.getAppIdentifier()); } }); - App.addAppDeletedListener(new AppDeletedListener() { - public void onAppDeleted(App app) { - if (app != null) { - H2Utils.deleteTable(app.getAppIdentifier()); - } + App.addAppDeletedListener((App app) -> { + if (app != null) { + H2Utils.deleteTable(app.getAppIdentifier()); } }); } } + /** + * Default constructor. + */ + public H2DAO() { + } + @Override public

String create(String appid, P object) { if (object == null) { diff --git a/src/main/java/com/erudika/para/persistence/SqlDAO.java b/src/main/java/com/erudika/para/persistence/SqlDAO.java index c18f493..c7228ee 100755 --- a/src/main/java/com/erudika/para/persistence/SqlDAO.java +++ b/src/main/java/com/erudika/para/persistence/SqlDAO.java @@ -18,8 +18,6 @@ package com.erudika.para.persistence; -import com.erudika.para.AppCreatedListener; -import com.erudika.para.AppDeletedListener; import com.erudika.para.core.App; import com.erudika.para.core.ParaObject; import com.erudika.para.utils.Config; @@ -42,29 +40,28 @@ public class SqlDAO implements DAO { private static final Logger logger = LoggerFactory.getLogger(SqlDAO.class); - /** - * Default constructor. - */ - public SqlDAO() { - if (getClass().getSimpleName().equals(Config.getConfigParam("dao", ""))) { + static { + if (SqlDAO.class.getSimpleName().equals(Config.getConfigParam("dao", ""))) { // set up automatic table creation and deletion - App.addAppCreatedListener(new AppCreatedListener() { - public void onAppCreated(App app) { - if (app != null) { - SqlUtils.createTable(app.getAppIdentifier()); - } + App.addAppCreatedListener((App app) -> { + if (app != null) { + SqlUtils.createTable(app.getAppIdentifier()); } }); - App.addAppDeletedListener(new AppDeletedListener() { - public void onAppDeleted(App app) { - if (app != null) { - SqlUtils.deleteTable(app.getAppIdentifier()); - } + App.addAppDeletedListener((App app) -> { + if (app != null) { + SqlUtils.deleteTable(app.getAppIdentifier()); } }); } } + /** + * Default constructor. + */ + public SqlDAO() { + } + @Override public

String create(String appid, P object) { if (object == null) {