From bdbb9ad427b9849a4a37578ad850d68323501309 Mon Sep 17 00:00:00 2001 From: mdb Date: Thu, 1 Mar 2001 22:59:51 +0000 Subject: [PATCH] Added isDuplicateRowException() for determining whether or not an exception was caused by inserting a duplicate row into a table that disallows such actions. git-svn-id: https://samskivert.googlecode.com/svn/trunk@63 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/jdbc/MySQLRepository.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/jdbc/MySQLRepository.java b/projects/samskivert/src/java/com/samskivert/jdbc/MySQLRepository.java index b27ef135..2683cd3f 100644 --- a/projects/samskivert/src/java/com/samskivert/jdbc/MySQLRepository.java +++ b/projects/samskivert/src/java/com/samskivert/jdbc/MySQLRepository.java @@ -1,5 +1,5 @@ // -// $Id: MySQLRepository.java,v 1.1 2001/02/13 00:25:14 mdb Exp $ +// $Id: MySQLRepository.java,v 1.2 2001/03/01 22:59:51 mdb Exp $ package com.samskivert.jdbc; @@ -38,4 +38,18 @@ public abstract class MySQLRepository extends Repository return -1; } } + + /** + * Determines whether or not the supplied SQL exception originated + * from a duplicate row error. + * + * @return true if the exception was thrown because a duplicate row + * was inserted into a table that does not allow such things, false if + * the exception is not related to duplicate rows. + */ + protected boolean isDuplicateRowException (SQLException sqe) + { + String msg = sqe.getMessage(); + return (msg != null && msg.indexOf("Duplicate entry") != -1); + } }