View Javadoc

1   package com.github.smokestack.jca.cci;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import javax.naming.NamingException;
7   import javax.naming.Reference;
8   import javax.resource.ResourceException;
9   import javax.resource.cci.Connection;
10  import javax.resource.cci.ConnectionFactory;
11  import javax.resource.cci.ConnectionSpec;
12  import javax.resource.cci.RecordFactory;
13  import javax.resource.cci.ResourceAdapterMetaData;
14  
15  import org.apache.commons.lang.builder.ReflectionToStringBuilder;
16  import org.apache.commons.lang.builder.ToStringStyle;
17  
18  public class MockConnectionFactory implements ConnectionFactory {
19  
20  	/**
21  	 * Generated
22  	 */
23  	private static final long serialVersionUID = -4549014744671003973L;
24  
25  	protected List<MockConnection> mockConnections=new ArrayList<MockConnection>();
26  	protected Reference reference=null;
27  	protected MockResourceAdapterMetaData mockResourceAdapterMetaData;
28  	protected MockRecordFactory mockRecordFactory;
29  	
30  	/* (non-Javadoc)
31  	 * @see javax.resource.cci.ConnectionFactory#getConnection()
32  	 */
33  	public Connection getConnection() throws ResourceException {	
34  		_getConnection();
35  		MockConnection c=new MockConnection();
36  		mockConnections.add(c);
37  		return c;
38  	}
39  
40  	public MockConnection _getConnection() throws ResourceException {
41  		return null; 
42  	}
43  
44  	/* (non-Javadoc)
45  	 * @see javax.resource.cci.ConnectionFactory#getConnection(javax.resource.cci.ConnectionSpec)
46  	 */
47  	public Connection getConnection(ConnectionSpec connectionSpec) throws ResourceException {	
48  		_getConnection(connectionSpec);
49  		MockConnection c=new MockConnection(connectionSpec);
50  		mockConnections.add(c);
51  		return c;
52  	}
53  
54  	public MockConnection _getConnection(ConnectionSpec connectionSpec) throws ResourceException {
55  		return null;
56  	}
57  
58  	/* (non-Javadoc)
59  	 * @see javax.resource.cci.ConnectionFactory#getMetaData()
60  	 */
61  	public ResourceAdapterMetaData getMetaData() throws ResourceException {
62  		_getMetaData();	
63  		if (mockResourceAdapterMetaData==null){
64  			mockResourceAdapterMetaData=new MockResourceAdapterMetaData();
65  		}
66  		return mockResourceAdapterMetaData;
67  	}
68  
69  	public MockResourceAdapterMetaData _getMetaData() throws ResourceException {
70  		return null;
71  	}
72  
73  	/* (non-Javadoc)
74  	 * @see javax.resource.cci.ConnectionFactory#getRecordFactory()
75  	 */
76  	public RecordFactory getRecordFactory() throws ResourceException {
77  		_getRecordFactory();
78  		if (mockRecordFactory==null){
79  			mockRecordFactory=new MockRecordFactory();
80  		}
81  		return mockRecordFactory;
82  	}
83  
84  	public MockRecordFactory _getRecordFactory() throws ResourceException {
85  		return null;
86  	}
87  
88  	/* (non-Javadoc)
89  	 * @see javax.resource.Referenceable#setReference(javax.naming.Reference)
90  	 */
91  	public void setReference(Reference reference) {	
92  		_setReference(reference);
93  		this.reference=reference;
94  	}
95  
96  	public void _setReference(Reference reference) {
97  	}
98  
99  	/* (non-Javadoc)
100 	 * @see javax.naming.Referenceable#getReference()
101 	 */
102 	public Reference getReference() throws NamingException {
103 		_getReference();
104 		return reference;
105 		
106 	}
107 	
108 	public Reference _getReference() throws NamingException {
109 		return null;
110 	}
111 	
112 	public void validateMockComplete(){
113 		for (MockConnection c: mockConnections){
114 			c.validateMockComplete();
115 		}
116 	}
117 
118 	public void validateMockCommit(){
119 		for (MockConnection c: mockConnections){
120 			c.validateMockCommit();
121 		}
122 	}
123 	
124 	public void validateMockRollback(){
125 		for (MockConnection c: mockConnections){
126 			c.validateMockRollback();
127 		}
128 	}
129 
130 	@Override
131 	public String toString(){
132 		return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
133 	}
134 }