KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > adapter > jdbc > remote > WrapperDataSourceService


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.resource.adapter.jdbc.remote;
23
24 import java.io.ByteArrayOutputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.io.ObjectOutputStream JavaDoc;
28 import java.io.Serializable JavaDoc;
29 import java.lang.reflect.InvocationTargetException JavaDoc;
30 import java.lang.reflect.Method JavaDoc;
31 import java.lang.reflect.UndeclaredThrowableException JavaDoc;
32 import java.sql.CallableStatement JavaDoc;
33 import java.sql.Connection JavaDoc;
34 import java.sql.DatabaseMetaData JavaDoc;
35 import java.sql.ParameterMetaData JavaDoc;
36 import java.sql.PreparedStatement JavaDoc;
37 import java.sql.ResultSet JavaDoc;
38 import java.sql.ResultSetMetaData JavaDoc;
39 import java.sql.SQLException JavaDoc;
40 import java.sql.Statement JavaDoc;
41 import java.util.ArrayList JavaDoc;
42 import java.util.HashMap JavaDoc;
43 import java.util.Iterator JavaDoc;
44 import java.util.Map JavaDoc;
45
46 import javax.management.ObjectName JavaDoc;
47 import javax.naming.BinaryRefAddr JavaDoc;
48 import javax.naming.InitialContext JavaDoc;
49 import javax.naming.NamingException JavaDoc;
50 import javax.naming.Reference JavaDoc;
51 import javax.naming.StringRefAddr JavaDoc;
52 import javax.resource.Referenceable JavaDoc;
53 import javax.sql.DataSource JavaDoc;
54
55 import org.jboss.deployment.DeploymentException;
56 import org.jboss.invocation.Invocation;
57 import org.jboss.invocation.Invoker;
58 import org.jboss.invocation.InvokerInterceptor;
59 import org.jboss.invocation.MarshalledInvocation;
60 import org.jboss.logging.Logger;
61 import org.jboss.proxy.ClientMethodInterceptor;
62 import org.jboss.proxy.GenericProxyFactory;
63 import org.jboss.resource.connectionmanager.ConnectionFactoryBindingService;
64 import org.jboss.system.Registry;
65 import org.jboss.util.naming.NonSerializableFactory;
66 import org.jboss.util.naming.Util;
67 import org.jboss.util.Classes;
68
69
70 /**
71  * An mbean service that pvovides the detached invoker ops for the
72  * javax.sql.DataSource and related java.sql.* interfaces.
73  *
74  * TODO this does not belong in the resource adapter
75  * @author Scott.Stark@jboss.org
76  * @author Tom.Elrod@jboss.org
77  * @author adrian@jboss.com
78  * @version $Revision: 42017 $
79  */

80 public class WrapperDataSourceService extends ConnectionFactoryBindingService implements WrapperDataSourceServiceMBean
81 {
82    private static Logger log = Logger.getLogger(WrapperDataSourceService.class);
83
84    private ObjectName JavaDoc jmxInvokerName;
85    private Invoker delegateInvoker;
86    private Object JavaDoc theProxy;
87    private HashMap JavaDoc marshalledInvocationMapping = new HashMap JavaDoc();
88    private HashMap JavaDoc connectionMap = new HashMap JavaDoc();
89    private HashMap JavaDoc statementMap = new HashMap JavaDoc();
90    private HashMap JavaDoc resultSetMap = new HashMap JavaDoc();
91    private HashMap JavaDoc lobMap = new HashMap JavaDoc();
92    private HashMap JavaDoc databaseMetaDataMap = new HashMap JavaDoc();
93    private boolean trace = log.isTraceEnabled();
94
95    protected void startService() throws Exception JavaDoc
96    {
97       determineBindName();
98       createConnectionFactory();
99       if( jmxInvokerName != null )
100       {
101          createProxy();
102          calculateMethodHases();
103          bindConnectionFactory();
104       }
105       else
106       {
107          super.bindConnectionFactory();
108       }
109    }
110
111    protected void stopService() throws Exception JavaDoc
112    {
113       unbindConnectionFactory();
114       if( jmxInvokerName != null )
115       destroyProxy();
116    }
117
118    protected void bindConnectionFactory() throws Exception JavaDoc
119    {
120       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
121       try
122       {
123          log.debug("Binding object '" + cf + "' into JNDI at '" + bindName + "'");
124          // Associated the local cf with the NonSerializable factory
125
NonSerializableFactory.rebind(bindName, cf);
126          /* Create a reference that uses the the DataSourceFactory as the
127          reference factory class. This class detects whether the lookup
128          is being done locally or remotely and returns either the just bound
129          connection factory, or a DataSource proxy that uses the detached
130          invoker framework to expose remote proxies to the server side
131          DataSource and related elements.
132          */

133          Referenceable JavaDoc referenceable = (Referenceable JavaDoc) cf;
134          // Set the DataSource proxy as the ProxyData ref address
135
ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
136          ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
137          oos.writeObject(theProxy);
138          oos.close();
139          byte[] proxyBytes = baos.toByteArray();
140          BinaryRefAddr JavaDoc dsAddr = new BinaryRefAddr JavaDoc("ProxyData", proxyBytes);
141          String JavaDoc factory = DataSourceFactory.class.getName();
142          Reference JavaDoc dsRef = new Reference JavaDoc("javax.sql.DataSource", dsAddr, factory, null);
143          referenceable.setReference(dsRef);
144          // Set the VMID as the address local/remote indicator
145
baos.reset();
146          ObjectOutputStream JavaDoc oos2 = new ObjectOutputStream JavaDoc(baos);
147          oos2.writeObject(DataSourceFactory.vmID);
148          oos2.close();
149          byte[] id = baos.toByteArray();
150          BinaryRefAddr JavaDoc localAddr = new BinaryRefAddr JavaDoc("VMID", id);
151          dsRef.add(localAddr);
152          /* Bind the Referenceable connection factory into JNDI and set the
153          JndiName value of the reference address for use by the DataSourceFactory
154          when looking up the local factory from the NonSerializableFactory.
155          */

156          StringRefAddr JavaDoc jndiRef = new StringRefAddr JavaDoc("JndiName", bindName);
157          dsRef.add(jndiRef);
158          Util.rebind(ctx, bindName, cf);
159          log.info("Bound ConnectionManager '" + serviceName + "' to JNDI name '" + bindName + "'");
160       }
161       catch (NamingException JavaDoc ne)
162       {
163          throw new DeploymentException("Could not bind ConnectionFactory into jndi: " + bindName, ne);
164       }
165       finally
166       {
167          ctx.close();
168       }
169    }
170
171    public ObjectName JavaDoc getJMXInvokerName()
172    {
173       return jmxInvokerName;
174    }
175
176    public void setJMXInvokerName(ObjectName JavaDoc jmxInvokerName)
177    {
178       this.jmxInvokerName = jmxInvokerName;
179    }
180
181    public Object JavaDoc invoke(Invocation invocation) throws Exception JavaDoc
182    {
183       // Set the method hash to Method mapping
184
if (invocation instanceof MarshalledInvocation)
185       {
186          MarshalledInvocation mi = (MarshalledInvocation) invocation;
187          mi.setMethodMap(marshalledInvocationMapping);
188       }
189       // Invoke the Naming method via reflection
190
Method JavaDoc method = invocation.getMethod();
191       Class JavaDoc methodClass = method.getDeclaringClass();
192       Object JavaDoc[] args = invocation.getArguments();
193       Object JavaDoc value = null;
194
195       try
196       {
197          if( methodClass.isAssignableFrom(DataSource JavaDoc.class) )
198          {
199             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
200             DataSource JavaDoc ds = (DataSource JavaDoc) ctx.lookup(bindName);
201             value = doDataSourceMethod(ds, method, args);
202          }
203          else if( methodClass.isAssignableFrom(Connection JavaDoc.class) )
204          {
205             Integer JavaDoc id = (Integer JavaDoc) invocation.getId();
206             Connection JavaDoc conn = (Connection JavaDoc) connectionMap.get(id);
207             if( conn == null )
208             {
209                throw new IllegalAccessException JavaDoc("Failed to find connection: "+id);
210             }
211             value = doConnectionMethod(conn, method, args);
212          }
213          else if( methodClass.isAssignableFrom(Statement JavaDoc.class) ||
214             methodClass.isAssignableFrom(PreparedStatement JavaDoc.class) ||
215             methodClass.isAssignableFrom(CallableStatement JavaDoc.class))
216          {
217             Integer JavaDoc id = (Integer JavaDoc) invocation.getId();
218             Statement JavaDoc stmt = (Statement JavaDoc) statementMap.get(id);
219             if( stmt == null )
220             {
221                throw new SQLException JavaDoc("Failed to find Statement: " + id);
222             }
223             value = doStatementMethod(stmt, method, args);
224          }
225          else if( methodClass.isAssignableFrom(ResultSet JavaDoc.class) )
226          {
227             Integer JavaDoc id = (Integer JavaDoc) invocation.getId();
228             ResultSet JavaDoc results = (ResultSet JavaDoc) resultSetMap.get(id);
229             if( results == null )
230             {
231                throw new IllegalAccessException JavaDoc("Failed to find ResultSet: "+id);
232             }
233             value = doResultSetMethod(results, method, args);
234          }
235          else if (methodClass.isAssignableFrom(DatabaseMetaData JavaDoc.class))
236          {
237             Integer JavaDoc id = (Integer JavaDoc) invocation.getId();
238             DatabaseMetaData JavaDoc dbMetaData = (DatabaseMetaData JavaDoc) databaseMetaDataMap.get(id);
239             if(dbMetaData == null)
240             {
241                throw new IllegalAccessException JavaDoc("Failed to find DatabaseMetaData: " + id);
242             }
243             value = doDatabaseMetaDataMethod(dbMetaData, method, args);
244          }
245          else
246          {
247             throw new UnsupportedOperationException JavaDoc("Do not know how to handle method="+method);
248          }
249       }
250       catch (InvocationTargetException JavaDoc e)
251       {
252          Throwable JavaDoc t = e.getTargetException();
253          if (t instanceof Exception JavaDoc)
254             throw (Exception JavaDoc) t;
255          else
256             throw new UndeclaredThrowableException JavaDoc(t, method.toString());
257       }
258
259       return value;
260    }
261
262    /**
263     * Create the proxy
264     *
265     * TODO this should be external configuration
266     */

267    protected void createProxy() throws Exception JavaDoc
268    {
269       /* Create an JRMPInvokerProxy that will be associated with a naming JMX
270       invoker given by the jmxInvokerName.
271       */

272      delegateInvoker = (Invoker) Registry.lookup(jmxInvokerName);
273      log.debug("Using delegate: " + delegateInvoker
274         + " for invoker=" + jmxInvokerName);
275      ObjectName JavaDoc targetName = getServiceName();
276      Integer JavaDoc nameHash = new Integer JavaDoc(targetName.hashCode());
277      Registry.bind(nameHash, targetName);
278
279      Object JavaDoc cacheID = null;
280      String JavaDoc proxyBindingName = null;
281      String JavaDoc jndiName = null;
282      Class JavaDoc[] ifaces = {javax.sql.DataSource JavaDoc.class};
283      /* Initialize interceptorClasses with default client interceptor list
284         if no client interceptor configuration was provided */

285      ArrayList JavaDoc interceptorClasses = new ArrayList JavaDoc();
286      interceptorClasses.add(ClientMethodInterceptor.class);
287      interceptorClasses.add(InvokerInterceptor.class);
288      ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
289      GenericProxyFactory proxyFactory = new GenericProxyFactory();
290      theProxy = proxyFactory.createProxy(cacheID, targetName,
291         delegateInvoker, jndiName, proxyBindingName, interceptorClasses,
292         loader, ifaces);
293      log.debug("Created proxy for invoker=" + jmxInvokerName
294         + ", targetName=" + targetName + ", nameHash=" + nameHash);
295    }
296
297    /**
298     * Destroy the proxy
299     */

300    protected void destroyProxy() throws Exception JavaDoc
301    {
302       ObjectName JavaDoc name = getServiceName();
303       Integer JavaDoc nameHash = new Integer JavaDoc(name.hashCode());
304       Registry.unbind(nameHash);
305    }
306
307    /**
308     * Calculate the method hashes
309     */

310    protected void calculateMethodHases() throws Exception JavaDoc
311    {
312       Method JavaDoc[] methods = DataSource JavaDoc.class.getMethods();
313       for(int m = 0; m < methods.length; m ++)
314       {
315          Method JavaDoc method = methods[m];
316          Long JavaDoc hash = new Long JavaDoc(MarshalledInvocation.calculateHash(method));
317          marshalledInvocationMapping.put(hash, method);
318       }
319
320       // Get the Long to Method mappings
321
Map JavaDoc m = MarshalledInvocation.methodToHashesMap(Connection JavaDoc.class);
322       displayHashes(m);
323       marshalledInvocationMapping.putAll(m);
324       m = MarshalledInvocation.methodToHashesMap(Statement JavaDoc.class);
325       displayHashes(m);
326       marshalledInvocationMapping.putAll(m);
327       m = MarshalledInvocation.methodToHashesMap(CallableStatement JavaDoc.class);
328       displayHashes(m);
329       marshalledInvocationMapping.putAll(m);
330       m = MarshalledInvocation.methodToHashesMap(PreparedStatement JavaDoc.class);
331       displayHashes(m);
332       marshalledInvocationMapping.putAll(m);
333       m = MarshalledInvocation.methodToHashesMap(ResultSet JavaDoc.class);
334       displayHashes(m);
335       marshalledInvocationMapping.putAll(m);
336       m = MarshalledInvocation.methodToHashesMap(DatabaseMetaData JavaDoc.class);
337       displayHashes(m);
338       marshalledInvocationMapping.putAll(m);
339    }
340
341    private Object JavaDoc doDataSourceMethod(DataSource JavaDoc ds, Method JavaDoc method, Object JavaDoc[] args)
342       throws InvocationTargetException JavaDoc, IllegalAccessException JavaDoc
343    {
344       Object JavaDoc value = method.invoke(ds, args);
345       if( value instanceof Connection JavaDoc )
346       {
347          value = createConnectionProxy(value);
348       }
349       else if( value != null && (value instanceof Serializable JavaDoc) == false )
350       {
351          throw new IllegalAccessException JavaDoc("Method="+method+" does not return Serializable");
352       }
353       return value;
354    }
355
356    private Object JavaDoc doConnectionMethod(Connection JavaDoc conn, Method JavaDoc method, Object JavaDoc[] args)
357          throws InvocationTargetException JavaDoc, IllegalAccessException JavaDoc, SQLException JavaDoc
358    {
359       if( trace )
360       {
361          log.trace("doConnectionMethod, conn="+conn+", method="+method);
362       }
363       Object JavaDoc value = method.invoke(conn, args);
364       if( value instanceof Statement JavaDoc )
365       {
366          value = createStatementProxy(value);
367       }
368       else if(value instanceof DatabaseMetaData JavaDoc)
369       {
370          value = createDatabaseMetaData(value);
371       }
372       else if( value != null && (value instanceof Serializable JavaDoc) == false )
373       {
374          throw new IllegalAccessException JavaDoc("Method="+method+" does not return Serializable");
375       }
376       return value;
377    }
378
379    private Object JavaDoc doStatementMethod(Statement JavaDoc stmt, Method JavaDoc method, Object JavaDoc[] args)
380          throws InvocationTargetException JavaDoc, IllegalAccessException JavaDoc, SQLException JavaDoc
381    {
382       if( trace )
383       {
384          log.trace("doStatementMethod, conn="+stmt+", method="+method);
385       }
386
387       if( method.getName().equals("close") )
388       {
389          Integer JavaDoc id = new Integer JavaDoc(stmt.hashCode());
390          statementMap.remove(id);
391          log.debug("Closed Statement="+id);
392       }
393
394       Object JavaDoc value = method.invoke(stmt, args);
395       if( value instanceof ResultSet JavaDoc )
396       {
397          value = createResultSetProxy(value);
398       }
399       else if( value instanceof ResultSetMetaData JavaDoc )
400       {
401          ResultSetMetaData JavaDoc rmd = (ResultSetMetaData JavaDoc) value;
402          value = new SerializableResultSetMetaData(rmd);
403       }
404       else if ( value instanceof ParameterMetaData JavaDoc )
405       {
406          ParameterMetaData JavaDoc pmd = (ParameterMetaData JavaDoc) value;
407          value = new SerializableParameterMetaData(pmd);
408       }
409       else if( value != null && (value instanceof Serializable JavaDoc) == false )
410       {
411          throw new IllegalAccessException JavaDoc("Method="+method+" does not return Serializable");
412       }
413       return value;
414    }
415
416    private Object JavaDoc doResultSetMethod(ResultSet JavaDoc results, Method JavaDoc method, Object JavaDoc[] args)
417          throws InvocationTargetException JavaDoc, IllegalAccessException JavaDoc, SQLException JavaDoc, IOException JavaDoc
418    {
419       if( trace )
420       {
421          log.trace("doStatementMethod, results="+results+", method="+method);
422       }
423
424       if( method.getName().equals("close") )
425       {
426          Integer JavaDoc id = new Integer JavaDoc(results.hashCode());
427          resultSetMap.remove(id);
428          log.debug("Closed ResultSet="+id);
429       }
430
431       Object JavaDoc value = method.invoke(results, args);
432       if( value instanceof ResultSetMetaData JavaDoc )
433       {
434          ResultSetMetaData JavaDoc rmd = (ResultSetMetaData JavaDoc) value;
435          value = new SerializableResultSetMetaData(rmd);
436       }
437       // Need to create serializable version of ascii stream returned by result set
438
if(("getBinaryStream".equals(method.getName()) || "getAsciiStream".equals(method.getName())) && value instanceof InputStream JavaDoc)
439       {
440          InputStream JavaDoc ins = (InputStream JavaDoc)value;
441          value = new SerializableInputStream(ins);
442       }
443       else if ("getCharacterStream".equals(method.getName()) && value instanceof java.io.Reader JavaDoc)
444       {
445          java.io.Reader JavaDoc ins = (java.io.Reader JavaDoc)value;
446          value = new SerializableReader(ins);
447       }
448       else if("getClob".equals(method.getName()) || "getBlob".equals(method.getName()))
449       {
450         value = createLobProxy(value);
451       }
452
453       if( value != null && (value instanceof Serializable JavaDoc) == false )
454       {
455          throw new IllegalAccessException JavaDoc("Method="+method+" does not return Serializable");
456       }
457       return value;
458    }
459
460    private Object JavaDoc doDatabaseMetaDataMethod(DatabaseMetaData JavaDoc dbMetaData, Method JavaDoc method, Object JavaDoc[] args)
461          throws InvocationTargetException JavaDoc, IllegalAccessException JavaDoc
462    {
463       if( trace )
464       {
465          log.trace("doDatabaseMetaDataMethod, dbMetaData="+dbMetaData+", method="+method);
466       }
467
468       Object JavaDoc value = method.invoke(dbMetaData, args);
469       if( value instanceof ResultSet JavaDoc )
470       {
471          value = createResultSetProxy(value);
472       }
473       else if( value instanceof Connection JavaDoc )
474       {
475          value = createConnectionProxy(value);
476       }
477       if( value != null && (value instanceof Serializable JavaDoc) == false )
478       {
479          throw new IllegalAccessException JavaDoc("Method="+method+" does not return Serializable");
480       }
481       return value;
482    }
483
484    private Object JavaDoc createConnectionProxy(Object JavaDoc conn)
485    {
486       Object JavaDoc cacheID = new Integer JavaDoc(conn.hashCode());
487       ObjectName JavaDoc targetName = getServiceName();
488       String JavaDoc proxyBindingName = null;
489       String JavaDoc jndiName = null;
490       Class JavaDoc[] ifaces = {java.sql.Connection JavaDoc.class};
491       ArrayList JavaDoc interceptorClasses = new ArrayList JavaDoc();
492       interceptorClasses.add(ClientMethodInterceptor.class);
493       interceptorClasses.add(InvokerInterceptor.class);
494       ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
495       GenericProxyFactory proxyFactory = new GenericProxyFactory();
496       Object JavaDoc connProxy = proxyFactory.createProxy(cacheID, targetName,
497          delegateInvoker, jndiName, proxyBindingName, interceptorClasses,
498          loader, ifaces);
499       connectionMap.put(cacheID, conn);
500       log.debug("Created Connection proxy for invoker=" + jmxInvokerName
501          + ", targetName=" + targetName + ", cacheID=" + cacheID);
502       return connProxy;
503    }
504
505    private Object JavaDoc createStatementProxy(Object JavaDoc stmt)
506    {
507       Object JavaDoc cacheID = new Integer JavaDoc(stmt.hashCode());
508       ObjectName JavaDoc targetName = getServiceName();
509       String JavaDoc proxyBindingName = null;
510       String JavaDoc jndiName = null;
511       // Filter out all but java* interfaces
512
Class JavaDoc[] ifaces = getJavaInterfaces(stmt.getClass());
513       ArrayList JavaDoc interceptorClasses = new ArrayList JavaDoc();
514       interceptorClasses.add(StatementInterceptor.class);
515       interceptorClasses.add(ClientMethodInterceptor.class);
516       interceptorClasses.add(InvokerInterceptor.class);
517       ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
518       GenericProxyFactory proxyFactory = new GenericProxyFactory();
519       Object JavaDoc stmtProxy = proxyFactory.createProxy(cacheID, targetName,
520          delegateInvoker, jndiName, proxyBindingName, interceptorClasses,
521          loader, ifaces);
522       statementMap.put(cacheID, stmt);
523       log.debug("Created Statement proxy for invoker=" + jmxInvokerName
524          + ", targetName=" + targetName + ", cacheID=" + cacheID);
525       return stmtProxy;
526    }
527
528    private Object JavaDoc createResultSetProxy(Object JavaDoc results)
529    {
530       Object JavaDoc cacheID = new Integer JavaDoc(results.hashCode());
531       ObjectName JavaDoc targetName = getServiceName();
532       String JavaDoc proxyBindingName = null;
533       String JavaDoc jndiName = null;
534       // Filter out all but java* interfaces
535
Class JavaDoc[] ifaces = getJavaInterfaces(results.getClass());
536
537       ArrayList JavaDoc interceptorClasses = new ArrayList JavaDoc();
538       interceptorClasses.add(ClientMethodInterceptor.class);
539       interceptorClasses.add(InvokerInterceptor.class);
540       ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
541       GenericProxyFactory proxyFactory = new GenericProxyFactory();
542       Object JavaDoc resultsProxy = proxyFactory.createProxy(cacheID, targetName,
543          delegateInvoker, jndiName, proxyBindingName, interceptorClasses,
544          loader, ifaces);
545       resultSetMap.put(cacheID, results);
546       log.debug("Created ResultSet proxy for invoker=" + jmxInvokerName
547          + ", targetName=" + targetName + ", cacheID=" + cacheID);
548       return resultsProxy;
549    }
550
551     private Object JavaDoc createLobProxy(Object JavaDoc results)
552    {
553       Object JavaDoc cacheID = new Integer JavaDoc(results.hashCode());
554       ObjectName JavaDoc targetName = getServiceName();
555       String JavaDoc proxyBindingName = null;
556       String JavaDoc jndiName = null;
557       Class JavaDoc[] ifaces = results.getClass().getInterfaces();
558       ArrayList JavaDoc interceptorClasses = new ArrayList JavaDoc();
559       interceptorClasses.add(ClientMethodInterceptor.class);
560       interceptorClasses.add(InvokerInterceptor.class);
561       ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
562       GenericProxyFactory proxyFactory = new GenericProxyFactory();
563       Object JavaDoc resultsProxy = proxyFactory.createProxy(cacheID, targetName,
564          delegateInvoker, jndiName, proxyBindingName, interceptorClasses,
565          loader, ifaces);
566       lobMap.put(cacheID, results);
567       log.debug("Created LOB proxy for invoker=" + jmxInvokerName
568          + ", targetName=" + targetName + ", cacheID=" + cacheID);
569       return resultsProxy;
570    }
571
572    private Object JavaDoc createDatabaseMetaData(Object JavaDoc dbMetaData)
573    {
574       Object JavaDoc cacheID = new Integer JavaDoc(dbMetaData.hashCode());
575       ObjectName JavaDoc targetName = getServiceName();
576       String JavaDoc proxyBindingName = null;
577       String JavaDoc jndiName = null;
578       Class JavaDoc[] ifaces = {java.sql.DatabaseMetaData JavaDoc.class};
579       ArrayList JavaDoc interceptorClasses = new ArrayList JavaDoc();
580       interceptorClasses.add(ClientMethodInterceptor.class);
581       interceptorClasses.add(InvokerInterceptor.class);
582       ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
583       GenericProxyFactory proxyFactory = new GenericProxyFactory();
584       Object JavaDoc dbMetaDataProxy = proxyFactory.createProxy(cacheID, targetName,
585          delegateInvoker, jndiName, proxyBindingName, interceptorClasses,
586          loader, ifaces);
587       databaseMetaDataMap.put(cacheID, dbMetaData);
588       log.debug("Created DatabaseMetadata proxy for invoker=" + jmxInvokerName
589          + ", targetName=" + targetName + ", cacheID=" + cacheID);
590       return dbMetaDataProxy;
591
592    }
593
594    private void displayHashes(Map JavaDoc m)
595    {
596       if( trace == false )
597          return;
598
599       Iterator JavaDoc keys = m.keySet().iterator();
600       while( keys.hasNext() )
601       {
602          Long JavaDoc key = (Long JavaDoc) keys.next();
603          log.trace(key+"="+m.get(key));
604       }
605    }
606
607    private Class JavaDoc[] getJavaInterfaces(Class JavaDoc clazz)
608    {
609       ArrayList JavaDoc tmp = new ArrayList JavaDoc();
610       Classes.getAllInterfaces(tmp, clazz);
611       Iterator JavaDoc iter = tmp.iterator();
612       while( iter.hasNext() )
613       {
614          Class JavaDoc c = (Class JavaDoc) iter.next();
615          if( c.getName().startsWith("java") == false )
616             iter.remove();
617       }
618       Class JavaDoc[] ifaces = new Class JavaDoc[tmp.size()];
619       return (Class JavaDoc[]) tmp.toArray(ifaces);
620    }
621 }
622
Popular Tags