亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? abstractjpatests.java

?? struts+spring 源碼 希望能給大家?guī)?lái)幫助
?? JAVA
字號(hào):
/*
 * Copyright 2002-2006 the original author or authors.
 *
 * 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 org.springframework.test.jpa;

import java.lang.instrument.ClassFileTransformer;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import junit.framework.TestCase;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.instrument.classloading.LoadTimeWeaver;
import org.springframework.instrument.classloading.ResourceOverridingShadowingClassLoader;
import org.springframework.instrument.classloading.ShadowingClassLoader;
import org.springframework.orm.jpa.ExtendedEntityManagerCreator;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.SharedEntityManagerCreator;
import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager;
import org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests;
import org.springframework.util.StringUtils;

/**
 * Convenient support class for JPA-related tests.
 * Offers the same contract as AbstractTransactionalDataSourceSpringContextTests
 * and equally good performance, even when performing the instrumentation
 * required by the JPA specification.
 *
 * <p>Exposes an EntityManagerFactory and a shared EntityManager.
 * Requires EntityManagerFactory to be injected, plus DataSource and
 * JpaTransactionManager from superclass.
 *
 * @author Rod Johnson
 * @author Rob Harrop
 * @since 2.0
 */
public abstract class AbstractJpaTests extends AbstractAnnotationAwareTransactionalTests {

	private static final String DEFAULT_ORM_XML_LOCATION = "META-INF/orm.xml";
	
	/**
	 * Map from String defining unique combination of config locations, to ApplicationContext.
	 * Values are intentionally not strongly typed, to avoid potential class cast exceptions
	 * through use between different class loaders.
	 */
	private static Map<String, Object> contextCache = new HashMap<String, Object>();

	private static Map<String, ClassLoader> classLoaderCache = new HashMap<String, ClassLoader>();

	protected EntityManagerFactory entityManagerFactory;

	/**
	 * If this instance is in a shadow loader, this variable
	 * will contain the parent instance of the subclass.
	 * The class will not be the same as the class of the
	 * shadow instance, as it was loaded by a different class loader,
	 * but it can be invoked reflectively. The shadowParent
	 * and the shadow loader can communicate reflectively
	 * but not through direct invocation.
	 */
	private Object shadowParent;

	/**
	 * Subclasses can use this in test cases.
	 * It will participate in any current transaction.
	 */
	protected EntityManager sharedEntityManager;


	public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
		this.entityManagerFactory = entityManagerFactory;
		this.sharedEntityManager = SharedEntityManagerCreator.createSharedEntityManager(this.entityManagerFactory);
	}

	/**
	 * Create an EntityManager that will always automatically enlist itself in current
	 * transactions, in contrast to an EntityManager returned by
	 * <code>EntityManagerFactory.createEntityManager()</code>
	 * (which requires an explicit <code>joinTransaction()</code> call).
	 */
	protected EntityManager createContainerManagedEntityManager() {
		return ExtendedEntityManagerCreator.createContainerManagedEntityManager(this.entityManagerFactory);
	}
	
	/**
	 * Subclasses should override this method if they wish
	 * to disable shadow class loading. Do this only
	 * if instrumentation is not required in your
	 * JPA implementation. 
	 * @return whether to disable shadow loading functionality
	 */
	protected boolean shouldUseShadowLoader() {
		return true;
	}
	
	@Override
	public void setDirty() {
		super.setDirty();		
		contextCache.remove(cacheKeys());
		classLoaderCache.remove(cacheKeys());
		
		// If we are a shadow loader, we need to invoke
		// the shadow parent to set it dirty, as 
		// it is the shadow parent that maintains the cache state,
		// not the child
		if (this.shadowParent != null) {			
			try {
				Method m = shadowParent.getClass().getMethod("setDirty", (Class[]) null);
				m.invoke(shadowParent, (Object[]) null);
			}
			catch (Exception ex) {
				throw new RuntimeException(ex);
			}
		}
	}

	
	@Override
	public void runBare() throws Throwable {
		if (!shouldUseShadowLoader()) {
			super.runBare();
			return;
		}
		
		String combinationOfContextLocationsForThisTestClass = cacheKeys(); 			
		ClassLoader classLoaderForThisTestClass = getClass().getClassLoader();
		// save the TCCL
		ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader();
		
		if (this.shadowParent != null) {
			Thread.currentThread().setContextClassLoader(classLoaderForThisTestClass);
			super.runBare();
		}
		else {
			ShadowingClassLoader shadowingClassLoader = (ShadowingClassLoader) classLoaderCache.get(combinationOfContextLocationsForThisTestClass);

			if (shadowingClassLoader == null) {
				shadowingClassLoader = (ShadowingClassLoader) createShadowingClassLoader(classLoaderForThisTestClass);
				classLoaderCache.put(combinationOfContextLocationsForThisTestClass, shadowingClassLoader);
			}
			try {
				Thread.currentThread().setContextClassLoader(shadowingClassLoader);
				String[] configLocations = getConfigLocations();

				// Do not strongly type, to avoid ClassCastException
				Object cachedContext = contextCache.get(combinationOfContextLocationsForThisTestClass);

				if (cachedContext == null) {

					// create load time weaver
					Class shadowingLoadTimeWeaverClass = shadowingClassLoader.loadClass(ShadowingLoadTimeWeaver.class.getName());
					Constructor constructor = shadowingLoadTimeWeaverClass.getConstructor(ClassLoader.class);
					constructor.setAccessible(true);
					Object ltw = constructor.newInstance(shadowingClassLoader);

					// create the bean factory
					Class beanFactoryClass = shadowingClassLoader.loadClass(DefaultListableBeanFactory.class.getName());
					Object beanFactory = BeanUtils.instantiateClass(beanFactoryClass);

					// create the BeanDefinitionReader
					Class beanDefinitionReaderClass = shadowingClassLoader.loadClass(XmlBeanDefinitionReader.class.getName());
					Class beanDefinitionRegistryClass = shadowingClassLoader.loadClass(BeanDefinitionRegistry.class.getName());
					Object reader = beanDefinitionReaderClass.getConstructor(beanDefinitionRegistryClass).newInstance(beanFactory);

					// load the bean definitions into the bean factory
					Method loadBeanDefinitions = beanDefinitionReaderClass.getMethod("loadBeanDefinitions", String[].class);
					loadBeanDefinitions.invoke(reader, new Object[]{configLocations});

					// create BeanPostProcessor
					Class loadTimeWeaverInjectingBeanPostProcessorClass = shadowingClassLoader.loadClass(LoadTimeWeaverInjectingBeanPostProcessor.class.getName());
					Class loadTimeWeaverClass = shadowingClassLoader.loadClass(LoadTimeWeaver.class.getName());
					Constructor bppConstructor = loadTimeWeaverInjectingBeanPostProcessorClass.getConstructor(loadTimeWeaverClass);
					bppConstructor.setAccessible(true);
					Object beanPostProcessor = bppConstructor.newInstance(ltw);

					// add BeanPostProcessor
					Class beanPostProcessorClass = shadowingClassLoader.loadClass(BeanPostProcessor.class.getName());
					Method addBeanPostProcessor = beanFactoryClass.getMethod("addBeanPostProcessor", beanPostProcessorClass);
					addBeanPostProcessor.invoke(beanFactory, beanPostProcessor);

					// create the GenericApplicationContext
					Class genericApplicationContextClass = shadowingClassLoader.loadClass(GenericApplicationContext.class.getName());
					Class defaultListableBeanFactoryClass = shadowingClassLoader.loadClass(DefaultListableBeanFactory.class.getName());
					cachedContext = genericApplicationContextClass.getConstructor(defaultListableBeanFactoryClass).newInstance(beanFactory);
					contextCache.put(combinationOfContextLocationsForThisTestClass, cachedContext);

					// refresh
					genericApplicationContextClass.getMethod("refresh").invoke(cachedContext);

				}
				// create the shadowed test
				Class shadowedTestClass = shadowingClassLoader.loadClass(getClass().getName());
				
				// So long as JUnit is excluded from shadowing we
				// can minimize reflective invocation here
				TestCase shadowedTestCase = (TestCase) BeanUtils.instantiateClass(shadowedTestClass);

				/* shadowParent = this */
				Class thisShadowedClass = shadowingClassLoader.loadClass(AbstractJpaTests.class.getName());
				Field shadowed = thisShadowedClass.getDeclaredField("shadowParent");
				shadowed.setAccessible(true);
				shadowed.set(shadowedTestCase, this);

				/* AbstractSpringContextTests.addContext(Object, ApplicationContext) */
				Class applicationContextClass = shadowingClassLoader.loadClass(ConfigurableApplicationContext.class.getName());
				Method addContextMethod = shadowedTestClass.getMethod("addContext", Object.class, applicationContextClass);
				addContextMethod.invoke(shadowedTestCase, configLocations, cachedContext);

				// Invoke tests on shadowed test case
				shadowedTestCase.setName(getName());
				shadowedTestCase.runBare();
			}
			catch (InvocationTargetException ex) {
				// Unwrap this for better exception reporting
				// when running tests
				throw ex.getTargetException();
			}
			finally {
				Thread.currentThread().setContextClassLoader(initialClassLoader);
			}
		}
	}

	protected String cacheKeys() {
		return StringUtils.arrayToCommaDelimitedString(getConfigLocations());
	}

	/**
	 * NB: This method must <b>not</b> have a return type of ShadowingClassLoader as that would cause that
	 * class to be loaded eagerly when this test case loads, creating verify errors at runtime.
	 */
	protected ClassLoader createShadowingClassLoader(ClassLoader classLoader) {
		OrmXmlOverridingShadowingClassLoader orxl = new OrmXmlOverridingShadowingClassLoader(classLoader, 
				getActualOrmXmlLocation());		
		customizeResourceOverridingShadowingClassLoader(orxl);
		return orxl;
	}
	
	/**
	 * Customize the shadowing class loader
	 * @param shadowingClassLoader this parameter is actually of type
	 * ResourceOverridingShadowingClassLoader, and can safely to be
	 * cast to that type. However, the signature must not be of that
	 * type as that would cause the present class loader to load
	 * that type.
	 */
	protected void customizeResourceOverridingShadowingClassLoader(ClassLoader shadowingClassLoader) {
		// empty
	}
	
	/**
	 * Subclasses can override this to return the real location path for
	 * orm.xml or null if they do not wish to find any orm.xml
	 * @return orm.xml path or null to hide any such file
	 */
	protected String getActualOrmXmlLocation() {
		return DEFAULT_ORM_XML_LOCATION;
	}


	private static class LoadTimeWeaverInjectingBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter {

		private final LoadTimeWeaver ltw;

		public LoadTimeWeaverInjectingBeanPostProcessor(LoadTimeWeaver ltw) {
			this.ltw = ltw;
		}

		public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
			if (bean instanceof LocalContainerEntityManagerFactoryBean) {
				((LocalContainerEntityManagerFactoryBean) bean).setLoadTimeWeaver(this.ltw);
			}
			if (bean instanceof DefaultPersistenceUnitManager) {
				((DefaultPersistenceUnitManager) bean).setLoadTimeWeaver(this.ltw);
			}
			return bean;
		}
	}


	private static class ShadowingLoadTimeWeaver implements LoadTimeWeaver {

		private final ClassLoader shadowingClassLoader;

		private final Class shadowingClassLoaderClass;

		public ShadowingLoadTimeWeaver(ClassLoader shadowingClassLoader) {
			this.shadowingClassLoader = shadowingClassLoader;
			this.shadowingClassLoaderClass = shadowingClassLoader.getClass();
		}

		public ClassLoader getInstrumentableClassLoader() {
			return (ClassLoader) this.shadowingClassLoader;
		}
		
		public ClassLoader getThrowawayClassLoader() {
			// Be sure to copy the same resource overrides
			// and same class file transformers:
			// We want the throwaway class loader to behave
			// like the instrumentable class loader
			ResourceOverridingShadowingClassLoader roscl = new ResourceOverridingShadowingClassLoader(getClass().getClassLoader());
			if (shadowingClassLoader instanceof ResourceOverridingShadowingClassLoader) {
				roscl.copyOverrides((ResourceOverridingShadowingClassLoader) shadowingClassLoader);
			}
			if (shadowingClassLoader instanceof ShadowingClassLoader) {
				roscl.addTransformers((ShadowingClassLoader) shadowingClassLoader);
			}
			return roscl;
		}

		public void addTransformer(ClassFileTransformer transformer) {
			try {
				Method addClassFileTransformer =
						this.shadowingClassLoaderClass.getMethod("addTransformer", ClassFileTransformer.class);
				addClassFileTransformer.setAccessible(true);
				addClassFileTransformer.invoke(this.shadowingClassLoader, transformer);
			}
			catch (Exception ex) {
				throw new RuntimeException(ex);
			}
		}
	}

}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线播放视频一区| 亚洲黄色在线视频| 欧美性色黄大片| 99re成人精品视频| 国产成人精品1024| 国产精品自拍一区| 国产呦精品一区二区三区网站| 亚洲午夜精品久久久久久久久| 亚洲三级在线看| 亚洲人成网站在线| 日本一区二区三区在线不卡 | 国产精品久久久久9999吃药| 久久精品这里都是精品| 精品奇米国产一区二区三区| 欧美一卡在线观看| 欧美大片免费久久精品三p| 日韩一区二区在线免费观看| 国产清纯白嫩初高生在线观看91| 中文字幕成人av| 亚洲欧美日韩国产综合在线| 亚洲一区在线视频| 欧美a一区二区| 国产成人av一区| 色综合视频在线观看| 欧美在线一区二区| 日韩欧美在线一区二区三区| 久久精品男人天堂av| 亚洲视频一二三| 日韩二区在线观看| 粗大黑人巨茎大战欧美成人| 99久久99久久综合| 91精品国产91久久久久久最新毛片| 日韩午夜激情av| 国产精品久久久久9999吃药| 婷婷中文字幕综合| 成人午夜在线播放| 在线观看91精品国产麻豆| 久久久高清一区二区三区| 亚洲欧美日本在线| 久久66热re国产| 欧美videos大乳护士334| 久久久久久电影| 亚洲一区二区四区蜜桃| 国产老妇另类xxxxx| 欧美撒尿777hd撒尿| 久久久综合精品| 亚洲福利视频三区| eeuss鲁片一区二区三区在线观看 eeuss鲁片一区二区三区在线看 | 26uuu国产电影一区二区| 亚洲欧美电影院| 国产一区二区在线观看视频| 欧美日韩在线播放| 国产精品网站在线观看| 蜜臀91精品一区二区三区 | 91精品欧美福利在线观看| 综合欧美一区二区三区| 国产一区二区三区免费| 欧美精品久久99久久在免费线| 中文字幕久久午夜不卡| 九九国产精品视频| 欧美精品 国产精品| 亚洲免费伊人电影| 成人性生交大片免费看中文网站| 日韩一二三区视频| 偷拍与自拍一区| 欧美手机在线视频| 亚洲精品福利视频网站| 成人精品视频网站| 国产日产欧美一区二区三区| 麻豆国产欧美一区二区三区| 欧美视频一区在线| 夜夜嗨av一区二区三区| 色综合 综合色| 亚洲精品高清视频在线观看| 91成人在线精品| 亚洲人成影院在线观看| 色94色欧美sute亚洲线路一久| 国产精品灌醉下药二区| 成人爱爱电影网址| 亚洲色图都市小说| 欧美性做爰猛烈叫床潮| 亚洲成a人片在线观看中文| 日本韩国一区二区三区| 亚洲一区二区影院| 欧美日韩成人综合天天影院| 亚洲成人精品一区| 在线播放一区二区三区| 免费看欧美女人艹b| 久久久久久一二三区| 国产1区2区3区精品美女| 欧美国产精品劲爆| 色狠狠一区二区三区香蕉| 亚洲综合一二三区| 91精品麻豆日日躁夜夜躁| 蜜臀国产一区二区三区在线播放 | av电影天堂一区二区在线| 日韩毛片视频在线看| 91香蕉视频在线| 五月婷婷久久综合| 精品盗摄一区二区三区| 成人黄色777网| 亚洲午夜久久久久久久久电影院 | 亚洲综合成人网| 欧美一级xxx| 国产成人在线电影| 亚洲精品欧美专区| 5566中文字幕一区二区电影| 国产一区二区三区视频在线播放| 国产精品久久久久久久裸模| 欧美视频一区二区三区四区 | 91免费观看国产| 丝袜亚洲另类欧美综合| 久久精品夜夜夜夜久久| 在线观看成人小视频| 精品一区二区三区欧美| 成人欧美一区二区三区| 欧美一区在线视频| jiyouzz国产精品久久| 天天色天天爱天天射综合| 国产拍欧美日韩视频二区| 欧美色综合久久| 高清视频一区二区| 三级久久三级久久| 一区在线中文字幕| 精品国产乱码久久久久久牛牛| caoporn国产一区二区| 另类小说图片综合网| 亚洲欧美偷拍另类a∨色屁股| 日韩欧美色电影| 欧日韩精品视频| 成人免费看的视频| 久久精品免费看| 亚洲第一激情av| 亚洲欧美视频一区| 中文字幕精品一区| 精品久久久久久久一区二区蜜臀| 91久久精品一区二区三| 成人午夜精品在线| 国产馆精品极品| 国产在线精品一区二区| 奇米精品一区二区三区在线观看一| 亚洲欧美视频在线观看| 国产精品国产三级国产aⅴ无密码| 欧美成人免费网站| 91麻豆精品国产综合久久久久久| 91国内精品野花午夜精品| 成人午夜电影网站| 国产成人精品一区二区三区网站观看| 免费精品视频最新在线| 日韩精品亚洲一区二区三区免费| 亚洲综合清纯丝袜自拍| 一区二区三区在线观看动漫| 中文字幕一区二区三区乱码在线| 精品日本一线二线三线不卡| 日韩免费电影网站| 日韩欧美国产麻豆| 精品欧美久久久| 精品美女一区二区三区| 欧美成人精品福利| 久久综合久久综合九色| 久久亚洲一区二区三区四区| 欧美不卡视频一区| 久久夜色精品国产噜噜av| 久久在线免费观看| 中文字幕欧美激情一区| 国产精品伦一区| 亚洲女子a中天字幕| 亚洲一区中文日韩| 青青草精品视频| 激情久久久久久久久久久久久久久久| 美国十次了思思久久精品导航| 久久99国产精品久久| 国产99久久久国产精品免费看 | 亚欧色一区w666天堂| 日韩高清欧美激情| 激情偷乱视频一区二区三区| 成人手机在线视频| 91麻豆免费看| 3d动漫精品啪啪| 精品国产污网站| 日韩高清一区二区| 国产成人在线观看| 欧美亚洲国产一卡| 精品欧美乱码久久久久久1区2区| 欧美国产禁国产网站cc| 亚洲国产日韩在线一区模特| 美女诱惑一区二区| 成人av免费在线播放| 欧美日韩久久久| 久久久亚洲精华液精华液精华液| 中文字幕制服丝袜一区二区三区| 亚洲一区视频在线观看视频| 久久精品99国产精品| aa级大片欧美| 欧美一级xxx| 亚洲精品菠萝久久久久久久| 另类小说综合欧美亚洲| 日本高清免费不卡视频| 26uuuu精品一区二区| 亚洲一区国产视频|