|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2014 the original author or authors. |
|
|
|
* Copyright 2002-2015 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
@ -202,7 +202,8 @@ public class TableMetaDataContext { |
|
|
|
* @param generatedKeyNames name of generated keys |
|
|
|
* @param generatedKeyNames name of generated keys |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void processMetaData(DataSource dataSource, List<String> declaredColumns, String[] generatedKeyNames) { |
|
|
|
public void processMetaData(DataSource dataSource, List<String> declaredColumns, String[] generatedKeyNames) { |
|
|
|
this.metaDataProvider = TableMetaDataProviderFactory.createMetaDataProvider(dataSource, this, this.nativeJdbcExtractor); |
|
|
|
this.metaDataProvider = |
|
|
|
|
|
|
|
TableMetaDataProviderFactory.createMetaDataProvider(dataSource, this, this.nativeJdbcExtractor); |
|
|
|
this.tableColumns = reconcileColumnsToUse(declaredColumns, generatedKeyNames); |
|
|
|
this.tableColumns = reconcileColumnsToUse(declaredColumns, generatedKeyNames); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -299,14 +300,14 @@ public class TableMetaDataContext { |
|
|
|
} |
|
|
|
} |
|
|
|
StringBuilder insertStatement = new StringBuilder(); |
|
|
|
StringBuilder insertStatement = new StringBuilder(); |
|
|
|
insertStatement.append("INSERT INTO "); |
|
|
|
insertStatement.append("INSERT INTO "); |
|
|
|
if (this.getSchemaName() != null) { |
|
|
|
if (getSchemaName() != null) { |
|
|
|
insertStatement.append(this.getSchemaName()); |
|
|
|
insertStatement.append(getSchemaName()); |
|
|
|
insertStatement.append("."); |
|
|
|
insertStatement.append("."); |
|
|
|
} |
|
|
|
} |
|
|
|
insertStatement.append(this.getTableName()); |
|
|
|
insertStatement.append(getTableName()); |
|
|
|
insertStatement.append(" ("); |
|
|
|
insertStatement.append(" ("); |
|
|
|
int columnCount = 0; |
|
|
|
int columnCount = 0; |
|
|
|
for (String columnName : this.getTableColumns()) { |
|
|
|
for (String columnName : getTableColumns()) { |
|
|
|
if (!keys.contains(columnName.toUpperCase())) { |
|
|
|
if (!keys.contains(columnName.toUpperCase())) { |
|
|
|
columnCount++; |
|
|
|
columnCount++; |
|
|
|
if (columnCount > 1) { |
|
|
|
if (columnCount > 1) { |
|
|
@ -319,11 +320,11 @@ public class TableMetaDataContext { |
|
|
|
if (columnCount < 1) { |
|
|
|
if (columnCount < 1) { |
|
|
|
if (this.generatedKeyColumnsUsed) { |
|
|
|
if (this.generatedKeyColumnsUsed) { |
|
|
|
logger.info("Unable to locate non-key columns for table '" + |
|
|
|
logger.info("Unable to locate non-key columns for table '" + |
|
|
|
this.getTableName() + "' so an empty insert statement is generated"); |
|
|
|
getTableName() + "' so an empty insert statement is generated"); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
throw new InvalidDataAccessApiUsageException("Unable to locate columns for table '" + |
|
|
|
throw new InvalidDataAccessApiUsageException("Unable to locate columns for table '" + |
|
|
|
this.getTableName() + "' so an insert statement can't be generated"); |
|
|
|
getTableName() + "' so an insert statement can't be generated"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for (int i = 0; i < columnCount; i++) { |
|
|
|
for (int i = 0; i < columnCount; i++) { |
|
|
@ -341,7 +342,7 @@ public class TableMetaDataContext { |
|
|
|
* @return the array of types to be used |
|
|
|
* @return the array of types to be used |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public int[] createInsertTypes() { |
|
|
|
public int[] createInsertTypes() { |
|
|
|
int[] types = new int[this.getTableColumns().size()]; |
|
|
|
int[] types = new int[getTableColumns().size()]; |
|
|
|
List<TableParameterMetaData> parameters = this.metaDataProvider.getTableParameterMetaData(); |
|
|
|
List<TableParameterMetaData> parameters = this.metaDataProvider.getTableParameterMetaData(); |
|
|
|
Map<String, TableParameterMetaData> parameterMap = |
|
|
|
Map<String, TableParameterMetaData> parameterMap = |
|
|
|
new LinkedHashMap<String, TableParameterMetaData>(parameters.size()); |
|
|
|
new LinkedHashMap<String, TableParameterMetaData>(parameters.size()); |
|
|
@ -349,7 +350,7 @@ public class TableMetaDataContext { |
|
|
|
parameterMap.put(tpmd.getParameterName().toUpperCase(), tpmd); |
|
|
|
parameterMap.put(tpmd.getParameterName().toUpperCase(), tpmd); |
|
|
|
} |
|
|
|
} |
|
|
|
int typeIndx = 0; |
|
|
|
int typeIndx = 0; |
|
|
|
for (String column : this.getTableColumns()) { |
|
|
|
for (String column : getTableColumns()) { |
|
|
|
if (column == null) { |
|
|
|
if (column == null) { |
|
|
|
types[typeIndx] = SqlTypeValue.TYPE_UNKNOWN; |
|
|
|
types[typeIndx] = SqlTypeValue.TYPE_UNKNOWN; |
|
|
|
} |
|
|
|
} |
|
|
|