Added files and folders for TARGET_JVM code base
[mono.git] / mcs / class / System.Data / System.Data.ProviderBase.jvm / AbstractDbException.cs
1 /*\r
2   * Copyright (c) 2002-2004 Mainsoft Corporation.\r
3   *\r
4   * Permission is hereby granted, free of charge, to any person obtaining a\r
5   * copy of this software and associated documentation files (the "Software"),\r
6   * to deal in the Software without restriction, including without limitation\r
7   * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
8   * and/or sell copies of the Software, and to permit persons to whom the\r
9   * Software is furnished to do so, subject to the following conditions:\r
10   *\r
11   * The above copyright notice and this permission notice shall be included in\r
12   * all copies or substantial portions of the Software.\r
13   *\r
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
19   * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
20   * DEALINGS IN THE SOFTWARE.\r
21   */\r
22 \r
23 \r
24 namespace System.Data.ProviderBase {\r
25 \r
26         using java.sql;\r
27         using System.Text;\r
28         using System.Data.Common;\r
29 \r
30         /*\r
31         * CURRENT LIMITATIONS\r
32         * 1. Constructor for serialization SqlException(SerializationInfo info, StreamingContext sc) \r
33         *    is not supported.\r
34         * 2. Method "void GetObjectData(...,...)" is not supported (serialization)\r
35         */\r
36 \r
37         public abstract class AbstractDbException :  System.SystemException {\r
38                 protected SQLException _cause;\r
39                 protected AbstractDBConnection _connection;\r
40 \r
41                 protected AbstractDbException(Exception cause, AbstractDBConnection connection) : base(cause.Message, cause) {\r
42                         _connection = connection;\r
43                 }\r
44 \r
45                 protected AbstractDbException(SQLException cause, AbstractDBConnection connection) : this(String.Empty, cause, connection) {}\r
46 \r
47                 protected AbstractDbException(string message, SQLException cause, AbstractDBConnection connection) : base(message, cause) {\r
48                         _connection = connection;\r
49                         _cause = cause;\r
50                 }\r
51 \r
52                 abstract protected AbstractDbErrorCollection DbErrors { get; }\r
53 \r
54                 /**\r
55                  * Gets the error code of the error.\r
56                  * @return The error code of the error.\r
57                  */\r
58                 protected int DbErrorCode {\r
59                         get {\r
60                                 return _cause != null ? _cause.getErrorCode() : 0;\r
61                         }\r
62                 }\r
63 \r
64  \r
65                 /**\r
66                  * Gets the name of the OLE DB provider that generated the error.\r
67                  * @return the name of the OLE DB provider that generated the error. \r
68                  */\r
69                 public override String Source {\r
70                         get {\r
71                                 return _connection != null ? _connection.JdbcProvider : null;\r
72                         }\r
73                 }\r
74 \r
75                 public override string Message {\r
76                         get {\r
77                                 StringBuilder sb = new StringBuilder();\r
78                                 string message = base.Message;\r
79                                 bool addNewLine = false;\r
80                                 if (message != null && message.Length > 0) {\r
81                                         sb.Append(message);\r
82                                         addNewLine = true;\r
83                                 }\r
84 \r
85                                 foreach (AbstractDbError err in DbErrors) {\r
86                                         if (addNewLine)\r
87                                                 sb.Append(Environment.NewLine);\r
88 \r
89                                         addNewLine = true;\r
90                                         sb.Append(err.DbMessage);\r
91                                 }\r
92                                 return sb.ToString();\r
93                         }\r
94                 }\r
95 \r
96         }\r
97 }