Commit 21e22f65 authored by Stefan Huehner's avatar Stefan Huehner
Browse files

Fixes ISSUE-47036: Remove obsolete support code to ease maintenance

This removes obsolete support code needed in the past for:
- ant update.database.mod (long dead and removed)
- ezattributes (Easy Extensible Attributes) module
  Unuspported and already non-working since a while

Mostly it removes the duplication of all the ModelLoader code making it
much more readable.
parents a29a08bf e39072fe
......@@ -1131,9 +1131,6 @@ public interface Platform {
public Database loadTablesFromDatabase(ExcludeFilter filter) throws DatabaseOperationException;
public Database loadModelFromDatabase(ExcludeFilter filter, String prefix,
boolean loadCompleteTables, String moduleId) throws DatabaseOperationException;
/**
* Reads the database model from the live database as specified by the data source set for this
* platform.
......@@ -1353,9 +1350,6 @@ public interface Platform {
public void deleteInvalidConstraintRows(Database model, OBDataset dataset,
Set<String> tablesWithRemovedRecords, boolean continueOnError);
public void deleteInvalidConstraintRows(Database model, OBDataset dataset,
boolean continueOnError);
public void deleteInvalidConstraintRows(Connection connection, Database model, OBDataset dataset,
Set<String> tablesWithRemovedRecords, boolean continueOnError);
......@@ -1363,19 +1357,6 @@ public interface Platform {
public ModelLoader getModelLoader();
public void insertNonModuleTablesFromXML(Database loadedDatabase, Database correctDatabase);
public void insertNonModuleTablesFromDatabase(Database loadedDatabase, Database fullXMLDatabase,
Database filteredDatabase);
public void insertFunctionsInBothModels(Database loadedDatabase, Database fullXMLDatabase,
Database filteredDatabase);
public void insertViewsInBothModels(Database loadedDatabase, Database fullXMLDatabase,
Database filteredDatabase);
public void removeDeletedFKTriggers(Database modifiedDatabase, Database fullXMLDatabase);
public void disableNOTNULLColumns(Database database, OBDataset dataset);
public void enableNOTNULLColumns(Database database);
......
......@@ -198,15 +198,6 @@ public class DatabaseDataIO implements DataSetTableExporter {
this._writePrimaryKeyComment = _writePrimaryKeyComment;
}
/**
* Kept as org.openbravo.ezattributes module in at least version 2.0.5 (for 3.0) is still calling
* it. The method is changed to do nothing, as in case of that module the existing call was
* useless.
*/
@Deprecated
public void setDatabaseFilter(DatabaseFilter value) {
}
/**
* Specifies whether DdlUtils should try to find the schema of the tables when reading data from a
* live database.
......
......@@ -40,8 +40,6 @@ import org.apache.ddlutils.dynabean.SqlDynaClass;
import org.apache.ddlutils.dynabean.SqlDynaException;
import org.apache.ddlutils.platform.ExcludeFilter;
import org.apache.ddlutils.util.ExtTypes;
import org.openbravo.ddlutils.util.OBDataset;
import org.openbravo.ddlutils.util.OBDatasetTable;
/**
* Represents the database model, ie. the tables in the database. It also contains the corresponding
......@@ -1655,23 +1653,6 @@ public class Database implements Serializable, Cloneable {
applyNamingConventionToRest(filter);
}
public void applyNamingConventionToUpdate(ExcludeFilter filter) {
try {
for (int i = 0; i < _tables.size(); i++) {
Table t = (Table) _tables.get(i);
Table clonedT = (Table) t.clone();
clonedT.applyNamingConventionFilter(filter);
if (clonedT.isEmpty()) {
_tables.remove(t);
i--;
}
}
applyNamingConventionToRest(filter);
} catch (Exception e) {
e.printStackTrace();
}
}
private void applyNamingConventionToRest(ExcludeFilter filter) {
for (int i = 0; i < _sequences.size(); i++) {
......@@ -1726,32 +1707,6 @@ public class Database implements Serializable, Cloneable {
_tables = new ArrayList();
}
public void filterByDataset(OBDataset dataset) {
ArrayList oldTables = _tables;
_tables = new ArrayList();
Vector<OBDatasetTable> tables = dataset.getTableList();
for (OBDatasetTable table : tables) {
for (int i = 0; i < oldTables.size(); i++) {
Table t = (Table) oldTables.get(i);
if (t.getName().equalsIgnoreCase(table.getName())) {
_tables.add(t);
}
}
}
_views = new ArrayList();
ArrayList oldTriggers = _triggers;
_triggers = new ArrayList();
for (int i = 0; i < oldTriggers.size(); i++) {
Trigger trigger = (Trigger) oldTriggers.get(i);
if (findTable(trigger.getTable()) != null) {
_triggers.add(trigger);
}
}
// _functions=new ArrayList();
_sequences = new ArrayList();
_modifiedTables = new ArrayList();
}
public void checkDataTypes() throws SQLException {
for (int i = 0; i < this.getTableCount(); i++) {
Table t = this.getTable(i);
......
......@@ -29,17 +29,12 @@ public interface ModelLoader {
public Database getDatabase(Connection connection, ExcludeFilter filter,
boolean doPlSqlStandardization) throws SQLException;
public Database getDatabase(Connection connection, ExcludeFilter filter, String prefix,
boolean loadCompleteTables, String moduleId) throws SQLException;
public void setLog(Log log);
public Log getLog();
public void setOnlyLoadTableColumns(boolean onlyLoadTableColumns);
public void addAdditionalTableIfExists(Connection connection, Database model, String tablename);
/** Defines how many threads can be used to execute parallelizable tasks */
public void setMaxThreads(int threads);
......
......@@ -53,29 +53,17 @@ public abstract class ModelLoaderBase implements ModelLoader {
protected PreparedStatement _stmt_listtables;
protected PreparedStatement _stmt_pkname;
protected PreparedStatement _stmt_pkname_prefix;
protected PreparedStatement _stmt_pkname_noprefix;
protected PreparedStatement _stmt_listcolumns;
protected PreparedStatement _stmt_listcolumns_prefix;
protected PreparedStatement _stmt_listcolumns_noprefix;
protected PreparedStatement _stmt_pkcolumns;
protected PreparedStatement _stmt_listchecks;
protected PreparedStatement _stmt_listchecks_prefix;
protected PreparedStatement _stmt_listchecks_noprefix;
protected PreparedStatement _stmt_listfks;
protected PreparedStatement _stmt_listfks_prefix;
protected PreparedStatement _stmt_listfks_noprefix;
protected PreparedStatement _stmt_fkcolumns;
protected PreparedStatement _stmt_listindexes;
protected PreparedStatement _stmt_listindexes_prefix;
protected PreparedStatement _stmt_listindexes_noprefix;
protected PreparedStatement _stmt_indexcolumns;
protected PreparedStatement _stmt_listuniques;
protected PreparedStatement _stmt_listuniques_prefix;
protected PreparedStatement _stmt_listuniques_noprefix;
protected PreparedStatement _stmt_uniquecolumns;
protected PreparedStatement _stmt_listviews;
......@@ -90,10 +78,6 @@ public abstract class ModelLoaderBase implements ModelLoader {
protected Log _log;
protected String _prefix;
protected boolean _loadCompleteTables;
protected String _moduleId;
private boolean onlyLoadTableColumns = false;
private int maxThreads = 1;
......@@ -126,26 +110,6 @@ public abstract class ModelLoaderBase implements ModelLoader {
}
}
@Override
public Database getDatabase(Connection connection, ExcludeFilter filter, String prefix,
boolean loadCompleteTables, String moduleId) throws SQLException {
_filter = filter == null ? new ExcludeFilter() : filter;
_prefix = prefix.toUpperCase();
_loadCompleteTables = loadCompleteTables;
_moduleId = moduleId;
try {
_connection = connection;
initMetadataSentences();
return readDatabase();
} finally {
closeMetadataSentences();
}
}
@Override
public void setLog(Log log) {
_log = log;
......@@ -202,11 +166,7 @@ public abstract class ModelLoaderBase implements ModelLoader {
filteredTables.add(table);
}
}
if (_prefix != null && _loadCompleteTables) {
addTablesToCorrectPlace(db, readTablesFromList(filteredTables));
} else {
addTablesToCorrectPlace(db, filteredTables);
}
addTablesToCorrectPlace(db, filteredTables);
if (!onlyLoadTableColumns) {
_log.info("Reading views...");
db.addViews(readViews());
......@@ -233,13 +193,7 @@ public abstract class ModelLoaderBase implements ModelLoader {
Iterator it = tables.iterator();
while (it.hasNext()) {
Table table = (Table) it.next();
if (_prefix == null) {
db.addTable(table);
} else if (_filter.compliesWithNamingRuleObject(table.getName())) {
db.addTable(table);
} else {
db.addModifiedTable(table);
}
db.addTable(table);
}
}
......@@ -248,33 +202,12 @@ public abstract class ModelLoaderBase implements ModelLoader {
@Override
public Object getRow(ResultSet r) throws SQLException {
_log.debug("Table " + r.getString(1));
return readTable(r.getString(1), true);
return readTable(r.getString(1));
}
});
}
protected List readTableNames() throws SQLException {
return readList(_stmt_listtables, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
_log.debug("Table " + r.getString(1));
return r.getString(1);
}
});
}
protected Collection readTablesFromList(Collection tables) throws SQLException {
ArrayList newTables = new ArrayList();
Iterator it = tables.iterator();
while (it.hasNext()) {
Table table = (Table) it.next();
newTables.add(readTable(table.getName(), false));
}
return newTables;
}
protected Table readTable(String tablename, boolean usePrefix) throws SQLException {
protected Table readTable(String tablename) throws SQLException {
// on postgres this readTable gets called from the PostgreSqlModelLoader
// with the tablename having the same case as the table has in the database.
......@@ -293,36 +226,16 @@ public abstract class ModelLoaderBase implements ModelLoader {
t.setName(tablename);
if (_prefix == null || !usePrefix) {
_stmt_pkname.setString(1, tableRealName);
fillRow(_stmt_pkname, new RowFiller() {
@Override
public void fillRow(ResultSet r) throws SQLException {
t.setPrimaryKey(r.getString(1).toUpperCase());
pkNameHolder.append(r.getString(1));
}
});
} else if (_filter.compliesWithNamingRuleObject(tableRealName)) {
_stmt_pkname_noprefix.setString(1, tableRealName);
fillRow(_stmt_pkname_noprefix, new RowFiller() {
@Override
public void fillRow(ResultSet r) throws SQLException {
t.setPrimaryKey(r.getString(1).toUpperCase());
pkNameHolder.append(r.getString(1));
}
});
} else {
_stmt_pkname_prefix.setString(1, tableRealName);
fillRow(_stmt_pkname_prefix, new RowFiller() {
@Override
public void fillRow(ResultSet r) throws SQLException {
t.setPrimaryKey(r.getString(1).toUpperCase());
pkNameHolder.append(r.getString(1));
}
});
}
_stmt_pkname.setString(1, tableRealName);
fillRow(_stmt_pkname, new RowFiller() {
@Override
public void fillRow(ResultSet r) throws SQLException {
t.setPrimaryKey(r.getString(1).toUpperCase());
pkNameHolder.append(r.getString(1));
}
});
// Columns
t.addColumns(readColumns(tableRealName, usePrefix));
t.addColumns(readColumns(tableRealName));
// PKS
if (t.getPrimaryKey() != null && !t.getPrimaryKey().equals("")) {
......@@ -336,49 +249,29 @@ public abstract class ModelLoaderBase implements ModelLoader {
}
// Checks
t.addChecks(readChecks(tableRealName, usePrefix));
t.addChecks(readChecks(tableRealName));
// FKS
t.addForeignKeys(readForeignKeys(tableRealName, usePrefix));
t.addForeignKeys(readForeignKeys(tableRealName));
// Indexes
t.addIndices(readIndexes(tableRealName, usePrefix));
t.addIndices(readIndexes(tableRealName));
// Uniques
t.adduniques(readUniques(tableRealName, usePrefix));
t.adduniques(readUniques(tableRealName));
return t;
}
protected Collection readColumns(String tablename, boolean usePrefix) throws SQLException {
if (_prefix == null || !usePrefix) {
_stmt_listcolumns.setString(1, tablename);
protected Collection readColumns(String tablename) throws SQLException {
_stmt_listcolumns.setString(1, tablename);
return readList(_stmt_listcolumns, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readColumn(r);
}
});
} else if (_filter.compliesWithNamingRuleObject(tablename)) {
_stmt_listcolumns_noprefix.setString(1, tablename);
return readList(_stmt_listcolumns_noprefix, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readColumn(r);
}
});
} else {
_stmt_listcolumns_prefix.setString(1, tablename);
return readList(_stmt_listcolumns_prefix, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readColumn(r);
}
});
}
return readList(_stmt_listcolumns, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readColumn(r);
}
});
}
protected Column readColumn(ResultSet rs) throws SQLException {
......@@ -409,32 +302,14 @@ public abstract class ModelLoaderBase implements ModelLoader {
return c;
}
protected Collection readChecks(String tablename, boolean usePrefix) throws SQLException {
if (_prefix == null || !usePrefix) {
_stmt_listchecks.setString(1, tablename);
return readList(_stmt_listchecks, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readCheck(r);
}
});
} else if (_filter.compliesWithNamingRuleObject(tablename)) {
_stmt_listchecks_noprefix.setString(1, tablename);
return readList(_stmt_listchecks_noprefix, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readCheck(r);
}
});
} else {
_stmt_listchecks_prefix.setString(1, tablename);
return readList(_stmt_listchecks_prefix, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readCheck(r);
}
});
}
protected Collection readChecks(String tablename) throws SQLException {
_stmt_listchecks.setString(1, tablename);
return readList(_stmt_listchecks, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readCheck(r);
}
});
}
protected Check readCheck(ResultSet rs) throws SQLException {
......@@ -453,64 +328,26 @@ public abstract class ModelLoaderBase implements ModelLoader {
return c;
}
protected Collection readForeignKeys(String tablename, boolean usePrefix) throws SQLException {
if (_prefix == null || !usePrefix) {
_stmt_listfks.setString(1, tablename);
return readList(_stmt_listfks, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readForeignKey(r);
}
});
} else if (_filter.compliesWithNamingRuleObject(tablename)) {
_stmt_listfks_noprefix.setString(1, tablename);
return readList(_stmt_listfks_noprefix, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readForeignKey(r);
}
});
} else {
_stmt_listfks_prefix.setString(1, tablename);
return readList(_stmt_listfks_prefix, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readForeignKey(r);
}
});
}
protected Collection readForeignKeys(String tablename) throws SQLException {
_stmt_listfks.setString(1, tablename);
return readList(_stmt_listfks, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readForeignKey(r);
}
});
}
abstract protected ForeignKey readForeignKey(ResultSet rs) throws SQLException;
protected Collection readIndexes(String tablename, boolean usePrefix) throws SQLException {
if (_prefix == null || !usePrefix) {
_stmt_listindexes.setString(1, tablename);
return readList(_stmt_listindexes, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readIndex(r);
}
});
} else if (_filter.compliesWithNamingRuleObject(tablename)) {
_stmt_listindexes_noprefix.setString(1, tablename);
return readList(_stmt_listindexes_noprefix, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readIndex(r);
}
});
} else {
_stmt_listindexes_prefix.setString(1, tablename);
return readList(_stmt_listindexes_prefix, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readIndex(r);
}
});
}
protected Collection readIndexes(String tablename) throws SQLException {
_stmt_listindexes.setString(1, tablename);
return readList(_stmt_listindexes, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readIndex(r);
}
});
}
protected Index readIndex(ResultSet rs) throws SQLException {
......@@ -535,33 +372,14 @@ public abstract class ModelLoaderBase implements ModelLoader {
return inx;
}
protected Collection readUniques(String tablename, boolean usePrefix) throws SQLException {
if (_prefix == null || !usePrefix) {
_stmt_listuniques.setString(1, tablename);
return readList(_stmt_listuniques, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readUnique(r);
}
});
} else if (_filter.compliesWithNamingRuleObject(tablename)) {
_stmt_listuniques_noprefix.setString(1, tablename);
return readList(_stmt_listuniques_noprefix, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readUnique(r);
}
});
} else {
_stmt_listuniques_prefix.setString(1, tablename);
return readList(_stmt_listuniques_prefix, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readUnique(r);
}
});
}
protected Collection readUniques(String tablename) throws SQLException {
_stmt_listuniques.setString(1, tablename);
return readList(_stmt_listuniques, new RowConstructor() {
@Override
public Object getRow(ResultSet r) throws SQLException {
return readUnique(r);
}
});
}
protected Unique readUnique(ResultSet rs) throws SQLException {
......@@ -608,9 +426,8 @@ public abstract class ModelLoaderBase implements ModelLoader {
mv.setName(materializedViewName.toUpperCase());
mv.setStatement(translateSQL(r.getString(2)));
boolean usePrefix = false;
mv.addColumns(readColumns(materializedViewName, usePrefix));
mv.addIndices(readIndexes(materializedViewName, usePrefix));
mv.addColumns(readColumns(materializedViewName));
mv.addIndices(readIndexes(materializedViewName));
return mv;
});
......@@ -885,25 +702,6 @@ public abstract class ModelLoaderBase implements ModelLoader {
this.onlyLoadTableColumns = onlyLoadTableColumns;
}
@Override
public void addAdditionalTableIfExists(Connection connection, Database model, String tablename) {
try {
this._connection = connection;
initMetadataSentences();
List tablenames = readTableNames();
for (int i = 0; i < tablenames.size(); i++) {
String tablenameDB = (String) tablenames.get(i);
if (tablenameDB.equals(tablename)) {
// The table exists, we need to load it.
Table table = readTable(tablename, false);
model.addTable(table);
}
}
} catch (Exception e) {
getLog().error(e);
}
}
@Override
public void setMaxThreads(int maxThreads) {
this.maxThreads = maxThreads;
......
......@@ -43,7 +43,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
......@@ -86,13 +85,11 @@ import org.apache.ddlutils.dynabean.SqlDynaProperty;
import org.apache.ddlutils.model.Column;
import org.apache.ddlutils.model.Database;
import org.apache.ddlutils.model.ForeignKey;