_flags = fileFlags;
}
- @Override
public void update() throws IOException {
getComplexValueForeignKey().updateAttachment(this);
}
+ public void delete() throws IOException {
+ getComplexValueForeignKey().deleteAttachment(this);
+ }
+
@Override
public String toString()
{
return _typeCols;
}
- public int countValues(int complexValueFk)
- throws IOException
- {
+ public int countValues(int complexValueFk) throws IOException {
return getRawValues(complexValueFk,
Collections.singleton(_complexValFkCol.getName()))
.size();
{
return getRawValues(complexValueFk, null);
}
-
- public List<Map<String,Object>> getRawValues(int complexValueFk,
- Collection<String> columnNames)
+
+ private Iterator<Map<String,Object>> getComplexValFkIter(
+ int complexValueFk, Collection<String> columnNames)
throws IOException
{
if(_complexValIdCursor == null) {
.toIndexCursor();
}
+ return _complexValIdCursor.entryIterator(columnNames, complexValueFk);
+ }
+
+ public List<Map<String,Object>> getRawValues(int complexValueFk,
+ Collection<String> columnNames)
+ throws IOException
+ {
Iterator<Map<String,Object>> entryIter =
- _complexValIdCursor.entryIterator(columnNames, complexValueFk);
+ getComplexValFkIter(complexValueFk, columnNames);
if(!entryIter.hasNext()) {
return Collections.emptyList();
}
return values;
}
- public List<V> getValues(
- ComplexValueForeignKey complexValueFk)
+ public List<V> getValues(ComplexValueForeignKey complexValueFk)
throws IOException
{
List<Map<String,Object>> rawValues = getRawValues(complexValueFk.get());
return id;
}
- public void addValues(Collection<? extends V> values)
- throws IOException
- {
+ public void addValues(Collection<? extends V> values) throws IOException {
for(V value : values) {
addValue(value);
}
return id;
}
- public void updateValues(Collection<? extends V> values)
- throws IOException
- {
+ public void updateValues(Collection<? extends V> values) throws IOException {
for(V value : values) {
updateValue(value);
}
}
- private void updateRow(Integer id, Object[] row) throws IOException {
+ public void deleteRawValue(Map<String,Object> rawValue) throws IOException {
+ deleteRow((Integer)_pkCol.getRowValue(rawValue));
+ }
+
+ public void deleteValue(V value) throws IOException {
+ deleteRow(value.getId());
+ }
+
+ public void deleteValues(Collection<? extends V> values) throws IOException {
+ for(V value : values) {
+ deleteValue(value);
+ }
+ }
+
+ public void deleteAllValues(int complexValueFk) throws IOException {
+ Iterator<Map<String,Object>> entryIter =
+ getComplexValFkIter(complexValueFk, Collections.<String>emptySet());
+ try {
+ while(entryIter.hasNext()) {
+ entryIter.next();
+ entryIter.remove();
+ }
+ } catch(RuntimeException e) {
+ if(e.getCause() instanceof IOException) {
+ throw (IOException)e.getCause();
+ }
+ throw e;
+ }
+ }
+
+ public void deleteAllValues(ComplexValueForeignKey complexValueFk)
+ throws IOException
+ {
+ deleteAllValues(complexValueFk.get());
+ }
+
+ private void moveToRow(Integer id) throws IOException {
if(_pkCursor == null) {
_pkCursor = new CursorBuilder(_flatTable)
.setIndexByColumns(_pkCol)
if(!_pkCursor.findRowByEntry(id)) {
throw new IllegalArgumentException("Row with id " + id +
" does not exist");
- }
-
+ }
+ }
+
+ private void updateRow(Integer id, Object[] row) throws IOException {
+ moveToRow(id);
_pkCursor.updateCurrentRow(row);
}
+ private void deleteRow(Integer id) throws IOException {
+ moveToRow(id);
+ _pkCursor.deleteCurrentRow();
+ }
+
protected Object[] asRow(Object[] row, V value) {
int id = value.getId();
_pkCol.setRowValue(row, ((id != INVALID_ID) ? id : Column.AUTO_NUMBER));
Map<String,Object> rawValues)
throws IOException;
- protected static class ComplexValueImpl implements ComplexValue
+ protected static abstract class ComplexValueImpl implements ComplexValue
{
private int _id;
private ComplexValueForeignKey _complexValueFk;
public Column getColumn() {
return _complexValueFk.getColumn();
}
-
- public void update() throws IOException {
- throw new UnsupportedOperationException(
- "This column does not support value updates");
- }
@Override
public int hashCode() {
* Writes any updated data for this complex value to the database.
*/
public void update() throws IOException;
+
+ /**
+ * Deletes the data for this complex value from the database.
+ */
+ public void delete() throws IOException;
+
}
return attachment;
}
+ public Attachment deleteAttachment(Attachment attachment)
+ throws IOException
+ {
+ reset();
+ getAttachmentInfo().deleteValue(attachment);
+ return attachment;
+ }
+
public SingleValue addMultiValue(Object value)
throws IOException
{
return value;
}
+ public SingleValue deleteMultiValue(SingleValue value)
+ throws IOException
+ {
+ reset();
+ getMultiValueInfo().deleteValue(value);
+ return value;
+ }
+
public UnsupportedValue addUnsupportedValue(Map<String,Object> values)
throws IOException
{
return value;
}
+ public UnsupportedValue deleteUnsupportedValue(UnsupportedValue value)
+ throws IOException
+ {
+ reset();
+ getUnsupportedInfo().deleteValue(value);
+ return value;
+ }
+
+ public void deleteAllValues()
+ throws IOException
+ {
+ reset();
+ getComplexInfo().deleteAllValues(this);
+ }
+
private Object writeReplace() throws ObjectStreamException {
// if we are going to serialize this ComplexValueForeignKey, convert it
// back to a normal Integer (in case it is restored outside of the context
_value = value;
}
- @Override
public void update() throws IOException {
getComplexValueForeignKey().updateMultiValue(this);
}
+ public void delete() throws IOException {
+ getComplexValueForeignKey().deleteMultiValue(this);
+ }
+
@Override
public String toString()
{
getValues().put(columnName, value);
}
- @Override
public void update() throws IOException {
getComplexValueForeignKey().updateUnsupportedValue(this);
}
+ public void delete() throws IOException {
+ getComplexValueForeignKey().deleteUnsupportedValue(this);
+ }
+
@Override
public String toString()
{
/**
* Complex column info for a column which tracking the version history of an
* "append only" memo column.
+ * <p>
+ * Note, the strongly typed update/delete methods are <i>not</i> supported for
+ * version history columns (the data is supposed to be immutable). That said,
+ * the "raw" update/delete methods are supported for those that <i>really</i>
+ * want to muck with the version history data.
*
* @author James Ahlborn
*/
return ComplexDataType.VERSION_HISTORY;
}
+ @Override
+ public int updateValue(Version value) throws IOException {
+ throw new UnsupportedOperationException(
+ "This column does not support value updates");
+ }
+
+ @Override
+ public void deleteValue(Version value) throws IOException {
+ throw new UnsupportedOperationException(
+ "This column does not support value deletes");
+ }
+
+ @Override
+ public void deleteAllValues(int complexValueFk) throws IOException {
+ throw new UnsupportedOperationException(
+ "This column does not support value deletes");
+ }
+
@Override
protected List<Version> toValues(ComplexValueForeignKey complexValueFk,
List<Map<String,Object>> rawValues)
((id1 < id2) ? 1 : 0));
}
+ public void update() throws IOException {
+ throw new UnsupportedOperationException(
+ "This column does not support value updates");
+ }
+
+ public void delete() throws IOException {
+ throw new UnsupportedOperationException(
+ "This column does not support value deletes");
+ }
+
@Override
public String toString()
{
} catch(UnsupportedOperationException expected) {
// success
}
+
+ checkVersions(3, row3ValFk, "new-value",
+ "new-value", upTime,
+ "row3-memo-again", new Date(1315876965382L),
+ "row3-memo-revised", new Date(1315876953077L),
+ "row3-memo", new Date(1315876879126L));
+
+ try {
+ v.delete();
+ fail("UnsupportedOperationException should have been thrown");
+ } catch(UnsupportedOperationException expected) {
+ // success
+ }
+
+ checkVersions(3, row3ValFk, "new-value",
+ "new-value", upTime,
+ "row3-memo-again", new Date(1315876965382L),
+ "row3-memo-revised", new Date(1315876953077L),
+ "row3-memo", new Date(1315876879126L));
+
+ try {
+ v.getComplexValueForeignKey().deleteAllValues();
+ fail("UnsupportedOperationException should have been thrown");
+ } catch(UnsupportedOperationException expected) {
+ // success
+ }
+
+ checkVersions(3, row3ValFk, "new-value",
+ "new-value", upTime,
+ "row3-memo-again", new Date(1315876965382L),
+ "row3-memo-revised", new Date(1315876953077L),
+ "row3-memo", new Date(1315876879126L));
db.close();
}
assertEquals("xml", updated.getFileType());
assertEquals("some_data.xml", updated.getFileName());
assertTrue(Arrays.equals(newBytes, updated.getFileData()));
+
+ updated.delete();
+ checkAttachments(4, row4ValFk, "test_data2.txt");
+ row4ValFk.getAttachments().get(0).delete();
+ checkAttachments(4, row4ValFk);
+
+ assertTrue(cursor.findRow(t1.getColumn("id"), "row2"));
+ ComplexValueForeignKey row2ValFk = (ComplexValueForeignKey)
+ cursor.getCurrentRowValue(col);
+ row2ValFk.deleteAllValues();
+ checkAttachments(2, row2ValFk);
db.close();
}
v.set("value5");
v.update();
checkMultiValues(2, row2ValFk, "value1", "value4", "value5", "value3");
+
+ v.delete();
+ checkMultiValues(2, row2ValFk, "value1", "value4", "value3");
+ row2ValFk.getMultiValues().get(0).delete();
+ checkMultiValues(2, row2ValFk, "value4", "value3");
+ row2ValFk.getMultiValues().get(1).delete();
+ checkMultiValues(2, row2ValFk, "value4");
+ row2ValFk.getMultiValues().get(0).delete();
+ checkMultiValues(2, row2ValFk);
+
+ assertTrue(cursor.findRow(t1.getColumn("id"), "row3"));
+ ComplexValueForeignKey row3ValFk = (ComplexValueForeignKey)
+ cursor.getCurrentRowValue(col);
+ row3ValFk.deleteAllValues();
+ checkMultiValues(3, row3ValFk);
db.close();
}