mirror of
https://github.com/Wisser/Jailer.git
synced 2026-02-21 10:18:32 -06:00
internal refactoring
git-svn-id: https://svn.code.sf.net/p/jailer/code/trunk@539 3dd849cd-670e-4645-a7cd-dd197c8d0e81
This commit is contained in:
@@ -16,6 +16,7 @@ ant package
|
||||
rm -rf admin
|
||||
rm -rf doc
|
||||
rm -rf out
|
||||
rm -rf beta
|
||||
rm svn-commit.tmp
|
||||
mv datamodel.def datamodel
|
||||
rm -rf datamodel.scr
|
||||
|
||||
@@ -26,8 +26,8 @@ import java.util.regex.Pattern;
|
||||
import net.sf.jailer.database.StatementExecutor;
|
||||
import net.sf.jailer.database.StatisticRenovator;
|
||||
import net.sf.jailer.database.TemporaryTableManager;
|
||||
import net.sf.jailer.datamodel.PrimaryKeyFactory;
|
||||
import net.sf.jailer.enhancer.ScriptEnhancer;
|
||||
import net.sf.jailer.modelbuilder.ModelElementFinder;
|
||||
import net.sf.jailer.render.DataModelRenderer;
|
||||
|
||||
import org.springframework.context.support.AbstractXmlApplicationContext;
|
||||
@@ -43,12 +43,12 @@ public class Configuration {
|
||||
/**
|
||||
* The scipt-enhancer.
|
||||
*/
|
||||
public static final List<ScriptEnhancer> scriptEnhancer;
|
||||
private static List<ScriptEnhancer> theScriptEnhancer;
|
||||
|
||||
/**
|
||||
* The renderer.
|
||||
*/
|
||||
public static final DataModelRenderer renderer;
|
||||
private static DataModelRenderer theRenderer;
|
||||
|
||||
/**
|
||||
* DB-URL pattern of DBMS for which this holds the configuration.
|
||||
@@ -91,15 +91,42 @@ public class Configuration {
|
||||
*/
|
||||
private static final Configuration defaultConfiguration = new Configuration();
|
||||
|
||||
/**
|
||||
* If <code>true</code>, the UPK don't preserve order. This minimizes the size of the UPK.
|
||||
*/
|
||||
private static boolean doMinimizeUPK = false;
|
||||
|
||||
/**
|
||||
* Returns <code>true</code>, the UPK don't preserve order. This minimizes the size of the UPK.
|
||||
*/
|
||||
public static boolean getDoMinimizeUPK() {
|
||||
getContext();
|
||||
return doMinimizeUPK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all {@link ModelElementFinder}.
|
||||
*
|
||||
* @return all {@link ModelElementFinder}
|
||||
*/
|
||||
public static List<ModelElementFinder> getModelElementFinder() throws Exception {
|
||||
List<ModelElementFinder> modelElementFinder = (List<ModelElementFinder>) getContext().getBean("model-finder");
|
||||
return modelElementFinder;
|
||||
}
|
||||
|
||||
/**
|
||||
* The configuration.
|
||||
*/
|
||||
private static AbstractXmlApplicationContext applicationContext = new FileSystemXmlApplicationContext("config" + File.separator + "config.xml");
|
||||
static {
|
||||
PrimaryKeyFactory.minimizeUPK = Boolean.TRUE.equals(applicationContext.getBean("minimize-UPK"));
|
||||
scriptEnhancer = (List<ScriptEnhancer>) applicationContext.getBean("script-enhancer");
|
||||
renderer = (DataModelRenderer) applicationContext.getBean("renderer");
|
||||
}
|
||||
private static AbstractXmlApplicationContext theApplicationContext = null;
|
||||
private static AbstractXmlApplicationContext getContext() {
|
||||
if (theApplicationContext == null) {
|
||||
theApplicationContext = new FileSystemXmlApplicationContext("config" + File.separator + "config.xml");
|
||||
doMinimizeUPK = Boolean.TRUE.equals(theApplicationContext.getBean("minimize-UPK"));
|
||||
theScriptEnhancer = (List<ScriptEnhancer>) theApplicationContext.getBean("script-enhancer");
|
||||
theRenderer = (DataModelRenderer) theApplicationContext.getBean("renderer");
|
||||
}
|
||||
return theApplicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds configurations.
|
||||
@@ -119,8 +146,8 @@ public class Configuration {
|
||||
if (perUrl.containsKey(statementExecutor.dbUrl)) {
|
||||
return perUrl.get(statementExecutor.dbUrl);
|
||||
}
|
||||
if (applicationContext.containsBean("dbms-configuration")) {
|
||||
List<Configuration> cs = (List<Configuration>) applicationContext.getBean("dbms-configuration");
|
||||
if (getContext().containsBean("dbms-configuration")) {
|
||||
List<Configuration> cs = (List<Configuration>) getContext().getBean("dbms-configuration");
|
||||
for (Configuration c: cs) {
|
||||
if (Pattern.matches(c.urlPattern, statementExecutor.dbUrl)) {
|
||||
perUrl.put(statementExecutor.dbUrl, c);
|
||||
@@ -221,4 +248,20 @@ public class Configuration {
|
||||
transactionTemporaryTableManager = tableManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the scipt-enhancer.
|
||||
*/
|
||||
public static List<ScriptEnhancer> getScriptEnhancer() {
|
||||
getContext();
|
||||
return theScriptEnhancer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the renderer.
|
||||
*/
|
||||
public static DataModelRenderer getRenderer() {
|
||||
getContext();
|
||||
return theRenderer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package net.sf.jailer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
@@ -86,7 +87,7 @@ public class Jailer {
|
||||
/**
|
||||
* The Jailer version.
|
||||
*/
|
||||
public static final String VERSION = "2.9.3.beta";
|
||||
public static final String VERSION = "2.9.3.beta2";
|
||||
|
||||
/**
|
||||
* The relational data model.
|
||||
@@ -474,12 +475,12 @@ public class Jailer {
|
||||
result = new OutputStreamWriter(outputStream);
|
||||
result.append(commentHeader);
|
||||
result.append(System.getProperty("line.separator"));
|
||||
for (ScriptEnhancer enhancer: Configuration.scriptEnhancer) {
|
||||
for (ScriptEnhancer enhancer: Configuration.getScriptEnhancer()) {
|
||||
enhancer.addComments(result, scriptType, statementExecutor, entityGraph, progress);
|
||||
}
|
||||
result.append(System.getProperty("line.separator"));
|
||||
result.append(System.getProperty("line.separator"));
|
||||
for (ScriptEnhancer enhancer: Configuration.scriptEnhancer) {
|
||||
for (ScriptEnhancer enhancer: Configuration.getScriptEnhancer()) {
|
||||
enhancer.addProlog(result, scriptType, statementExecutor, entityGraph, progress);
|
||||
}
|
||||
}
|
||||
@@ -565,7 +566,7 @@ public class Jailer {
|
||||
|
||||
if (result != null) {
|
||||
// write epilogs
|
||||
for (ScriptEnhancer enhancer: Configuration.scriptEnhancer) {
|
||||
for (ScriptEnhancer enhancer: Configuration.getScriptEnhancer()) {
|
||||
enhancer.addEpilog(result, scriptType, statementExecutor, entityGraph, progress);
|
||||
}
|
||||
result.close();
|
||||
@@ -807,11 +808,11 @@ public class Jailer {
|
||||
statistic.setLength(0);
|
||||
StatementExecutor.closeTemporaryTableSession();
|
||||
|
||||
if (PrimaryKeyFactory.minimizeUPK) {
|
||||
_log.info("minimize-UPK=" + PrimaryKeyFactory.minimizeUPK);
|
||||
}
|
||||
|
||||
try {
|
||||
if (Configuration.getDoMinimizeUPK()) {
|
||||
_log.info("minimize-UPK=" + Configuration.getDoMinimizeUPK());
|
||||
}
|
||||
|
||||
CommandLineParser.parse(args);
|
||||
CommandLineParser clp = CommandLineParser.getInstance();
|
||||
|
||||
@@ -886,6 +887,8 @@ public class Jailer {
|
||||
} catch (Exception e) {
|
||||
_log.error(e.getMessage(), e);
|
||||
System.out.println("Error: " + e.getClass().getName() + ": " + e.getMessage());
|
||||
String workingDirectory = System.getProperty("user.dir");
|
||||
_log.error("working directory is " + workingDirectory);
|
||||
throw e;
|
||||
} finally {
|
||||
StatementExecutor.closeTemporaryTableSession();
|
||||
@@ -904,7 +907,7 @@ public class Jailer {
|
||||
}
|
||||
dataModel.getRestrictionModel().addRestrictionDefinition(rm, null);
|
||||
}
|
||||
DataModelRenderer renderer = Configuration.renderer;
|
||||
DataModelRenderer renderer = Configuration.getRenderer();
|
||||
if (renderer == null) {
|
||||
throw new RuntimeException("no renderer found in config/config.xml");
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sf.jailer.Configuration;
|
||||
|
||||
|
||||
/**
|
||||
* Primary-key of a {@link Table}.
|
||||
@@ -62,7 +64,7 @@ public class PrimaryKey {
|
||||
* @return a match of all columns of <code>primaryKey</code>
|
||||
*/
|
||||
public Map<Column, Column> match(PrimaryKey primaryKey) {
|
||||
if (PrimaryKeyFactory.minimizeUPK) {
|
||||
if (Configuration.getDoMinimizeUPK()) {
|
||||
Set<Integer> assignedUPKColumns = new HashSet<Integer>();
|
||||
Map<Column, Column> match = new HashMap<Column, Column>();
|
||||
for (Column column: getColumns()) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sf.jailer.Configuration;
|
||||
import net.sf.jailer.database.SQLDialect;
|
||||
import net.sf.jailer.database.StatementExecutor;
|
||||
|
||||
@@ -44,11 +45,6 @@ public class PrimaryKeyFactory {
|
||||
private PrimaryKey universalPrimaryKey = new PrimaryKey(
|
||||
new ArrayList<Column>());
|
||||
|
||||
/**
|
||||
* If <code>true</code>, the UPK don't preserve order. This minimizes the size of the UPK.
|
||||
*/
|
||||
public static boolean minimizeUPK = false;
|
||||
|
||||
/**
|
||||
* Constructs a new primary-key.
|
||||
*
|
||||
@@ -63,7 +59,7 @@ public class PrimaryKeyFactory {
|
||||
}
|
||||
PrimaryKey primaryKey = new PrimaryKey(columns);
|
||||
|
||||
if (minimizeUPK) {
|
||||
if (Configuration.getDoMinimizeUPK()) {
|
||||
Set<Integer> assignedUPKColumns = new HashSet<Integer>();
|
||||
for (Column column: columns) {
|
||||
boolean assigned = false;
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sf.jailer.Configuration;
|
||||
import net.sf.jailer.database.StatementExecutor;
|
||||
import net.sf.jailer.datamodel.Association;
|
||||
import net.sf.jailer.datamodel.Cardinality;
|
||||
@@ -58,26 +59,11 @@ import org.springframework.context.support.FileSystemXmlApplicationContext;
|
||||
*/
|
||||
public class ModelBuilder {
|
||||
|
||||
/**
|
||||
* The configuration.
|
||||
*/
|
||||
private static AbstractXmlApplicationContext applicationContext = new FileSystemXmlApplicationContext("config" + File.separator + "config.xml");
|
||||
|
||||
/**
|
||||
* The logger.
|
||||
*/
|
||||
private static final Logger _log = Logger.getLogger(ModelBuilder.class);
|
||||
|
||||
/**
|
||||
* Gets all {@link ModelElementFinder}.
|
||||
*
|
||||
* @return all {@link ModelElementFinder}
|
||||
*/
|
||||
private static List<ModelElementFinder> getModelElementFinder() throws Exception {
|
||||
List<ModelElementFinder> modelElementFinder = (List<ModelElementFinder>) applicationContext.getBean("model-finder");
|
||||
return modelElementFinder;
|
||||
}
|
||||
|
||||
/**
|
||||
* The statement executor for executing SQL statements.
|
||||
*/
|
||||
@@ -144,7 +130,7 @@ public class ModelBuilder {
|
||||
DataModel dataModel = new DataModel();
|
||||
Collection<Table> tables = new ArrayList<Table>();
|
||||
|
||||
List<ModelElementFinder> modelElementFinder = getModelElementFinder();
|
||||
List<ModelElementFinder> modelElementFinder = Configuration.getModelElementFinder();
|
||||
for (ModelElementFinder finder: modelElementFinder) {
|
||||
_log.info("find tables with " + finder);
|
||||
tables.addAll(finder.findTables(statementExecutor));
|
||||
|
||||
Reference in New Issue
Block a user