1 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 ; 29 import javax.transaction.xa.Xid ; 30 import javax.transaction.xa.XAException ; 31 import javax.sql.XAConnection ; 32 import java.sql.DriverManager ; 33 import java.sql.SQLException ; 34 35 import oracle.jdbc.OracleDriver; 36 import oracle.jdbc.xa.client.OracleXADataSource; 37 38 44 public class OracleRecoverable extends ServiceMBeanSupport implements Recoverable, OracleRecoverableMBean 45 { 46 private String id; 47 private String url; 48 private String username; 49 private String password; 50 private RecoveryManagerServiceMBean manager; 51 private OracleXADataSource oxds1; 52 private XAConnection connection; 53 private XAResource resource; 54 55 56 protected void startService() throws Exception 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 getId() 73 { 74 return id; 75 } 76 77 public void setId(String id) 78 { 79 this.id = id; 80 } 81 82 public String getUrl() 83 { 84 return url; 85 } 86 87 public void setUrl(String url) 88 { 89 this.url = url; 90 } 91 92 public String getUsername() 93 { 94 return username; 95 } 96 97 public void setUsername(String username) 98 { 99 this.username = username; 100 } 101 102 public String getPassword() 103 { 104 return password; 105 } 106 107 public void setPassword(String password) 108 { 109 this.password = password; 110 } 111 112 public XAResource getResource() 113 { 114 try 115 { 116 connection = oxds1.getXAConnection(); 117 resource = connection.getXAResource(); 118 return resource; 119 } 120 catch (SQLException e) 121 { 122 throw new RuntimeException (e); 123 } 124 } 125 126 public Xid [] scan() throws XAException 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 e) 138 { 139 throw new RuntimeException (e); 140 } 141 } 142 } 143 | Popular Tags |