Package org.jpox

Source Code of org.jpox.ObjectManagerHelper

/**********************************************************************
Copyright (c) 2007 Erik Bengtson and others. All rights reserved.
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.

Contributors:
     ...
**********************************************************************/
package org.jpox;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.spi.PersistenceCapable;

import org.jpox.jdo.AbstractPersistenceManager;

/**
* Helper methods for accessing the ObjectManager for particular objects.
*
* @version $Revision: 1.3 $
*/
public class ObjectManagerHelper
{
    /**
     * Accessor for the ObjectManager for a PersistenceCapable object
     * @param pc The PersistenceCapable object
     * @return Its ObjectManager (if any)
     */
    public static ObjectManager getObjectManager(PersistenceCapable pc)
    {
        if (pc == null)
        {
            return null;
        }
        PersistenceManager pm = JDOHelper.getPersistenceManager(pc);
        if (pm == null)
        {
            return null;
        }
        return ((AbstractPersistenceManager)pm).getObjectManager();
    }

    /**
     * Accessor for the ObjectManager for a PersistenceManager.
     * @param pm The PM
     * @return The ObjectManager
     */
    public static ObjectManager getObjectManager(PersistenceManager pm)
    {
        if (pm == null)
        {
            return null;
        }
        return ((AbstractPersistenceManager)pm).getObjectManager();
    }

    /**
     * Accessor for the ObjectManager for an Object.
     * @param obj The Object
     * @return The ObjectManager
     */
    public static ObjectManager getObjectManager(Object obj)
    {
        if (obj == null)
        {
            return null;
        }
        if (obj instanceof PersistenceCapable)
        {
            return getObjectManager((PersistenceCapable)obj);
        }
        else if (obj instanceof PersistenceManager)
        {
            return getObjectManager((PersistenceManager)obj);
        }
        return null;
    }
}
TOP

Related Classes of org.jpox.ObjectManagerHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.