Author: mes
Date: 2012-05-30 14:27:32 -0700 (Wed, 30 May 2012)
New Revision: 29400
Modified:
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/VirtualColumn.java
Log:
fixes #965 Now not creating new rows for non-existent rows accessed through
virtual columns.
Modified:
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
===================================================================
---
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
2012-05-30 21:12:16 UTC (rev 29399)
+++
core3/api/trunk/model-api/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
2012-05-30 21:27:32 UTC (rev 29400)
@@ -628,6 +628,26 @@
}
@Test
+ public void testVirtualColumnGetNoCreate() {
+ table2.createColumn("s", String.class, false);
+
+ // make sure we don't start with any rows
+ assertEquals(0,table2.getAllRows().size());
+
+ table.addVirtualColumn("s1", "s", table2,
table.getPrimaryKey().getName(), false);
+ CyRow row1 = table.getRow(1L);
+
+ // Since there is no row (or data) in table2, this
+ // should return null.
+ assertNull(row1.get("s1", String.class));
+
+ // Getting data through a virtual column shouldn't create a row
in
+ // the target table when no matching row exists, so there should
+ // still be 0 rows.
+ assertEquals(0,table2.getAllRows().size());
+ }
+
+ @Test
public void testVirtualColumnSetWithAReplacementValue() {
CyRow row1 = table.getRow(1L);
CyRow row2 = table2.getRow(1L);
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
2012-05-30 21:12:16 UTC (rev 29399)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
2012-05-30 21:27:32 UTC (rev 29400)
@@ -462,6 +462,16 @@
return l;
}
+ // Used in virtual columns so that we don't create new rows in tables
+ // that are only being referenced. We expect it to return null.
+ CyRow getRowNoCreate(final Object key) {
+ checkKey(key);
+
+ synchronized(this) {
+ return rows.get(key);
+ }
+ }
+
@Override
public CyRow getRow(final Object key) {
checkKey(key);
@@ -471,11 +481,9 @@
row = rows.get(key);
if (row != null)
return row;
-
-
+
row = new InternalRow(key);
rows.put(key, row);
-
}
if (fireEvents)
@@ -921,7 +929,7 @@
targetName = getUniqueColumnName(virtualColumnName);
final String normalizedTargetName =
normalizeColumnName(targetName);
types.put(normalizedTargetName, targetColumn);
- virtualColumnMap.put(normalizedTargetName, new
VirtualColumn(sourceTable, sourceColumnName, this,
+ virtualColumnMap.put(normalizedTargetName, new
VirtualColumn((CyTableImpl)sourceTable, sourceColumnName, this,
sourceTable.getPrimaryKey().getName(),
targetJoinKeyName));
}
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/VirtualColumn.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/VirtualColumn.java
2012-05-30 21:12:16 UTC (rev 29399)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/VirtualColumn.java
2012-05-30 21:27:32 UTC (rev 29400)
@@ -43,13 +43,13 @@
final class VirtualColumn {
- private final CyTable sourceTable;
+ private final CyTableImpl sourceTable;
private final CyColumn sourceColumn;
private final CyTableImpl targetTable;
private final CyColumn sourceJoinColumn;
private final CyColumn targetJoinColumn;
- VirtualColumn(final CyTable sourceTable, final String sourceColumnName,
+ VirtualColumn(final CyTableImpl sourceTable, final String
sourceColumnName,
final CyTableImpl targetTable, final String
sourceJoinColumnName,
final String targetJoinColumnName)
{
@@ -100,7 +100,7 @@
final Object joinKey = targetTable.getValue(targetKey,
targetJoinColumn.getName());
if (joinKey == null)
return null;
- return sourceTable.getRow(joinKey);
+ return sourceTable.getRowNoCreate(joinKey);
/*
final Collection<CyRow> sourceRows =
sourceTable.getMatchingRows(sourceJoinColumn.getName(),
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.