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