diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2013-11-13 23:12:40 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2013-11-13 23:12:40 +0000 |
commit | 1b850aa21fad8d3abe3c51373612f0f2d4558041 (patch) | |
tree | b33a971a8753abf563726ff1f51320fc9bf94a15 /src/main/java/com/healthmarketscience | |
parent | 0f766b14c3b9a5382a4d69b82c422ff8a277c3a6 (diff) | |
download | jackcess-1b850aa21fad8d3abe3c51373612f0f2d4558041.tar.gz jackcess-1b850aa21fad8d3abe3c51373612f0f2d4558041.zip |
Add ConstraintViolationException to distinguish exceptions due to violating database constraints from other random errors.
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@835 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/main/java/com/healthmarketscience')
3 files changed, 52 insertions, 8 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/ConstraintViolationException.java b/src/main/java/com/healthmarketscience/jackcess/ConstraintViolationException.java new file mode 100644 index 0000000..c558622 --- /dev/null +++ b/src/main/java/com/healthmarketscience/jackcess/ConstraintViolationException.java @@ -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); + } +} + diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/FKEnforcer.java b/src/main/java/com/healthmarketscience/jackcess/impl/FKEnforcer.java index e2b1156..0eca86b 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/FKEnforcer.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/FKEnforcer.java @@ -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()); } } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/IndexData.java b/src/main/java/com/healthmarketscience/jackcess/impl/IndexData.java index 0479395..3aaf579 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/IndexData.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/IndexData.java @@ -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); |