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.integration;
020
021import javax.jdo.PersistenceManager;
022
023import org.springframework.transaction.support.ResourceHolderSupport;
024import org.springframework.util.Assert;
025
026/**
027 * Holder wrapping a JDO PersistenceManager.
028 * JdoTransactionManager binds instances of this class
029 * to the thread, for a given PersistenceManagerFactory.
030 *
031 * <p>Note: This is an SPI class, not intended to be used by applications.
032 *
033 * @see JdoTransactionManager
034 * @see PersistenceManagerFactoryUtils
035 */
036public class PersistenceManagerHolder extends ResourceHolderSupport {
037
038        private final PersistenceManager persistenceManager;
039
040        private boolean transactionActive;
041
042
043        public PersistenceManagerHolder(PersistenceManager persistenceManager) {
044                Assert.notNull(persistenceManager, "PersistenceManager must not be null");
045                this.persistenceManager = persistenceManager;
046        }
047
048
049        public PersistenceManager getPersistenceManager() {
050                return this.persistenceManager;
051        }
052
053        protected void setTransactionActive(boolean transactionActive) {
054                this.transactionActive = transactionActive;
055        }
056
057        protected boolean isTransactionActive() {
058                return this.transactionActive;
059        }
060
061        @Override
062        public void clear() {
063                super.clear();
064                this.transactionActive = false;
065        }
066
067}