01: /*
02: * Copyright 2006 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package com.ibatis.sqlmap.engine.execution;
17:
18: import java.sql.BatchUpdateException;
19: import java.util.List;
20:
21: /**
22: * This exception is thrown if a <code>java.sql.BatchUpdateException</code> is caught
23: * during the execution of any nested batch. The exception contains the
24: * java.sql.BatchUpdateException that is the root cause, as well as
25: * the results from any prior nested batch that executed successfully. This exception
26: * is only thrown from the executeBatchDetailed method.
27: *
28: * @author Jeff Butler
29: *
30: */
31: public class BatchException extends Exception {
32:
33: private List successfulBatchResults;
34: private BatchUpdateException batchUpdateException;
35: private String failingSqlStatement;
36: private String failingStatementId;
37:
38: /**
39: *
40: */
41: public BatchException(String message, BatchUpdateException cause,
42: List successfulBatchResults, String failingStatementId,
43: String failingSqlStatement) {
44: super (message, cause);
45: this .batchUpdateException = cause;
46: this .successfulBatchResults = successfulBatchResults;
47: this .failingStatementId = failingStatementId;
48: this .failingSqlStatement = failingSqlStatement;
49: }
50:
51: /**
52: * Returns the BatchUpdateException that caused the nested batch
53: * to fail. That exception contains an array of row counts
54: * that can be used to determine exactly which statemtn of the
55: * batch caused the failure (or failures).
56: *
57: * @return the root BatchUpdateException
58: */
59: public BatchUpdateException getBatchUpdateException() {
60: return batchUpdateException;
61: }
62:
63: /**
64: * Returns a list of BatchResult objects. There will be one entry
65: * in the list for each successful sub-batch executed before the failing
66: * batch.
67: *
68: * @return the previously successful batch results (may be an empty list
69: * if no batch has executed successfully)
70: */
71: public List getSuccessfulBatchResults() {
72: return successfulBatchResults;
73: }
74:
75: /**
76: * Returns the SQL statement that caused the failure
77: * (not the parameters)
78: *
79: * @return the failing SQL string
80: */
81: public String getFailingSqlStatement() {
82: return failingSqlStatement;
83: }
84:
85: /**
86: * Returns the statement id of the statement that caused the failure
87: *
88: * @return the statement id
89: */
90: public String getFailingStatementId() {
91: return failingStatementId;
92: }
93: }
|