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

EJBHashSet

public class EJBHashSet extends HashSet

Fields Summary
private com.sun.jdo.api.persistence.support.PersistenceManager
pm
private com.sun.jdo.api.persistence.support.Transaction
tx
private HashSet
pcSet
private com.sun.jdo.spi.persistence.support.sqlstore.ejb.JDOEJB20Helper
helper
private boolean
valid
private static com.sun.jdo.spi.persistence.utility.logging.Logger
logger
Constructors Summary
public EJBHashSet(com.sun.jdo.api.persistence.support.PersistenceManager pm, com.sun.jdo.spi.persistence.support.sqlstore.ejb.JDOEJB20Helper helper, Collection pcs)
Creates new instance of EJBHashSet for this parameters.

param
pm the PersistenceManager associated with the calling bean.
param
helper the JDOEJB20Helper instance.
param
pcs a Collection of persistence-capable instances.


                                       
           
        this.pm = pm;
        tx = pm.currentTransaction();
        this.helper = helper;
        if (logger.isLoggable(Logger.FINEST)) {
            logger.finest("---EJBHashSet.new--- " + // NOI18N
                ((pcs == null)? -1: pcs.size()));
        }

        // Convert Collection.
        setSCOHashSet(pcs);

        valid = true;
    
Methods Summary
public booleanadd(java.lang.Object o)
Adds the specified element to this set if it is not already present.

param
o element to be added to this set.
return
true if the set did not already contain the specified element.
see
java.util.HashSet

        logger.finest("---EJBHashSet.add---"); // NOI18N
        assertIsValid();
        assertInTransaction();
        helper.assertInstanceOfLocalInterfaceImpl(o);
        Object pc = helper.convertEJBLocalObjectToPC((EJBLocalObject) o, pm, true);
        return pcSet.add(pc);
    
public booleanaddAll(java.util.Collection c)
Adds all of the elements in the specified collection to this collection

param
c collection whose elements are to be added to this collection.
return
true if this collection changed as a result of the call.
throws
UnsupportedOperationException if the addAll method is not supported by this collection.
see
java.util.AbstractCollection
see
java.util.HashSet

        logger.finest("---EJBHashSet.addAll---"); // NOI18N
        assertIsValid();
        assertInTransaction();
        assertInstancesOfLocalInterfaceImpl(c); 
        return pcSet.addAll(helper.convertCollectionEJBLocalObjectToPC(c, pm, true));
    
private voidassertInTransaction()
Verifies that persistence manager is not closed and the current transaction is active.

throw
IllegalStateException of validation fails.

        if (pm.isClosed() || !tx.isActive()) {
            invalidate();
            throw new IllegalStateException(); // RESOLVE Exception text.
        }
    
private voidassertInstancesOfLocalInterfaceImpl(java.util.Collection c)
Verifies that elements of this Collection are of the expected type.

param
c the Collection to verify.
throw
EJBException of validation fails.

        for (Iterator it = c.iterator(); it.hasNext();)
            helper.assertInstanceOfLocalInterfaceImpl(it.next());
    
private voidassertIsValid()
Verifies that this Set is not marked as invalid.

throw
IllegalStateException of validation fails.

        if (!valid)
            throw new IllegalStateException(); // RESOLVE Exception text.
    
public voidclear()
Removes all of the elements from this set.

see
java.util.HashSet

        logger.finest("---EJBHashSet.clear---"); // NOI18N
        assertIsValid();
        assertInTransaction();
        pcSet.clear();
    
public java.lang.Objectclone()
Returns a shallow copy of this HashSet instance: the elements themselves are not cloned.

return
a shallow copy of this set.

        logger.finest("---EJBHashSet.clone---"); // NOI18N
        EJBHashSet newSet = (EJBHashSet)super.clone();
        newSet.pcSet = (HashSet)pcSet.clone();
        return newSet;
    
public booleancontains(java.lang.Object o)
Returns true if this set contains the specified element.

param
o element whose presence in this set is to be tested.
return
true if this set contains the specified element.

        logger.finest("---EJBHashSet.contains---"); // NOI18N
        assertIsValid();
        assertInTransaction();
        helper.assertInstanceOfLocalInterfaceImpl(o);
        EJBLocalObject lo = (EJBLocalObject) o;
        return pcSet.contains(helper.convertEJBLocalObjectToPC(lo, pm, true));
    
public booleancontainsAll(java.util.Collection c)
Returns true if this collection contains all of the elements in the specified collection.

This implementation iterates over the specified collection, checking each element returned by the iterator in turn to see if it's contained in this collection. If all elements are so contained true is returned, otherwise false.

param
c collection to be checked for containment in this collection.
return
true if this collection contains all of the elements in the specified collection.
see
#contains(Object)

        logger.finest("---EJBHashSet.containsAll---"); // NOI18N
        assertIsValid();
        assertInTransaction();
        assertInstancesOfLocalInterfaceImpl(c);
        return pcSet.containsAll(helper.convertCollectionEJBLocalObjectToPC(c, pm, true));
    
public java.util.HashSetgetSCOHashSet()
Returns set of the persistence-capable instances associated with this Set.

return
Set of the persistence-capable instances.

        assertIsValid();
        assertInTransaction();
        return (pcSet != null) ? (HashSet)pcSet.clone() : null;
    
public voidinvalidate()
Marks this Set as invalid and releases all references.

        valid = false;
        pm = null;
        tx = null;
        helper = null;
        pcSet = null;
    
public booleanisEmpty()
Returns true if this set contains no elements.

return
true if this set contains no elements.

        logger.finest("---EJBHashSet.isEmpty---"); // NOI18N
        assertIsValid();
        assertInTransaction();
        return pcSet.isEmpty();
    
public java.util.Iteratoriterator()
Returns an iterator over the elements in this set. The elements are returned in no particular order.

return
an Iterator over the elements in this set.
see
ConcurrentModificationException

        assertIsValid();
        assertInTransaction();
        return new EJBHashIterator();
    
public booleanremove(java.lang.Object o)
Removes the given element from this set if it is present.

param
o object to be removed from this set, if present.
return
true if the set contained the specified element.
see
java.util.HashSet

        logger.finest("---EJBHashSet.remove---"); // NOI18N
        assertIsValid();
        assertInTransaction();
        helper.assertInstanceOfLocalInterfaceImpl(o);
        EJBLocalObject lo = (EJBLocalObject) o;
        return pcSet.remove(helper.convertEJBLocalObjectToPC(lo, pm, true));
    
public booleanremoveAll(java.util.Collection c)
Removes from this collection all of its elements that are contained in the specified collection (optional operation).

Processes each element remove internally not to have call backs into #remove(Object).

param
c elements to be removed from this collection.
return
true if this collection changed as a result of the call.
throws
UnsupportedOperationException removeAll is not supported by this collection.
see
java.util.HashSet
see
java.util.AbstractCollection

        logger.finest("---EJBHashSet.removeAll---"); // NOI18N
        assertIsValid();
        assertInTransaction();
        assertInstancesOfLocalInterfaceImpl(c); 
        return pcSet.removeAll(helper.convertCollectionEJBLocalObjectToPC(c, pm, true));
    
public booleanretainAll(java.util.Collection c)
Retains only the elements in this collection that are contained in the specified collection (optional operation).

return
true if this collection changed as a result of the call.
throws
UnsupportedOperationException if the retainAll method is not supported by this collection.
see
java.util.HashSet
see
java.util.AbstractCollection

        logger.finest("---EJBHashSet.retainAll---"); // NOI18N
        assertIsValid();
        assertInTransaction();
        assertInstancesOfLocalInterfaceImpl(c); 
        return pcSet.retainAll(helper.convertCollectionEJBLocalObjectToPC(c, pm, true));
    
public voidsetSCOHashSet(java.util.Collection coll)
Replace the set of the persistence-capable instances associated with this EJBHashSet. There is no need to check transaction as it has already been checked in this case.

        if (coll instanceof java.util.HashSet)
            pcSet = (java.util.HashSet)coll;
        else
            pcSet = new java.util.HashSet(coll);
    
public intsize()
Returns the number of elements in this set (its cardinality).

return
the number of elements in this set (its cardinality).

        logger.finest("---EJBHashSet.size---"); // NOI18N
        assertIsValid();
        assertInTransaction();
        return pcSet.size();