FileDocCategorySizeDatePackage
ObjectCopyingPolicy.javaAPI DocGlassfish v2 API7080Tue May 22 16:54:52 BST 2007oracle.toplink.essentials.sessions

ObjectCopyingPolicy

public class ObjectCopyingPolicy extends Object
Purpose: Define how an object is to be copied.

Description: This is for usage with the object copying feature, not the unit of work. This is useful for copying an entire object graph as part of the host application's logic.

Responsibilities:

  • Inidcate through CASCADE levels the depth relationships will copied.
  • Indicate if PK attributes should be copied with existing value or should be reset.
since
TOPLink/Java 3.0
see
Session#copyObject(Object, ObjectCopyingPolicy)

Fields Summary
protected boolean
shouldResetPrimaryKey
protected AbstractSession
session
protected IdentityHashtable
copies
protected int
depth
Policy depth that determines how the copy will cascade to the object's related parts
public static final int
NO_CASCADE
Depth level indicating that NO relationships should be included in the copy. Relationships that are not copied will include the default value of the object's instantiation policy
public static final int
CASCADE_PRIVATE_PARTS
Depth level indicating that only relationships with mapping indicated privately- owned should be copied
public static final int
CASCADE_ALL_PARTS
Depth level indicating that all relationships with mappings should be used when building the copied object graph
Constructors Summary
public ObjectCopyingPolicy()
PUBLIC: Return a new copying policy. By default the policy cascades privately owned parts and nulls primary keys.


                           
      
        this.shouldResetPrimaryKey = true;
        // 2612538 - the default size of IdentityHashtable (32) is appropriate
        this.copies = new IdentityHashtable();
        this.depth = CASCADE_PRIVATE_PARTS;
    
Methods Summary
public voidcascadeAllParts()
PUBLIC: Set if the copy should cascade all relationships when copying the object(s).

        setDepth(CASCADE_ALL_PARTS);
    
public voidcascadePrivateParts()
PUBLIC: Set if the copy should cascade only those relationships that are configured as privately-owned.

        setDepth(CASCADE_PRIVATE_PARTS);
    
public voiddontCascade()
PUBLIC: Set if the copy should not cascade relationships when copying the object(s)

        setDepth(NO_CASCADE);
    
public oracle.toplink.essentials.internal.helper.IdentityHashtablegetCopies()
INTERNAL: Get the session.

        return copies;
    
public intgetDepth()
INTERNAL: Return the cascade depth.

        return depth;
    
public oracle.toplink.essentials.internal.sessions.AbstractSessiongetSession()
INTERNAL: Return the session.

        return session;
    
public voidsetCopies(oracle.toplink.essentials.internal.helper.IdentityHashtable newCopies)
INTERNAL: Set the copies.

        copies = newCopies;
    
public voidsetDepth(int newDepth)
INTERNAL: Set the cascade depth.

        depth = newDepth;
    
public voidsetSession(oracle.toplink.essentials.internal.sessions.AbstractSession newSession)
INTERNAL: Set the session.

        session = newSession;
    
public voidsetShouldResetPrimaryKey(boolean newShouldResetPrimaryKey)
PUBLIC: Set if the primary key should be reset to null.

        shouldResetPrimaryKey = newShouldResetPrimaryKey;
    
public booleanshouldCascade()
PUBLIC: Return true if the policy has been configured to CASCADE_ALL_PARTS or CASCADE_PRIVATE_PARTS.

        return getDepth() != NO_CASCADE;
    
public booleanshouldCascadeAllParts()
PUBLIC: Return true if the policy should CASCADE_ALL_PARTS

        return getDepth() == CASCADE_ALL_PARTS;
    
public booleanshouldCascadePrivateParts()
PUBLIC: Return true if the policy should CASCADE_PRIVATE_PARTS

        return getDepth() == CASCADE_PRIVATE_PARTS;
    
public booleanshouldResetPrimaryKey()
PUBLIC: Return if the primary key should be reset to null.

        return shouldResetPrimaryKey;
    
public java.lang.StringtoString()
INTERNAL:

        String depthString = "";
        if (shouldCascadeAllParts()) {
            depthString = "CASCADE_ALL_PARTS";
        } else if (shouldCascadePrivateParts()) {
            depthString = "CASCADE_PRIVATE_PARTS";
        } else {
            depthString = "NO_CASCADING";
        }
        Object[] args = { depthString, new Boolean(shouldResetPrimaryKey()) };
        return Helper.getShortClassName(this) + ToStringLocalization.buildMessage("depth_reset_key", args);