View Javadoc
1   /*
2    * $Source$
3    * $Revision$
4    *
5    * Copyright (C) 2008 Tim Pizey
6    *
7    * Part of Melati (http://melati.org), a framework for the rapid
8    * development of clean, maintainable web applications.
9    *
10   * Melati is free software; Permission is granted to copy, distribute
11   * and/or modify this software under the terms either:
12   *
13   * a) the GNU General Public License as published by the Free Software
14   *    Foundation; either version 2 of the License, or (at your option)
15   *    any later version,
16   *
17   *    or
18   *
19   * b) any version of the Melati Software License, as published
20   *    at http://melati.org
21   *
22   * You should have received a copy of the GNU General Public License and
23   * the Melati Software License along with this program;
24   * if not, write to the Free Software Foundation, Inc.,
25   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the
26   * GNU General Public License and visit http://melati.org to obtain the
27   * Melati Software License.
28   *
29   * Feel free to contact the Developers of Melati (http://melati.org),
30   * if you would like to work out a different arrangement than the options
31   * outlined here.  It is our intention to allow Melati to be used by as
32   * wide an audience as possible.
33   *
34   * This program is distributed in the hope that it will be useful,
35   * but WITHOUT ANY WARRANTY; without even the implied warranty of
36   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37   * GNU General Public License for more details.
38   *
39   * Contact details for copyright holder:
40   *
41   *     Tim Pizey <timp At paneris.org>
42   *     http://paneris.org/~timp
43   */
44  
45  package org.melati.poem.dbms.test.sql;
46  
47  import java.sql.Array;
48  import java.sql.Blob;
49  import java.sql.Clob;
50  import java.sql.Connection;
51  import java.sql.NClob;
52  import java.sql.SQLClientInfoException;
53  import java.sql.SQLException;
54  import java.sql.SQLXML;
55  import java.sql.Struct;
56  import java.util.Properties;
57  
58  /**
59   * A JDBC4 {@link Connection}, decorated to throw an SQLException on command.
60   * 
61   * @author timp
62   * @since  5 Feb 2008
63   *
64   */
65  public abstract class ThrowingConnectionJdbc4 
66      extends ThrowingConnectionJdbc3 
67      implements Connection {
68    /**
69     *  JDBC 4.0
70     */
71    
72    
73    /** 
74     * {@inheritDoc}
75     * @see java.sql.Connection#createArrayOf(java.lang.String, java.lang.Object[])
76     */
77  
78    public Array createArrayOf(String typeName, Object[] elements)
79            throws SQLException {
80      if (shouldThrow(this.getClass().getInterfaces()[0], "createArrayOf"))
81        throw new SQLException("Connection bombed");
82      return new ThrowingArray(it.createArrayOf(typeName, elements));
83    }
84    /** 
85     * {@inheritDoc}
86     * @see java.sql.Connection#createBlob()
87     */
88  
89    public Blob createBlob() throws SQLException {
90      if (shouldThrow(this.getClass().getInterfaces()[0], "createBlob"))
91        throw new SQLException("Connection bombed");
92      return new ThrowingBlob(it.createBlob());
93    }
94    /** 
95     * {@inheritDoc}
96     * @see java.sql.Connection#createClob()
97     */
98  
99    public Clob createClob() throws SQLException {
100     if (shouldThrow(this.getClass().getInterfaces()[0], "createClob"))
101       throw new SQLException("Connection bombed");
102     return new ThrowingClob(it.createClob());
103   }
104   /** 
105    * {@inheritDoc}
106    * @see java.sql.Connection#createNClob()
107    */
108 
109   public NClob createNClob() throws SQLException {
110     if (shouldThrow(this.getClass().getInterfaces()[0], "createNClob"))
111       throw new SQLException("Connection bombed");
112     return  new ThrowingNClob(it.createNClob());
113   }
114   /** 
115    * {@inheritDoc}
116    * @see java.sql.Connection#createSQLXML()
117    */
118 
119   public SQLXML createSQLXML() throws SQLException {
120     if (shouldThrow(this.getClass().getInterfaces()[0], "createSQLXML"))
121       throw new SQLException("Connection bombed");
122     return new ThrowingSQLXML(it.createSQLXML());
123   }
124   /** 
125    * {@inheritDoc}
126    * @see java.sql.Connection#createStruct(java.lang.String, java.lang.Object[])
127    */
128 
129   public Struct createStruct(String typeName, Object[] attributes)
130           throws SQLException {
131     if (shouldThrow(this.getClass().getInterfaces()[0], "createStruct"))
132       throw new SQLException("Connection bombed");
133     return new ThrowingStruct(it.createStruct(typeName, attributes));
134   }
135   /** 
136    * {@inheritDoc}
137    * @see java.sql.Connection#getClientInfo()
138    */
139 
140   public Properties getClientInfo() throws SQLException {
141     if (shouldThrow(this.getClass().getInterfaces()[0], "getClientInfo"))
142       throw new SQLException("Connection bombed");
143     return it.getClientInfo();
144   }
145   /** 
146    * {@inheritDoc}
147    * @see java.sql.Connection#getClientInfo(java.lang.String)
148    */
149 
150   public String getClientInfo(String name) throws SQLException {
151     if (shouldThrow(this.getClass().getInterfaces()[0], "getClientInfo"))
152       throw new SQLException("Connection bombed");
153     return it.getClientInfo(name);
154   }
155   /** 
156    * {@inheritDoc}
157    * @see java.sql.Connection#isValid(int)
158    */
159 
160   public boolean isValid(int timeout) throws SQLException {
161     if (shouldThrow(this.getClass().getInterfaces()[0], "isValid"))
162       throw new SQLException("Connection bombed");
163     return it.isValid(timeout);
164   }
165   /** 
166    * {@inheritDoc}
167    * @see java.sql.Connection#setClientInfo(java.util.Properties)
168    */
169 
170   public void setClientInfo(Properties properties)
171           throws SQLClientInfoException {
172     if (shouldThrow(this.getClass().getInterfaces()[0], "setClientInfo"))
173       throw new SQLClientInfoException();
174     it.setClientInfo(properties);
175   }
176   /** 
177    * {@inheritDoc}
178    * @see java.sql.Connection#setClientInfo(java.lang.String, java.lang.String)
179    */
180 
181   public void setClientInfo(String name, String value)
182           throws SQLClientInfoException {
183     if (shouldThrow(this.getClass().getInterfaces()[0], "setClientInfo"))
184       throw new SQLClientInfoException();
185     it.setClientInfo(name, value);
186   }
187   /** 
188    * {@inheritDoc}
189    * @see java.sql.Wrapper#isWrapperFor(java.lang.Class)
190    */
191 
192   public boolean isWrapperFor(Class<?> iface) throws SQLException {
193     if (shouldThrow(this.getClass().getInterfaces()[0], "isWrapperFor"))
194       throw new SQLException("Connection bombed");
195     return it.isWrapperFor(iface);
196   }
197   /** 
198    * {@inheritDoc}
199    * @see java.sql.Wrapper#unwrap(java.lang.Class)
200    */
201 
202   public <T> T unwrap(Class<T> iface) throws SQLException {
203     if (shouldThrow(this.getClass().getInterfaces()[0], "unwrap"))
204       throw new SQLException("Connection bombed");
205     return it.unwrap(iface);
206   }
207   
208 
209 
210 }