1 28 29 package org.apache.commons.transaction.memory.jca; 30 31 import javax.naming.NamingException ; 32 import javax.naming.Reference ; 33 import javax.resource.NotSupportedException ; 34 import javax.resource.ResourceException ; 35 import javax.resource.cci.Connection ; 36 import javax.resource.cci.ConnectionFactory ; 37 import javax.resource.cci.ConnectionSpec ; 38 import javax.resource.cci.RecordFactory ; 39 import javax.resource.cci.ResourceAdapterMetaData ; 40 import javax.resource.spi.ConnectionManager ; 41 import javax.resource.spi.ManagedConnectionFactory ; 42 43 48 public class MapConnectionFactory implements ConnectionFactory { 49 50 Reference reference; 51 ConnectionManager cm; 52 ManagedConnectionFactory mcf; 53 54 String name; 55 56 public MapConnectionFactory(ManagedConnectionFactory mcf, ConnectionManager cm) { 57 System.out.println("MCF Init with mcf " + mcf + " cm " + cm); 58 this.mcf = mcf; 59 this.cm = cm; 60 } 61 62 public Connection getConnection() throws ResourceException { 63 throw new NotSupportedException ("Need name of accessed map. Call getConnection(ConnectionSpec spec) instead"); 64 } 65 66 public Connection getConnection(ConnectionSpec spec) throws ResourceException { 67 if (!(spec instanceof MapConnectionSpec)) { 68 throw new NotSupportedException ("ConnectionSpec must be instance of MapConnectionSpec"); 69 } 70 System.out.println("Getting connection with spec "+spec); 71 return (Connection ) cm.allocateConnection(mcf, (MapConnectionSpec)spec); 72 } 73 74 public RecordFactory getRecordFactory() throws ResourceException { 75 return null; 76 } 77 78 public ResourceAdapterMetaData getMetaData() throws ResourceException { 79 return null; 80 } 81 82 public void setReference(Reference reference) { 83 this.reference = reference; 84 } 85 86 public Reference getReference() throws NamingException { 87 return reference; 88 } 89 90 public String getName() { 91 System.out.println("Getting name " + name); 92 return name; 93 } 94 95 public void setName(String string) { 96 System.out.println("Setting name " + string); 97 name = string; 98 } 99 100 } 101 | Popular Tags |