KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > recover > oracle > OracleRecoverable


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.test.recover.oracle;
23
24 import org.jboss.tm.recovery.Recoverable;
25 import org.jboss.tm.recovery.RecoveryManagerServiceMBean;
26 import org.jboss.system.ServiceMBeanSupport;
27
28 import javax.transaction.xa.XAResource JavaDoc;
29 import javax.transaction.xa.Xid JavaDoc;
30 import javax.transaction.xa.XAException JavaDoc;
31 import javax.sql.XAConnection JavaDoc;
32 import java.sql.DriverManager JavaDoc;
33 import java.sql.SQLException JavaDoc;
34
35 import oracle.jdbc.OracleDriver;
36 import oracle.jdbc.xa.client.OracleXADataSource;
37
38 /**
39  * Test for Oracle 9i (maybe 10g too?)
40  *
41  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
42  * @version $Revision: 37406 $
43  */

44 public class OracleRecoverable extends ServiceMBeanSupport implements Recoverable, OracleRecoverableMBean
45 {
46    private String JavaDoc id;
47    private String JavaDoc url;
48    private String JavaDoc username;
49    private String JavaDoc password;
50    private RecoveryManagerServiceMBean manager;
51    private OracleXADataSource oxds1;
52    private XAConnection JavaDoc connection;
53    private XAResource JavaDoc resource;
54
55
56    protected void startService() throws Exception JavaDoc
57    {
58       super.startService();
59       oxds1 = new OracleXADataSource();
60       oxds1.setURL(url);
61       oxds1.setUser(username);
62       oxds1.setPassword(password);
63       manager.registerRecoverable(this);
64    }
65
66    public void setManager(RecoveryManagerServiceMBean manager)
67    {
68       this.manager = manager;
69    }
70
71
72    public String JavaDoc getId()
73    {
74       return id;
75    }
76
77    public void setId(String JavaDoc id)
78    {
79       this.id = id;
80    }
81
82    public String JavaDoc getUrl()
83    {
84       return url;
85    }
86
87    public void setUrl(String JavaDoc url)
88    {
89       this.url = url;
90    }
91
92    public String JavaDoc getUsername()
93    {
94       return username;
95    }
96
97    public void setUsername(String JavaDoc username)
98    {
99       this.username = username;
100    }
101
102    public String JavaDoc getPassword()
103    {
104       return password;
105    }
106
107    public void setPassword(String JavaDoc password)
108    {
109       this.password = password;
110    }
111
112    public XAResource JavaDoc getResource()
113    {
114       try
115       {
116          connection = oxds1.getXAConnection();
117          resource = connection.getXAResource();
118          return resource;
119       }
120       catch (SQLException JavaDoc e)
121       {
122          throw new RuntimeException JavaDoc(e);
123       }
124    }
125
126    public Xid JavaDoc[] scan() throws XAException JavaDoc
127    {
128       return resource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN);
129    }
130
131    public void cleanupResource()
132    {
133       try
134       {
135          connection.close();
136       }
137       catch (SQLException JavaDoc e)
138       {
139          throw new RuntimeException JavaDoc(e);
140       }
141    }
142 }
143
Popular Tags