Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions api/src/org/labkey/api/data/StatementUtils.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@ public enum Operation {insert, update, merge}
// configuration parameters
private Operation _operation = Operation.insert;
private SqlDialect _dialect;
private TableInfo _table;
private TableInfo _targetTable;
private Set<String> _keyColumnNames = null; // override the primary key of _table
private Set<String> _skipColumnNames = null;
private Set<String> _dontUpdateColumnNames = new CaseInsensitiveHashSet();
Expand All@@ -97,7 +97,7 @@ public StatementUtils(@NotNull Operation op, @NotNull TableInfo table)
{
_operation = op;
_dialect = table.getSqlDialect();
_table = table;
_targetTable = table;
}

public StatementUtils dialect(SqlDialect dialect)
Expand DownExpand Up@@ -465,10 +465,10 @@ public void setObjectUriPreselect(SQLFragment sqlfPreselectObject, TableInfo tab

public ParameterMapStatement createStatement(Connection conn, @Nullable Container c, User user) throws SQLException
{
if (!(_table instanceof UpdateableTableInfo))
if (!(_targetTable instanceof UpdateableTableInfo))
throw new IllegalArgumentException("Table must be an UpdateableTableInfo");

UpdateableTableInfo updatable = (UpdateableTableInfo)_table;
UpdateableTableInfo updatable = (UpdateableTableInfo) _targetTable;
TableInfo table = updatable.getSchemaTableInfo();

if (table.getTableType() != DatabaseTableType.TABLE || null == table.getMetaDataName())
Expand DownExpand Up@@ -534,8 +534,17 @@ public ParameterMapStatement createStatement(Connection conn, @Nullable Containe
keys.put(col.getFieldKey(), col);
else
{
for (ColumnInfo pk : _table.getPkColumns())
keys.put(pk.getFieldKey(), pk);
// see 26661 and 41053
// NOTE: IMO we should not be using updatable.getPkColumns() here! If the caller doesn't want to use the
// 'real' PK from the SchemaTableInfo for update/merge, then the alternate keys should be explicitly specified
// using StatementUtils.keys()
for (String pkName : updatable.getPkColumnNames())
{
col = table.getColumn(pkName);
if (null == col)
throw new IllegalStateException("pk column not found: " + pkName);
keys.put(col.getFieldKey(), col);
}
}
}

Expand All@@ -550,8 +559,8 @@ public ParameterMapStatement createStatement(Connection conn, @Nullable Containe
SQLFragment sqlfObjectProperty = new SQLFragment();
SQLFragment sqlfDelete = new SQLFragment();

Domain domain = _table.getDomain();
DomainKind domainKind = _table.getDomainKind();
Domain domain = updatable.getDomain();
DomainKind domainKind = updatable.getDomainKind();
List<? extends DomainProperty> properties = Collections.emptyList();

boolean hasObjectURIColumn = objectURIColumnName != null && table.getColumn(objectURIColumnName) != null;
Expand Down
1 change: 1 addition & 0 deletions api/src/org/labkey/api/data/WrappedColumnInfo.java
Original file line numberDiff line numberDiff line change
Expand Up@@ -114,6 +114,7 @@ public SQLFragment getValueSql(String tableAlias)
@Override
public String getSelectName()
{
assert getParentTable() instanceof SchemaTableInfo : "Use getValueSql()";
return sourceColumnInfo.getSelectName();
}

Expand Down