/tests/com/google/appengine/datanucleus/jdo/JDOBatchTestCase.java
Java | 69 lines | 39 code | 12 blank | 18 comment | 1 complexity | 6492e8797b8bf12ac8ec0401db2ce118 MD5 | raw file
Possible License(s): Apache-2.0
- /**********************************************************************
- Copyright (c) 2009 Google Inc.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- **********************************************************************/
- package com.google.appengine.datanucleus.jdo;
- import com.google.appengine.api.datastore.DatastoreService;
- import com.google.appengine.api.datastore.DatastoreServiceConfig;
- import com.google.appengine.datanucleus.DatastoreServiceFactoryInternal;
- import java.lang.reflect.InvocationHandler;
- import java.lang.reflect.InvocationTargetException;
- import java.lang.reflect.Method;
- import java.lang.reflect.Proxy;
- /**
- * @author Max Ross <maxr@google.com>
- */
- abstract class JDOBatchTestCase extends JDOTestCase {
- BatchRecorder batchRecorder;
- static abstract class BatchRecorder implements InvocationHandler {
- private final DatastoreService delegate;
- int batchOps = 0;
- public BatchRecorder(DatastoreServiceConfig config) {
- this.delegate = DatastoreServiceFactoryInternal.getDatastoreService(config);
- }
- public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
- method.setAccessible(true);
- if (isBatchMethod(method)) {
- batchOps++;
- }
- try {
- return method.invoke(delegate, objects);
- } catch (InvocationTargetException ite) {
- throw ite.getTargetException();
- }
- }
- abstract boolean isBatchMethod(Method m);
- }
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- batchRecorder = newBatchRecorder();
- DatastoreService recordBatchPuts = (DatastoreService)
- Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {DatastoreService.class}, batchRecorder);
- DatastoreServiceFactoryInternal.setDatastoreService(recordBatchPuts);
- }
- abstract BatchRecorder newBatchRecorder();
- }