aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2011-11-08 03:01:41 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2011-11-08 03:01:41 +0000
commiteaccccc1358f9af0214a48ba93c05df5b759d091 (patch)
tree3c5464d0c77e54989bde3396d912445b7547b15f /src/java/com
parent651986878ed45d0bd0f868044c272654407eb598 (diff)
downloadjackcess-eaccccc1358f9af0214a48ba93c05df5b759d091.tar.gz
jackcess-eaccccc1358f9af0214a48ba93c05df5b759d091.zip
implement complex value deletion
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@589 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java/com')
-rw-r--r--src/java/com/healthmarketscience/jackcess/complex/AttachmentColumnInfo.java5
-rw-r--r--src/java/com/healthmarketscience/jackcess/complex/ComplexColumnInfo.java87
-rw-r--r--src/java/com/healthmarketscience/jackcess/complex/ComplexValue.java6
-rw-r--r--src/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java31
-rw-r--r--src/java/com/healthmarketscience/jackcess/complex/MultiValueColumnInfo.java5
-rw-r--r--src/java/com/healthmarketscience/jackcess/complex/UnsupportedColumnInfo.java5
-rw-r--r--src/java/com/healthmarketscience/jackcess/complex/VersionHistoryColumnInfo.java33
7 files changed, 145 insertions, 27 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/complex/AttachmentColumnInfo.java b/src/java/com/healthmarketscience/jackcess/complex/AttachmentColumnInfo.java
index b86b9d1..5410e41 100644
--- a/src/java/com/healthmarketscience/jackcess/complex/AttachmentColumnInfo.java
+++ b/src/java/com/healthmarketscience/jackcess/complex/AttachmentColumnInfo.java
@@ -297,11 +297,14 @@ public class AttachmentColumnInfo extends ComplexColumnInfo<Attachment>
_flags = fileFlags;
}
- @Override
public void update() throws IOException {
getComplexValueForeignKey().updateAttachment(this);
}
+ public void delete() throws IOException {
+ getComplexValueForeignKey().deleteAttachment(this);
+ }
+
@Override
public String toString()
{
diff --git a/src/java/com/healthmarketscience/jackcess/complex/ComplexColumnInfo.java b/src/java/com/healthmarketscience/jackcess/complex/ComplexColumnInfo.java
index bcdaf9f..f9de56d 100644
--- a/src/java/com/healthmarketscience/jackcess/complex/ComplexColumnInfo.java
+++ b/src/java/com/healthmarketscience/jackcess/complex/ComplexColumnInfo.java
@@ -186,9 +186,7 @@ public abstract class ComplexColumnInfo<V extends ComplexValue>
return _typeCols;
}
- public int countValues(int complexValueFk)
- throws IOException
- {
+ public int countValues(int complexValueFk) throws IOException {
return getRawValues(complexValueFk,
Collections.singleton(_complexValFkCol.getName()))
.size();
@@ -199,9 +197,9 @@ public abstract class ComplexColumnInfo<V extends ComplexValue>
{
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) {
@@ -210,8 +208,15 @@ public abstract class ComplexColumnInfo<V extends ComplexValue>
.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();
}
@@ -224,8 +229,7 @@ public abstract class ComplexColumnInfo<V extends ComplexValue>
return values;
}
- public List<V> getValues(
- ComplexValueForeignKey complexValueFk)
+ public List<V> getValues(ComplexValueForeignKey complexValueFk)
throws IOException
{
List<Map<String,Object>> rawValues = getRawValues(complexValueFk.get());
@@ -262,9 +266,7 @@ public abstract class ComplexColumnInfo<V extends ComplexValue>
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);
}
@@ -282,15 +284,49 @@ public abstract class ComplexColumnInfo<V extends ComplexValue>
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)
@@ -300,11 +336,19 @@ public abstract class ComplexColumnInfo<V extends ComplexValue>
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));
@@ -355,7 +399,7 @@ public abstract class ComplexColumnInfo<V extends ComplexValue>
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;
@@ -391,11 +435,6 @@ public abstract class ComplexColumnInfo<V extends ComplexValue>
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() {
diff --git a/src/java/com/healthmarketscience/jackcess/complex/ComplexValue.java b/src/java/com/healthmarketscience/jackcess/complex/ComplexValue.java
index b2f7d8c..4e6f19a 100644
--- a/src/java/com/healthmarketscience/jackcess/complex/ComplexValue.java
+++ b/src/java/com/healthmarketscience/jackcess/complex/ComplexValue.java
@@ -63,4 +63,10 @@ public interface ComplexValue
* 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;
+
}
diff --git a/src/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java b/src/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java
index 843cc5e..d236afe 100644
--- a/src/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java
+++ b/src/java/com/healthmarketscience/jackcess/complex/ComplexValueForeignKey.java
@@ -213,6 +213,14 @@ public class ComplexValueForeignKey extends Number
return attachment;
}
+ public Attachment deleteAttachment(Attachment attachment)
+ throws IOException
+ {
+ reset();
+ getAttachmentInfo().deleteValue(attachment);
+ return attachment;
+ }
+
public SingleValue addMultiValue(Object value)
throws IOException
{
@@ -230,6 +238,14 @@ public class ComplexValueForeignKey extends Number
return value;
}
+ public SingleValue deleteMultiValue(SingleValue value)
+ throws IOException
+ {
+ reset();
+ getMultiValueInfo().deleteValue(value);
+ return value;
+ }
+
public UnsupportedValue addUnsupportedValue(Map<String,Object> values)
throws IOException
{
@@ -247,6 +263,21 @@ public class ComplexValueForeignKey extends Number
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
diff --git a/src/java/com/healthmarketscience/jackcess/complex/MultiValueColumnInfo.java b/src/java/com/healthmarketscience/jackcess/complex/MultiValueColumnInfo.java
index 61488c1..b1bec20 100644
--- a/src/java/com/healthmarketscience/jackcess/complex/MultiValueColumnInfo.java
+++ b/src/java/com/healthmarketscience/jackcess/complex/MultiValueColumnInfo.java
@@ -116,11 +116,14 @@ public class MultiValueColumnInfo extends ComplexColumnInfo<SingleValue>
_value = value;
}
- @Override
public void update() throws IOException {
getComplexValueForeignKey().updateMultiValue(this);
}
+ public void delete() throws IOException {
+ getComplexValueForeignKey().deleteMultiValue(this);
+ }
+
@Override
public String toString()
{
diff --git a/src/java/com/healthmarketscience/jackcess/complex/UnsupportedColumnInfo.java b/src/java/com/healthmarketscience/jackcess/complex/UnsupportedColumnInfo.java
index d362aa7..7275511 100644
--- a/src/java/com/healthmarketscience/jackcess/complex/UnsupportedColumnInfo.java
+++ b/src/java/com/healthmarketscience/jackcess/complex/UnsupportedColumnInfo.java
@@ -110,11 +110,14 @@ public class UnsupportedColumnInfo extends ComplexColumnInfo<UnsupportedValue>
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()
{
diff --git a/src/java/com/healthmarketscience/jackcess/complex/VersionHistoryColumnInfo.java b/src/java/com/healthmarketscience/jackcess/complex/VersionHistoryColumnInfo.java
index ba98708..8fc5622 100644
--- a/src/java/com/healthmarketscience/jackcess/complex/VersionHistoryColumnInfo.java
+++ b/src/java/com/healthmarketscience/jackcess/complex/VersionHistoryColumnInfo.java
@@ -31,6 +31,11 @@ import com.healthmarketscience.jackcess.Table;
/**
* 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
*/
@@ -89,6 +94,24 @@ public class VersionHistoryColumnInfo extends ComplexColumnInfo<Version>
}
@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)
throws IOException
@@ -200,6 +223,16 @@ public class VersionHistoryColumnInfo extends ComplexColumnInfo<Version>
((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()
{