]> source.dussan.org Git - jackcess.git/commitdiff
Add ConstraintViolationException to distinguish exceptions due to violating database...
authorJames Ahlborn <jtahlborn@yahoo.com>
Wed, 13 Nov 2013 23:12:40 +0000 (23:12 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Wed, 13 Nov 2013 23:12:40 +0000 (23:12 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@835 f203690c-595d-4dc9-a70b-905162fa7fd2

src/changes/changes.xml
src/main/java/com/healthmarketscience/jackcess/ConstraintViolationException.java [new file with mode: 0644]
src/main/java/com/healthmarketscience/jackcess/impl/FKEnforcer.java
src/main/java/com/healthmarketscience/jackcess/impl/IndexData.java

index 21173b89b10dc48f2c7986e7f4a9801605050f13..6a251c574690db2579be16717112ac98db960307 100644 (file)
@@ -4,6 +4,12 @@
     <author email="javajedi@users.sf.net">Tim McCune</author>
   </properties>
   <body>
+    <release version="2.0.2" date="TBD">
+      <action dev="jahlborn" type="update">
+        Add ConstraintViolationException to distinguish exceptions due to
+        violating database constraints from other random errors.
+      </action>
+    </release>
     <release version="2.0.1" date="2013-10-13">
       <action dev="jahlborn" type="add">
         Add initial support for creating/parsing ole content.
diff --git a/src/main/java/com/healthmarketscience/jackcess/ConstraintViolationException.java b/src/main/java/com/healthmarketscience/jackcess/ConstraintViolationException.java
new file mode 100644 (file)
index 0000000..c558622
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+Copyright (c) 2013 James Ahlborn
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+USA
+*/
+
+package com.healthmarketscience.jackcess;
+
+import java.io.IOException;
+
+/**
+ * IOException which indicates that the failure was caused by a database
+ * constraint violation.
+ *
+ * @author James Ahlborn
+ */
+public class ConstraintViolationException extends IOException 
+{
+  private static final long serialVersionUID = 20131113L;  
+  
+  public ConstraintViolationException(String msg) {
+    super(msg);
+  }
+}
+
index e2b11568bb63a42f4465b8994d0e4a549473cc75..0eca86b62878d18ded26b7c3e20609a01b206d36 100644 (file)
@@ -29,6 +29,7 @@ import java.util.Set;
 import java.util.TreeSet;
 
 import com.healthmarketscience.jackcess.Column;
+import com.healthmarketscience.jackcess.ConstraintViolationException;
 import com.healthmarketscience.jackcess.Index;
 import com.healthmarketscience.jackcess.IndexCursor;
 import com.healthmarketscience.jackcess.Row;
@@ -223,8 +224,9 @@ final class FKEnforcer
     // ensure that the relevant rows exist in the primary tables for which
     // this table is a secondary table.
     if(!joiner.hasRows(row)) {
-      throw new IOException("Adding new row " + Arrays.asList(row) + 
-                            " violates constraint " + joiner.toFKString());
+      throw new ConstraintViolationException(
+          "Adding new row " + Arrays.asList(row) + " violates constraint " +
+          joiner.toFKString());
     }
   }
 
@@ -234,8 +236,9 @@ final class FKEnforcer
     // ensure that no rows exist in the secondary table for which this table is
     // the primary table.
     if(joiner.hasRows(row)) {
-      throw new IOException("Removing old row " + Arrays.asList(row) + 
-                            " violates constraint " + joiner.toFKString());
+      throw new ConstraintViolationException(
+          "Removing old row " + Arrays.asList(row) + " violates constraint " +
+          joiner.toFKString());
     }
   }
 
index 047939583361de170f7da43ba2b47fa38cbbedeb..3aaf5799ee48f6c2d8eb93a29963a46ec10f0280 100644 (file)
@@ -38,8 +38,10 @@ import java.util.List;
 import java.util.Map;
 
 import com.healthmarketscience.jackcess.ColumnBuilder;
+import com.healthmarketscience.jackcess.ConstraintViolationException;
 import com.healthmarketscience.jackcess.Index;
 import com.healthmarketscience.jackcess.IndexBuilder;
+import com.healthmarketscience.jackcess.RuntimeIOException;
 import static com.healthmarketscience.jackcess.impl.ByteUtil.ByteStream;
 import static com.healthmarketscience.jackcess.impl.IndexCodes.*;
 import org.apache.commons.lang.builder.ToStringBuilder;
@@ -537,8 +539,9 @@ public class IndexData {
       return;
     }
     if(isBackingPrimaryKey() && (nullCount > 0)) {
-      throw new IOException("Null value found in row " + Arrays.asList(row)
-                            + " for primary key index " + this);
+      throw new ConstraintViolationException(
+          "Null value found in row " + Arrays.asList(row) +
+          " for primary key index " + this);
     }
     
     // make sure we've parsed the entries
@@ -578,7 +581,7 @@ public class IndexData {
           ((prevPos != null) &&
            newEntry.equalsEntryBytes(prevPos.getEntry())));
       if(isUnique() && !isNullEntry && isDupeEntry) {
-        throw new IOException(
+        throw new ConstraintViolationException(
             "New row " + Arrays.asList(row) +
             " violates uniqueness constraint for index " + this);
       }
@@ -863,7 +866,7 @@ public class IndexData {
       try {
         sb.append("entryCount", getEntryCount());
       } catch(IOException e) {
-        throw new RuntimeException(e);
+        throw new RuntimeIOException(e);
       }
     }
     sb.append("pageCache", _pageCache);