1 8 9 package com.sleepycat.je; 10 11 import com.sleepycat.je.utilint.DatabaseUtil; 12 13 17 public class SecondaryConfig extends DatabaseConfig { 18 19 23 public static final SecondaryConfig DEFAULT = new SecondaryConfig(); 24 25 private boolean allowPopulate; 26 private SecondaryKeyCreator keyCreator; 27 private SecondaryMultiKeyCreator multiKeyCreator; 28 private Database foreignKeyDatabase; 29 private ForeignKeyDeleteAction foreignKeyDeleteAction = 30 ForeignKeyDeleteAction.ABORT; 31 private ForeignKeyNullifier foreignKeyNullifier; 32 private ForeignMultiKeyNullifier foreignMultiKeyNullifier; 33 private boolean immutableSecondaryKey; 34 35 39 public SecondaryConfig() { 40 } 41 42 46 public void setKeyCreator(SecondaryKeyCreator keyCreator) { 47 this.keyCreator = keyCreator; 48 } 49 50 54 public SecondaryKeyCreator getKeyCreator() { 55 return keyCreator; 56 } 57 58 62 public void setMultiKeyCreator(SecondaryMultiKeyCreator multiKeyCreator) { 63 this.multiKeyCreator = multiKeyCreator; 64 } 65 66 70 public SecondaryMultiKeyCreator getMultiKeyCreator() { 71 return multiKeyCreator; 72 } 73 74 78 public void setAllowPopulate(boolean allowPopulate) { 79 this.allowPopulate = allowPopulate; 80 } 81 82 86 public boolean getAllowPopulate() { 87 return allowPopulate; 88 } 89 90 94 public void setForeignKeyDatabase(Database foreignKeyDatabase) { 95 this.foreignKeyDatabase = foreignKeyDatabase; 96 } 97 98 102 public Database getForeignKeyDatabase() { 103 return foreignKeyDatabase; 104 } 105 106 110 public void setForeignKeyDeleteAction(ForeignKeyDeleteAction 111 foreignKeyDeleteAction) { 112 DatabaseUtil.checkForNullParam(foreignKeyDeleteAction, 113 "foreignKeyDeleteAction"); 114 this.foreignKeyDeleteAction = foreignKeyDeleteAction; 115 } 116 117 121 public ForeignKeyDeleteAction getForeignKeyDeleteAction() { 122 return foreignKeyDeleteAction; 123 } 124 125 129 public void setForeignKeyNullifier(ForeignKeyNullifier 130 foreignKeyNullifier) { 131 this.foreignKeyNullifier = foreignKeyNullifier; 132 } 133 134 138 public ForeignKeyNullifier getForeignKeyNullifier() { 139 return foreignKeyNullifier; 140 } 141 142 146 public void setForeignMultiKeyNullifier(ForeignMultiKeyNullifier 147 foreignMultiKeyNullifier) { 148 this.foreignMultiKeyNullifier = foreignMultiKeyNullifier; 149 } 150 151 155 public ForeignMultiKeyNullifier getForeignMultiKeyNullifier() { 156 return foreignMultiKeyNullifier; 157 } 158 159 163 public void setImmutableSecondaryKey(boolean immutableSecondaryKey) { 164 this.immutableSecondaryKey = immutableSecondaryKey; 165 } 166 167 171 public boolean getImmutableSecondaryKey() { 172 return immutableSecondaryKey; 173 } 174 175 178 void validate(DatabaseConfig configArg) 179 throws DatabaseException { 180 181 super.validate(configArg); 182 183 if (configArg == null || 184 !(configArg instanceof SecondaryConfig)) { 185 throw new DatabaseException 186 ("The SecondaryConfig argument is null."); 187 } 188 189 SecondaryConfig config = (SecondaryConfig) configArg; 190 191 boolean kcMatch = equalOrBothNull 192 (config.getKeyCreator(), keyCreator); 193 boolean mkcMatch = equalOrBothNull 194 (config.getMultiKeyCreator(), multiKeyCreator); 195 boolean fkdMatch = 196 (config.getForeignKeyDatabase() == foreignKeyDatabase); 197 boolean fkdaMatch = 198 (config.getForeignKeyDeleteAction() == foreignKeyDeleteAction); 199 boolean fknMatch = equalOrBothNull 200 (config.getForeignKeyNullifier(), foreignKeyNullifier); 201 boolean fmknMatch = equalOrBothNull 202 (config.getForeignMultiKeyNullifier(), foreignMultiKeyNullifier); 203 boolean imskMatch = 204 (config.getImmutableSecondaryKey() == immutableSecondaryKey); 205 if (kcMatch && 206 mkcMatch && 207 fkdMatch && 208 fkdaMatch && 209 fknMatch && 210 fmknMatch && 211 imskMatch) { 212 return; 213 } 214 215 String message = 216 genSecondaryConfigMismatchMessage( 217 config, kcMatch, mkcMatch, fkdMatch, fkdaMatch, 218 fknMatch, fmknMatch, imskMatch); 219 throw new DatabaseException(message); 220 } 221 222 private boolean equalOrBothNull(Object o1, Object o2) { 223 return (o1 != null) ? o1.equals(o2) : (o2 == null); 224 } 225 226 String genSecondaryConfigMismatchMessage(DatabaseConfig config, 227 boolean kcMatch, 228 boolean mkcMatch, 229 boolean fkdMatch, 230 boolean fkdaMatch, 231 boolean fknMatch, 232 boolean fmknMatch, 233 boolean imskMatch) { 234 StringBuffer ret = new StringBuffer 235 ("The following SecondaryConfig parameters for the\n" + 236 "cached Database do not match the parameters for the\n" + 237 "requested Database:\n"); 238 if (!kcMatch) { 239 ret.append(" SecondaryKeyCreator\n"); 240 } 241 242 if (!mkcMatch) { 243 ret.append(" SecondaryMultiKeyCreator\n"); 244 } 245 246 if (!fkdMatch) { 247 ret.append(" ForeignKeyDelete\n"); 248 } 249 250 if (!fkdaMatch) { 251 ret.append(" ForeignKeyDeleteAction\n"); 252 } 253 254 if (!fknMatch) { 255 ret.append(" ForeignKeyNullifier\n"); 256 } 257 258 if (!fknMatch) { 259 ret.append(" ForeignMultiKeyNullifier\n"); 260 } 261 262 if (!imskMatch) { 263 ret.append(" ImmutableSecondaryKey\n"); 264 } 265 266 return ret.toString(); 267 } 268 } 269 | Popular Tags |