From e2c85737e43fa92d2baeb57ae7cb9f07d7b2c98a Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Sat, 8 Jun 2019 14:59:02 +0000 Subject: [PATCH] =?UTF-8?q?Improved:=20Add=20static=20modifiers=20in=20?= =?UTF-8?q?=E2=80=98EntityDataLoadContainer=E2=80=99=20(OFBIZ-11070)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When no reference to ‘this’ is made, it is better to declare methods as static. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1860838 13f79535-47bb-0310-9956-ffa450edef68 --- .../data/EntityDataLoadContainer.java | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataLoadContainer.java b/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataLoadContainer.java index a13a069f2c..ccf0eb22f6 100644 --- a/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataLoadContainer.java +++ b/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataLoadContainer.java @@ -131,7 +131,7 @@ public class EntityDataLoadContainer implements Container { return name; } - private List getTenantList(Property delegatorNameProp) throws ContainerException { + private static List getTenantList(Property delegatorNameProp) throws ContainerException { if (!EntityUtil.isMultiTenantEnabled()) { throw new ContainerException("Multitenant is disabled, must be enabled in general.properties -> multitenant=Y"); } @@ -148,7 +148,7 @@ public class EntityDataLoadContainer implements Container { } } - private void loadDataForDelegator(Map loadDataProps, Configuration configuration, + private static void loadDataForDelegator(Map loadDataProps, Configuration configuration, Property delegatorNameProp, String overrideDelegator) throws ContainerException{ // prepare command line properties passed by user @@ -207,7 +207,8 @@ public class EntityDataLoadContainer implements Container { * Gets the default entity-group-name defined in the container definition * unless overridden by the user */ - private String getEntityGroupNameFromConfig(Configuration cfg, String overrideGroup) throws ContainerException { + private static String getEntityGroupNameFromConfig(Configuration cfg, String overrideGroup) + throws ContainerException { if (overrideGroup != null) { return overrideGroup; } else { @@ -225,7 +226,8 @@ public class EntityDataLoadContainer implements Container { * overridden by the user. This method will create all the tables, keys and * indices if missing and hence might take a long time. */ - private Delegator getDelegator(Property delegatorNameProp, String overrideDelegator) throws ContainerException { + private static Delegator getDelegator(Property delegatorNameProp, String overrideDelegator) + throws ContainerException { if (overrideDelegator != null) { return DelegatorFactory.getDelegator(overrideDelegator); } else { @@ -233,7 +235,7 @@ public class EntityDataLoadContainer implements Container { } } - private Delegator getDelegatorFromProp(Property delegatorNameProp) throws ContainerException { + private static Delegator getDelegatorFromProp(Property delegatorNameProp) throws ContainerException { if (delegatorNameProp != null && UtilValidate.isNotEmpty(delegatorNameProp.value)) { Delegator delegator = DelegatorFactory.getDelegator(delegatorNameProp.value); if (delegator != null) { @@ -246,7 +248,7 @@ public class EntityDataLoadContainer implements Container { } } - private Delegator getBaseDelegator(Delegator delegator) { + private static Delegator getBaseDelegator(Delegator delegator) { if (delegator.getDelegatorTenantId() != null) { return DelegatorFactory.getDelegator(delegator.getDelegatorBaseName()); } else { @@ -254,7 +256,7 @@ public class EntityDataLoadContainer implements Container { } } - private GenericHelperInfo getHelperInfo(Delegator delegator, String entityGroup) throws ContainerException { + private static GenericHelperInfo getHelperInfo(Delegator delegator, String entityGroup) throws ContainerException { GenericHelperInfo helperInfo = delegator.getGroupHelperInfo(entityGroup); if (helperInfo == null) { throw new ContainerException("Unable to locate the datasource helper for the group: " + entityGroup); @@ -262,8 +264,8 @@ public class EntityDataLoadContainer implements Container { return helperInfo; } - private Map getModelEntities(Delegator delegator, - String entityGroup) throws ContainerException { + private static Map getModelEntities(Delegator delegator, String entityGroup) + throws ContainerException { try { return delegator.getModelEntityMapByGroup(entityGroup); } catch (GenericEntityException e) { @@ -271,7 +273,7 @@ public class EntityDataLoadContainer implements Container { } } - private void createOrUpdateComponentEntities(Delegator baseDelegator, + private static void createOrUpdateComponentEntities(Delegator baseDelegator, Collection allComponents) { for (ComponentConfig config : allComponents) { @@ -294,7 +296,7 @@ public class EntityDataLoadContainer implements Container { } } - private void dropDbConstraints(DatabaseUtil dbUtil, Map modelEntities, + private static void dropDbConstraints(DatabaseUtil dbUtil, Map modelEntities, TreeSet modelEntityNames) { List messages = new ArrayList<>(); @@ -326,7 +328,7 @@ public class EntityDataLoadContainer implements Container { logMessageList(messages); } - private void createDbConstraints(DatabaseUtil dbUtil, Map modelEntities, + private static void createDbConstraints(DatabaseUtil dbUtil, Map modelEntities, TreeSet modelEntityNames) { List messages = new ArrayList<>(); @@ -358,7 +360,7 @@ public class EntityDataLoadContainer implements Container { logMessageList(messages); } - private void dropPrimaryKeys(DatabaseUtil dbUtil, Map modelEntities, + private static void dropPrimaryKeys(DatabaseUtil dbUtil, Map modelEntities, TreeSet modelEntityNames) { List messages = new ArrayList<>(); @@ -374,7 +376,7 @@ public class EntityDataLoadContainer implements Container { logMessageList(messages); } - private void createPrimaryKeys(DatabaseUtil dbUtil, Map modelEntities, + private static void createPrimaryKeys(DatabaseUtil dbUtil, Map modelEntities, TreeSet modelEntityNames) { List messages = new ArrayList<>(); @@ -390,7 +392,7 @@ public class EntityDataLoadContainer implements Container { logMessageList(messages); } - private void repairDbColumns(DatabaseUtil dbUtil, Map modelEntities) { + private static void repairDbColumns(DatabaseUtil dbUtil, Map modelEntities) { List fieldsToRepair = new ArrayList<>(); List messages = new ArrayList<>(); dbUtil.checkDb(modelEntities, fieldsToRepair, messages, false, false, false, false); @@ -401,15 +403,14 @@ public class EntityDataLoadContainer implements Container { logMessageList(messages); } - private void logMessageList(List messages) { + private static void logMessageList(List messages) { if (Debug.infoOn()) { messages.forEach(message -> Debug.logInfo(message, module)); } } - private void loadData(Delegator delegator, Delegator baseDelegator, - Collection allComponents, - GenericHelperInfo helperInfo, + private static void loadData(Delegator delegator, Delegator baseDelegator, + Collection allComponents, GenericHelperInfo helperInfo, Map loadDataProps) throws ContainerException { // prepare command line properties passed by user @@ -444,7 +445,7 @@ public class EntityDataLoadContainer implements Container { logDataLoadingResults(infoMessages, errorMessages, totalRowsChanged); } - private int getTransactionTimeout(String timeout) { + private static int getTransactionTimeout(String timeout) { try { return Integer.parseInt(timeout); } catch (Exception e) { @@ -452,7 +453,7 @@ public class EntityDataLoadContainer implements Container { } } - private List prepareDataUrls(Delegator delegator, Delegator baseDelegator, + private static List prepareDataUrls(Delegator delegator, Delegator baseDelegator, Collection allComponents, GenericHelperInfo helperInfo, Map loadDataProps) throws ContainerException { @@ -493,7 +494,7 @@ public class EntityDataLoadContainer implements Container { return urlList; } - private List getLoadFiles(String fileProp) { + static private List getLoadFiles(String fileProp) { List fileList = new ArrayList<>(); Optional.ofNullable(fileProp) .ifPresent(props -> fileList.addAll(StringUtil.split(props, ","))); @@ -506,7 +507,7 @@ public class EntityDataLoadContainer implements Container { return readers != null || (files.isEmpty() && directory == null); } - private List prepareTenantLoadComponents(Delegator delegator, Delegator baseDelegator, + private static List prepareTenantLoadComponents(Delegator delegator, Delegator baseDelegator, Collection allComponents, String component) { List loadComponents = new ArrayList<>(); @@ -536,7 +537,7 @@ public class EntityDataLoadContainer implements Container { return loadComponents; } - private List retireveDataUrlsFromFileList(List files) throws ContainerException { + private static List retireveDataUrlsFromFileList(List files) throws ContainerException { List fileUrls = new ArrayList<>(); for(String file: files) { URL url = UtilURL.fromResource(file); @@ -549,7 +550,7 @@ public class EntityDataLoadContainer implements Container { return fileUrls; } - private List retrieveDataUrlsFromDirectory(String directory) { + private static List retrieveDataUrlsFromDirectory(String directory) { return Optional.ofNullable(directory) .map(dir -> Arrays.asList(new File(dir).listFiles()).stream() .filter(file -> file.getName().toLowerCase(Locale.getDefault()).endsWith(".xml")) @@ -558,7 +559,7 @@ public class EntityDataLoadContainer implements Container { .orElse(new ArrayList()); } - private void logDataLoadingPlan(List urlList, String delegatorName) { + private static void logDataLoadingPlan(List urlList, String delegatorName) { if (UtilValidate.isNotEmpty(urlList)) { Debug.logImportant("=-=-=-=-=-=-= Doing a data load using delegator '" + delegatorName + "' with the following files:", module); @@ -569,7 +570,7 @@ public class EntityDataLoadContainer implements Container { } } - private String createDataLoadMessage(URL dataUrl, int rowsChanged, int totalRowsChanged) { + private static String createDataLoadMessage(URL dataUrl, int rowsChanged, int totalRowsChanged) { NumberFormat formatter = NumberFormat.getIntegerInstance(); formatter.setMinimumIntegerDigits(5); formatter.setGroupingUsed(false); @@ -578,7 +579,7 @@ public class EntityDataLoadContainer implements Container { + " from " + dataUrl.toExternalForm(); } - private void logDataLoadingResults(List infoMessages, + private static void logDataLoadingResults(List infoMessages, List errorMessages, int totalRowsChanged) { if (UtilValidate.isNotEmpty(infoMessages)) {