2 Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
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.
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.
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
18 package testsuite.clusterj.domaintypehandler;
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;
34 import java.lang.reflect.Constructor;
35 import java.lang.reflect.InvocationTargetException;
36 import java.util.BitSet;
37 import java.util.HashMap;
41 public class CrazyDomainTypeHandlerFactoryImpl implements DomainTypeHandlerFactory {
43 static Map<String, Constructor> constructorMap = new HashMap<String, Constructor>();
45 static Class[] exceptions = new Class[] {NullPointerException.class, IllegalAccessException.class};
48 for (Class exception: exceptions) {
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);
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);
64 Constructor ctor = constructorMap.get(throwClassName);
65 RuntimeException throwable = (RuntimeException) ctor.newInstance(new Object[]{});
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);
78 } else if (className.equals("CrazyDelegate")) {
79 final String delegateName = className;
80 return new DomainTypeHandler<T>() {
82 public CandidateIndexImpl[] createCandidateIndexes() {
83 throw new UnsupportedOperationException("Not supported yet.");
86 public String getName() {
90 public boolean isSupportedType() {
91 throw new UnsupportedOperationException("Not supported yet.");
94 public String getTableName() {
95 throw new UnsupportedOperationException("Not supported yet.");
98 public DomainFieldHandler getFieldHandler(String fieldName) {
99 throw new UnsupportedOperationException("Not supported yet.");
102 public Class getProxyClass() {
103 throw new UnsupportedOperationException("Nice Job!");
106 public T newInstance() {
107 throw new UnsupportedOperationException("Not supported yet.");
110 public ValueHandler getValueHandler(Object instance) {
111 throw new UnsupportedOperationException("Not supported yet.");
114 public T getInstance(ValueHandler handler) {
115 throw new UnsupportedOperationException("Not supported yet.");
118 public void objectMarkModified(ValueHandler handler, String fieldName) {
119 throw new UnsupportedOperationException("Not supported yet.");
122 public void objectSetValues(ResultData rs, ValueHandler handler) {
123 throw new UnsupportedOperationException("Not supported yet.");
126 public void objectSetValuesExcept(ResultData rs, ValueHandler handler, String indexName) {
127 throw new UnsupportedOperationException("Not supported yet.");
130 public void objectSetCacheManager(CacheManager cm, Object instance) {
131 throw new UnsupportedOperationException("Not supported yet.");
134 public void objectResetModified(ValueHandler handler) {
135 throw new UnsupportedOperationException("Not supported yet.");
138 public void operationGetValues(Operation op) {
139 throw new UnsupportedOperationException("Not supported yet.");
142 public void operationGetValues(Operation op, BitSet fields) {
143 throw new UnsupportedOperationException("Not supported yet.");
146 public void operationSetKeys(ValueHandler handler, Operation op) {
147 throw new UnsupportedOperationException("Not supported yet.");
150 public void operationSetModifiedValues(ValueHandler handler, Operation op) {
151 throw new UnsupportedOperationException("Not supported yet.");
154 public void operationSetModifiedNonPKValues(ValueHandler valueHandler, Operation op) {
155 throw new UnsupportedOperationException("Not supported yet.");
158 public void operationSetNonPKValues(ValueHandler handler, Operation op) {
159 throw new UnsupportedOperationException("Not supported yet.");
162 public ValueHandler createKeyValueHandler(Object keys) {
163 throw new UnsupportedOperationException("Not supported yet.");
166 public int[] getKeyFieldNumbers() {
167 throw new UnsupportedOperationException("Not supported yet.");
170 public Class getOidClass() {
171 throw new UnsupportedOperationException("Not supported yet.");
174 public Set<Column> getStoreColumns(BitSet fields) {
175 throw new UnsupportedOperationException("Not supported yet.");
178 public Table getStoreTable() {
179 throw new UnsupportedOperationException("Not supported yet.");
182 public PartitionKey createPartitionKey(
183 ValueHandler handler) {
184 throw new UnsupportedOperationException("Not supported yet.");
187 public String[] getFieldNames() {
188 throw new UnsupportedOperationException("Not supported yet.");
191 public void operationSetValues(ValueHandler valueHandler,
193 throw new UnsupportedOperationException("Not supported yet.");
196 public void objectSetKeys(Object keys, Object instance) {
197 throw new UnsupportedOperationException("Not supported yet.");