KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > varia > stats > DataSourceInterceptor


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * 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.varia.stats;
23
24 import org.jboss.system.ServiceMBeanSupport;
25 import org.jboss.system.ServiceMBean;
26 import org.jboss.naming.NonSerializableFactory;
27
28 import javax.sql.DataSource JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import javax.naming.NamingException JavaDoc;
31 import javax.naming.Name JavaDoc;
32 import javax.naming.InitialContext JavaDoc;
33 import java.sql.SQLException JavaDoc;
34 import java.sql.Connection JavaDoc;
35 import java.sql.DatabaseMetaData JavaDoc;
36 import java.sql.SQLWarning JavaDoc;
37 import java.sql.Statement JavaDoc;
38 import java.sql.CallableStatement JavaDoc;
39 import java.sql.PreparedStatement JavaDoc;
40 import java.sql.ResultSet JavaDoc;
41 import java.sql.Array JavaDoc;
42 import java.sql.Blob JavaDoc;
43 import java.sql.Clob JavaDoc;
44 import java.sql.Date JavaDoc;
45 import java.sql.Ref JavaDoc;
46 import java.sql.ResultSetMetaData JavaDoc;
47 import java.sql.Time JavaDoc;
48 import java.sql.Timestamp JavaDoc;
49
50 import java.sql.Savepoint JavaDoc;
51 import java.sql.ParameterMetaData JavaDoc;
52
53 import java.io.PrintWriter JavaDoc;
54 import java.io.InputStream JavaDoc;
55 import java.io.Reader JavaDoc;
56 import java.util.Map JavaDoc;
57 import java.util.Calendar JavaDoc;
58 import java.math.BigDecimal JavaDoc;
59 import java.net.URL JavaDoc;
60
61 /**
62  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
63  * @version <tt>$Revision: 37459 $</tt>
64  * @@jmx:mbean name="jboss.stats:name=DataSourceInterceptor"
65  * extends="org.jboss.system.ServiceMBean"
66  */

67 public class DataSourceInterceptor
68    extends ServiceMBeanSupport
69    implements DataSource JavaDoc, DataSourceInterceptorMBean
70 {
71    /**
72     * JNDI name the service will be bound under
73     */

74    private String JavaDoc bindName;
75    /**
76     * target DataSource JNDI name
77     */

78    private String JavaDoc targetName;
79    /**
80     * target DataSource
81     */

82    private DataSource JavaDoc target;
83
84    private ObjectName JavaDoc statsCollector;
85
86    // MBean implementation
87

88    /**
89     * @jmx.managed-attribute
90     */

91    public ObjectName JavaDoc getStatsCollector()
92    {
93       return statsCollector;
94    }
95
96    /**
97     * @jmx.managed-attribute
98     */

99    public void setStatsCollector(ObjectName JavaDoc statsCollector)
100    {
101       this.statsCollector = statsCollector;
102    }
103
104    /**
105     * @jmx.managed-attribute
106     */

107    public String JavaDoc getBindName()
108    {
109       return bindName;
110    }
111
112    /**
113     * @jmx.managed-attribute
114     */

115    public void setBindName(String JavaDoc bindName) throws NamingException JavaDoc
116    {
117       this.bindName = bindName;
118       if(getState() == ServiceMBean.STARTED)
119       {
120          bind();
121       }
122    }
123
124    /**
125     * @jmx.managed-attribute
126     */

127    public String JavaDoc getTargetName()
128    {
129       return targetName;
130    }
131
132    /**
133     * @jmx.managed-attribute
134     */

135    public void setTargetName(String JavaDoc targetName) throws NamingException JavaDoc
136    {
137       this.targetName = targetName;
138       if(getState() == ServiceMBean.STARTED)
139       {
140          updateTarget();
141       }
142    }
143
144    public void startService()
145       throws Exception JavaDoc
146    {
147       updateTarget();
148       bind();
149    }
150
151    public void stopService()
152       throws Exception JavaDoc
153    {
154       unbind();
155    }
156
157    // DataSource implementation
158

159    public int getLoginTimeout() throws SQLException JavaDoc
160    {
161       return target.getLoginTimeout();
162    }
163
164    public void setLoginTimeout(int seconds) throws SQLException JavaDoc
165    {
166       target.setLoginTimeout(seconds);
167    }
168
169    public PrintWriter JavaDoc getLogWriter() throws SQLException JavaDoc
170    {
171       return target.getLogWriter();
172    }
173
174    public void setLogWriter(PrintWriter JavaDoc out) throws SQLException JavaDoc
175    {
176       target.setLogWriter(out);
177    }
178
179    public Connection JavaDoc getConnection() throws SQLException JavaDoc
180    {
181       return new ConnectionInterceptor(target.getConnection());
182    }
183
184    public Connection JavaDoc getConnection(String JavaDoc username, String JavaDoc password) throws SQLException JavaDoc
185    {
186       return new ConnectionInterceptor(target.getConnection());
187    }
188
189    // Inner
190

191    public class ConnectionInterceptor
192       implements Connection JavaDoc
193    {
194       private final Connection JavaDoc target;
195
196       public ConnectionInterceptor(Connection JavaDoc target)
197       {
198          this.target = target;
199       }
200
201       
202       public int getHoldability() throws SQLException JavaDoc
203       {
204          return target.getHoldability();
205       }
206       
207
208       public int getTransactionIsolation() throws SQLException JavaDoc
209       {
210          return target.getTransactionIsolation();
211       }
212
213       public void clearWarnings() throws SQLException JavaDoc
214       {
215          target.clearWarnings();
216       }
217
218       public void close() throws SQLException JavaDoc
219       {
220          target.close();
221       }
222
223       public void commit() throws SQLException JavaDoc
224       {
225          target.commit();
226       }
227
228       public void rollback() throws SQLException JavaDoc
229       {
230          target.rollback();
231       }
232
233       public boolean getAutoCommit() throws SQLException JavaDoc
234       {
235          return target.getAutoCommit();
236       }
237
238       public boolean isClosed() throws SQLException JavaDoc
239       {
240          return target.isClosed();
241       }
242
243       public boolean isReadOnly() throws SQLException JavaDoc
244       {
245          return target.isReadOnly();
246       }
247
248       
249       public void setHoldability(int holdability) throws SQLException JavaDoc
250       {
251          target.setHoldability(holdability);
252       }
253       
254
255       public void setTransactionIsolation(int level) throws SQLException JavaDoc
256       {
257          target.setTransactionIsolation(level);
258       }
259
260       public void setAutoCommit(boolean autoCommit) throws SQLException JavaDoc
261       {
262          target.setAutoCommit(autoCommit);
263       }
264
265       public void setReadOnly(boolean readOnly) throws SQLException JavaDoc
266       {
267          target.setReadOnly(readOnly);
268       }
269
270       public String JavaDoc getCatalog() throws SQLException JavaDoc
271       {
272          return target.getCatalog();
273       }
274
275       public void setCatalog(String JavaDoc catalog) throws SQLException JavaDoc
276       {
277          target.setCatalog(catalog);
278       }
279
280       public DatabaseMetaData JavaDoc getMetaData() throws SQLException JavaDoc
281       {
282          return target.getMetaData();
283       }
284
285       public SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc
286       {
287          return target.getWarnings();
288       }
289
290       
291       public Savepoint JavaDoc setSavepoint() throws SQLException JavaDoc
292       {
293          return target.setSavepoint();
294       }
295       
296
297       
298       public void releaseSavepoint(Savepoint JavaDoc savepoint) throws SQLException JavaDoc
299       {
300          target.releaseSavepoint(savepoint);
301       }
302       
303
304       
305       public void rollback(Savepoint JavaDoc savepoint) throws SQLException JavaDoc
306       {
307          target.rollback(savepoint);
308       }
309       
310
311       public Statement JavaDoc createStatement() throws SQLException JavaDoc
312       {
313          return new StatementInterceptor(this, target.createStatement());
314       }
315
316       public Statement JavaDoc createStatement(int resultSetType, int resultSetConcurrency) throws SQLException JavaDoc
317       {
318          return new StatementInterceptor(this, target.createStatement(resultSetType, resultSetConcurrency));
319       }
320
321       
322       public Statement JavaDoc createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
323          throws SQLException JavaDoc
324       {
325          return new StatementInterceptor(this,
326             target.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability));
327       }
328       
329
330       public Map JavaDoc getTypeMap() throws SQLException JavaDoc
331       {
332          return target.getTypeMap();
333       }
334
335       public void setTypeMap(Map JavaDoc map) throws SQLException JavaDoc
336       {
337          target.setTypeMap(map);
338       }
339
340       public String JavaDoc nativeSQL(String JavaDoc sql) throws SQLException JavaDoc
341       {
342          return target.nativeSQL(sql);
343       }
344
345       public CallableStatement JavaDoc prepareCall(String JavaDoc sql) throws SQLException JavaDoc
346       {
347          return target.prepareCall(sql);
348       }
349
350       public CallableStatement JavaDoc prepareCall(String JavaDoc sql, int resultSetType, int resultSetConcurrency)
351          throws SQLException JavaDoc
352       {
353          return target.prepareCall(sql, resultSetType, resultSetConcurrency);
354       }
355
356       
357       public CallableStatement JavaDoc prepareCall(String JavaDoc sql,
358                                            int resultSetType,
359                                            int resultSetConcurrency,
360                                            int resultSetHoldability) throws SQLException JavaDoc
361       {
362          return target.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
363       }
364       
365
366       public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql) throws SQLException JavaDoc
367       {
368          logSql(sql);
369          return new PreparedStatementInterceptor(this, target.prepareStatement(sql));
370       }
371
372       
373       public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int autoGeneratedKeys) throws SQLException JavaDoc
374       {
375          logSql(sql);
376          return new PreparedStatementInterceptor(this, target.prepareStatement(sql, autoGeneratedKeys));
377       }
378       
379
380       public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int resultSetType, int resultSetConcurrency)
381          throws SQLException JavaDoc
382       {
383          logSql(sql);
384          return new PreparedStatementInterceptor(this,
385             target.prepareStatement(sql, resultSetType, resultSetConcurrency));
386       }
387
388       
389       public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql,
390                                                 int resultSetType,
391                                                 int resultSetConcurrency,
392                                                 int resultSetHoldability) throws SQLException JavaDoc
393       {
394          logSql(sql);
395          return new PreparedStatementInterceptor(this,
396             target.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
397       }
398       
399
400       
401       public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int columnIndexes[]) throws SQLException JavaDoc
402       {
403          logSql(sql);
404          return new PreparedStatementInterceptor(this, target.prepareStatement(sql, columnIndexes));
405       }
406       
407
408       
409       public Savepoint JavaDoc setSavepoint(String JavaDoc name) throws SQLException JavaDoc
410       {
411          return target.setSavepoint(name);
412       }
413       
414
415       
416       public PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, String JavaDoc columnNames[]) throws SQLException JavaDoc
417       {
418          logSql(sql);
419          return new PreparedStatementInterceptor(this, target.prepareStatement(sql, columnNames));
420       }
421       
422    }
423
424    public class StatementInterceptor
425       implements Statement JavaDoc
426    {
427       private final Connection JavaDoc con;
428       private final Statement JavaDoc target;
429
430       public StatementInterceptor(Connection JavaDoc con, Statement JavaDoc target)
431       {
432          this.con = con;
433          this.target = target;
434       }
435
436       public int getFetchDirection() throws SQLException JavaDoc
437       {
438          return target.getFetchDirection();
439       }
440
441       public int getFetchSize() throws SQLException JavaDoc
442       {
443          return target.getFetchSize();
444       }
445
446       public int getMaxFieldSize() throws SQLException JavaDoc
447       {
448          return target.getMaxFieldSize();
449       }
450
451       public int getMaxRows() throws SQLException JavaDoc
452       {
453          return target.getMaxRows();
454       }
455
456       public int getQueryTimeout() throws SQLException JavaDoc
457       {
458          return target.getQueryTimeout();
459       }
460
461       public int getResultSetConcurrency() throws SQLException JavaDoc
462       {
463          return target.getResultSetConcurrency();
464       }
465
466       
467       public int getResultSetHoldability() throws SQLException JavaDoc
468       {
469          return target.getResultSetHoldability();
470       }
471       
472
473       public int getResultSetType() throws SQLException JavaDoc
474       {
475          return target.getResultSetType();
476       }
477
478       public int getUpdateCount() throws SQLException JavaDoc
479       {
480          return target.getUpdateCount();
481       }
482
483       public void cancel() throws SQLException JavaDoc
484       {
485          target.cancel();
486       }
487
488       public void clearBatch() throws SQLException JavaDoc
489       {
490          target.clearBatch();
491       }
492
493       public void clearWarnings() throws SQLException JavaDoc
494       {
495          target.clearWarnings();
496       }
497
498       public void close() throws SQLException JavaDoc
499       {
500          target.close();
501       }
502
503       public boolean getMoreResults() throws SQLException JavaDoc
504       {
505          return target.getMoreResults();
506       }
507
508       public int[] executeBatch() throws SQLException JavaDoc
509       {
510          return target.executeBatch();
511       }
512
513       public void setFetchDirection(int direction) throws SQLException JavaDoc
514       {
515          target.setFetchDirection(direction);
516       }
517
518       public void setFetchSize(int rows) throws SQLException JavaDoc
519       {
520          target.setFetchSize(rows);
521       }
522
523       public void setMaxFieldSize(int max) throws SQLException JavaDoc
524       {
525          target.setMaxFieldSize(max);
526       }
527
528       public void setMaxRows(int max) throws SQLException JavaDoc
529       {
530          target.setMaxRows(max);
531       }
532
533       public void setQueryTimeout(int seconds) throws SQLException JavaDoc
534       {
535          target.setQueryTimeout(seconds);
536       }
537
538       
539       public boolean getMoreResults(int current) throws SQLException JavaDoc
540       {
541          return target.getMoreResults(current);
542       }
543       
544
545       public void setEscapeProcessing(boolean enable) throws SQLException JavaDoc
546       {
547          target.setEscapeProcessing(enable);
548       }
549
550       public int executeUpdate(String JavaDoc sql) throws SQLException JavaDoc
551       {
552          logSql(sql);
553          return target.executeUpdate(sql);
554       }
555
556       public void addBatch(String JavaDoc sql) throws SQLException JavaDoc
557       {
558          logSql(sql);
559          target.addBatch(sql);
560       }
561
562       public void setCursorName(String JavaDoc name) throws SQLException JavaDoc
563       {
564          target.setCursorName(name);
565       }
566
567       public boolean execute(String JavaDoc sql) throws SQLException JavaDoc
568       {
569          logSql(sql);
570          return target.execute(sql);
571       }
572
573       
574       public int executeUpdate(String JavaDoc sql, int autoGeneratedKeys) throws SQLException JavaDoc
575       {
576          logSql(sql);
577          return target.executeUpdate(sql, autoGeneratedKeys);
578       }
579       
580
581       
582       public boolean execute(String JavaDoc sql, int autoGeneratedKeys) throws SQLException JavaDoc
583       {
584          logSql(sql);
585          return target.execute(sql, autoGeneratedKeys);
586       }
587       
588
589       
590       public int executeUpdate(String JavaDoc sql, int columnIndexes[]) throws SQLException JavaDoc
591       {
592          logSql(sql);
593          return target.executeUpdate(sql, columnIndexes);
594       }
595       
596
597       
598       public boolean execute(String JavaDoc sql, int columnIndexes[]) throws SQLException JavaDoc
599       {
600          logSql(sql);
601          return target.execute(sql, columnIndexes);
602       }
603       
604
605       public Connection JavaDoc getConnection() throws SQLException JavaDoc
606       {
607          return con;
608       }
609
610       
611       public ResultSet JavaDoc getGeneratedKeys() throws SQLException JavaDoc
612       {
613          return target.getGeneratedKeys();
614       }
615       
616
617       public ResultSet JavaDoc getResultSet() throws SQLException JavaDoc
618       {
619          return target.getResultSet();
620       }
621
622       public SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc
623       {
624          return target.getWarnings();
625       }
626
627       
628       public int executeUpdate(String JavaDoc sql, String JavaDoc columnNames[]) throws SQLException JavaDoc
629       {
630          logSql(sql);
631          return target.executeUpdate(sql, columnNames);
632       }
633       
634
635       
636       public boolean execute(String JavaDoc sql, String JavaDoc columnNames[]) throws SQLException JavaDoc
637       {
638          logSql(sql);
639          return target.execute(sql, columnNames);
640       }
641       
642
643       public ResultSet JavaDoc executeQuery(String JavaDoc sql) throws SQLException JavaDoc
644       {
645          logSql(sql);
646          return target.executeQuery(sql);
647       }
648    }
649
650    public class PreparedStatementInterceptor
651       extends StatementInterceptor
652       implements PreparedStatement JavaDoc
653    {
654       private final PreparedStatement JavaDoc target;
655
656       public PreparedStatementInterceptor(Connection JavaDoc con, PreparedStatement JavaDoc target)
657       {
658          super(con, target);
659          this.target = target;
660       }
661
662       public int executeUpdate() throws SQLException JavaDoc
663       {
664          return target.executeUpdate();
665       }
666
667       public void addBatch() throws SQLException JavaDoc
668       {
669          target.addBatch();
670       }
671
672       public void clearParameters() throws SQLException JavaDoc
673       {
674          target.clearParameters();
675       }
676
677       public boolean execute() throws SQLException JavaDoc
678       {
679          return target.execute();
680       }
681
682       public void setByte(int parameterIndex, byte x) throws SQLException JavaDoc
683       {
684          target.setByte(parameterIndex, x);
685       }
686
687       public void setDouble(int parameterIndex, double x) throws SQLException JavaDoc
688       {
689          target.setDouble(parameterIndex, x);
690       }
691
692       public void setFloat(int parameterIndex, float x) throws SQLException JavaDoc
693       {
694          target.setFloat(parameterIndex, x);
695       }
696
697       public void setInt(int parameterIndex, int x) throws SQLException JavaDoc
698       {
699          target.setInt(parameterIndex, x);
700       }
701
702       public void setNull(int parameterIndex, int sqlType) throws SQLException JavaDoc
703       {
704          target.setNull(parameterIndex, sqlType);
705       }
706
707       public void setLong(int parameterIndex, long x) throws SQLException JavaDoc
708       {
709          target.setLong(parameterIndex, x);
710       }
711
712       public void setShort(int parameterIndex, short x) throws SQLException JavaDoc
713       {
714          target.setShort(parameterIndex, x);
715       }
716
717       public void setBoolean(int parameterIndex, boolean x) throws SQLException JavaDoc
718       {
719          target.setBoolean(parameterIndex, x);
720       }
721
722       public void setBytes(int parameterIndex, byte x[]) throws SQLException JavaDoc
723       {
724          target.setBytes(parameterIndex, x);
725       }
726
727       public void setAsciiStream(int parameterIndex, InputStream JavaDoc x, int length) throws SQLException JavaDoc
728       {
729          target.setAsciiStream(parameterIndex, x, length);
730       }
731
732       public void setBinaryStream(int parameterIndex, InputStream JavaDoc x, int length) throws SQLException JavaDoc
733       {
734          target.setBinaryStream(parameterIndex, x, length);
735       }
736
737       public void setUnicodeStream(int parameterIndex, InputStream JavaDoc x, int length) throws SQLException JavaDoc
738       {
739          target.setUnicodeStream(parameterIndex, x, length);
740       }
741
742       public void setCharacterStream(int parameterIndex, Reader JavaDoc reader, int length) throws SQLException JavaDoc
743       {
744          target.setCharacterStream(parameterIndex, reader, length);
745       }
746
747       public void setObject(int parameterIndex, Object JavaDoc x) throws SQLException JavaDoc
748       {
749          target.setObject(parameterIndex, x);
750       }
751
752       public void setObject(int parameterIndex, Object JavaDoc x, int targetSqlType) throws SQLException JavaDoc
753       {
754          target.setObject(parameterIndex, x, targetSqlType);
755       }
756
757       public void setObject(int parameterIndex, Object JavaDoc x, int targetSqlType, int scale) throws SQLException JavaDoc
758       {
759          target.setObject(parameterIndex, x, targetSqlType, scale);
760       }
761
762       public void setNull(int paramIndex, int sqlType, String JavaDoc typeName) throws SQLException JavaDoc
763       {
764          target.setNull(paramIndex, sqlType, typeName);
765       }
766
767       public void setString(int parameterIndex, String JavaDoc x) throws SQLException JavaDoc
768       {
769          target.setString(parameterIndex, x);
770       }
771
772       public void setBigDecimal(int parameterIndex, BigDecimal JavaDoc x) throws SQLException JavaDoc
773       {
774          target.setBigDecimal(parameterIndex, x);
775       }
776
777       
778       public void setURL(int parameterIndex, URL JavaDoc x) throws SQLException JavaDoc
779       {
780          target.setURL(parameterIndex, x);
781       }
782       
783
784       public void setArray(int i, Array JavaDoc x) throws SQLException JavaDoc
785       {
786          target.setArray(i, x);
787       }
788
789       public void setBlob(int i, Blob JavaDoc x) throws SQLException JavaDoc
790       {
791          target.setBlob(i, x);
792       }
793
794       public void setClob(int i, Clob JavaDoc x) throws SQLException JavaDoc
795       {
796          target.setClob(i, x);
797       }
798
799       public void setDate(int parameterIndex, Date JavaDoc x) throws SQLException JavaDoc
800       {
801          target.setDate(parameterIndex, x);
802       }
803
804       
805       public ParameterMetaData JavaDoc getParameterMetaData() throws SQLException JavaDoc
806       {
807          return target.getParameterMetaData();
808       }
809       
810
811       public void setRef(int i, Ref JavaDoc x) throws SQLException JavaDoc
812       {
813          target.setRef(i, x);
814       }
815
816       public ResultSet JavaDoc executeQuery() throws SQLException JavaDoc
817       {
818          return target.executeQuery();
819       }
820
821       public ResultSetMetaData JavaDoc getMetaData() throws SQLException JavaDoc
822       {
823          return target.getMetaData();
824       }
825
826       public void setTime(int parameterIndex, Time JavaDoc x) throws SQLException JavaDoc
827       {
828          target.setTime(parameterIndex, x);
829       }
830
831       public void setTimestamp(int parameterIndex, Timestamp JavaDoc x) throws SQLException JavaDoc
832       {
833          target.setTimestamp(parameterIndex, x);
834       }
835
836       public void setDate(int parameterIndex, Date JavaDoc x, Calendar JavaDoc cal) throws SQLException JavaDoc
837       {
838          target.setDate(parameterIndex, x, cal);
839       }
840
841       public void setTime(int parameterIndex, Time JavaDoc x, Calendar JavaDoc cal) throws SQLException JavaDoc
842       {
843          target.setTime(parameterIndex, x, cal);
844       }
845
846       public void setTimestamp(int parameterIndex, Timestamp JavaDoc x, Calendar JavaDoc cal) throws SQLException JavaDoc
847       {
848          target.setTimestamp(parameterIndex, x, cal);
849       }
850    }
851
852    // Private
853

854    private void logSql(String JavaDoc sql)
855    {
856       try
857       {
858          StatisticalItem item = new TxReport.SqlStats(sql);
859          server.invoke(statsCollector, "addStatisticalItem",
860             new Object JavaDoc[]{item},
861             new String JavaDoc[]{StatisticalItem.class.getName()});
862       }
863       catch(Exception JavaDoc e)
864       {
865          log.error("Failed to add invocation.", e);
866       }
867    }
868
869    private void bind()
870       throws NamingException JavaDoc
871    {
872       InitialContext JavaDoc ic = null;
873       try
874       {
875          ic = new InitialContext JavaDoc();
876          Name JavaDoc name = ic.getNameParser("").parse(bindName);
877          NonSerializableFactory.rebind(name, this, true);
878          log.debug("bound to JNDI name " + bindName);
879       }
880       finally
881       {
882          if(ic != null)
883          {
884             ic.close();
885          }
886       }
887    }
888
889    private void unbind()
890       throws NamingException JavaDoc
891    {
892       InitialContext JavaDoc ic = null;
893       try
894       {
895          ic = new InitialContext JavaDoc();
896          ic.unbind(bindName);
897          NonSerializableFactory.unbind(bindName);
898       }
899       finally
900       {
901          if(ic != null)
902          {
903             ic.close();
904          }
905       }
906    }
907
908    private void updateTarget()
909       throws NamingException JavaDoc
910    {
911       InitialContext JavaDoc ic = null;
912       try
913       {
914          ic = new InitialContext JavaDoc();
915          target = (DataSource JavaDoc) ic.lookup(targetName);
916          log.debug("target updated to " + targetName);
917       }
918       finally
919       {
920          if(ic != null)
921          {
922             ic.close();
923          }
924       }
925    }
926 }
927
Popular Tags