View Javadoc
1   package de.fhdw.wtf.context.core;
2   
3   import java.math.BigInteger;
4   import java.util.Collection;
5   
6   import de.fhdw.wtf.context.exception.OutOfScopeException;
7   import de.fhdw.wtf.persistence.facade.TypeManager;
8   import de.fhdw.wtf.persistence.meta.Link;
9   import de.fhdw.wtf.persistence.meta.MapLink;
10  import de.fhdw.wtf.persistence.meta.Object;
11  import de.fhdw.wtf.persistence.meta.UnidirectionalLink;
12  import de.fhdw.wtf.persistence.meta.UserObject;
13  import de.fhdw.wtf.persistence.utils.Tuple;
14  
15  /**
16   * An implementation of a Context to represent the absence of a Context. Every call to this Context will result in an
17   * exception except from methods like commit, savePoint or rollback. These methods will simply have no effect.
18   */
19  public class NoContext extends Context {
20  	
21  	/**
22  	 * Creates a new NoContext.
23  	 */
24  	public NoContext() {
25  	}
26  	
27  	@Override
28  	public Collection<UserObject> find(final String associationName, final String value) {
29  		this.throwException();
30  		return null;
31  	}
32  	
33  	@Override
34  	public Collection<UserObject> find(final String associationName, final BigInteger value) {
35  		this.throwException();
36  		return null;
37  	}
38  	
39  	@Override
40  	public Collection<Tuple<UnidirectionalLink, UserObject>> inverseGet(final String associationName,
41  			final UserObject object) {
42  		this.throwException();
43  		return null;
44  	}
45  	
46  	@Override
47  	public Collection<Tuple<UnidirectionalLink, Object>> get(final UserObject object, final String associationName) {
48  		this.throwException();
49  		return null;
50  	}
51  	
52  	@Override
53  	public Collection<Tuple<MapLink, Object>> get(final UserObject object,
54  			final String associationName,
55  			final String key) {
56  		this.throwException();
57  		return null;
58  	}
59  	
60  	@Override
61  	public Collection<Tuple<MapLink, Object>> get(final UserObject object,
62  			final String associationName,
63  			final BigInteger key) {
64  		this.throwException();
65  		return null;
66  	}
67  	
68  	@Override
69  	public Collection<Tuple<MapLink, Object>> get(final UserObject object,
70  			final String associationName,
71  			final UserObject key) {
72  		this.throwException();
73  		return null;
74  	}
75  	
76  	@Override
77  	public UserObject create(final String typeName) {
78  		this.throwException();
79  		return null;
80  	}
81  	
82  	@Override
83  	public UnidirectionalLink set(final UserObject object, final String associationName, final String val) {
84  		this.throwException();
85  		return null;
86  	}
87  	
88  	@Override
89  	public UnidirectionalLink set(final UserObject object, final String associationName, final BigInteger val) {
90  		this.throwException();
91  		return null;
92  	}
93  	
94  	@Override
95  	public UnidirectionalLink set(final UserObject object, final String associationName, final UserObject target) {
96  		this.throwException();
97  		return null;
98  	}
99  	
100 	@Override
101 	public MapLink put(final UserObject owner, final String associationName, final UserObject target, final String key) {
102 		this.throwException();
103 		return null;
104 	}
105 	
106 	@Override
107 	public MapLink put(final UserObject owner, final String associationName, final BigInteger target, final String key) {
108 		this.throwException();
109 		return null;
110 	}
111 	
112 	@Override
113 	public MapLink put(final UserObject owner, final String associationName, final String target, final String key) {
114 		this.throwException();
115 		return null;
116 	}
117 	
118 	@Override
119 	public MapLink put(final UserObject owner,
120 			final String associationName,
121 			final UserObject target,
122 			final BigInteger key) {
123 		this.throwException();
124 		return null;
125 	}
126 	
127 	@Override
128 	public MapLink put(final UserObject owner,
129 			final String associationName,
130 			final BigInteger target,
131 			final BigInteger key) {
132 		this.throwException();
133 		return null;
134 	}
135 	
136 	@Override
137 	public MapLink put(final UserObject owner, final String associationName, final String target, final BigInteger key) {
138 		this.throwException();
139 		return null;
140 	}
141 	
142 	@Override
143 	public MapLink put(final UserObject owner,
144 			final String associationName,
145 			final UserObject target,
146 			final UserObject key) {
147 		this.throwException();
148 		return null;
149 	}
150 	
151 	@Override
152 	public MapLink put(final UserObject owner,
153 			final String associationName,
154 			final BigInteger target,
155 			final UserObject key) {
156 		this.throwException();
157 		return null;
158 	}
159 	
160 	@Override
161 	public MapLink put(final UserObject owner, final String associationName, final String target, final UserObject key) {
162 		this.throwException();
163 		return null;
164 	}
165 	
166 	@Override
167 	public void commit() {
168 		// nothing to do
169 	}
170 	
171 	@Override
172 	public void rollback() {
173 		// nothing to do
174 	}
175 	
176 	@Override
177 	public void savePoint() {
178 		// nothing to do
179 	}
180 	
181 	@Override
182 	public void rollbackToSavePoint() {
183 		// nothing to do
184 	}
185 	
186 	@Override
187 	public void unset(final Link toUnset) {
188 		this.throwException();
189 	}
190 	
191 	@Override
192 	public TypeManager getTypeManager() {
193 		this.throwException();
194 		return null;
195 	}
196 	
197 	@Override
198 	public Collection<UserObject> getObjectsByType(final String typeName) {
199 		this.throwException();
200 		return null;
201 	}
202 	
203 	@Override
204 	public UserObject checkout(final long object) {
205 		this.throwException();
206 		return null;
207 	}
208 	
209 	/**
210 	 * Throws an exception of type OutOfScopeException.
211 	 */
212 	private void throwException() {
213 		final OutOfScopeException excpetion = new OutOfScopeException(Thread.currentThread().getName());
214 		Logger.getInstance().logError(excpetion.getMessage());
215 		throw excpetion;
216 	}
217 }