1 21 package oracle.toplink.essentials.sessions; 23 24 import oracle.toplink.essentials.internal.helper.*; 25 import oracle.toplink.essentials.internal.localization.*; 26 27 39 public class ObjectCopyingPolicy { 40 protected boolean shouldResetPrimaryKey; 41 protected oracle.toplink.essentials.internal.sessions.AbstractSession session; 42 protected IdentityHashtable copies; 43 44 46 protected int depth; 47 48 51 public static final int NO_CASCADE = 1; 52 53 55 public static final int CASCADE_PRIVATE_PARTS = 2; 56 57 59 public static final int CASCADE_ALL_PARTS = 3; 60 61 66 public ObjectCopyingPolicy() { 67 this.shouldResetPrimaryKey = true; 68 this.copies = new IdentityHashtable(); 70 this.depth = CASCADE_PRIVATE_PARTS; 71 } 72 73 77 public void cascadeAllParts() { 78 setDepth(CASCADE_ALL_PARTS); 79 } 80 81 86 public void cascadePrivateParts() { 87 setDepth(CASCADE_PRIVATE_PARTS); 88 } 89 90 94 public void dontCascade() { 95 setDepth(NO_CASCADE); 96 } 97 98 101 public IdentityHashtable getCopies() { 102 return copies; 103 } 104 105 108 public int getDepth() { 109 return depth; 110 } 111 112 115 public oracle.toplink.essentials.internal.sessions.AbstractSession getSession() { 116 return session; 117 } 118 119 122 public void setCopies(IdentityHashtable newCopies) { 123 copies = newCopies; 124 } 125 126 129 public void setDepth(int newDepth) { 130 depth = newDepth; 131 } 132 133 136 public void setSession(oracle.toplink.essentials.internal.sessions.AbstractSession newSession) { 137 session = newSession; 138 } 139 140 144 public void setShouldResetPrimaryKey(boolean newShouldResetPrimaryKey) { 145 shouldResetPrimaryKey = newShouldResetPrimaryKey; 146 } 147 148 152 public boolean shouldCascade() { 153 return getDepth() != NO_CASCADE; 154 } 155 156 160 public boolean shouldCascadeAllParts() { 161 return getDepth() == CASCADE_ALL_PARTS; 162 } 163 164 168 public boolean shouldCascadePrivateParts() { 169 return getDepth() == CASCADE_PRIVATE_PARTS; 170 } 171 172 176 public boolean shouldResetPrimaryKey() { 177 return shouldResetPrimaryKey; 178 } 179 180 183 public String toString() { 184 String depthString = ""; 185 if (shouldCascadeAllParts()) { 186 depthString = "CASCADE_ALL_PARTS"; 187 } else if (shouldCascadePrivateParts()) { 188 depthString = "CASCADE_PRIVATE_PARTS"; 189 } else { 190 depthString = "NO_CASCADING"; 191 } 192 Object [] args = { depthString, new Boolean (shouldResetPrimaryKey()) }; 193 return Helper.getShortClassName(this) + ToStringLocalization.buildMessage("depth_reset_key", args); 194 } 195 } 196 | Popular Tags |