Skip to content
Permalink
Browse files

Improved: Add static modifiers in ‘EntityDataLoadContainer’

(OFBIZ-11070)

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@1860064 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed May 26, 2019
1 parent 655f19c commit 07406d341d8960bf747a4514e2f9253d6853c703
@@ -131,7 +131,7 @@ public String getName() {
return name;
}

private List<GenericValue> getTenantList(Property delegatorNameProp) throws ContainerException {
private static List<GenericValue> 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 String getName() {
}
}

private void loadDataForDelegator(Map<String, String> loadDataProps, Configuration configuration,
private static void loadDataForDelegator(Map<String, String> loadDataProps, Configuration configuration,
Property delegatorNameProp, String overrideDelegator) throws ContainerException{

// prepare command line properties passed by user
@@ -207,7 +207,8 @@ private static boolean isPropertySet(Map<String, String> props, String key) {
* 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,15 +226,16 @@ private String getEntityGroupNameFromConfig(Configuration cfg, String overrideGr
* 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 {
return getDelegatorFromProp(delegatorNameProp);
}
}

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,32 +248,32 @@ private Delegator getDelegatorFromProp(Property delegatorNameProp) throws Contai
}
}

private Delegator getBaseDelegator(Delegator delegator) {
private static Delegator getBaseDelegator(Delegator delegator) {
if (delegator.getDelegatorTenantId() != null) {
return DelegatorFactory.getDelegator(delegator.getDelegatorBaseName());
} else {
return delegator;
}
}

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);
}
return helperInfo;
}

private Map<String, ModelEntity> getModelEntities(Delegator delegator,
String entityGroup) throws ContainerException {
private static Map<String, ModelEntity> getModelEntities(Delegator delegator, String entityGroup)
throws ContainerException {
try {
return delegator.getModelEntityMapByGroup(entityGroup);
} catch (GenericEntityException e) {
throw new ContainerException(e);
}
}

private void createOrUpdateComponentEntities(Delegator baseDelegator,
private static void createOrUpdateComponentEntities(Delegator baseDelegator,
Collection<ComponentConfig> allComponents) {

for (ComponentConfig config : allComponents) {
@@ -294,7 +296,7 @@ private void createOrUpdateComponentEntities(Delegator baseDelegator,
}
}

private void dropDbConstraints(DatabaseUtil dbUtil, Map<String, ModelEntity> modelEntities,
private static void dropDbConstraints(DatabaseUtil dbUtil, Map<String, ModelEntity> modelEntities,
TreeSet<String> modelEntityNames) {

List<String> messages = new ArrayList<>();
@@ -326,7 +328,7 @@ private void dropDbConstraints(DatabaseUtil dbUtil, Map<String, ModelEntity> mod
logMessageList(messages);
}

private void createDbConstraints(DatabaseUtil dbUtil, Map<String, ModelEntity> modelEntities,
private static void createDbConstraints(DatabaseUtil dbUtil, Map<String, ModelEntity> modelEntities,
TreeSet<String> modelEntityNames) {

List<String> messages = new ArrayList<>();
@@ -358,7 +360,7 @@ private void createDbConstraints(DatabaseUtil dbUtil, Map<String, ModelEntity> m
logMessageList(messages);
}

private void dropPrimaryKeys(DatabaseUtil dbUtil, Map<String, ModelEntity> modelEntities,
private static void dropPrimaryKeys(DatabaseUtil dbUtil, Map<String, ModelEntity> modelEntities,
TreeSet<String> modelEntityNames) {

List<String> messages = new ArrayList<>();
@@ -374,7 +376,7 @@ private void dropPrimaryKeys(DatabaseUtil dbUtil, Map<String, ModelEntity> model
logMessageList(messages);
}

private void createPrimaryKeys(DatabaseUtil dbUtil, Map<String, ModelEntity> modelEntities,
private static void createPrimaryKeys(DatabaseUtil dbUtil, Map<String, ModelEntity> modelEntities,
TreeSet<String> modelEntityNames) {

List<String> messages = new ArrayList<>();
@@ -390,7 +392,7 @@ private void createPrimaryKeys(DatabaseUtil dbUtil, Map<String, ModelEntity> mod
logMessageList(messages);
}

private void repairDbColumns(DatabaseUtil dbUtil, Map<String, ModelEntity> modelEntities) {
private static void repairDbColumns(DatabaseUtil dbUtil, Map<String, ModelEntity> modelEntities) {
List<String> fieldsToRepair = new ArrayList<>();
List<String> messages = new ArrayList<>();
dbUtil.checkDb(modelEntities, fieldsToRepair, messages, false, false, false, false);
@@ -401,15 +403,14 @@ private void repairDbColumns(DatabaseUtil dbUtil, Map<String, ModelEntity> model
logMessageList(messages);
}

private void logMessageList(List<String> messages) {
private static void logMessageList(List<String> messages) {
if (Debug.infoOn()) {
messages.forEach(message -> Debug.logInfo(message, module));
}
}

private void loadData(Delegator delegator, Delegator baseDelegator,
Collection<ComponentConfig> allComponents,
GenericHelperInfo helperInfo,
private static void loadData(Delegator delegator, Delegator baseDelegator,
Collection<ComponentConfig> allComponents, GenericHelperInfo helperInfo,
Map<String, String> loadDataProps) throws ContainerException {

// prepare command line properties passed by user
@@ -444,15 +445,15 @@ private void loadData(Delegator delegator, Delegator baseDelegator,
logDataLoadingResults(infoMessages, errorMessages, totalRowsChanged);
}

private int getTransactionTimeout(String timeout) {
private static int getTransactionTimeout(String timeout) {
try {
return Integer.parseInt(timeout);
} catch (Exception e) {
return -1;
}
}

private List<URL> prepareDataUrls(Delegator delegator, Delegator baseDelegator,
private static List<URL> prepareDataUrls(Delegator delegator, Delegator baseDelegator,
Collection<ComponentConfig> allComponents, GenericHelperInfo helperInfo,
Map<String, String> loadDataProps) throws ContainerException {

@@ -499,7 +500,7 @@ private static boolean isDataReadersEnabled(List<String> files, String directory
return readers != null || (files.isEmpty() && directory == null);
}

private List<String> prepareTenantLoadComponents(Delegator delegator, Delegator baseDelegator,
private static List<String> prepareTenantLoadComponents(Delegator delegator, Delegator baseDelegator,
Collection<ComponentConfig> allComponents, String component) {

List<String> loadComponents = new ArrayList<>();
@@ -529,7 +530,7 @@ private static boolean isDataReadersEnabled(List<String> files, String directory
return loadComponents;
}

private List<URL> retireveDataUrlsFromFileList(List<String> files) throws ContainerException {
private static List<URL> retireveDataUrlsFromFileList(List<String> files) throws ContainerException {
List<URL> fileUrls = new ArrayList<>();
for(String file: files) {
URL url = UtilURL.fromResource(file);
@@ -542,7 +543,7 @@ private static boolean isDataReadersEnabled(List<String> files, String directory
return fileUrls;
}

private List<URL> retrieveDataUrlsFromDirectory(String directory) {
private static List<URL> 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"))
@@ -551,7 +552,7 @@ private static boolean isDataReadersEnabled(List<String> files, String directory
.orElse(new ArrayList<URL>());
}

private void logDataLoadingPlan(List<URL> urlList, String delegatorName) {
private static void logDataLoadingPlan(List<URL> urlList, String delegatorName) {
if (UtilValidate.isNotEmpty(urlList)) {
Debug.logImportant("=-=-=-=-=-=-= Doing a data load using delegator '"
+ delegatorName + "' with the following files:", module);
@@ -562,7 +563,7 @@ private void logDataLoadingPlan(List<URL> urlList, String delegatorName) {
}
}

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);
@@ -571,7 +572,7 @@ private String createDataLoadMessage(URL dataUrl, int rowsChanged, int totalRows
+ " from " + dataUrl.toExternalForm();
}

private void logDataLoadingResults(List<String> infoMessages,
private static void logDataLoadingResults(List<String> infoMessages,
List<Object> errorMessages, int totalRowsChanged) {

if (UtilValidate.isNotEmpty(infoMessages)) {

0 comments on commit 07406d3

Please sign in to comment.
You can’t perform that action at this time.