Save This Page
Home » jboss-5.0.0.CR1-src » org.jboss.resource.adapter » jdbc » [javadoc | source]
    1   /*
    2    * JBoss, Home of Professional Open Source.
    3    * Copyright 2006, Red Hat Middleware LLC, and individual contributors
    4    * as indicated by the @author tags. See the copyright.txt file in the
    5    * distribution for a full listing of individual contributors.
    6    *
    7    * This is free software; you can redistribute it and/or modify it
    8    * under the terms of the GNU Lesser General Public License as
    9    * published by the Free Software Foundation; either version 2.1 of
   10    * the License, or (at your option) any later version.
   11    *
   12    * This software is distributed in the hope that it will be useful,
   13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   15    * Lesser General Public License for more details.
   16    *
   17    * You should have received a copy of the GNU Lesser General Public
   18    * License along with this software; if not, write to the Free
   19    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   20    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   21    */
   22   package org.jboss.resource.adapter.jdbc;
   23   
   24   import java.io.InputStream;
   25   import java.io.Reader;
   26   import java.math.BigDecimal;
   27   import java.net.URL;
   28   import java.sql.Array;
   29   import java.sql.Blob;
   30   import java.sql.Clob;
   31   import java.sql.Date;
   32   import java.sql.ParameterMetaData;
   33   import java.sql.PreparedStatement;
   34   import java.sql.Ref;
   35   import java.sql.ResultSet;
   36   import java.sql.ResultSetMetaData;
   37   import java.sql.SQLException;
   38   import java.sql.Time;
   39   import java.sql.Timestamp;
   40   import java.util.Calendar;
   41   
   42   /**
   43    * A wrapper for a prepared statement.
   44    *
   45    * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
   46    * @author <a href="mailto:adrian@jboss.com">Adrian Brock</a>
   47    * @version $Revision: 71788 $
   48    */
   49   public abstract class WrappedPreparedStatement extends WrappedStatement implements PreparedStatement 
   50   {
   51      private final PreparedStatement ps;
   52   
   53      public WrappedPreparedStatement(final WrappedConnection lc, final PreparedStatement ps) 
   54      {
   55         super(lc, ps);
   56         this.ps = ps;
   57      }
   58   
   59      public PreparedStatement getUnderlyingStatement() throws SQLException
   60      {
   61         lock();
   62         try
   63         {
   64            checkState();
   65            if (ps instanceof CachedPreparedStatement)
   66            {
   67               return ((CachedPreparedStatement)ps).getUnderlyingPreparedStatement();
   68            }
   69            else
   70            {
   71               return ps;
   72            }
   73         }
   74         finally
   75         {
   76            unlock();
   77         }
   78      }
   79   
   80      public void setBoolean(int parameterIndex, boolean value) throws SQLException
   81      {
   82         lock();
   83         try
   84         {
   85            checkState();
   86            try 
   87            {
   88               ps.setBoolean(parameterIndex, value);         
   89            }
   90            catch (Throwable t)
   91            {
   92               throw checkException(t);
   93            }
   94         }
   95         finally
   96         {
   97            unlock();
   98         }
   99      }
  100   
  101      public void setByte(int parameterIndex, byte value) throws SQLException
  102      {
  103         lock();
  104         try
  105         {
  106            checkState();
  107            try 
  108            {
  109               ps.setByte(parameterIndex, value);         
  110            }
  111            catch (Throwable t)
  112            {
  113               throw checkException(t);
  114            }
  115         }
  116         finally
  117         {
  118            unlock();
  119         }
  120      }
  121   
  122      public void setShort(int parameterIndex, short value) throws SQLException
  123      {
  124         lock();
  125         try
  126         {
  127            checkState();
  128            try 
  129            {
  130               ps.setShort(parameterIndex, value);         
  131            }
  132            catch (Throwable t)
  133            {
  134               throw checkException(t);
  135            }
  136         }
  137         finally
  138         {
  139            unlock();
  140         }
  141      }
  142   
  143      public void setInt(int parameterIndex, int value) throws SQLException
  144      {
  145         lock();
  146         try
  147         {
  148            checkState();
  149            try 
  150            {
  151               ps.setInt(parameterIndex, value);         
  152            }
  153            catch (Throwable t)
  154            {
  155               throw checkException(t);
  156            }
  157         }
  158         finally
  159         {
  160            unlock();
  161         }
  162      }
  163   
  164      public void setLong(int parameterIndex, long value) throws SQLException
  165      {
  166         lock();
  167         try
  168         {
  169            checkState();
  170            try 
  171            {
  172               ps.setLong(parameterIndex, value);         
  173            }
  174            catch (Throwable t)
  175            {
  176               throw checkException(t);
  177            }
  178         }
  179         finally
  180         {
  181            unlock();
  182         }
  183      }
  184   
  185      public void setFloat(int parameterIndex, float value) throws SQLException
  186      {
  187         lock();
  188         try
  189         {
  190            checkState();
  191            try 
  192            {
  193               ps.setFloat(parameterIndex, value);         
  194            }
  195            catch (Throwable t)
  196            {
  197               throw checkException(t);
  198            }
  199         }
  200         finally
  201         {
  202            unlock();
  203         }
  204      }
  205   
  206      public void setDouble(int parameterIndex, double value) throws SQLException
  207      {
  208         lock();
  209         try
  210         {
  211            checkState();
  212            try 
  213            {
  214               ps.setDouble(parameterIndex, value);         
  215            }
  216            catch (Throwable t)
  217            {
  218               throw checkException(t);
  219            }
  220         }
  221         finally
  222         {
  223            unlock();
  224         }
  225      }
  226   
  227      public void setURL(int parameterIndex, URL value) throws SQLException
  228      {
  229         lock();
  230         try
  231         {
  232            checkState();
  233            try 
  234            {
  235               ps.setURL(parameterIndex, value);         
  236            }
  237            catch (Throwable t)
  238            {
  239               throw checkException(t);
  240            }
  241         }
  242         finally
  243         {
  244            unlock();
  245         }
  246      }
  247   
  248      public void setTime(int parameterIndex, Time value) throws SQLException
  249      {
  250         lock();
  251         try
  252         {
  253            checkState();
  254            try 
  255            {
  256               ps.setTime(parameterIndex, value);         
  257            }
  258            catch (Throwable t)
  259            {
  260               throw checkException(t);
  261            }
  262         }
  263         finally
  264         {
  265            unlock();
  266         }
  267      }
  268   
  269      public void setTime(int parameterIndex, Time value, Calendar calendar) throws SQLException
  270      {
  271         lock();
  272         try
  273         {
  274            checkState();
  275            try 
  276            {
  277               ps.setTime(parameterIndex, value, calendar);         
  278            }
  279            catch (Throwable t)
  280            {
  281               throw checkException(t);
  282            }
  283         }
  284         finally
  285         {
  286            unlock();
  287         }
  288      }
  289   
  290      public boolean execute() throws SQLException
  291      {
  292         lock();
  293         try
  294         {
  295            checkTransaction();
  296            try 
  297            {
  298               checkConfiguredQueryTimeout();
  299               return ps.execute();         
  300            }
  301            catch (Throwable t)
  302            {
  303               throw checkException(t);
  304            }
  305         }
  306         finally
  307         {
  308            unlock();
  309         }
  310      }
  311   
  312      public ResultSetMetaData getMetaData() throws SQLException
  313      {
  314         lock();
  315         try
  316         {
  317            checkState();
  318            try 
  319            {
  320               return ps.getMetaData();         
  321            }
  322            catch (Throwable t)
  323            {
  324               throw checkException(t);
  325            }
  326         }
  327         finally
  328         {
  329            unlock();
  330         }
  331      }
  332   
  333      public ResultSet executeQuery() throws SQLException
  334      {
  335         lock();
  336         try
  337         {
  338            checkTransaction();
  339            try 
  340            {
  341               checkConfiguredQueryTimeout();
  342               ResultSet resultSet = ps.executeQuery();
  343               return registerResultSet(resultSet);
  344            }
  345            catch (Throwable t)
  346            {
  347               throw checkException(t);
  348            }
  349         }
  350         finally
  351         {
  352            unlock();
  353         }
  354      }
  355   
  356      public int executeUpdate() throws SQLException
  357      {
  358         lock();
  359         try
  360         {
  361            checkTransaction();
  362            try 
  363            {
  364               checkConfiguredQueryTimeout();
  365               return ps.executeUpdate();         
  366            }
  367            catch (Throwable t)
  368            {
  369               throw checkException(t);
  370            }
  371         }
  372         finally
  373         {
  374            unlock();
  375         }
  376      }
  377   
  378      public void addBatch() throws SQLException
  379      {
  380         lock();
  381         try
  382         {
  383            checkState();
  384            try 
  385            {
  386               ps.addBatch();         
  387            }
  388            catch (Throwable t)
  389            {
  390               throw checkException(t);
  391            }
  392         }
  393         finally
  394         {
  395            unlock();
  396         }
  397      }
  398   
  399      public void setNull(int parameterIndex, int sqlType) throws SQLException
  400      {
  401         lock();
  402         try
  403         {
  404            checkState();
  405            try 
  406            {
  407               ps.setNull(parameterIndex, sqlType);         
  408            }
  409            catch (Throwable t)
  410            {
  411               throw checkException(t);
  412            }
  413         }
  414         finally
  415         {
  416            unlock();
  417         }
  418      }
  419   
  420      public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException
  421      {
  422         lock();
  423         try
  424         {
  425            checkState();
  426            try 
  427            {
  428               ps.setNull(parameterIndex, sqlType, typeName);         
  429            }
  430            catch (Throwable t)
  431            {
  432               throw checkException(t);
  433            }
  434         }
  435         finally
  436         {
  437            unlock();
  438         }
  439      }
  440   
  441      public void setBigDecimal(int parameterIndex, BigDecimal value) throws SQLException
  442      {
  443         lock();
  444         try
  445         {
  446            checkState();
  447            try 
  448            {
  449               ps.setBigDecimal(parameterIndex, value);         
  450            }
  451            catch (Throwable t)
  452            {
  453               throw checkException(t);
  454            }
  455         }
  456         finally
  457         {
  458            unlock();
  459         }
  460      }
  461   
  462      public void setString(int parameterIndex, String value) throws SQLException
  463      {
  464         lock();
  465         try
  466         {
  467            checkState();
  468            try 
  469            {
  470               ps.setString(parameterIndex, value);         
  471            }
  472            catch (Throwable t)
  473            {
  474               throw checkException(t);
  475            }
  476         }
  477         finally
  478         {
  479            unlock();
  480         }
  481      }
  482   
  483      public void setBytes(int parameterIndex, byte[] value) throws SQLException
  484      {
  485         lock();
  486         try
  487         {
  488            checkState();
  489            try 
  490            {
  491               ps.setBytes(parameterIndex, value);         
  492            }
  493            catch (Throwable t)
  494            {
  495               throw checkException(t);
  496            }
  497         }
  498         finally
  499         {
  500            unlock();
  501         }
  502      }
  503   
  504      public void setDate(int parameterIndex, Date value) throws SQLException
  505      {
  506         lock();
  507         try
  508         {
  509            checkState();
  510            try 
  511            {
  512               ps.setDate(parameterIndex, value);         
  513            }
  514            catch (Throwable t)
  515            {
  516               throw checkException(t);
  517            }
  518         }
  519         finally
  520         {
  521            unlock();
  522         }
  523      }
  524   
  525      public void setDate(int parameterIndex, Date value, Calendar calendar) throws SQLException
  526      {
  527         lock();
  528         try
  529         {
  530            checkState();
  531            try 
  532            {
  533               ps.setDate(parameterIndex, value, calendar);         
  534            }
  535            catch (Throwable t)
  536            {
  537               throw checkException(t);
  538            }
  539         }
  540         finally
  541         {
  542            unlock();
  543         }
  544      }
  545   
  546      public void setTimestamp(int parameterIndex, Timestamp value) throws SQLException
  547      {
  548         lock();
  549         try
  550         {
  551            checkState();
  552            try 
  553            {
  554               ps.setTimestamp(parameterIndex, value);         
  555            }
  556            catch (Throwable t)
  557            {
  558               throw checkException(t);
  559            }
  560         }
  561         finally
  562         {
  563            unlock();
  564         }
  565      }
  566   
  567      public void setTimestamp(int parameterIndex, Timestamp value, Calendar calendar) throws SQLException
  568      {
  569         lock();
  570         try
  571         {
  572            checkState();
  573            try 
  574            {
  575               ps.setTimestamp(parameterIndex, value, calendar);         
  576            }
  577            catch (Throwable t)
  578            {
  579               throw checkException(t);
  580            }
  581         }
  582         finally
  583         {
  584            unlock();
  585         }
  586      }
  587   
  588      @Deprecated
  589      public void setAsciiStream(int parameterIndex, InputStream stream, int length) throws SQLException
  590      {
  591         lock();
  592         try
  593         {
  594            checkState();
  595            try 
  596            {
  597               ps.setAsciiStream(parameterIndex, stream, length);         
  598            }
  599            catch (Throwable t)
  600            {
  601               throw checkException(t);
  602            }
  603         }
  604         finally
  605         {
  606            unlock();
  607         }
  608      }
  609   
  610      @Deprecated
  611      public void setUnicodeStream(int parameterIndex, InputStream stream, int length) throws SQLException
  612      {
  613         lock();
  614         try
  615         {
  616            checkState();
  617            try 
  618            {
  619               ps.setUnicodeStream(parameterIndex, stream, length);         
  620            }
  621            catch (Throwable t)
  622            {
  623               throw checkException(t);
  624            }
  625         }
  626         finally
  627         {
  628            unlock();
  629         }
  630      }
  631   
  632      public void setBinaryStream(int parameterIndex, InputStream stream, int length) throws SQLException
  633      {
  634         lock();
  635         try
  636         {
  637            checkState();
  638            try 
  639            {
  640               ps.setBinaryStream(parameterIndex, stream, length);         
  641            }
  642            catch (Throwable t)
  643            {
  644               throw checkException(t);
  645            }
  646         }
  647         finally
  648         {
  649            unlock();
  650         }
  651      }
  652   
  653      public void clearParameters() throws SQLException
  654      {
  655         lock();
  656         try
  657         {
  658            checkState();
  659            try 
  660            {
  661               ps.clearParameters();         
  662            }
  663            catch (Throwable t)
  664            {
  665               throw checkException(t);
  666            }
  667         }
  668         finally
  669         {
  670            unlock();
  671         }
  672      }
  673   
  674      public void setObject(int parameterIndex, Object value, int sqlType, int scale) throws SQLException
  675      {
  676         lock();
  677         try
  678         {
  679            checkState();
  680            try 
  681            {
  682               ps.setObject(parameterIndex, value, sqlType, scale);         
  683            }
  684            catch (Throwable t)
  685            {
  686               throw checkException(t);
  687            }
  688         }
  689         finally
  690         {
  691            unlock();
  692         }
  693      }
  694   
  695      public void setObject(int parameterIndex, Object value, int sqlType) throws SQLException
  696      {
  697         lock();
  698         try
  699         {
  700            checkState();
  701            try 
  702            {
  703               ps.setObject(parameterIndex, value, sqlType);         
  704            }
  705            catch (Throwable t)
  706            {
  707               throw checkException(t);
  708            }
  709         }
  710         finally
  711         {
  712            unlock();
  713         }
  714      }
  715   
  716      public void setObject(int parameterIndex, Object value) throws SQLException
  717      {
  718         lock();
  719         try
  720         {
  721            checkState();
  722            try 
  723            {
  724               ps.setObject(parameterIndex, value);         
  725            }
  726            catch (Throwable t)
  727            {
  728               throw checkException(t);
  729            }
  730         }
  731         finally
  732         {
  733            unlock();
  734         }
  735      }
  736   
  737      public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException
  738      {
  739         lock();
  740         try
  741         {
  742            checkState();
  743            try 
  744            {
  745               ps.setCharacterStream(parameterIndex, reader, length);         
  746            }
  747            catch (Throwable t)
  748            {
  749               throw checkException(t);
  750            }
  751         }
  752         finally
  753         {
  754            unlock();
  755         }
  756      }
  757   
  758      public void setRef(int parameterIndex, Ref value) throws SQLException
  759      {
  760         lock();
  761         try
  762         {
  763            checkState();
  764            try 
  765            {
  766               ps.setRef(parameterIndex, value);         
  767            }
  768            catch (Throwable t)
  769            {
  770               throw checkException(t);
  771            }
  772         }
  773         finally
  774         {
  775            unlock();
  776         }
  777      }
  778   
  779      public void setBlob(int parameterIndex, Blob value) throws SQLException
  780      {
  781         lock();
  782         try
  783         {
  784            checkState();
  785            try 
  786            {
  787               ps.setBlob(parameterIndex, value);         
  788            }
  789            catch (Throwable t)
  790            {
  791               throw checkException(t);
  792            }
  793         }
  794         finally
  795         {
  796            unlock();
  797         }
  798      }
  799   
  800      public void setClob(int parameterIndex, Clob value) throws SQLException
  801      {
  802         lock();
  803         try
  804         {
  805            checkState();
  806            try 
  807            {
  808               ps.setClob(parameterIndex, value);         
  809            }
  810            catch (Throwable t)
  811            {
  812               throw checkException(t);
  813            }
  814         }
  815         finally
  816         {
  817            unlock();
  818         }
  819      }
  820   
  821      public void setArray(int parameterIndex, Array value) throws SQLException
  822      {
  823         lock();
  824         try
  825         {
  826            checkState();
  827            try 
  828            {
  829               ps.setArray(parameterIndex, value);         
  830            }
  831            catch (Throwable t)
  832            {
  833               throw checkException(t);
  834            }
  835         }
  836         finally
  837         {
  838            unlock();
  839         }
  840      }
  841   
  842      public ParameterMetaData getParameterMetaData() throws SQLException
  843      {
  844         lock();
  845         try
  846         {
  847            checkState();
  848            try 
  849            {
  850               return ps.getParameterMetaData();         
  851            }
  852            catch (Throwable t)
  853            {
  854               throw checkException(t);
  855            }
  856         }
  857         finally
  858         {
  859            unlock();
  860         }
  861      }
  862   
  863      protected PreparedStatement getWrappedObject() throws SQLException
  864      {
  865         return (PreparedStatement) super.getWrappedObject();
  866      }
  867   }

Save This Page
Home » jboss-5.0.0.CR1-src » org.jboss.resource.adapter » jdbc » [javadoc | source]