MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CrazyDomainTypeHandlerFactoryImpl.java
1 /*
2  Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 package testsuite.clusterj.domaintypehandler;
19 
20 import com.mysql.clusterj.core.CacheManager;
21 import com.mysql.clusterj.core.query.CandidateIndexImpl;
22 import com.mysql.clusterj.core.spi.DomainFieldHandler;
23 import com.mysql.clusterj.core.spi.DomainTypeHandler;
24 import com.mysql.clusterj.core.spi.DomainTypeHandlerFactory;
25 import com.mysql.clusterj.core.spi.ValueHandler;
26 import com.mysql.clusterj.core.store.ClusterTransaction;
27 import com.mysql.clusterj.core.store.Column;
28 import com.mysql.clusterj.core.store.Dictionary;
29 import com.mysql.clusterj.core.store.Operation;
30 import com.mysql.clusterj.core.store.PartitionKey;
31 import com.mysql.clusterj.core.store.ResultData;
32 import com.mysql.clusterj.core.store.Table;
33 
34 import java.lang.reflect.Constructor;
35 import java.lang.reflect.InvocationTargetException;
36 import java.util.BitSet;
37 import java.util.HashMap;
38 import java.util.Map;
39 import java.util.Set;
40 
42 
43  static Map<String, Constructor> constructorMap = new HashMap<String, Constructor>();
44 
45  static Class[] exceptions = new Class[] {NullPointerException.class, IllegalAccessException.class};
46 
47  static {
48  for (Class exception: exceptions) {
49  try {
50  constructorMap.put(exception.getSimpleName(), exception.getConstructor(new Class[]{}));
51  } catch (NoSuchMethodException ex) {
52  throw new RuntimeException(ex);
53  } catch (SecurityException ex) {
54  throw new RuntimeException(ex);
55  }
56  }
57  }
58 
59  public <T> DomainTypeHandler<T> createDomainTypeHandler(Class<T> domainClass, Dictionary dictionary) {
60  String className = domainClass.getSimpleName();
61  if (className.startsWith("Throw")) {
62  String throwClassName = className.substring(5);
63  try {
64  Constructor ctor = constructorMap.get(throwClassName);
65  RuntimeException throwable = (RuntimeException) ctor.newInstance(new Object[]{});
66  throw throwable;
67  } catch (InstantiationException ex) {
68  throw new RuntimeException(ex);
69  } catch (IllegalAccessException ex) {
70  throw new RuntimeException(ex);
71  } catch (IllegalArgumentException ex) {
72  throw new RuntimeException(ex);
73  } catch (InvocationTargetException ex) {
74  throw new RuntimeException(ex);
75  } catch (SecurityException ex) {
76  throw new RuntimeException(ex);
77  }
78  } else if (className.equals("CrazyDelegate")) {
79  final String delegateName = className;
80  return new DomainTypeHandler<T>() {
81 
82  public CandidateIndexImpl[] createCandidateIndexes() {
83  throw new UnsupportedOperationException("Not supported yet.");
84  }
85 
86  public String getName() {
87  return delegateName;
88  }
89 
90  public boolean isSupportedType() {
91  throw new UnsupportedOperationException("Not supported yet.");
92  }
93 
94  public String getTableName() {
95  throw new UnsupportedOperationException("Not supported yet.");
96  }
97 
98  public DomainFieldHandler getFieldHandler(String fieldName) {
99  throw new UnsupportedOperationException("Not supported yet.");
100  }
101 
102  public Class getProxyClass() {
103  throw new UnsupportedOperationException("Nice Job!");
104  }
105 
106  public T newInstance() {
107  throw new UnsupportedOperationException("Not supported yet.");
108  }
109 
110  public ValueHandler getValueHandler(Object instance) {
111  throw new UnsupportedOperationException("Not supported yet.");
112  }
113 
114  public T getInstance(ValueHandler handler) {
115  throw new UnsupportedOperationException("Not supported yet.");
116  }
117 
118  public void objectMarkModified(ValueHandler handler, String fieldName) {
119  throw new UnsupportedOperationException("Not supported yet.");
120  }
121 
122  public void objectSetValues(ResultData rs, ValueHandler handler) {
123  throw new UnsupportedOperationException("Not supported yet.");
124  }
125 
126  public void objectSetValuesExcept(ResultData rs, ValueHandler handler, String indexName) {
127  throw new UnsupportedOperationException("Not supported yet.");
128  }
129 
130  public void objectSetCacheManager(CacheManager cm, Object instance) {
131  throw new UnsupportedOperationException("Not supported yet.");
132  }
133 
134  public void objectResetModified(ValueHandler handler) {
135  throw new UnsupportedOperationException("Not supported yet.");
136  }
137 
138  public void operationGetValues(Operation op) {
139  throw new UnsupportedOperationException("Not supported yet.");
140  }
141 
142  public void operationGetValues(Operation op, BitSet fields) {
143  throw new UnsupportedOperationException("Not supported yet.");
144  }
145 
146  public void operationSetKeys(ValueHandler handler, Operation op) {
147  throw new UnsupportedOperationException("Not supported yet.");
148  }
149 
150  public void operationSetModifiedValues(ValueHandler handler, Operation op) {
151  throw new UnsupportedOperationException("Not supported yet.");
152  }
153 
154  public void operationSetModifiedNonPKValues(ValueHandler valueHandler, Operation op) {
155  throw new UnsupportedOperationException("Not supported yet.");
156  }
157 
158  public void operationSetNonPKValues(ValueHandler handler, Operation op) {
159  throw new UnsupportedOperationException("Not supported yet.");
160  }
161 
162  public ValueHandler createKeyValueHandler(Object keys) {
163  throw new UnsupportedOperationException("Not supported yet.");
164  }
165 
166  public int[] getKeyFieldNumbers() {
167  throw new UnsupportedOperationException("Not supported yet.");
168  }
169 
170  public Class getOidClass() {
171  throw new UnsupportedOperationException("Not supported yet.");
172  }
173 
174  public Set<Column> getStoreColumns(BitSet fields) {
175  throw new UnsupportedOperationException("Not supported yet.");
176  }
177 
178  public Table getStoreTable() {
179  throw new UnsupportedOperationException("Not supported yet.");
180  }
181 
182  public PartitionKey createPartitionKey(
183  ValueHandler handler) {
184  throw new UnsupportedOperationException("Not supported yet.");
185  }
186 
187  public String[] getFieldNames() {
188  throw new UnsupportedOperationException("Not supported yet.");
189  }
190 
191  public void operationSetValues(ValueHandler valueHandler,
192  Operation op) {
193  throw new UnsupportedOperationException("Not supported yet.");
194  }
195 
196  public void objectSetKeys(Object keys, Object instance) {
197  throw new UnsupportedOperationException("Not supported yet.");
198  }
199  };
200  } else {
201  return null;
202  }
203  }
204 
205 }