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.io.InputStream;
48  import java.io.OutputStream;
49  import java.io.Reader;
50  import java.io.Writer;
51  import java.sql.Clob;
52  import java.sql.NClob;
53  import java.sql.SQLException;
54  
55  /**
56   * @author timp
57   * @since 5 Feb 2008
58   *
59   */
60  public class ThrowingNClob extends Thrower implements NClob {
61    
62    NClob it = null;
63  
64    /**
65     * Constructor.
66     */
67    public ThrowingNClob(NClob nc) {
68      it = nc;
69    }
70  
71    /** 
72     * {@inheritDoc}
73     * @see java.sql.Clob#free()
74     */
75  
76    public void free() throws SQLException {
77      if (shouldThrow(this.getClass().getInterfaces()[0], "free"))
78        throw new SQLException("NClob bombed");
79      it.free();
80    }
81  
82    /** 
83     * {@inheritDoc}
84     * @see java.sql.Clob#getAsciiStream()
85     */
86  
87    public InputStream getAsciiStream() throws SQLException {
88      if (shouldThrow(this.getClass().getInterfaces()[0], "getAsciiStream"))
89        throw new SQLException("NClob bombed");
90      return it.getAsciiStream();
91    }
92  
93    /** 
94     * {@inheritDoc}
95     * @see java.sql.Clob#getCharacterStream()
96     */
97  
98    public Reader getCharacterStream() throws SQLException {
99      if (shouldThrow(this.getClass().getInterfaces()[0], "getCharacterStream"))
100       throw new SQLException("NClob bombed");
101     return it.getCharacterStream();
102   }
103 
104   /** 
105    * {@inheritDoc}
106    * @see java.sql.Clob#getCharacterStream(long, long)
107    */
108 
109   public Reader getCharacterStream(long pos, long length) throws SQLException {
110     if (shouldThrow(this.getClass().getInterfaces()[0], "getCharacterStream"))
111       throw new SQLException("NClob bombed");
112     return it.getCharacterStream(pos, length);
113   }
114 
115   /** 
116    * {@inheritDoc}
117    * @see java.sql.Clob#getSubString(long, int)
118    */
119 
120   public String getSubString(long pos, int length) throws SQLException {
121     if (shouldThrow(this.getClass().getInterfaces()[0], "getSubString"))
122       throw new SQLException("NClob bombed");
123     return it.getSubString(pos, length);
124   }
125 
126   /** 
127    * {@inheritDoc}
128    * @see java.sql.Clob#length()
129    */
130 
131   public long length() throws SQLException {
132     if (shouldThrow(this.getClass().getInterfaces()[0], "length"))
133       throw new SQLException("NClob bombed");
134     return it.length();
135   }
136 
137   /** 
138    * {@inheritDoc}
139    * @see java.sql.Clob#position(java.lang.String, long)
140    */
141 
142   public long position(String searchstr, long start) throws SQLException {
143     if (shouldThrow(this.getClass().getInterfaces()[0], "position"))
144       throw new SQLException("NClob bombed");
145     return it.position(searchstr, start);
146   }
147 
148   /** 
149    * {@inheritDoc}
150    * @see java.sql.Clob#position(java.sql.Clob, long)
151    */
152 
153   public long position(Clob searchstr, long start) throws SQLException {
154     if (shouldThrow(this.getClass().getInterfaces()[0], "position"))
155       throw new SQLException("NClob bombed");
156     return it.position(searchstr, start);
157   }
158 
159   /** 
160    * {@inheritDoc}
161    * @see java.sql.Clob#setAsciiStream(long)
162    */
163 
164   public OutputStream setAsciiStream(long pos) throws SQLException {
165     if (shouldThrow(this.getClass().getInterfaces()[0], "setAsciiStream"))
166       throw new SQLException("NClob bombed");
167     return it.setAsciiStream(pos);
168   }
169 
170   /** 
171    * {@inheritDoc}
172    * @see java.sql.Clob#setCharacterStream(long)
173    */
174 
175   public Writer setCharacterStream(long pos) throws SQLException {
176     if (shouldThrow(this.getClass().getInterfaces()[0], "setCharacterStream"))
177       throw new SQLException("NClob bombed");
178     return it.setCharacterStream(pos);
179   }
180 
181   /** 
182    * {@inheritDoc}
183    * @see java.sql.Clob#setString(long, java.lang.String)
184    */
185 
186   public int setString(long pos, String str) throws SQLException {
187     if (shouldThrow(this.getClass().getInterfaces()[0], "setString"))
188       throw new SQLException("NClob bombed");
189     return it.setString(pos, str);
190   }
191 
192   /** 
193    * {@inheritDoc}
194    * @see java.sql.Clob#setString(long, java.lang.String, int, int)
195    */
196 
197   public int setString(long pos, String str, int offset, int len)
198           throws SQLException {
199     if (shouldThrow(this.getClass().getInterfaces()[0], "setString"))
200       throw new SQLException("NClob bombed");
201     return it.setString(pos, str, offset, len);
202   }
203 
204   /** 
205    * {@inheritDoc}
206    * @see java.sql.Clob#truncate(long)
207    */
208 
209   public void truncate(long len) throws SQLException {
210     if (shouldThrow(this.getClass().getInterfaces()[0], "truncate"))
211       throw new SQLException("NClob bombed");
212     it.truncate(len);
213   }
214 
215 }