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
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public void set(final String name, final Object value) {
throw new IllegalArgumentException(name);
}
try {
dynaClass.getResultSet().updateObject(name, value);
dynaClass.getResultSet().updateObject(dynaClass.getColumnName(name), value);
} catch (final SQLException e) {
throw new IllegalArgumentException("set(" + name + "): SQLException: " + e, e);
}
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/org/apache/commons/beanutils/DynaResultSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
package org.apache.commons.beanutils;

import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicReference;

import junit.framework.TestCase;

Expand Down Expand Up @@ -123,6 +126,28 @@ public void testGetName() {

}

/**
* With the default {@code lowerCase} option the property name differs from the real column name, and the read path resolves it through
* {@code getColumnName}. Verify that {@code set} resolves it the same way, so the update targets the real column name and not the lower-cased property
* name.
*/
public void testSetUsesColumnName() throws Exception {

final AtomicReference<String> updatedColumn = new AtomicReference<String>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rootvector2
In the future, you do not need the extra generics noise, you can simply say:

final AtomicReference<String> updatedColumn = new AtomicReference<>();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, I'll use the diamond going forward. thanks for merging this.

final ResultSet resultSet = TestResultSet.createProxy(new TestResultSet() {
@Override
public void updateObject(final String columnName, final Object value) throws SQLException {
updatedColumn.set(columnName);
}
});
final ResultSetDynaClass rsdc = new ResultSetDynaClass(resultSet);
final DynaBean row = rsdc.iterator().next();
row.set("stringproperty", "new value");
assertEquals("update targets the real column name",
"stringProperty", updatedColumn.get());

}

public void testIteratorCount() {

final Iterator<?> rows = dynaClass.iterator();
Expand Down
Loading