View Javadoc

1   /*
2    * $Source: /usr/cvsroot/melati/throwing-jdbc/src/main/java/org/melati/poem/dbms/test/sql/ThrowingClobJdbc3.java,v $
3    * $Revision: 1.3 $
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.SQLException;
53  
54  /**
55   * The JDBC3 members of a {@link Clob}, decorated to throw an SQLException on command.
56   * 
57   * @author timp
58   * @since 5 Feb 2008
59   *
60   */
61  public abstract class ThrowingClobJdbc3 
62      extends Thrower 
63      implements Clob {
64  
65    Clob it = null;
66    
67    /** 
68     * {@inheritDoc}
69     * @see java.sql.Clob#getAsciiStream()
70     */
71  
72    public InputStream getAsciiStream() throws SQLException {
73      if (shouldThrow(this.getClass().getInterfaces()[0], "getAsciiStream"))
74        throw new SQLException("Clob bombed");
75      return it.getAsciiStream();
76    }
77  
78    /** 
79     * {@inheritDoc}
80     * @see java.sql.Clob#getCharacterStream()
81     */
82  
83    public Reader getCharacterStream() throws SQLException {
84      if (shouldThrow(this.getClass().getInterfaces()[0], "getCharacterStream"))
85        throw new SQLException("Clob bombed");
86      return it.getCharacterStream();
87    }
88  
89    /** 
90     * {@inheritDoc}
91     * @see java.sql.Clob#getSubString(long, int)
92     */
93  
94    public String getSubString(long pos, int length) throws SQLException {
95      if (shouldThrow(this.getClass().getInterfaces()[0], "getSubString"))
96        throw new SQLException("Clob bombed");
97      return it.getSubString(pos, length);
98    }
99  
100   /** 
101    * {@inheritDoc}
102    * @see java.sql.Clob#length()
103    */
104 
105   public long length() throws SQLException {
106     if (shouldThrow(this.getClass().getInterfaces()[0], "length"))
107       throw new SQLException("Clob bombed");
108     return it.length();
109   }
110 
111   /** 
112    * {@inheritDoc}
113    * @see java.sql.Clob#position(java.lang.String, long)
114    */
115 
116   public long position(String searchstr, long start) throws SQLException {
117     if (shouldThrow(this.getClass().getInterfaces()[0], "position"))
118       throw new SQLException("Clob bombed");
119     return it.position(searchstr, start);
120   }
121 
122   /** 
123    * {@inheritDoc}
124    * @see java.sql.Clob#position(java.sql.Clob, long)
125    */
126 
127   public long position(Clob searchstr, long start) throws SQLException {
128     if (shouldThrow(this.getClass().getInterfaces()[0], "position"))
129       throw new SQLException("Clob bombed");
130     return it.position(searchstr, start);
131   }
132 
133   /** 
134    * {@inheritDoc}
135    * @see java.sql.Clob#setAsciiStream(long)
136    */
137 
138   public OutputStream setAsciiStream(long pos) throws SQLException {
139     if (shouldThrow(this.getClass().getInterfaces()[0], "setAsciiStream"))
140       throw new SQLException("Clob bombed");
141     return it.setAsciiStream(pos);
142   }
143 
144   /** 
145    * {@inheritDoc}
146    * @see java.sql.Clob#setCharacterStream(long)
147    */
148 
149   public Writer setCharacterStream(long pos) throws SQLException {
150     if (shouldThrow(this.getClass().getInterfaces()[0], "setCharacterStream"))
151       throw new SQLException("Clob bombed");
152     return it.setCharacterStream(pos);
153   }
154 
155   /** 
156    * {@inheritDoc}
157    * @see java.sql.Clob#setString(long, java.lang.String)
158    */
159 
160   public int setString(long pos, String str) throws SQLException {
161     if (shouldThrow(this.getClass().getInterfaces()[0], "setString"))
162       throw new SQLException("Clob bombed");
163     return it.setString(pos, str);
164   }
165 
166   /** 
167    * {@inheritDoc}
168    * @see java.sql.Clob#setString(long, java.lang.String, int, int)
169    */
170 
171   public int setString(long pos, String str, int offset, int len)
172           throws SQLException {
173     if (shouldThrow(this.getClass().getInterfaces()[0], "setString"))
174       throw new SQLException("Clob bombed");
175     return it.setString(pos, str, offset, len);
176   }
177 
178   /** 
179    * {@inheritDoc}
180    * @see java.sql.Clob#truncate(long)
181    */
182 
183   public void truncate(long len) throws SQLException {
184     if (shouldThrow(this.getClass().getInterfaces()[0], "truncate"))
185       throw new SQLException("Clob bombed");
186     it.truncate(len);
187   }
188 
189 }