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

JDOEJB11HelperImpl

public abstract class JDOEJB11HelperImpl extends Object implements com.sun.jdo.spi.persistence.support.sqlstore.ejb.JDOEJB11Helper

Fields Summary
protected static final ResourceBundle
messages
I18N message handler
protected static final com.sun.jdo.spi.persistence.utility.logging.Logger
logger
Constructors Summary
Methods Summary
public abstract voidassertInstanceOfRemoteInterfaceImpl(java.lang.Object o)
Validates that this instance is of the correct implementation class of a remote interface type.

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

protected voidassertInstanceOfRemoteInterfaceImpl(java.lang.Object o, java.lang.String beanName)
Validates that this instance is of the correct implementation class of bean remote interface. Throws IllegalArgumentException if the 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.assertValidRemoteObject(o, getContainer());

        } catch (EJBException ex) {
            String msg = I18NHelper.getMessage(messages, "EXC_WrongRemoteInstance", // NOI18N
                new Object[] {o.getClass().getName(), beanName, 
                    ex.getMessage()});
            logger.log(Logger.WARNING, msg);
            throw new IllegalArgumentException(msg); 
        }
    
protected voidassertObjectIdNotNull(java.lang.Object oid)
Validates that the object id instance is not null. Throws JDOFatalInternalException otherwise.

param
oid the object id instance to validate.
throws
JDOFatalInternalException if validation fails.

 
        if (oid == null) {
            throw new JDOFatalInternalException(I18NHelper.getMessage(
                messages, "EXC_oidnull_exception")); // NOI18N
        }
    
public voidassertPrimaryKeyFieldNotNull(java.lang.Object pkfield, java.lang.String pkfieldName, java.lang.String beanName)
Validates that the primary key field of an Object type is not null. Throws IllegalArgumentException otherwise.

param
pkfield the primary key field instance to validate.
param
pkfieldName the primary key field name.
param
beanName the EJB name.
throws
IllegalArgumentException if validation fails.


        if (pkfield == null) {
            throw new IllegalArgumentException(I18NHelper.getMessage(
                messages, "EXC_pkfieldnull_exception", // NOI18N
                pkfieldName, beanName));
        }
    
protected voidassertPrimaryKeyNotNull(java.lang.Object pk)
Validates that the primary key instance is not null. Throws IllegalArgumentException otherwise.

param
pk the primary key instance to validate.
throws
IllegalArgumentException if validation fails.

        if (pk == null) {
            throw new IllegalArgumentException(I18NHelper.getMessage(
                messages, "EXC_pknull_exception")); // NOI18N
        }
    
public java.util.CollectionconvertCollectionEJBObjectToPC(java.util.Collection coll, com.sun.jdo.api.persistence.support.PersistenceManager pm, boolean validate)
Converts Collection of EJBObjects to a Collection of persistence-capable instances.

param
coll the Collection of EJBObject 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;
        for (java.util.Iterator it = coll.iterator(); it.hasNext();) {
            o = convertEJBObjectToPC((EJBObject)it.next(), pm, validate);
            if(logger.isLoggable(Logger.FINEST) ) {
                logger.finest(
                    "\n---JDOEJB11HelperImpl.convertCollectionEJBObjectToPC() adding: " + o);// NOI18N
            }
            rc.add(o);
        }
        return rc;
    
public java.util.CollectionconvertCollectionObjectIdToPrimaryKey(java.util.Collection oids)
Converts Collection of Object Id's of persistence-capable instances to a Collection of of the PrimaryKey instances.

param
oids Collection of the Object Id to be converted.
return
Collection of of the PrimaryKey Class instances.

        Collection rc = new java.util.ArrayList();

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

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

        Collection rc = new java.util.ArrayList();

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

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

        java.util.Set rc = new java.util.HashSet();

        Object o = null;
        for (java.util.Iterator it = pcs.iterator(); it.hasNext();) {
            o = convertPCToEJBObject((Object)it.next(), pm);
            if(logger.isLoggable(Logger.FINEST) ) {
                logger.finest(
                    "\n---JDOEJB11HelperImpl.convertCollectionPCToEJBObjectSet() adding: " + o);// NOI18N
            }
            rc.add(o);
        }
        return rc;
    
public java.util.CollectionconvertCollectionPCToPrimaryKey(java.util.Collection pcs, com.sun.jdo.api.persistence.support.PersistenceManager pm)
Converts Collection of persistence-capable instances to a Collection of the PrimaryKey Class instances.

param
pcs Collection of the persistence-capable instances.
param
pm the associated instance of PersistenceManager.
return
Collection of the PrimaryKey Class instances.

        Collection rc = new java.util.ArrayList();

        Object o = null;
        for (java.util.Iterator it = pcs.iterator(); it.hasNext();) {
            o = convertPCToPrimaryKey(it.next(), pm);
            if(logger.isLoggable(Logger.FINEST) ) {
                logger.finest(
                    "\n---JDOEJB11HelperImpl.convertCollectionPCToPrimaryKey() adding: " + o);// NOI18N
            }
            rc.add(o);
        }
        return rc;
    
public java.util.CollectionconvertCollectionPrimaryKeyToObjectId(java.util.Collection keys)
Converts Collection of PrimaryKey instances to a Collection of Object Id's of a corresponding persistence-capable Class.

param
keys Collection of the PrimaryKey instances to be converted.
return
Collection of the Object Id's.

        Collection rc = new java.util.ArrayList();

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

param
o the EJBObject 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("JDOEJB11HelperImpl", "convertEJBObjectToPC", e); // NOI18N
            throw e;
        }
        return convertPrimaryKeyToPC(key, pm, validate);
    
public abstract java.lang.ObjectconvertObjectIdToPrimaryKey(java.lang.Object objectId)
Converts Object Id of a persistence-capable instance to an instance of the PrimaryKey Class.

param
objectId the Object Id to be converted.
return
instance of the PrimaryKey Class.

public javax.ejb.EJBObjectconvertPCToEJBObject(java.lang.Object pc, com.sun.jdo.api.persistence.support.PersistenceManager pm)
Converts persistence-capable instance to EJBObject.

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


                                    
           
        if (pc == null) return null;
        Object jdoObjectId = pm.getObjectId(pc);
        Object key = convertObjectIdToPrimaryKey(jdoObjectId);
        try {
            return CMPHelper.getEJBObject(key, getContainer());
        } catch (Exception ex) {
            EJBException e = new EJBException(I18NHelper.getMessage(messages,
                        "EXC_ConvertPCToEJBObject", key.toString()), ex);// NOI18N
            logger.throwing("JDOEJB11HelperImpl", "convertPCToEJBObject", e); // NOI18N
            throw e;
        }
    
public java.lang.ObjectconvertPCToPrimaryKey(java.lang.Object pc, com.sun.jdo.api.persistence.support.PersistenceManager pm)
Converts persistence-capable instance to an instance of the PrimaryKey Class.

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

        if (pc == null) return null;
        Object rc = convertObjectIdToPrimaryKey(pm.getObjectId(pc));

        if(logger.isLoggable(Logger.FINEST) ) {
            logger.finest("\n---JDOEJB11HelperImpl.convertPCToPrimaryKey() PK: " + rc);// NOI18N
        }
        return rc;
    
public abstract java.lang.ObjectconvertPrimaryKeyToObjectId(java.lang.Object key)
Converts instance of a PrimaryKey Class to an instance of the Object Id of a corresponding persistence-capable Class.

param
key the PrimaryKey instance to be converted.
return
instance of the Object Id.

protected java.lang.ObjectconvertPrimaryKeyToPC(java.lang.Object key, com.sun.jdo.api.persistence.support.PersistenceManager pm, boolean validate)
Converts PrimaryKey object to persistence-capable instance.

param
key the PrimaryKey object 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 pc = null;
        try {
            Object jdoObjectId = convertPrimaryKeyToObjectId(key);
            pc = pm.getObjectById(jdoObjectId, validate);
        } catch (JDOObjectNotFoundException ex) {
            logger.fine("---JDOEJB11HelperImpl.convertPrimaryKeyToPC: Object not found for: " + key); // NOI18N

            throw new IllegalArgumentException(I18NHelper.getMessage(messages,
                        "EXC_DeletedInstanceOtherTx", key.toString()));// NOI18N
        }

        if (validate && JDOHelper.isDeleted(pc)) {
            logger.fine("---JDOEJB11HelperImpl.convertPrimaryKeyToPC: Object is deleted for: " + key); // NOI18N

            throw new IllegalArgumentException(I18NHelper.getMessage(messages,
                        "EXC_DeletedInstanceThisTx", key.toString()));// NOI18N
        }

        return pc;
    
public com.sun.jdo.spi.persistence.support.sqlstore.utility.NumericConvertergetNumericConverter()
Return NumericConverter for conversion from Number to BigDecimal or BigInteger for this bean type. It is responsible for passing the correct policy value to the NumericConverterFactory.

return
NumericConverter for given object policy

        int policy = CMPHelper.getNumericConverterPolicy(getContainer());
        return NumericConverterFactory.getNumericConverter(policy);
    
public abstract java.lang.ClassgetPCClass()
Returns the class object of the corresponding persistence-capable class of the concrete bean class.

return
the pc class object

public java.io.SerializablereadSerializableObjectFromByteArray(byte[] byteArray)
Constructs a Serializable object from byteArray. It is expected that byteArray was constructed using a previous call to writeSerializableObjectToByteArray

param
byteArray Array of byte obtained from a call to writeSerializableObjectToByteArray
return
A Serializable object contructed from byteArray
see
#writeSerializableObjectToByteArray(Serializable)

        Serializable serializableObject = null;
        if(byteArray != null)
        {
            ByteArrayInputStream bis = new ByteArrayInputStream(byteArray);
            HelperObjectInputStream ois = null;

            //
            // Take the current class loader to resolve the class to be deserialized.
            //
            ClassLoader cl = this.getClass().getClassLoader();
            try
            {
                ois = new HelperObjectInputStream(bis, cl);
                serializableObject = (Serializable) ois.readObject();
            }
            catch (ClassNotFoundException e)
            {
                throw new JDOFatalDataStoreException(I18NHelper.getMessage(messages,
                        "EXC_CNFReadSerializableObject"), e);// NOI18N
            }
            catch(java.io.IOException e)
            {
                throw new JDOFatalDataStoreException(I18NHelper.getMessage(messages,
                        "EXC_IOReadSerializableObject"), e);// NOI18N
            }
        }
        return serializableObject;
    
public byte[]writeSerializableObjectToByteArray(java.io.Serializable serializableObject)
Serializes serializableObject into a byte array

param
serializableObject Instance of a Serializable Object
return
serializableObject serialized into a byte array

        byte[] byteArray = null;
        if(serializableObject != null)
        {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = null;
            try
            {
                oos = new ObjectOutputStream(bos);
                oos.writeObject(serializableObject);
                byteArray = bos.toByteArray();
            }
            catch(java.io.IOException e)
            {
                String clsName = serializableObject.getClass().getName();
                throw new JDOUserException(I18NHelper.getMessage(messages,
                        "EXC_IOWriteSerializableObject", clsName), e);// NOI18N
            }
        }
        return byteArray;