FileDocCategorySizeDatePackage
JDOEJB20HelperImpl.javaAPI DocGlassfish v2 API10512Fri May 04 22:34:48 BST 2007com.sun.jdo.spi.persistence.support.ejb.cmp

JDOEJB20HelperImpl

public abstract class JDOEJB20HelperImpl extends JDOEJB11HelperImpl implements com.sun.jdo.spi.persistence.support.sqlstore.ejb.JDOEJB20Helper

Fields Summary
Constructors Summary
Methods Summary
public abstract voidassertInstanceOfLocalInterfaceImpl(java.lang.Object o)
Validates that this instance is of the correct implementation class of a local interface type.

param
o the instance to validate.
return
true if the type is correct.
throws
IllegalArgumentException if validation fails.

protected voidassertInstanceOfLocalInterfaceImpl(java.lang.Object o, java.lang.String beanName)
Validates that this instance is of the correct implementation class of a local interface. Throws IllegalArgumentException if the passed argument is of a wrong type.

param
o the instance to validate.
param
bean name as String.
throws
IllegalArgumentException if validation fails.


        // We can't check if null is the correct type or not. So
        // we let it succeed.
        if (o == null)
            return;

        try {
            CMPHelper.assertValidLocalObject(o, getContainer());

        } catch (EJBException ex) {
            String msg = I18NHelper.getMessage(messages, "EXC_WrongLocalInstance", // NOI18N
                new Object[] {o.getClass().getName(), beanName,
                    ex.getMessage()});
            logger.log(Logger.WARNING, msg);
            throw new IllegalArgumentException(msg);
        }
    
public java.util.CollectionconvertCollectionEJBLocalObjectToPC(java.util.Collection coll, com.sun.jdo.api.persistence.support.PersistenceManager pm, boolean validate)
Converts Collection of EJBLocalObjects to a Collection of persistence-capable instances.

param
coll the Collection of EJBLocalObject instances to be converted.
param
pm the associated instance of PersistenceManager.
param
validate true if the existence of the instances is to be validated.
return
Collection of persistence-capable instance.
throws
IllegalArgumentException if validate is true and at least one instance does not exist in the database or is deleted.

        Collection rc = new java.util.ArrayList();
        Object o = null;

        boolean debug = false;

        for (java.util.Iterator it = coll.iterator(); it.hasNext();) {
            o = convertEJBLocalObjectToPC((EJBLocalObject)it.next(), pm, validate);
            if(logger.isLoggable(Logger.FINEST) ) {
                logger.finest(
                    "\n---JDOEJB20HelperImpl.convertCollectionEJBLocalObjectToPC() adding: " + o);// NOI18N
            }
            rc.add(o);
        }
        return rc;
    
public java.util.CollectionconvertCollectionPCToEJBLocalObject(java.util.Collection pcs, com.sun.jdo.api.persistence.support.PersistenceManager pm)
Converts Collection of persistence-capable instances to a Collection of EJBLocalObjects.

param
pcs the Collection of persistence-capable instance to be converted.
param
pm the associated instance of PersistenceManager.
return
Collection of EJBLocalObjects.

        Collection rc = new java.util.ArrayList();
        Object o = null;
        boolean debug = false;

        for (java.util.Iterator it = pcs.iterator(); it.hasNext();) {
            o = convertPCToEJBLocalObject((Object)it.next(), pm);
            if(logger.isLoggable(Logger.FINEST) ) {
                logger.finest(
                    "\n---JDOEJB20HelperImpl.convertCollectionPCToEJBLocalObject() adding: " + o);// NOI18N
            }
            rc.add(o);
        }
        return rc;
    
public java.util.SetconvertCollectionPCToEJBLocalObjectSet(java.util.Collection pcs, com.sun.jdo.api.persistence.support.PersistenceManager pm)
Converts Collection of persistence-capable instances to a Set of EJBLocalObjects.

param
pcs the Collection of persistence-capable instance to be converted.
param
pm the associated instance of PersistenceManager.
return
Set of EJBLocalObjects.

        java.util.Set rc = new java.util.HashSet();
        Object o = null;

        boolean debug = false;

        for (java.util.Iterator it = pcs.iterator(); it.hasNext();) {
            o = convertPCToEJBLocalObject((Object)it.next(), pm);
            if(logger.isLoggable(Logger.FINEST) ) {
                logger.finest(
                    "\n---JDOEJB20HelperImpl.convertCollectionPCToEJBLocalObjectSet() adding: " + o);// NOI18N
            }
            rc.add(o);
        }
        return rc;
    
public java.lang.ObjectconvertEJBLocalObjectToPC(javax.ejb.EJBLocalObject o, com.sun.jdo.api.persistence.support.PersistenceManager pm, boolean validate)
Converts EJBLocalObject to persistence-capable instance.

param
o the EJBLocalObject instance to be converted.
param
pm the associated instance of PersistenceManager.
param
validate true if the existence of the instance is to be validated.
return
persistence-capable instance.
throws
IllegalArgumentException if validate is true and instance does not exist in the database or is deleted.

        Object key = null; 
        try {
            key = o.getPrimaryKey();
        } catch (Exception ex) {   
            EJBException e = new EJBException(I18NHelper.getMessage(messages,
                        "EXC_ConvertEJBObjectToPC", o.getClass().getName()), ex);// NOI18N
            logger.throwing("JDOEJB20HelperImpl", "convertEJBLocalObjectToPC", e); // NOI18N
            throw e;
        }
        return convertPrimaryKeyToPC(key, pm, validate);
    
public javax.ejb.EJBLocalObjectconvertPCToEJBLocalObject(java.lang.Object pc, com.sun.jdo.api.persistence.support.PersistenceManager pm)
Converts persistence-capable instance to EJBLocalObject.

param
pc the persistence-capable instance to be converted as an Object.
param
pm the associated instance of PersistenceManager.
return
instance of EJBLocalObject.

        if (pc == null) return null;
        Object jdoObjectId = pm.getObjectId(pc);
        Object key = convertObjectIdToPrimaryKey(jdoObjectId);
        try {
            return CMPHelper.getEJBLocalObject(key, getContainer());
        } catch (Exception ex) {
            EJBException e = new EJBException(I18NHelper.getMessage(messages,
                        "EXC_ConvertPCToEJBLocalObject", key.toString()), ex);// NOI18N
            logger.throwing("JDOEJB20HelperImpl", "convertPCToEJBLocalObject", e); // NOI18N
            throw e;
        }
    
public javax.ejb.EJBLocalObjectconvertPCToEJBLocalObject(java.lang.Object pc, com.sun.jdo.api.persistence.support.PersistenceManager pm, javax.ejb.EJBContext context)
Converts persistence-capable instance to EJBLocalObject. Returns null if the instance is already removed via cascade-delete operation.

param
pc the persistence-capable instance to be converted as an Object.
param
pm the associated instance of PersistenceManager.
param
context the EJBContext of the calling bean.
return
instance of EJBLocalObject.

        if (pc == null) return null;
        Object jdoObjectId = pm.getObjectId(pc);
        Object key = convertObjectIdToPrimaryKey(jdoObjectId);
        try {
            return CMPHelper.getEJBLocalObject(key, getContainer(), context);
        } catch (Exception ex) {
            EJBException e = new EJBException(I18NHelper.getMessage(messages,
                        "EXC_ConvertPCToEJBLocalObjectCtx", key.toString()), ex);// NOI18N
            logger.throwing("JDOEJB20HelperImpl", "convertPCToEJBLocalObjectCtx", e); // NOI18N
            throw e;
        }