001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.isis.persistence.jdo.spring.support; 020 021import javax.jdo.PersistenceManager; 022import javax.jdo.PersistenceManagerFactory; 023 024import org.springframework.beans.factory.FactoryBean; 025import org.springframework.util.Assert; 026 027/** 028 * Proxy that implements the {@link javax.jdo.PersistenceManager} interface, 029 * delegating to a thread-bound PersistenceManager on each invocation - 030 * as defined by the JDO 3.0 specification. This class makes such a standard 031 * JDO PersistenceManager proxy available for bean references. 032 * 033 * <p>The main advantage of this proxy is that it allows DAOs to work with a 034 * plain JDO PersistenceManager reference in JDO 3.0 style 035 * (see {@link javax.jdo.PersistenceManagerFactory#getPersistenceManagerProxy()}), 036 * exposing the exact behavior that the target JDO provider implements. 037 * 038 * @see SpringPersistenceManagerProxyBean 039 * @see javax.jdo.PersistenceManagerFactory#getPersistenceManagerProxy() 040 */ 041public class StandardPersistenceManagerProxyBean implements FactoryBean<PersistenceManager> { 042 043 private PersistenceManager proxy; 044 045 046 /** 047 * Set the target JDO PersistenceManagerFactory that this proxy should 048 * delegate to. This should be the raw PersistenceManagerFactory, as 049 * accessed by JdoTransactionManager. 050 * @see org.apache.isis.persistence.jdo.spring.integration.JdoTransactionManager 051 */ 052 public void setPersistenceManagerFactory(PersistenceManagerFactory pmf) { 053 Assert.notNull(pmf, "PersistenceManagerFactory must not be null"); 054 this.proxy = pmf.getPersistenceManagerProxy(); 055 } 056 057 058 @Override 059 public PersistenceManager getObject() { 060 return this.proxy; 061 } 062 063 @Override 064 public Class<? extends PersistenceManager> getObjectType() { 065 return (this.proxy != null ? this.proxy.getClass() : PersistenceManager.class); 066 } 067 068 @Override 069 public boolean isSingleton() { 070 return true; 071 } 072 073}