Browse Source

Fix for #7434

svn changeset:20923/svn branch:6.7
tags/6.7.0.rc1
Jonatan Kronqvist 12 years ago
parent
commit
8c104cd1c5

+ 10
- 1
src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java View File

@@ -128,7 +128,7 @@ final public class ColumnProperty implements Property {
* If the value to be set is the same that has already been set, do
* not set it again.
*/
if (newValue.equals(value)) {
if (isValueAlreadySet(newValue)) {
return;
}
}
@@ -139,6 +139,15 @@ final public class ColumnProperty implements Property {
modified = true;
}

private boolean isValueAlreadySet(Object newValue) {
if (isModified()) {
return (isNullable() && newValue == null && changedValue == null)
|| newValue.equals(changedValue);
}
return (isNullable() && newValue == null && value == null)
|| newValue.equals(value);
}

public Class<?> getType() {
return type;
}

+ 24
- 4
tests/src/com/vaadin/tests/server/container/sqlcontainer/ColumnPropertyTest.java View File

@@ -11,7 +11,6 @@ import com.vaadin.data.util.sqlcontainer.ColumnProperty;
import com.vaadin.data.util.sqlcontainer.RowId;
import com.vaadin.data.util.sqlcontainer.RowItem;
import com.vaadin.data.util.sqlcontainer.SQLContainer;
import com.vaadin.data.util.sqlcontainer.ColumnProperty.NotNullableException;

public class ColumnPropertyTest {

@@ -56,7 +55,7 @@ public class ColumnPropertyTest {
Assert.assertEquals("Kalle", cp.getValue());
EasyMock.verify(container);
}
*/
*/

@Test(expected = ReadOnlyException.class)
public void setValue_readOnlyNullable_shouldFail() {
@@ -101,7 +100,7 @@ public class ColumnPropertyTest {
Assert.assertNotNull(cp.getValue());
EasyMock.verify(container);
}
*/
*/

@Test
public void getType_normal_returnsStringClass() {
@@ -165,7 +164,7 @@ public class ColumnPropertyTest {
Assert.assertTrue(cp.isModified());
EasyMock.verify(container);
}
*/
*/

@Test
public void isModified_valueNotModified_returnsFalse() {
@@ -174,4 +173,25 @@ public class ColumnPropertyTest {
Assert.assertFalse(cp.isModified());
}

@Test
public void setValue_nullOnNullable_shouldWork() {
ColumnProperty cp = new ColumnProperty("NAME", false, true, true,
"asdf", String.class);
SQLContainer container = EasyMock.createMock(SQLContainer.class);
new RowItem(container, new RowId(new Object[] { 1 }), Arrays.asList(cp));
cp.setValue(null);
Assert.assertNull(cp.getValue());
}

@Test
public void setValue_resetTonullOnNullable_shouldWork() {
ColumnProperty cp = new ColumnProperty("NAME", false, true, true, null,
String.class);
SQLContainer container = EasyMock.createMock(SQLContainer.class);
new RowItem(container, new RowId(new Object[] { 1 }), Arrays.asList(cp));
cp.setValue("asdf");
Assert.assertEquals("asdf", cp.getValue());
cp.setValue(null);
Assert.assertNull(cp.getValue());
}
}

+ 26
- 0
tests/src/com/vaadin/tests/server/container/sqlcontainer/TicketTests.java View File

@@ -13,6 +13,7 @@ import org.junit.Before;
import org.junit.Test;

import com.vaadin.data.Container.Filter;
import com.vaadin.data.Item;
import com.vaadin.data.util.filter.Compare.Equal;
import com.vaadin.data.util.sqlcontainer.SQLContainer;
import com.vaadin.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool;
@@ -154,4 +155,29 @@ public class TicketTests {
}
}

@Test
public void ticket7434_getItem_Modified_Changed_Unchanged()
throws SQLException {
SQLContainer container = new SQLContainer(new TableQuery("people",
connectionPool, AllTests.sqlGen));

Object id = container.firstItemId();
Item item = container.getItem(id);
String name = (String) item.getItemProperty("NAME").getValue();

// set a different name
item.getItemProperty("NAME").setValue("otherName");
Assert.assertEquals("otherName", item.getItemProperty("NAME")
.getValue());

// access the item and reset the name to its old value
Item item2 = container.getItem(id);
item2.getItemProperty("NAME").setValue(name);
Assert.assertEquals(name, item2.getItemProperty("NAME").getValue());

Item item3 = container.getItem(id);
String name3 = (String) item3.getItemProperty("NAME").getValue();

Assert.assertEquals(name, name3);
}
}

Loading…
Cancel
Save