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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? jdotemplate.java

?? spring framework 2.5.4源代碼
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
/*
 * Copyright 2002-2008 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.orm.jdo;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Collection;
import java.util.Map;

import javax.jdo.JDOException;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Query;

import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

/**
 * Helper class that simplifies JDO data access code, and converts
 * JDOExceptions into Spring DataAccessExceptions, following the
 * <code>org.springframework.dao</code> exception hierarchy.
 *
 * <p>The central method is <code>execute</code>, supporting JDO access code
 * implementing the {@link JdoCallback} interface. It provides JDO PersistenceManager
 * handling such that neither the JdoCallback implementation nor the calling
 * code needs to explicitly care about retrieving/closing PersistenceManagers,
 * or handling JDO lifecycle exceptions.
 *
 * <p>Typically used to implement data access or business logic services that
 * use JDO within their implementation but are JDO-agnostic in their interface.
 * The latter or code calling the latter only have to deal with business
 * objects, query objects, and <code>org.springframework.dao</code> exceptions.
 *
 * <p>Can be used within a service implementation via direct instantiation
 * with a PersistenceManagerFactory reference, or get prepared in an
 * application context and given to services as bean reference.
 * Note: The PersistenceManagerFactory should always be configured as bean in
 * the application context, in the first case given to the service directly,
 * in the second case to the prepared template.
 *
 * <p>This class can be considered as direct alternative to working with the
 * raw JDO PersistenceManager API (through
 * <code>PersistenceManagerFactoryUtils.getPersistenceManager()</code>).
 * The major advantage is its automatic conversion to DataAccessExceptions, the
 * major disadvantage that no checked application exceptions can get thrown from
 * within data access code. Corresponding checks and the actual throwing of such
 * exceptions can often be deferred to after callback execution, though.
 *
 * <p>{@link LocalPersistenceManagerFactoryBean} is the preferred way of obtaining
 * a reference to a specific PersistenceManagerFactory, at least in a non-EJB
 * environment. The Spring application context will manage its lifecycle,
 * initializing and shutting down the factory as part of the application.
 *
 * <p>Note that lazy loading will just work with an open JDO PersistenceManager,
 * either within a Spring-driven transaction (with JdoTransactionManager or
 * JtaTransactionManager) or within OpenPersistenceManagerInViewFilter/Interceptor.
 * Furthermore, some operations just make sense within transactions,
 * for example: <code>evict</code>, <code>evictAll</code>, <code>flush</code>.
 *
 * <p><b>NOTE: This class requires JDO 2.0 or higher, as of Spring 2.5.</b>
 *
 * @author Juergen Hoeller
 * @since 03.06.2003
 * @see #setPersistenceManagerFactory
 * @see JdoCallback
 * @see javax.jdo.PersistenceManager
 * @see LocalPersistenceManagerFactoryBean
 * @see JdoTransactionManager
 * @see org.springframework.transaction.jta.JtaTransactionManager
 * @see org.springframework.orm.jdo.support.OpenPersistenceManagerInViewFilter
 * @see org.springframework.orm.jdo.support.OpenPersistenceManagerInViewInterceptor
 */
public class JdoTemplate extends JdoAccessor implements JdoOperations {

	private boolean allowCreate = true;

	private boolean exposeNativePersistenceManager = false;


	/**
	 * Create a new JdoTemplate instance.
	 */
	public JdoTemplate() {
	}

	/**
	 * Create a new JdoTemplate instance.
	 * @param pmf PersistenceManagerFactory to create PersistenceManagers
	 */
	public JdoTemplate(PersistenceManagerFactory pmf) {
		setPersistenceManagerFactory(pmf);
		afterPropertiesSet();
	}

	/**
	 * Create a new JdoTemplate instance.
	 * @param pmf PersistenceManagerFactory to create PersistenceManagers
	 * @param allowCreate if a non-transactional PersistenceManager should be created
	 * when no transactional PersistenceManager can be found for the current thread
	 */
	public JdoTemplate(PersistenceManagerFactory pmf, boolean allowCreate) {
		setPersistenceManagerFactory(pmf);
		setAllowCreate(allowCreate);
		afterPropertiesSet();
	}

	/**
	 * Set if a new PersistenceManager should be created when no transactional
	 * PersistenceManager can be found for the current thread.
	 * <p>JdoTemplate is aware of a corresponding PersistenceManager bound to the
	 * current thread, for example when using JdoTransactionManager.
	 * If allowCreate is true, a new non-transactional PersistenceManager will be
	 * created if none found, which needs to be closed at the end of the operation.
	 * If false, an IllegalStateException will get thrown in this case.
	 * @see PersistenceManagerFactoryUtils#getPersistenceManager(javax.jdo.PersistenceManagerFactory, boolean)
	 */
	public void setAllowCreate(boolean allowCreate) {
		this.allowCreate = allowCreate;
	}

	/**
	 * Return if a new PersistenceManager should be created if no thread-bound found.
	 */
	public boolean isAllowCreate() {
		return this.allowCreate;
	}

	/**
	 * Set whether to expose the native JDO PersistenceManager to JdoCallback
	 * code. Default is "false": a PersistenceManager proxy will be returned,
	 * suppressing <code>close</code> calls and automatically applying transaction
	 * timeouts (if any).
	 * <p>As there is often a need to cast to a provider-specific PersistenceManager
	 * class in DAOs that use provider-specific functionality, the exposed proxy
	 * implements all interfaces implemented by the original PersistenceManager.
	 * If this is not sufficient, turn this flag to "true".
	 * @see JdoCallback
	 * @see javax.jdo.PersistenceManager
	 * @see #prepareQuery
	 */
	public void setExposeNativePersistenceManager(boolean exposeNativePersistenceManager) {
		this.exposeNativePersistenceManager = exposeNativePersistenceManager;
	}

	/**
	 * Return whether to expose the native JDO PersistenceManager to JdoCallback
	 * code, or rather a PersistenceManager proxy.
	 */
	public boolean isExposeNativePersistenceManager() {
		return this.exposeNativePersistenceManager;
	}


	public Object execute(JdoCallback action) throws DataAccessException {
		return execute(action, isExposeNativePersistenceManager());
	}

	public Collection executeFind(JdoCallback action) throws DataAccessException {
		Object result = execute(action, isExposeNativePersistenceManager());
		if (result != null && !(result instanceof Collection)) {
			throw new InvalidDataAccessApiUsageException(
					"Result object returned from JdoCallback isn't a Collection: [" + result + "]");
		}
		return (Collection) result;
	}

	/**
	 * Execute the action specified by the given action object within a
	 * PersistenceManager.
	 * @param action callback object that specifies the JDO action
	 * @param exposeNativePersistenceManager whether to expose the native
	 * JDO persistence manager to callback code
	 * @return a result object returned by the action, or <code>null</code>
	 * @throws org.springframework.dao.DataAccessException in case of JDO errors
	 */
	public Object execute(JdoCallback action, boolean exposeNativePersistenceManager) throws DataAccessException {
		Assert.notNull(action, "Callback object must not be null");

		PersistenceManager pm = PersistenceManagerFactoryUtils.getPersistenceManager(
		    getPersistenceManagerFactory(), isAllowCreate());
		boolean existingTransaction =
		    TransactionSynchronizationManager.hasResource(getPersistenceManagerFactory());
		try {
			PersistenceManager pmToExpose = (exposeNativePersistenceManager ? pm : createPersistenceManagerProxy(pm));
			Object result = action.doInJdo(pmToExpose);
			flushIfNecessary(pm, existingTransaction);
			return postProcessResult(result, pm, existingTransaction);
		}
		catch (JDOException ex) {
			throw convertJdoAccessException(ex);
		}
		catch (RuntimeException ex) {
			// callback code threw application exception
			throw ex;
		}
		finally {
			PersistenceManagerFactoryUtils.releasePersistenceManager(pm, getPersistenceManagerFactory());
		}
	}

	/**
	 * Create a close-suppressing proxy for the given JDO PersistenceManager.
	 * Called by the <code>execute</code> method.
	 * <p>The proxy also prepares returned JDO Query objects.
	 * @param pm the JDO PersistenceManager to create a proxy for
	 * @return the PersistenceManager proxy, implementing all interfaces
	 * implemented by the passed-in PersistenceManager object (that is,
	 * also implementing all provider-specific extension interfaces)
	 * @see javax.jdo.PersistenceManager#close()
	 * @see #execute(JdoCallback, boolean)
	 * @see #prepareQuery
	 */
	protected PersistenceManager createPersistenceManagerProxy(PersistenceManager pm) {
		Class[] ifcs = ClassUtils.getAllInterfacesForClass(pm.getClass(), getClass().getClassLoader());
		return (PersistenceManager) Proxy.newProxyInstance(
				getClass().getClassLoader(), ifcs, new CloseSuppressingInvocationHandler(pm));
	}

	/**
	 * Post-process the given result object, which might be a Collection.
	 * Called by the <code>execute</code> method.
	 * <p>Default implementation always returns the passed-in Object as-is.
	 * Subclasses might override this to automatically detach result
	 * collections or even single result objects.
	 * @param pm the current JDO PersistenceManager
	 * @param result the result object (might be a Collection)
	 * @param existingTransaction if executing within an existing transaction
	 * (within an existing JDO PersistenceManager that won't be closed immediately)
	 * @return the post-processed result object (can be simply be the passed-in object)
	 * @see #execute(JdoCallback, boolean)
	 */
	protected Object postProcessResult(Object result, PersistenceManager pm, boolean existingTransaction) {
		return result;
	}


	//-------------------------------------------------------------------------
	// Convenience methods for load, save, delete
	//-------------------------------------------------------------------------

	public Object getObjectById(final Object objectId) throws DataAccessException {
		return execute(new JdoCallback() {
			public Object doInJdo(PersistenceManager pm) throws JDOException {
				return pm.getObjectById(objectId, true);
			}
		}, true);
	}

	public Object getObjectById(final Class entityClass, final Object idValue) throws DataAccessException {
		return execute(new JdoCallback() {
			public Object doInJdo(PersistenceManager pm) throws JDOException {
				return pm.getObjectById(entityClass, idValue);
			}
		}, true);
	}

	public void evict(final Object entity) throws DataAccessException {
		execute(new JdoCallback() {
			public Object doInJdo(PersistenceManager pm) throws JDOException {
				pm.evict(entity);
				return null;
			}
		}, true);
	}

	public void evictAll(final Collection entities) throws DataAccessException {
		execute(new JdoCallback() {
			public Object doInJdo(PersistenceManager pm) throws JDOException {
				pm.evictAll(entities);
				return null;
			}
		}, true);
	}

	public void evictAll() throws DataAccessException {
		execute(new JdoCallback() {
			public Object doInJdo(PersistenceManager pm) throws JDOException {
				pm.evictAll();
				return null;
			}
		}, true);
	}

	public void refresh(final Object entity) throws DataAccessException {
		execute(new JdoCallback() {
			public Object doInJdo(PersistenceManager pm) throws JDOException {
				pm.refresh(entity);
				return null;
			}
		}, true);
	}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩电影一区二区三区| 国产日产亚洲精品系列| 亚洲最大色网站| 欧洲精品中文字幕| 亚洲成人在线网站| 91精品国产日韩91久久久久久| 三级在线观看一区二区| 日韩写真欧美这视频| 精油按摩中文字幕久久| 国产欧美日韩视频在线观看| 波多野结衣欧美| 亚洲午夜免费视频| 日韩欧美国产不卡| 成人免费观看av| 亚洲综合一区二区精品导航| 欧美一区日韩一区| 国产成人亚洲精品狼色在线| 亚洲欧洲av色图| 欧美精品在线一区二区三区| 国产综合色产在线精品| 国产精品美日韩| 欧美日韩一区国产| 国产精品一区一区三区| 日韩一区欧美小说| 91精品国产欧美一区二区成人| 国产剧情一区二区三区| 亚洲精品综合在线| 精品国产一区二区三区忘忧草 | 精品日韩一区二区三区| 国产激情一区二区三区桃花岛亚洲| 国产精品你懂的| 欧美浪妇xxxx高跟鞋交| 岛国精品在线播放| 日韩福利电影在线| 久久成人免费网| 中文字幕日本不卡| 91精品国产色综合久久不卡蜜臀| 大胆欧美人体老妇| 日本不卡一区二区三区高清视频| 中文字幕日韩欧美一区二区三区| 欧美一区三区二区| 在线免费观看日本一区| 国产一区二区三区免费| 婷婷成人激情在线网| 国产精品视频一二| 欧美成人在线直播| 欧美精品日日鲁夜夜添| 成人黄色一级视频| 日本不卡在线视频| 亚洲一区二区免费视频| 国产亚洲精品7777| 日韩女优毛片在线| 欧美日韩电影在线| 一本久道中文字幕精品亚洲嫩| 国产成人综合在线| 麻豆精品一区二区av白丝在线| 亚洲最大成人网4388xx| 国产精品国产三级国产a| 欧美sm美女调教| 欧美精品久久天天躁| 91精品办公室少妇高潮对白| av在线不卡免费看| 处破女av一区二区| 国产精品亚洲视频| 精品一区二区免费看| 青青草视频一区| 视频在线观看国产精品| 亚洲国产成人tv| 亚洲国产精品天堂| 一区二区三区在线观看欧美| 中文字幕欧美一区| 国产精品―色哟哟| 青青草97国产精品免费观看| 亚洲v中文字幕| 亚洲一区欧美一区| 亚洲国产精品久久人人爱| 一区二区视频在线看| 亚洲精品少妇30p| 一区二区在线观看免费| 一区二区三区在线视频观看| 亚洲精品中文字幕在线观看| 有码一区二区三区| 亚洲图片一区二区| 日韩中文字幕麻豆| 蜜臀久久久久久久| 看电影不卡的网站| 国产在线不卡视频| 国产成人av一区二区三区在线 | 91丨porny丨最新| 日本道色综合久久| 欧美美女网站色| 欧美一级黄色片| 精品国产成人在线影院 | 国产一区二三区| 精品一区二区三区在线观看 | 91黄色小视频| 欧美精品 日韩| 欧美成人女星排名| 国产欧美视频一区二区| 国产精品久久久久久久久免费相片 | 亚洲图片欧美视频| 成人免费看黄yyy456| 91蝌蚪porny成人天涯| 欧美亚洲国产bt| 日韩视频中午一区| 久久久99精品免费观看不卡| 一区在线中文字幕| 午夜婷婷国产麻豆精品| 激情六月婷婷综合| 色综合久久六月婷婷中文字幕| 欧美日本一道本在线视频| 337p日本欧洲亚洲大胆精品| 亚洲欧美综合网| 免费人成在线不卡| 东方欧美亚洲色图在线| 在线中文字幕一区二区| 欧美成人一区二区三区在线观看 | 蜜桃一区二区三区四区| 国产不卡视频一区二区三区| 欧美午夜一区二区三区免费大片| 精品国产一区二区国模嫣然| 1024精品合集| 久久精品国产亚洲a| 97se狠狠狠综合亚洲狠狠| 日韩一区二区三区在线| 日韩美女视频一区二区| 久久99国产精品尤物| 97se亚洲国产综合在线| 精品理论电影在线观看| 亚洲影院免费观看| 顶级嫩模精品视频在线看| 7777精品久久久大香线蕉 | 国产精品情趣视频| 日韩经典一区二区| 色综合久久久网| 国产无人区一区二区三区| 婷婷激情综合网| 色婷婷综合久色| 国产日韩欧美综合一区| 欧美a级一区二区| 91色.com| 久久久精品2019中文字幕之3| 日韩黄色免费电影| 91国偷自产一区二区使用方法| 久久久国产精品不卡| 日韩和的一区二区| 色天使色偷偷av一区二区| 欧美国产视频在线| 国内精品久久久久影院一蜜桃| 91精品国产综合久久精品图片| 一区二区三区中文在线观看| 国内精品免费**视频| 日韩精品中文字幕一区二区三区 | 欧美韩国一区二区| 国产在线不卡一区| 欧美白人最猛性xxxxx69交| 日韩av电影天堂| 欧美日韩成人高清| 亚洲国产毛片aaaaa无费看| 91麻豆国产香蕉久久精品| 欧美激情一区二区三区四区| 国产一区二区三区在线观看免费视频 | 69av一区二区三区| 亚洲一区二区三区自拍| 色综合久久中文综合久久97| 1024国产精品| 97se狠狠狠综合亚洲狠狠| 国产精品免费av| 91免费观看视频| 亚洲乱码国产乱码精品精小说| 成人精品一区二区三区中文字幕 | 91免费版在线看| 一区二区三区免费网站| 欧洲一区二区av| 亚洲成a人在线观看| 精品视频一区二区三区免费| 亚洲一区二区av在线| 欧美在线免费视屏| 视频一区二区不卡| 日韩三区在线观看| 国产专区欧美精品| 欧美激情综合在线| av不卡免费电影| 亚洲高清免费在线| 91精品国产黑色紧身裤美女| 久久99久国产精品黄毛片色诱| 日韩一级高清毛片| 国模一区二区三区白浆| 国产日韩视频一区二区三区| 97久久久精品综合88久久| 亚洲在线视频一区| 欧美日韩激情一区二区| 免费成人av资源网| 欧美国产97人人爽人人喊| 色婷婷精品大在线视频| 免费在线观看成人| 国产精品日产欧美久久久久| 色综合一个色综合| 日本视频免费一区| 国产精品全国免费观看高清 |