Skip to content

Commit

Permalink
Fixed 0000826: Support oracle's raw datatype as a PK
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Feb 4, 2014
1 parent cbfdfe4 commit e450023
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 40 deletions.
Expand Up @@ -775,5 +775,9 @@ public Database readDatabaseFromXml(InputStream is, boolean alterCaseToMatchData
return database;

}

public boolean canColumnBeUsedInWhereClause(Column column) {
return true;
}

}
Expand Up @@ -39,12 +39,6 @@ public class DatabaseInfo {
/** The Log to which logging calls will be made. */
private final Logger log = LoggerFactory.getLogger(DatabaseInfo.class);

/**
* Indicate whether a blob column will match when used in a SQL where
* clause.
*/
private boolean blobsWorkInWhereClause = true;

/**
* Whether the database requires the explicit stating of NULL as the default
* value.
Expand Down Expand Up @@ -1251,14 +1245,6 @@ public boolean isRequiresAutoCommitForDdl() {
return requiresAutoCommitForDdl;
}

public boolean isBlobsWorkInWhereClause() {
return blobsWorkInWhereClause;
}

public void setBlobsWorkInWhereClause(boolean blobsWorkInWhereClause) {
this.blobsWorkInWhereClause = blobsWorkInWhereClause;
}

public void setRequiresSavePointsInTransaction(boolean requiresSavePointsInTransaction) {
this.requiresSavePointsInTransaction = requiresSavePointsInTransaction;
}
Expand Down
Expand Up @@ -172,4 +172,7 @@ public Object[] getObjectValues(BinaryEncoding encoding, String[] values,
public java.util.Date parseDate(int type, String value, boolean useVariableDates);

public Table makeAllColumnsPrimaryKeys(Table table);

public boolean canColumnBeUsedInWhereClause(Column column);

}
Expand Up @@ -48,8 +48,6 @@ public class Db2DdlBuilder extends AbstractDdlBuilder {
public Db2DdlBuilder() {
super(DatabaseNamesConstants.DB2);

// the BINARY types are also handled by Db2Builder.getSqlType(Column)
databaseInfo.setBlobsWorkInWhereClause(false);
databaseInfo.addNativeTypeMapping(Types.ARRAY, "BLOB", Types.BLOB);
databaseInfo.addNativeTypeMapping(Types.BINARY, "CHAR {0} FOR BIT DATA");
databaseInfo.addNativeTypeMapping(Types.BIT, "SMALLINT", Types.SMALLINT);
Expand Down
Expand Up @@ -44,7 +44,6 @@ public DerbyDdlBuilder() {

databaseInfo.setMaxIdentifierLength(128);
databaseInfo.setSystemForeignKeyIndicesAlwaysNonUnique(true);
databaseInfo.setBlobsWorkInWhereClause(false);
databaseInfo.addNativeTypeMapping(Types.ARRAY, "BLOB", Types.BLOB);
databaseInfo.addNativeTypeMapping(Types.BINARY, "CHAR {0} FOR BIT DATA");
databaseInfo.addNativeTypeMapping(Types.BIT, "SMALLINT", Types.SMALLINT);
Expand Down
Expand Up @@ -70,7 +70,6 @@ public MsSqlDdlBuilder() {
super(DatabaseNamesConstants.MSSQL);

databaseInfo.setMaxIdentifierLength(128);
databaseInfo.setBlobsWorkInWhereClause(false);
databaseInfo.addNativeTypeMapping(Types.ARRAY, "IMAGE", Types.LONGVARBINARY);
// BIGINT will be mapped back to BIGINT by the model reader
databaseInfo.addNativeTypeMapping(Types.BIGINT, "DECIMAL(19,0)");
Expand Down
Expand Up @@ -59,7 +59,6 @@ public OracleDdlBuilder() {

databaseInfo.setMaxIdentifierLength(30);
databaseInfo.setIdentityStatusReadingSupported(false);
databaseInfo.setBlobsWorkInWhereClause(false);

// Note that the back-mappings are partially done by the model reader,
// not the driver
Expand Down
Expand Up @@ -586,24 +586,22 @@ protected LoadStatus delete(CsvData data, boolean useConflictDetection) {
lookupKeys = targetTable.getColumnsAsList();
}

int lookupKeyCountBeforeLobRemoval = lookupKeys.size();

if (!platform.getDatabaseInfo().isBlobsWorkInWhereClause()
|| data.isNoBinaryOldData()) {
Iterator<Column> it = lookupKeys.iterator();
while (it.hasNext()) {
Column col = it.next();
if (col.isOfBinaryType()) {
it.remove();
}
int lookupKeyCountBeforeColumnRemoval = lookupKeys.size();

Iterator<Column> it = lookupKeys.iterator();
while (it.hasNext()) {
Column col = it.next();
if ((col.isOfBinaryType() && data.isNoBinaryOldData())
|| !platform.canColumnBeUsedInWhereClause(col)) {
it.remove();
}
}

if (lookupKeys.size() == 0) {
String msg = "There are no keys defined for "
+ targetTable.getFullyQualifiedTableName()
+ ". Cannot build an update statement. ";
if (lookupKeyCountBeforeLobRemoval > 0) {
if (lookupKeyCountBeforeColumnRemoval > 0) {
msg += "The only keys defined are binary and they have been removed.";
}
throw new IllegalStateException(msg);
Expand Down Expand Up @@ -735,24 +733,22 @@ protected LoadStatus update(CsvData data, boolean applyChangesOnly, boolean useC
lookupKeys = targetTable.getColumnsAsList();
}

int lookupKeyCountBeforeLobRemoval = lookupKeys.size();
int lookupKeyCountBeforeColumnRemoval = lookupKeys.size();

if (!platform.getDatabaseInfo().isBlobsWorkInWhereClause()
|| data.isNoBinaryOldData()) {
Iterator<Column> it = lookupKeys.iterator();
while (it.hasNext()) {
Column col = it.next();
if (col.isOfBinaryType()) {
it.remove();
}
Iterator<Column> it = lookupKeys.iterator();
while (it.hasNext()) {
Column col = it.next();
if ((col.isOfBinaryType() && data.isNoBinaryOldData())
|| !platform.canColumnBeUsedInWhereClause(col)) {
it.remove();
}
}

if (lookupKeys.size() == 0) {
String msg = "There are no keys defined for "
+ targetTable.getFullyQualifiedTableName()
+ ". Cannot build an update statement. ";
if (lookupKeyCountBeforeLobRemoval > 0) {
if (lookupKeyCountBeforeColumnRemoval > 0) {
msg += "The only keys defined are binary and they have been removed.";
}
throw new IllegalStateException(msg);
Expand Down
Expand Up @@ -22,6 +22,7 @@
import javax.sql.DataSource;

import org.apache.commons.lang.StringUtils;
import org.jumpmind.db.model.Column;
import org.jumpmind.db.platform.AbstractJdbcDatabasePlatform;
import org.jumpmind.db.platform.DatabaseNamesConstants;
import org.jumpmind.db.sql.SqlTemplateSettings;
Expand Down Expand Up @@ -74,4 +75,9 @@ public String getDefaultCatalog() {
return "";
}

@Override
public boolean canColumnBeUsedInWhereClause(Column column) {
return !column.isOfBinaryType();
}

}
Expand Up @@ -24,6 +24,7 @@
import javax.sql.DataSource;

import org.apache.commons.lang.StringUtils;
import org.jumpmind.db.model.Column;
import org.jumpmind.db.platform.AbstractJdbcDatabasePlatform;
import org.jumpmind.db.platform.DatabaseNamesConstants;
import org.jumpmind.db.sql.SqlTemplateSettings;
Expand Down Expand Up @@ -83,5 +84,10 @@ public String getDefaultCatalog() {
public boolean isClob(int type) {
return type == Types.CLOB;
}

@Override
public boolean canColumnBeUsedInWhereClause(Column column) {
return !column.isOfBinaryType();
}

}
Expand Up @@ -22,6 +22,7 @@
import javax.sql.DataSource;

import org.apache.commons.lang.StringUtils;
import org.jumpmind.db.model.Column;
import org.jumpmind.db.platform.AbstractJdbcDatabasePlatform;
import org.jumpmind.db.platform.DatabaseNamesConstants;
import org.jumpmind.db.sql.SqlTemplateSettings;
Expand Down Expand Up @@ -93,4 +94,9 @@ public boolean isClob(int type) {
type == -10;
}

@Override
public boolean canColumnBeUsedInWhereClause(Column column) {
return !column.isOfBinaryType();
}

}
Expand Up @@ -22,6 +22,7 @@
import javax.sql.DataSource;

import org.apache.commons.lang.StringUtils;
import org.jumpmind.db.model.Column;
import org.jumpmind.db.platform.AbstractJdbcDatabasePlatform;
import org.jumpmind.db.platform.DatabaseNamesConstants;
import org.jumpmind.db.sql.JdbcUtils;
Expand Down Expand Up @@ -92,5 +93,11 @@ public String getDefaultSchema() {
}
return defaultSchema;
}

@Override
public boolean canColumnBeUsedInWhereClause(Column column) {
String jdbcTypeName = column.getJdbcTypeName();
return !column.isOfBinaryType() || "RAW".equals(jdbcTypeName);
}

}

0 comments on commit e450023

Please sign in to comment.