Skip to content

Commit

Permalink
Moving informix to the ddl project
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Jun 26, 2010
1 parent 63be07f commit 593fe96
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 71 deletions.
Expand Up @@ -855,7 +855,7 @@ protected String readPrimaryKeyName(DatabaseMetaDataWrapper metaData, Map values
*/
protected Collection<String> readForeignKeys(DatabaseMetaDataWrapper metaData, String tableName) throws SQLException
{
Map fks = new ListOrderedMap();
Map fks = new ListOrderedMap();
ResultSet fkData = null;

try
Expand All @@ -864,7 +864,7 @@ protected Collection<String> readForeignKeys(DatabaseMetaDataWrapper metaData, S

while (fkData.next())
{
Map<String,Object> values = readColumns(fkData, getColumnsForFK());
Map values = readColumns(fkData, getColumnsForFK());

readForeignKey(metaData, values, fks);
}
Expand Down Expand Up @@ -1013,9 +1013,13 @@ protected Map<String,Object> readColumns(ResultSet resultSet, List<MetaDataColum

protected void determineAutoIncrementFromResultSetMetaData(Table table,
final Column columnsToCheck[]) throws SQLException {
determineAutoIncrementFromResultSetMetaData(table, columnsToCheck, ".");
determineAutoIncrementFromResultSetMetaData(getConnection(), table, columnsToCheck);
}

protected void determineAutoIncrementFromResultSetMetaData(Connection conn, Table table,
final Column columnsToCheck[]) throws SQLException {
determineAutoIncrementFromResultSetMetaData(conn, table, columnsToCheck, ".");
}

/**
* Helper method that determines the auto increment status for the given columns via the
Expand All @@ -1026,7 +1030,7 @@ protected void determineAutoIncrementFromResultSetMetaData(Table table,
* * @param table The table
* @param columnsToCheck The columns to check (e.g. the primary key columns)
*/
protected void determineAutoIncrementFromResultSetMetaData(Table table,
public void determineAutoIncrementFromResultSetMetaData(Connection conn, Table table,
final Column columnsToCheck[], String catalogSeparator) throws SQLException {
if (columnsToCheck == null || columnsToCheck.length == 0) {
return;
Expand All @@ -1053,7 +1057,7 @@ protected void determineAutoIncrementFromResultSetMetaData(Table table,

Statement stmt = null;
try {
stmt = getConnection().createStatement();
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query.toString());
ResultSetMetaData rsMetaData = rs.getMetaData();

Expand Down
Expand Up @@ -9,6 +9,7 @@

import org.apache.commons.collections.map.ListOrderedMap;
import org.jumpmind.symmetric.ddl.Platform;
import org.jumpmind.symmetric.ddl.model.Column;
import org.jumpmind.symmetric.ddl.model.ForeignKey;
import org.jumpmind.symmetric.ddl.model.Index;
import org.jumpmind.symmetric.ddl.model.Table;
Expand All @@ -27,10 +28,16 @@ public InformixModelReader(Platform platform) {
protected Table readTable(DatabaseMetaDataWrapper metaData, Map<String,Object> values) throws SQLException {
Table table = super.readTable(metaData, values);
if (table != null) {
determineAutoIncrementFromResultSetMetaData(table, table.getColumns(), ":");
determineAutoIncrementFromResultSetMetaData(table, table.getColumns());
}
return table;
}

@Override
protected void determineAutoIncrementFromResultSetMetaData(Table table, Column[] columnsToCheck)
throws SQLException {
determineAutoIncrementFromResultSetMetaData(getConnection(), table, columnsToCheck, ":");
}

@Override
public Collection readIndices(DatabaseMetaDataWrapper metaData, String tableName)
Expand Down
Expand Up @@ -2,13 +2,10 @@

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;

import org.jumpmind.symmetric.ddl.Platform;
import org.jumpmind.symmetric.ddl.model.Column;
import org.jumpmind.symmetric.ddl.model.Table;
import org.jumpmind.symmetric.ddl.platform.DatabaseMetaDataWrapper;
import org.jumpmind.symmetric.ddl.platform.JdbcModelReader;
Expand Down Expand Up @@ -76,66 +73,4 @@ protected boolean doesMatch(Table table, String catalogName, String schemaName,
}
}

public void determineAutoIncrementFromResultSetMetaData(Connection conn, Table table,
final Column columnsToCheck[]) throws SQLException {
determineAutoIncrementFromResultSetMetaData(conn, table, columnsToCheck, ".");
}

/**
* Fix problems following problems: 1) identifiers that use keywords 2)
* different catalog and schema 3) different catalog separator character
*/
public void determineAutoIncrementFromResultSetMetaData(Connection conn, Table table,
final Column columnsToCheck[], String catalogSeparator) throws SQLException {
if (columnsToCheck == null || columnsToCheck.length == 0) {
return;
}
StringBuilder query = new StringBuilder();
query.append("SELECT ");
for (int idx = 0; idx < columnsToCheck.length; idx++) {
if (idx > 0) {
query.append(",");
}
query.append("t.");
appendIdentifier(query, columnsToCheck[idx].getName());
}
query.append(" FROM ");

if (table.getCatalog() != null && !table.getCatalog().trim().equals("")) {
appendIdentifier(query, table.getCatalog());
query.append(catalogSeparator);
}
if (table.getSchema() != null && !table.getSchema().trim().equals("")) {
appendIdentifier(query, table.getSchema()).append(".");
}
appendIdentifier(query, table.getName()).append(" t WHERE 1 = 0");

Statement stmt = null;
try {
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query.toString());
ResultSetMetaData rsMetaData = rs.getMetaData();

for (int idx = 0; idx < columnsToCheck.length; idx++) {
if (rsMetaData.isAutoIncrement(idx + 1)) {
columnsToCheck[idx].setAutoIncrement(true);
}
}
} finally {
if (stmt != null) {
stmt.close();
}
}
}

public StringBuilder appendIdentifier(StringBuilder query, String identifier) {
if (getPlatform().isDelimitedIdentifierModeOn()) {
query.append(getPlatformInfo().getDelimiterToken());
}
query.append(identifier);
if (getPlatform().isDelimitedIdentifierModeOn()) {
query.append(getPlatformInfo().getDelimiterToken());
}
return query;
}
}

0 comments on commit 593fe96

Please sign in to comment.