expect invalid regexp in prefix/suffix and throw wrapped exception → better exit code
1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/SQLCommandNamed.java Wed Dec 25 16:38:05 2013 +0100
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/SQLCommandNamed.java Wed Dec 25 20:52:41 2013 +0100
1.3 @@ -28,6 +28,7 @@
1.4 import java.util.logging.Logger;
1.5 import java.util.regex.Matcher;
1.6 import java.util.regex.Pattern;
1.7 +import java.util.regex.PatternSyntaxException;
1.8
1.9 /**
1.10 *
1.11 @@ -53,9 +54,13 @@
1.12
1.13 @Override
1.14 public PreparedStatement prepareStatement(Connection c) throws SQLException {
1.15 - buildPattern();
1.16 - placeParametersAndUpdateQuery();
1.17 - logPossiblyMissingParameters();
1.18 + try {
1.19 + buildPattern();
1.20 + placeParametersAndUpdateQuery();
1.21 + logPossiblyMissingParameters();
1.22 + } catch (PatternSyntaxException e) {
1.23 + throw new SQLException("Name prefix „" + namePrefix + "“ or suffix „" + nameSuffix + "“ contain a wrong regular expression. " + e.getLocalizedMessage(), e);
1.24 + }
1.25 return c.prepareStatement(updatedQuery.toString());
1.26 }
1.27