1 9 package fictional.resourceadapter; 10 11 import javax.resource.ResourceException; 12 import javax.resource.NotSupportedException; 13 import javax.resource.cci.*; 14 import javax.resource.spi.ManagedConnection; 15 import javax.resource.spi.ConnectionEvent; 16 import org.objectweb.jonas.common.Log; 17 import org.objectweb.util.monolog.api.Logger; 18 import org.objectweb.util.monolog.api.BasicLevel; 19 20 28 public class ConnectionImpl 29 implements Connection, 30 ConnectionMetaData, 31 java.io.Serializable 32 { 33 public String product="Fictional EIS"; String version="1.1"; 35 String UserName="Fictional_User_Name"; private ManagedConnection mc; 37 public LocalTransactionImpl lt; 38 boolean closed = false; private Logger logger = null; 40 String cName = ""; 41 private boolean autoCommitMode = false; 42 43 public ConnectionImpl(Object mc) { if (logger == null) { 50 logger = Log.getLogger("fictional.resourceadapter"); 51 } 52 logger.log(BasicLevel.DEBUG, impl(this)+".constructor"); 53 this.mc=(ManagedConnection)mc; 54 } 55 private String impl(Object obj) { 56 if (obj instanceof Connection) { 57 return "ConnectionImpl"; 58 } else if (obj instanceof ConnectionImpl) { 59 return "Connection"; 60 } else if (obj instanceof ConnectionMetaData) { 61 return "ConnectionMetaData"; 62 } else 63 return "ConnectionImpl. Is this an error"; 64 } 65 public void close() throws ResourceException 69 { 70 logger.log(BasicLevel.DEBUG, impl(this) 71 +".close with ConnectionEvent.CONNECTION_CLOSED=" 72 +ConnectionEvent.CONNECTION_CLOSED); 73 closed = true; 74 75 if (mc != null) { 76 try { 77 JtestResourceAdapter omc = (JtestResourceAdapter) mc; 78 omc.sendEvent(ConnectionEvent.CONNECTION_CLOSED, null, this); 79 mc=null; 80 logger.log(BasicLevel.DEBUG, impl(this) 81 +".close sendevent 'CONNECTION_CLOSED'"); 82 } catch (ResourceException e) { 83 logger.log(BasicLevel.DEBUG, impl(this)+".close error: unable to close"); 84 throw e; 85 } 86 } else { 87 logger.log(BasicLevel.DEBUG, impl(this)+".close error: mc=null"); 88 } 89 return; 90 } 91 public void close(int eType) throws ResourceException 99 { 100 logger.log(BasicLevel.DEBUG, impl(this)+".close("+eType+")"); 101 closed = true; 102 103 if (mc != null) { 104 try { 105 JtestResourceAdapter omc = (JtestResourceAdapter) mc; 106 omc.sendEvent(eType, null, this); 107 mc=null; 108 logger.log(BasicLevel.DEBUG, impl(this) 109 +".close(CONNECTION_ERROR_OCCURRED=" 110 +ConnectionEvent.CONNECTION_ERROR_OCCURRED+") to " 111 +"close physical connection"); 112 } catch (ResourceException e) { 113 logger.log(BasicLevel.DEBUG, impl(this) 114 +".close error: unable to close physical connection" 115 +" with 'CONNECTION_ERROR_OCCURRED'"); 116 throw e; 117 } 118 } else { 119 logger.log(BasicLevel.DEBUG, impl(this)+".close error: mc=null already"); 120 } 121 return; 122 } 123 public Interaction createInteraction() throws ResourceException 124 { 125 logger.log(BasicLevel.DEBUG, impl(this)+".createInteraction"); 126 Interaction gi=new JtestInteraction(this, mc); 127 return gi; 129 } 130 public ConnectionMetaData getMetaData() throws ResourceException 131 { 132 logger.log(BasicLevel.DEBUG, impl(this)+".getMetaData"); 133 ConnectionMetaData eisInfo = (ConnectionMetaData)new ConnectionImpl(mc); 134 return eisInfo; 135 } 136 public LocalTransaction getLocalTransaction() 137 throws ResourceException 138 { 139 try { 140 JtestResourceAdapter jmc = (JtestResourceAdapter)mc; 141 lt = (LocalTransactionImpl) jmc.getLocalTransaction(true); 142 logger.log(BasicLevel.DEBUG, impl(this)+".getLocalTransaction lt="+lt); 143 } catch (Exception e) { 144 logger.log(BasicLevel.DEBUG, impl(this)+".getLocalTransaction error: " 145 +e.getMessage()+" <<<<<<<<<<<<"); 146 } 147 return (lt); 148 } 149 public ResultSetInfo getResultSetInfo() throws ResourceException 150 { 151 logger.log(BasicLevel.DEBUG, impl(this)+".getResultSetInfo"); 152 NotSupportedException nse = new NotSupportedException("getResultSetInfo is not supported"); 153 throw nse; 154 } 155 public void associateConnection(ManagedConnection mc) throws IllegalStateException 156 { 157 logger.log(BasicLevel.DEBUG, impl(this)+".associateConnection"); 158 this.mc=mc; 159 } 160 public ManagedConnection getMC() throws ResourceException 161 { 162 logger.log(BasicLevel.DEBUG, impl(this)+".getMC mc="+this.mc); 163 return this.mc; 164 } 165 public void setAutoCommit(boolean a) { 166 autoCommitMode=a; 167 } 168 public boolean getAutoCommit() { 169 return autoCommitMode; 170 } 171 public String getEISProductName() 182 throws ResourceException 183 { 184 return (product); 185 } 186 public String getEISProductVersion() 187 throws ResourceException 188 { 189 return (version); 190 } 191 public String getUserName() 192 throws ResourceException 193 { 194 return (UserName); 195 } 196 } 197 | Popular Tags |