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 @@ -249,7 +249,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

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

import org.apache.commons.beanutils2.DynaBean;
import org.apache.commons.beanutils2.DynaProperty;
Expand Down Expand Up @@ -96,6 +99,26 @@ void testGetName() {
assertEquals("org.apache.commons.beanutils2.sql.ResultSetDynaClass", dynaClass.getName(), "DynaClass name");
}

/**
* 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.
*/
@Test
void testSetUsesColumnName() throws Exception {
final AtomicReference<String> updatedColumn = new AtomicReference<>();
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("stringProperty", updatedColumn.get(), "update targets the real column name");
}

@Test
void testIteratorCount() {

Expand Down
Loading