|
|
|
|
@ -36,7 +36,7 @@ import org.springframework.lang.Nullable;
@@ -36,7 +36,7 @@ import org.springframework.lang.Nullable;
|
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Class to manage context metadata used for the configuration |
|
|
|
|
* Class to manage context meta-data used for the configuration |
|
|
|
|
* and execution of operations on a database table. |
|
|
|
|
* |
|
|
|
|
* @author Thomas Risberg |
|
|
|
|
@ -63,13 +63,13 @@ public class TableMetaDataContext {
@@ -63,13 +63,13 @@ public class TableMetaDataContext {
|
|
|
|
|
// List of columns objects to be used in this context
|
|
|
|
|
private List<String> tableColumns = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
// Should we access insert parameter meta data info or not
|
|
|
|
|
// Should we access insert parameter meta-data info or not
|
|
|
|
|
private boolean accessTableColumnMetaData = true; |
|
|
|
|
|
|
|
|
|
// Should we override default for including synonyms for meta data lookups
|
|
|
|
|
// Should we override default for including synonyms for meta-data lookups
|
|
|
|
|
private boolean overrideIncludeSynonymsDefault = false; |
|
|
|
|
|
|
|
|
|
// The provider of table meta data
|
|
|
|
|
// The provider of table meta-data
|
|
|
|
|
@Nullable |
|
|
|
|
private TableMetaDataProvider metaDataProvider; |
|
|
|
|
|
|
|
|
|
@ -123,14 +123,14 @@ public class TableMetaDataContext {
@@ -123,14 +123,14 @@ public class TableMetaDataContext {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Specify whether we should access table column meta data. |
|
|
|
|
* Specify whether we should access table column meta-data. |
|
|
|
|
*/ |
|
|
|
|
public void setAccessTableColumnMetaData(boolean accessTableColumnMetaData) { |
|
|
|
|
this.accessTableColumnMetaData = accessTableColumnMetaData; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Are we accessing table meta data? |
|
|
|
|
* Are we accessing table meta-data? |
|
|
|
|
*/ |
|
|
|
|
public boolean isAccessTableColumnMetaData() { |
|
|
|
|
return this.accessTableColumnMetaData; |
|
|
|
|
@ -160,7 +160,7 @@ public class TableMetaDataContext {
@@ -160,7 +160,7 @@ public class TableMetaDataContext {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Process the current meta data with the provided configuration options. |
|
|
|
|
* Process the current meta-data with the provided configuration options. |
|
|
|
|
* @param dataSource the DataSource being used |
|
|
|
|
* @param declaredColumns any columns that are declared |
|
|
|
|
* @param generatedKeyNames name of generated keys |
|
|
|
|
@ -176,7 +176,7 @@ public class TableMetaDataContext {
@@ -176,7 +176,7 @@ public class TableMetaDataContext {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Compare columns created from metadata with declared columns and return a reconciled list. |
|
|
|
|
* Compare columns created from meta-data with declared columns and return a reconciled list. |
|
|
|
|
* @param declaredColumns declared column names |
|
|
|
|
* @param generatedKeyNames names of generated key columns |
|
|
|
|
*/ |
|
|
|
|
@ -207,7 +207,7 @@ public class TableMetaDataContext {
@@ -207,7 +207,7 @@ public class TableMetaDataContext {
|
|
|
|
|
public List<Object> matchInParameterValuesWithInsertColumns(SqlParameterSource parameterSource) { |
|
|
|
|
List<Object> values = new ArrayList<>(); |
|
|
|
|
// For parameter source lookups we need to provide case-insensitive lookup support since the
|
|
|
|
|
// database metadata is not necessarily providing case-sensitive column names
|
|
|
|
|
// database meta-data is not necessarily providing case-sensitive column names
|
|
|
|
|
Map<String, String> caseInsensitiveParameterNames = |
|
|
|
|
SqlParameterSourceUtils.extractCaseInsensitiveParameterNames(parameterSource); |
|
|
|
|
for (String column : this.tableColumns) { |
|
|
|
|
@ -257,7 +257,7 @@ public class TableMetaDataContext {
@@ -257,7 +257,7 @@ public class TableMetaDataContext {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Build the insert string based on configuration and metadata information |
|
|
|
|
* Build the insert string based on configuration and meta-data information |
|
|
|
|
* @return the insert string to be used |
|
|
|
|
*/ |
|
|
|
|
public String createInsertString(String... generatedKeyNames) { |
|
|
|
|
@ -305,14 +305,13 @@ public class TableMetaDataContext {
@@ -305,14 +305,13 @@ public class TableMetaDataContext {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Build the array of {@link java.sql.Types} based on configuration and metadata information |
|
|
|
|
* Build the array of {@link java.sql.Types} based on configuration and meta-data information. |
|
|
|
|
* @return the array of types to be used |
|
|
|
|
*/ |
|
|
|
|
public int[] createInsertTypes() { |
|
|
|
|
int[] types = new int[getTableColumns().size()]; |
|
|
|
|
List<TableParameterMetaData> parameters = obtainMetaDataProvider().getTableParameterMetaData(); |
|
|
|
|
Map<String, TableParameterMetaData> parameterMap = |
|
|
|
|
new LinkedHashMap<>(parameters.size()); |
|
|
|
|
Map<String, TableParameterMetaData> parameterMap = new LinkedHashMap<>(parameters.size()); |
|
|
|
|
for (TableParameterMetaData tpmd : parameters) { |
|
|
|
|
parameterMap.put(tpmd.getParameterName().toUpperCase(), tpmd); |
|
|
|
|
} |
|
|
|
|
@ -337,7 +336,7 @@ public class TableMetaDataContext {
@@ -337,7 +336,7 @@ public class TableMetaDataContext {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Does this database support the JDBC 3.0 feature of retrieving generated keys |
|
|
|
|
* Does this database support the JDBC 3.0 feature of retrieving generated keys: |
|
|
|
|
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}? |
|
|
|
|
*/ |
|
|
|
|
public boolean isGetGeneratedKeysSupported() { |
|
|
|
|
@ -346,7 +345,7 @@ public class TableMetaDataContext {
@@ -346,7 +345,7 @@ public class TableMetaDataContext {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Does this database support simple query to retrieve generated keys |
|
|
|
|
* when the JDBC 3.0 feature is not supported. |
|
|
|
|
* when the JDBC 3.0 feature is not supported: |
|
|
|
|
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}? |
|
|
|
|
*/ |
|
|
|
|
public boolean isGetGeneratedKeysSimulated() { |
|
|
|
|
@ -354,17 +353,26 @@ public class TableMetaDataContext {
@@ -354,17 +353,26 @@ public class TableMetaDataContext {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Does this database support simple query to retrieve generated keys |
|
|
|
|
* when the JDBC 3.0 feature is not supported. |
|
|
|
|
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}? |
|
|
|
|
* @deprecated as of 4.3.15, in favor of {@link #getSimpleQueryForGetGeneratedKey} |
|
|
|
|
*/ |
|
|
|
|
@Deprecated |
|
|
|
|
@Nullable |
|
|
|
|
public String getSimulationQueryForGetGeneratedKey(String tableName, String keyColumnName) { |
|
|
|
|
return getSimpleQueryForGetGeneratedKey(tableName, keyColumnName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Does this database support a simple query to retrieve generated keys |
|
|
|
|
* when the JDBC 3.0 feature is not supported: |
|
|
|
|
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}? |
|
|
|
|
*/ |
|
|
|
|
@Nullable |
|
|
|
|
public String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) { |
|
|
|
|
return obtainMetaDataProvider().getSimpleQueryForGetGeneratedKey(tableName, keyColumnName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Is a column name String array for retrieving generated keys supported? |
|
|
|
|
* Is a column name String array for retrieving generated keys supported: |
|
|
|
|
* {@link java.sql.Connection#createStruct(String, Object[])}? |
|
|
|
|
*/ |
|
|
|
|
public boolean isGeneratedKeysColumnNameArraySupported() { |
|
|
|
|
|