001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 */ 016package org.opends.server.admin.std.meta; 017 018 019 020import java.util.Collection; 021import java.util.SortedSet; 022import org.forgerock.opendj.ldap.DN; 023import org.forgerock.opendj.ldap.schema.AttributeType; 024import org.opends.server.admin.AdministratorAction; 025import org.opends.server.admin.AliasDefaultBehaviorProvider; 026import org.opends.server.admin.AttributeTypePropertyDefinition; 027import org.opends.server.admin.client.AuthorizationException; 028import org.opends.server.admin.client.CommunicationException; 029import org.opends.server.admin.client.ConcurrentModificationException; 030import org.opends.server.admin.client.ManagedObject; 031import org.opends.server.admin.client.MissingMandatoryPropertiesException; 032import org.opends.server.admin.client.OperationRejectedException; 033import org.opends.server.admin.DefaultBehaviorProvider; 034import org.opends.server.admin.DefinedDefaultBehaviorProvider; 035import org.opends.server.admin.EnumPropertyDefinition; 036import org.opends.server.admin.IntegerPropertyDefinition; 037import org.opends.server.admin.ManagedObjectAlreadyExistsException; 038import org.opends.server.admin.ManagedObjectDefinition; 039import org.opends.server.admin.PropertyException; 040import org.opends.server.admin.PropertyOption; 041import org.opends.server.admin.PropertyProvider; 042import org.opends.server.admin.RelativeInheritedDefaultBehaviorProvider; 043import org.opends.server.admin.server.ConfigurationChangeListener; 044import org.opends.server.admin.server.ServerManagedObject; 045import org.opends.server.admin.std.client.BackendIndexCfgClient; 046import org.opends.server.admin.std.server.BackendIndexCfg; 047import org.opends.server.admin.StringPropertyDefinition; 048import org.opends.server.admin.Tag; 049import org.opends.server.admin.TopCfgDefn; 050import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 051 052 053 054/** 055 * An interface for querying the Backend Index managed object 056 * definition meta information. 057 * <p> 058 * Backend Indexes are used to store information that makes it 059 * possible to locate entries very quickly when processing search 060 * operations. 061 */ 062public final class BackendIndexCfgDefn extends ManagedObjectDefinition<BackendIndexCfgClient, BackendIndexCfg> { 063 064 // The singleton configuration definition instance. 065 private static final BackendIndexCfgDefn INSTANCE = new BackendIndexCfgDefn(); 066 067 068 069 /** 070 * Defines the set of permissable values for the "index-type" property. 071 * <p> 072 * Specifies the type(s) of indexing that should be performed for 073 * the associated attribute. 074 * <p> 075 * For equality, presence, and substring index types, the associated 076 * attribute type must have a corresponding matching rule. 077 */ 078 public static enum IndexType { 079 080 /** 081 * This index type is used to improve the efficiency of searches 082 * using approximate matching search filters. 083 */ 084 APPROXIMATE("approximate"), 085 086 087 088 /** 089 * This index type is used to improve the efficiency of searches 090 * using equality search filters. 091 */ 092 EQUALITY("equality"), 093 094 095 096 /** 097 * This index type is used to improve the efficiency of searches 098 * using extensible matching search filters. 099 */ 100 EXTENSIBLE("extensible"), 101 102 103 104 /** 105 * This index type is used to improve the efficiency of searches 106 * using "greater than or equal to" or "less then or equal to" 107 * search filters. 108 */ 109 ORDERING("ordering"), 110 111 112 113 /** 114 * This index type is used to improve the efficiency of searches 115 * using the presence search filters. 116 */ 117 PRESENCE("presence"), 118 119 120 121 /** 122 * This index type is used to improve the efficiency of searches 123 * using substring search filters. 124 */ 125 SUBSTRING("substring"); 126 127 128 129 // String representation of the value. 130 private final String name; 131 132 133 134 // Private constructor. 135 private IndexType(String name) { this.name = name; } 136 137 138 139 /** 140 * {@inheritDoc} 141 */ 142 public String toString() { return name; } 143 144 } 145 146 147 148 // The "attribute" property definition. 149 private static final AttributeTypePropertyDefinition PD_ATTRIBUTE; 150 151 152 153 // The "index-entry-limit" property definition. 154 private static final IntegerPropertyDefinition PD_INDEX_ENTRY_LIMIT; 155 156 157 158 // The "index-extensible-matching-rule" property definition. 159 private static final StringPropertyDefinition PD_INDEX_EXTENSIBLE_MATCHING_RULE; 160 161 162 163 // The "index-type" property definition. 164 private static final EnumPropertyDefinition<IndexType> PD_INDEX_TYPE; 165 166 167 168 // The "substring-length" property definition. 169 private static final IntegerPropertyDefinition PD_SUBSTRING_LENGTH; 170 171 172 173 // Build the "attribute" property definition. 174 static { 175 AttributeTypePropertyDefinition.Builder builder = AttributeTypePropertyDefinition.createBuilder(INSTANCE, "attribute"); 176 builder.setOption(PropertyOption.READ_ONLY); 177 builder.setOption(PropertyOption.MANDATORY); 178 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "attribute")); 179 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<AttributeType>()); 180 PD_ATTRIBUTE = builder.getInstance(); 181 INSTANCE.registerPropertyDefinition(PD_ATTRIBUTE); 182 } 183 184 185 186 // Build the "index-entry-limit" property definition. 187 static { 188 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "index-entry-limit"); 189 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "index-entry-limit")); 190 DefaultBehaviorProvider<Integer> provider = new RelativeInheritedDefaultBehaviorProvider<Integer>(PluggableBackendCfgDefn.getInstance(), "index-entry-limit", 1); 191 builder.setDefaultBehaviorProvider(provider); 192 builder.setUpperLimit(2147483647); 193 builder.setLowerLimit(0); 194 PD_INDEX_ENTRY_LIMIT = builder.getInstance(); 195 INSTANCE.registerPropertyDefinition(PD_INDEX_ENTRY_LIMIT); 196 } 197 198 199 200 // Build the "index-extensible-matching-rule" property definition. 201 static { 202 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "index-extensible-matching-rule"); 203 builder.setOption(PropertyOption.MULTI_VALUED); 204 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "index-extensible-matching-rule")); 205 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "index-extensible-matching-rule")); 206 builder.setPattern("([a-z][a-z](-[A-Z][A-Z]){0,2}(.(([a-z]{2,3})|\\d))?)|(^\\d.((\\d)+.)+\\d$)", "LOCALE | OID"); 207 PD_INDEX_EXTENSIBLE_MATCHING_RULE = builder.getInstance(); 208 INSTANCE.registerPropertyDefinition(PD_INDEX_EXTENSIBLE_MATCHING_RULE); 209 } 210 211 212 213 // Build the "index-type" property definition. 214 static { 215 EnumPropertyDefinition.Builder<IndexType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "index-type"); 216 builder.setOption(PropertyOption.MULTI_VALUED); 217 builder.setOption(PropertyOption.MANDATORY); 218 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "index-type")); 219 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<IndexType>()); 220 builder.setEnumClass(IndexType.class); 221 PD_INDEX_TYPE = builder.getInstance(); 222 INSTANCE.registerPropertyDefinition(PD_INDEX_TYPE); 223 } 224 225 226 227 // Build the "substring-length" property definition. 228 static { 229 IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "substring-length"); 230 builder.setOption(PropertyOption.ADVANCED); 231 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "substring-length")); 232 DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("6"); 233 builder.setDefaultBehaviorProvider(provider); 234 builder.setLowerLimit(3); 235 PD_SUBSTRING_LENGTH = builder.getInstance(); 236 INSTANCE.registerPropertyDefinition(PD_SUBSTRING_LENGTH); 237 } 238 239 240 241 // Register the tags associated with this managed object definition. 242 static { 243 INSTANCE.registerTag(Tag.valueOf("database")); 244 } 245 246 247 248 /** 249 * Get the Backend Index configuration definition singleton. 250 * 251 * @return Returns the Backend Index configuration definition 252 * singleton. 253 */ 254 public static BackendIndexCfgDefn getInstance() { 255 return INSTANCE; 256 } 257 258 259 260 /** 261 * Private constructor. 262 */ 263 private BackendIndexCfgDefn() { 264 super("backend-index", TopCfgDefn.getInstance()); 265 } 266 267 268 269 /** 270 * {@inheritDoc} 271 */ 272 public BackendIndexCfgClient createClientConfiguration( 273 ManagedObject<? extends BackendIndexCfgClient> impl) { 274 return new BackendIndexCfgClientImpl(impl); 275 } 276 277 278 279 /** 280 * {@inheritDoc} 281 */ 282 public BackendIndexCfg createServerConfiguration( 283 ServerManagedObject<? extends BackendIndexCfg> impl) { 284 return new BackendIndexCfgServerImpl(impl); 285 } 286 287 288 289 /** 290 * {@inheritDoc} 291 */ 292 public Class<BackendIndexCfg> getServerConfigurationClass() { 293 return BackendIndexCfg.class; 294 } 295 296 297 298 /** 299 * Get the "attribute" property definition. 300 * <p> 301 * Specifies the name of the attribute for which the index is to be 302 * maintained. 303 * 304 * @return Returns the "attribute" property definition. 305 */ 306 public AttributeTypePropertyDefinition getAttributePropertyDefinition() { 307 return PD_ATTRIBUTE; 308 } 309 310 311 312 /** 313 * Get the "index-entry-limit" property definition. 314 * <p> 315 * Specifies the maximum number of entries that are allowed to match 316 * a given index key before that particular index key is no longer 317 * maintained. 318 * <p> 319 * This is analogous to the ALL IDs threshold in the Sun Java System 320 * Directory Server. If this is specified, its value overrides the JE 321 * backend-wide configuration. For no limit, use 0 for the value. 322 * 323 * @return Returns the "index-entry-limit" property definition. 324 */ 325 public IntegerPropertyDefinition getIndexEntryLimitPropertyDefinition() { 326 return PD_INDEX_ENTRY_LIMIT; 327 } 328 329 330 331 /** 332 * Get the "index-extensible-matching-rule" property definition. 333 * <p> 334 * The extensible matching rule in an extensible index. 335 * <p> 336 * An extensible matching rule must be specified using either LOCALE 337 * or OID of the matching rule. 338 * 339 * @return Returns the "index-extensible-matching-rule" property definition. 340 */ 341 public StringPropertyDefinition getIndexExtensibleMatchingRulePropertyDefinition() { 342 return PD_INDEX_EXTENSIBLE_MATCHING_RULE; 343 } 344 345 346 347 /** 348 * Get the "index-type" property definition. 349 * <p> 350 * Specifies the type(s) of indexing that should be performed for 351 * the associated attribute. 352 * <p> 353 * For equality, presence, and substring index types, the associated 354 * attribute type must have a corresponding matching rule. 355 * 356 * @return Returns the "index-type" property definition. 357 */ 358 public EnumPropertyDefinition<IndexType> getIndexTypePropertyDefinition() { 359 return PD_INDEX_TYPE; 360 } 361 362 363 364 /** 365 * Get the "substring-length" property definition. 366 * <p> 367 * The length of substrings in a substring index. 368 * 369 * @return Returns the "substring-length" property definition. 370 */ 371 public IntegerPropertyDefinition getSubstringLengthPropertyDefinition() { 372 return PD_SUBSTRING_LENGTH; 373 } 374 375 376 377 /** 378 * Managed object client implementation. 379 */ 380 private static class BackendIndexCfgClientImpl implements 381 BackendIndexCfgClient { 382 383 // Private implementation. 384 private ManagedObject<? extends BackendIndexCfgClient> impl; 385 386 387 388 // Private constructor. 389 private BackendIndexCfgClientImpl( 390 ManagedObject<? extends BackendIndexCfgClient> impl) { 391 this.impl = impl; 392 } 393 394 395 396 /** 397 * {@inheritDoc} 398 */ 399 public AttributeType getAttribute() { 400 return impl.getPropertyValue(INSTANCE.getAttributePropertyDefinition()); 401 } 402 403 404 405 /** 406 * {@inheritDoc} 407 */ 408 public void setAttribute(AttributeType value) throws PropertyException { 409 impl.setPropertyValue(INSTANCE.getAttributePropertyDefinition(), value); 410 } 411 412 413 414 /** 415 * {@inheritDoc} 416 */ 417 public Integer getIndexEntryLimit() { 418 return impl.getPropertyValue(INSTANCE.getIndexEntryLimitPropertyDefinition()); 419 } 420 421 422 423 /** 424 * {@inheritDoc} 425 */ 426 public void setIndexEntryLimit(Integer value) { 427 impl.setPropertyValue(INSTANCE.getIndexEntryLimitPropertyDefinition(), value); 428 } 429 430 431 432 /** 433 * {@inheritDoc} 434 */ 435 public SortedSet<String> getIndexExtensibleMatchingRule() { 436 return impl.getPropertyValues(INSTANCE.getIndexExtensibleMatchingRulePropertyDefinition()); 437 } 438 439 440 441 /** 442 * {@inheritDoc} 443 */ 444 public void setIndexExtensibleMatchingRule(Collection<String> values) { 445 impl.setPropertyValues(INSTANCE.getIndexExtensibleMatchingRulePropertyDefinition(), values); 446 } 447 448 449 450 /** 451 * {@inheritDoc} 452 */ 453 public SortedSet<IndexType> getIndexType() { 454 return impl.getPropertyValues(INSTANCE.getIndexTypePropertyDefinition()); 455 } 456 457 458 459 /** 460 * {@inheritDoc} 461 */ 462 public void setIndexType(Collection<IndexType> values) { 463 impl.setPropertyValues(INSTANCE.getIndexTypePropertyDefinition(), values); 464 } 465 466 467 468 /** 469 * {@inheritDoc} 470 */ 471 public int getSubstringLength() { 472 return impl.getPropertyValue(INSTANCE.getSubstringLengthPropertyDefinition()); 473 } 474 475 476 477 /** 478 * {@inheritDoc} 479 */ 480 public void setSubstringLength(Integer value) { 481 impl.setPropertyValue(INSTANCE.getSubstringLengthPropertyDefinition(), value); 482 } 483 484 485 486 /** 487 * {@inheritDoc} 488 */ 489 public ManagedObjectDefinition<? extends BackendIndexCfgClient, ? extends BackendIndexCfg> definition() { 490 return INSTANCE; 491 } 492 493 494 495 /** 496 * {@inheritDoc} 497 */ 498 public PropertyProvider properties() { 499 return impl; 500 } 501 502 503 504 /** 505 * {@inheritDoc} 506 */ 507 public void commit() throws ManagedObjectAlreadyExistsException, 508 MissingMandatoryPropertiesException, ConcurrentModificationException, 509 OperationRejectedException, AuthorizationException, 510 CommunicationException { 511 impl.commit(); 512 } 513 514 515 516 /** {@inheritDoc} */ 517 public String toString() { 518 return impl.toString(); 519 } 520 } 521 522 523 524 /** 525 * Managed object server implementation. 526 */ 527 private static class BackendIndexCfgServerImpl implements 528 BackendIndexCfg { 529 530 // Private implementation. 531 private ServerManagedObject<? extends BackendIndexCfg> impl; 532 533 // The value of the "attribute" property. 534 private final AttributeType pAttribute; 535 536 // The value of the "index-entry-limit" property. 537 private final Integer pIndexEntryLimit; 538 539 // The value of the "index-extensible-matching-rule" property. 540 private final SortedSet<String> pIndexExtensibleMatchingRule; 541 542 // The value of the "index-type" property. 543 private final SortedSet<IndexType> pIndexType; 544 545 // The value of the "substring-length" property. 546 private final int pSubstringLength; 547 548 549 550 // Private constructor. 551 private BackendIndexCfgServerImpl(ServerManagedObject<? extends BackendIndexCfg> impl) { 552 this.impl = impl; 553 this.pAttribute = impl.getPropertyValue(INSTANCE.getAttributePropertyDefinition()); 554 this.pIndexEntryLimit = impl.getPropertyValue(INSTANCE.getIndexEntryLimitPropertyDefinition()); 555 this.pIndexExtensibleMatchingRule = impl.getPropertyValues(INSTANCE.getIndexExtensibleMatchingRulePropertyDefinition()); 556 this.pIndexType = impl.getPropertyValues(INSTANCE.getIndexTypePropertyDefinition()); 557 this.pSubstringLength = impl.getPropertyValue(INSTANCE.getSubstringLengthPropertyDefinition()); 558 } 559 560 561 562 /** 563 * {@inheritDoc} 564 */ 565 public void addChangeListener( 566 ConfigurationChangeListener<BackendIndexCfg> listener) { 567 impl.registerChangeListener(listener); 568 } 569 570 571 572 /** 573 * {@inheritDoc} 574 */ 575 public void removeChangeListener( 576 ConfigurationChangeListener<BackendIndexCfg> listener) { 577 impl.deregisterChangeListener(listener); 578 } 579 580 581 582 /** 583 * {@inheritDoc} 584 */ 585 public AttributeType getAttribute() { 586 return pAttribute; 587 } 588 589 590 591 /** 592 * {@inheritDoc} 593 */ 594 public Integer getIndexEntryLimit() { 595 return pIndexEntryLimit; 596 } 597 598 599 600 /** 601 * {@inheritDoc} 602 */ 603 public SortedSet<String> getIndexExtensibleMatchingRule() { 604 return pIndexExtensibleMatchingRule; 605 } 606 607 608 609 /** 610 * {@inheritDoc} 611 */ 612 public SortedSet<IndexType> getIndexType() { 613 return pIndexType; 614 } 615 616 617 618 /** 619 * {@inheritDoc} 620 */ 621 public int getSubstringLength() { 622 return pSubstringLength; 623 } 624 625 626 627 /** 628 * {@inheritDoc} 629 */ 630 public Class<? extends BackendIndexCfg> configurationClass() { 631 return BackendIndexCfg.class; 632 } 633 634 635 636 /** 637 * {@inheritDoc} 638 */ 639 public DN dn() { 640 return impl.getDN(); 641 } 642 643 644 645 /** {@inheritDoc} */ 646 public String toString() { 647 return impl.toString(); 648 } 649 } 650}