KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > jca > ra > JEManagedConnectionFactory


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: JEManagedConnectionFactory.java,v 1.9 2006/10/30 21:14:18 bostic Exp $
7  */

8
9 package com.sleepycat.je.jca.ra;
10
11 import java.io.PrintWriter JavaDoc;
12 import java.io.Serializable JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import javax.resource.ResourceException JavaDoc;
17 import javax.resource.spi.ConnectionManager JavaDoc;
18 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
19 import javax.resource.spi.ManagedConnection JavaDoc;
20 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
21 import javax.security.auth.Subject JavaDoc;
22
23 import com.sleepycat.je.DbInternal;
24 import com.sleepycat.je.dbi.EnvironmentImpl;
25
26 public class JEManagedConnectionFactory
27     implements ManagedConnectionFactory JavaDoc, Serializable JavaDoc {
28
29     public JEManagedConnectionFactory() {
30     }
31
32     public Object JavaDoc createConnectionFactory(ConnectionManager JavaDoc cxManager)
33     throws ResourceException JavaDoc {
34
35         return new JEConnectionFactoryImpl(cxManager, this);
36     }
37
38     public Object JavaDoc createConnectionFactory()
39     throws ResourceException JavaDoc {
40
41     throw new UnsupportedOperationException JavaDoc("must supply a connMgr");
42     }
43
44     public ManagedConnection JavaDoc
45     createManagedConnection(Subject JavaDoc subject,
46                 ConnectionRequestInfo JavaDoc info)
47     throws ResourceException JavaDoc {
48
49     JERequestInfo jeInfo = (JERequestInfo) info;
50     return new JEManagedConnection(subject, jeInfo);
51     }
52
53     public ManagedConnection JavaDoc
54     matchManagedConnections(Set JavaDoc connectionSet,
55                 Subject JavaDoc subject,
56                 ConnectionRequestInfo JavaDoc info)
57         throws ResourceException JavaDoc {
58
59     JERequestInfo jeInfo = (JERequestInfo) info;
60     Iterator JavaDoc iter = connectionSet.iterator();
61     while (iter.hasNext()) {
62         Object JavaDoc next = iter.next();
63         if (next instanceof JEManagedConnection) {
64         JEManagedConnection mc = (JEManagedConnection) next;
65         EnvironmentImpl nextEnvImpl =
66             DbInternal.envGetEnvironmentImpl(mc.getEnvironment());
67         /* Do we need to match on more than root dir and r/o? */
68         if (nextEnvImpl.getEnvironmentHome().
69             equals(jeInfo.getJERootDir()) &&
70             nextEnvImpl.isReadOnly() ==
71             jeInfo.getEnvConfig().getReadOnly()) {
72             return mc;
73         }
74         }
75     }
76         return null;
77     }
78
79     public void setLogWriter(PrintWriter JavaDoc out)
80     throws ResourceException JavaDoc {
81
82     }
83
84     public PrintWriter JavaDoc getLogWriter()
85     throws ResourceException JavaDoc {
86
87         return null;
88     }
89
90     public boolean equals(Object JavaDoc obj) {
91     if (obj == null) {
92         return false;
93     }
94
95     if (obj instanceof JEManagedConnectionFactory) {
96         return true;
97     } else {
98         return false;
99     }
100     }
101
102     public int hashCode() {
103     return 0;
104     }
105 }
106
Popular Tags