Skip to content

Commit

Permalink
Merge pull request #859 from TheNewEconomy/master
Browse files Browse the repository at this point in the history
Allow the overriding of the setting of a custom models file. Addresses #829.
  • Loading branch information
Igor Polevoy committed Jun 5, 2019
2 parents 4e029de + 9da87ba commit 14108ee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Expand Up @@ -37,7 +37,7 @@ private static synchronized Map<String, Set<String>> getModelMap() {
if (modelMap == null) {
try {
modelMap = new HashMap<>();
Enumeration<URL> urls = Registry.instance().getClass().getClassLoader().getResources("activejdbc_models.properties");
Enumeration<URL> urls = Registry.instance().getClass().getClassLoader().getResources(Registry.instance().getModelFile());
while(urls.hasMoreElements()) {
URL url = urls.nextElement();
LogFilter.log(LOGGER, LogLevel.INFO, "Loading models from: {}", url.toExternalForm());
Expand Down
37 changes: 28 additions & 9 deletions activejdbc/src/main/java/org/javalite/activejdbc/Registry.java
Expand Up @@ -22,20 +22,19 @@
import org.javalite.activejdbc.logging.LogFilter;
import org.javalite.activejdbc.logging.LogLevel;
import org.javalite.activejdbc.statistics.StatisticsQueue;
import org.javalite.common.Inflector;
import org.javalite.common.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.sql.DatabaseMetaData;
import java.util.*;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;

import org.javalite.common.Inflector;
import org.javalite.common.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.*;


/**
Expand All @@ -57,6 +56,7 @@ public enum Registry {
private final StatisticsQueue statisticsQueue;
private final Set<String> initedDbs = new HashSet<>();
private int staticMetadataStatus = 0;
private String modelFile = "activejdbc_models.properties";

Registry() {
statisticsQueue = configuration.collectStatistics()
Expand Down Expand Up @@ -529,4 +529,23 @@ protected List<String> getEdges(String join) {
private void registerColumnMetadata(String table, Map<String, ColumnMetadata> metaParams) {
metaModels.setColumnMetadata(table, metaParams);
}
}

public String getModelFile() {
return modelFile;
}

/**
* Used to override the default model file, activejdbc_models.properties.
* Please note: After initial registration of the model classes in ActiveJDBC this method
* will not function. That means in order to utilize this method, you must call it before
* doing any work with models.
*
* Usage of this method is only advised if you know what you're doing, and understand the risks
* of improperly using the method.
*
* @param modelFile The name of the file to use as your models properties file.
*/
public void setModelFile(String modelFile) {
this.modelFile = modelFile;
}
}

0 comments on commit 14108ee

Please sign in to comment.