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