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.BackendIndexCfgClient;
054import org.opends.server.admin.std.server.BackendIndexCfg;
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 Backend Index managed object
066 * definition meta information.
067 * <p>
068 * Backend 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 BackendIndexCfgDefn extends ManagedObjectDefinition<BackendIndexCfgClient, BackendIndexCfg> {
073
074  // The singleton configuration definition instance.
075  private static final BackendIndexCfgDefn INSTANCE = new BackendIndexCfgDefn();
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>(PluggableBackendCfgDefn.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 Backend Index configuration definition singleton.
260   *
261   * @return Returns the Backend Index configuration definition
262   *         singleton.
263   */
264  public static BackendIndexCfgDefn getInstance() {
265    return INSTANCE;
266  }
267
268
269
270  /**
271   * Private constructor.
272   */
273  private BackendIndexCfgDefn() {
274    super("backend-index", TopCfgDefn.getInstance());
275  }
276
277
278
279  /**
280   * {@inheritDoc}
281   */
282  public BackendIndexCfgClient createClientConfiguration(
283      ManagedObject<? extends BackendIndexCfgClient> impl) {
284    return new BackendIndexCfgClientImpl(impl);
285  }
286
287
288
289  /**
290   * {@inheritDoc}
291   */
292  public BackendIndexCfg createServerConfiguration(
293      ServerManagedObject<? extends BackendIndexCfg> impl) {
294    return new BackendIndexCfgServerImpl(impl);
295  }
296
297
298
299  /**
300   * {@inheritDoc}
301   */
302  public Class<BackendIndexCfg> getServerConfigurationClass() {
303    return BackendIndexCfg.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 BackendIndexCfgClientImpl implements
391    BackendIndexCfgClient {
392
393    // Private implementation.
394    private ManagedObject<? extends BackendIndexCfgClient> impl;
395
396
397
398    // Private constructor.
399    private BackendIndexCfgClientImpl(
400        ManagedObject<? extends BackendIndexCfgClient> 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 BackendIndexCfgClient, ? extends BackendIndexCfg> 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    /** {@inheritDoc} */
527    public String toString() {
528      return impl.toString();
529    }
530  }
531
532
533
534  /**
535   * Managed object server implementation.
536   */
537  private static class BackendIndexCfgServerImpl implements
538    BackendIndexCfg {
539
540    // Private implementation.
541    private ServerManagedObject<? extends BackendIndexCfg> impl;
542
543    // The value of the "attribute" property.
544    private final AttributeType pAttribute;
545
546    // The value of the "index-entry-limit" property.
547    private final Integer pIndexEntryLimit;
548
549    // The value of the "index-extensible-matching-rule" property.
550    private final SortedSet<String> pIndexExtensibleMatchingRule;
551
552    // The value of the "index-type" property.
553    private final SortedSet<IndexType> pIndexType;
554
555    // The value of the "substring-length" property.
556    private final int pSubstringLength;
557
558
559
560    // Private constructor.
561    private BackendIndexCfgServerImpl(ServerManagedObject<? extends BackendIndexCfg> impl) {
562      this.impl = impl;
563      this.pAttribute = impl.getPropertyValue(INSTANCE.getAttributePropertyDefinition());
564      this.pIndexEntryLimit = impl.getPropertyValue(INSTANCE.getIndexEntryLimitPropertyDefinition());
565      this.pIndexExtensibleMatchingRule = impl.getPropertyValues(INSTANCE.getIndexExtensibleMatchingRulePropertyDefinition());
566      this.pIndexType = impl.getPropertyValues(INSTANCE.getIndexTypePropertyDefinition());
567      this.pSubstringLength = impl.getPropertyValue(INSTANCE.getSubstringLengthPropertyDefinition());
568    }
569
570
571
572    /**
573     * {@inheritDoc}
574     */
575    public void addChangeListener(
576        ConfigurationChangeListener<BackendIndexCfg> listener) {
577      impl.registerChangeListener(listener);
578    }
579
580
581
582    /**
583     * {@inheritDoc}
584     */
585    public void removeChangeListener(
586        ConfigurationChangeListener<BackendIndexCfg> listener) {
587      impl.deregisterChangeListener(listener);
588    }
589
590
591
592    /**
593     * {@inheritDoc}
594     */
595    public AttributeType getAttribute() {
596      return pAttribute;
597    }
598
599
600
601    /**
602     * {@inheritDoc}
603     */
604    public Integer getIndexEntryLimit() {
605      return pIndexEntryLimit;
606    }
607
608
609
610    /**
611     * {@inheritDoc}
612     */
613    public SortedSet<String> getIndexExtensibleMatchingRule() {
614      return pIndexExtensibleMatchingRule;
615    }
616
617
618
619    /**
620     * {@inheritDoc}
621     */
622    public SortedSet<IndexType> getIndexType() {
623      return pIndexType;
624    }
625
626
627
628    /**
629     * {@inheritDoc}
630     */
631    public int getSubstringLength() {
632      return pSubstringLength;
633    }
634
635
636
637    /**
638     * {@inheritDoc}
639     */
640    public Class<? extends BackendIndexCfg> configurationClass() {
641      return BackendIndexCfg.class;
642    }
643
644
645
646    /**
647     * {@inheritDoc}
648     */
649    public DN dn() {
650      return impl.getDN();
651    }
652
653
654
655    /** {@inheritDoc} */
656    public String toString() {
657      return impl.toString();
658    }
659  }
660}