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
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.admin.std.meta;
028    
029    
030    
031    import java.util.Collection;
032    import java.util.SortedSet;
033    import org.opends.server.admin.AdministratorAction;
034    import org.opends.server.admin.AttributeTypePropertyDefinition;
035    import org.opends.server.admin.client.AuthorizationException;
036    import org.opends.server.admin.client.CommunicationException;
037    import org.opends.server.admin.client.ConcurrentModificationException;
038    import org.opends.server.admin.client.ManagedObject;
039    import org.opends.server.admin.client.MissingMandatoryPropertiesException;
040    import org.opends.server.admin.client.OperationRejectedException;
041    import org.opends.server.admin.DefaultBehaviorProvider;
042    import org.opends.server.admin.DefinedDefaultBehaviorProvider;
043    import org.opends.server.admin.EnumPropertyDefinition;
044    import org.opends.server.admin.IntegerPropertyDefinition;
045    import org.opends.server.admin.ManagedObjectAlreadyExistsException;
046    import org.opends.server.admin.ManagedObjectDefinition;
047    import org.opends.server.admin.PropertyIsReadOnlyException;
048    import org.opends.server.admin.PropertyOption;
049    import org.opends.server.admin.PropertyProvider;
050    import org.opends.server.admin.RelativeInheritedDefaultBehaviorProvider;
051    import org.opends.server.admin.server.ConfigurationChangeListener;
052    import org.opends.server.admin.server.ServerManagedObject;
053    import org.opends.server.admin.std.client.LocalDBIndexCfgClient;
054    import org.opends.server.admin.std.server.LocalDBIndexCfg;
055    import org.opends.server.admin.Tag;
056    import org.opends.server.admin.TopCfgDefn;
057    import org.opends.server.admin.UndefinedDefaultBehaviorProvider;
058    import org.opends.server.types.AttributeType;
059    import org.opends.server.types.DN;
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     */
071    public 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 "greater than or equal to" or "less then or equal to"
108         * search filters.
109         */
110        ORDERING("ordering"),
111    
112    
113    
114        /**
115         * This index type is used to improve the efficiency of searches
116         * using the presence search filters.
117         */
118        PRESENCE("presence"),
119    
120    
121    
122        /**
123         * This index type is used to improve the efficiency of searches
124         * using substring search filters.
125         */
126        SUBSTRING("substring");
127    
128    
129    
130        // String representation of the value.
131        private final String name;
132    
133    
134    
135        // Private constructor.
136        private IndexType(String name) { this.name = name; }
137    
138    
139    
140        /**
141         * {@inheritDoc}
142         */
143        public String toString() { return name; }
144    
145      }
146    
147    
148    
149      // The "attribute" property definition.
150      private static final AttributeTypePropertyDefinition PD_ATTRIBUTE;
151    
152    
153    
154      // The "index-entry-limit" property definition.
155      private static final IntegerPropertyDefinition PD_INDEX_ENTRY_LIMIT;
156    
157    
158    
159      // The "index-type" property definition.
160      private static final EnumPropertyDefinition<IndexType> PD_INDEX_TYPE;
161    
162    
163    
164      // The "substring-length" property definition.
165      private static final IntegerPropertyDefinition PD_SUBSTRING_LENGTH;
166    
167    
168    
169      // Build the "attribute" property definition.
170      static {
171          AttributeTypePropertyDefinition.Builder builder = AttributeTypePropertyDefinition.createBuilder(INSTANCE, "attribute");
172          builder.setOption(PropertyOption.READ_ONLY);
173          builder.setOption(PropertyOption.MANDATORY);
174          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "attribute"));
175          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<AttributeType>());
176          PD_ATTRIBUTE = builder.getInstance();
177          INSTANCE.registerPropertyDefinition(PD_ATTRIBUTE);
178      }
179    
180    
181    
182      // Build the "index-entry-limit" property definition.
183      static {
184          IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "index-entry-limit");
185          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "index-entry-limit"));
186          DefaultBehaviorProvider<Integer> provider = new RelativeInheritedDefaultBehaviorProvider<Integer>(LocalDBBackendCfgDefn.getInstance(), "index-entry-limit", 1);
187          builder.setDefaultBehaviorProvider(provider);
188          builder.setUpperLimit(2147483647);
189          builder.setLowerLimit(0);
190          PD_INDEX_ENTRY_LIMIT = builder.getInstance();
191          INSTANCE.registerPropertyDefinition(PD_INDEX_ENTRY_LIMIT);
192      }
193    
194    
195    
196      // Build the "index-type" property definition.
197      static {
198          EnumPropertyDefinition.Builder<IndexType> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "index-type");
199          builder.setOption(PropertyOption.MULTI_VALUED);
200          builder.setOption(PropertyOption.MANDATORY);
201          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "index-type"));
202          builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<IndexType>());
203          builder.setEnumClass(IndexType.class);
204          PD_INDEX_TYPE = builder.getInstance();
205          INSTANCE.registerPropertyDefinition(PD_INDEX_TYPE);
206      }
207    
208    
209    
210      // Build the "substring-length" property definition.
211      static {
212          IntegerPropertyDefinition.Builder builder = IntegerPropertyDefinition.createBuilder(INSTANCE, "substring-length");
213          builder.setOption(PropertyOption.ADVANCED);
214          builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.OTHER, INSTANCE, "substring-length"));
215          DefaultBehaviorProvider<Integer> provider = new DefinedDefaultBehaviorProvider<Integer>("6");
216          builder.setDefaultBehaviorProvider(provider);
217          builder.setLowerLimit(3);
218          PD_SUBSTRING_LENGTH = builder.getInstance();
219          INSTANCE.registerPropertyDefinition(PD_SUBSTRING_LENGTH);
220      }
221    
222    
223    
224      // Register the tags associated with this managed object definition.
225      static {
226        INSTANCE.registerTag(Tag.valueOf("database"));
227      }
228    
229    
230    
231      /**
232       * Get the Local DB Index configuration definition singleton.
233       *
234       * @return Returns the Local DB Index configuration definition
235       *         singleton.
236       */
237      public static LocalDBIndexCfgDefn getInstance() {
238        return INSTANCE;
239      }
240    
241    
242    
243      /**
244       * Private constructor.
245       */
246      private LocalDBIndexCfgDefn() {
247        super("local-db-index", TopCfgDefn.getInstance());
248      }
249    
250    
251    
252      /**
253       * {@inheritDoc}
254       */
255      public LocalDBIndexCfgClient createClientConfiguration(
256          ManagedObject<? extends LocalDBIndexCfgClient> impl) {
257        return new LocalDBIndexCfgClientImpl(impl);
258      }
259    
260    
261    
262      /**
263       * {@inheritDoc}
264       */
265      public LocalDBIndexCfg createServerConfiguration(
266          ServerManagedObject<? extends LocalDBIndexCfg> impl) {
267        return new LocalDBIndexCfgServerImpl(impl);
268      }
269    
270    
271    
272      /**
273       * {@inheritDoc}
274       */
275      public Class<LocalDBIndexCfg> getServerConfigurationClass() {
276        return LocalDBIndexCfg.class;
277      }
278    
279    
280    
281      /**
282       * Get the "attribute" property definition.
283       * <p>
284       * Specifies the name of the attribute for which the index is to be
285       * maintained.
286       *
287       * @return Returns the "attribute" property definition.
288       */
289      public AttributeTypePropertyDefinition getAttributePropertyDefinition() {
290        return PD_ATTRIBUTE;
291      }
292    
293    
294    
295      /**
296       * Get the "index-entry-limit" property definition.
297       * <p>
298       * Specifies the maximum number of entries that are allowed to match
299       * a given index key before that particular index key is no longer
300       * maintained.
301       * <p>
302       * This is analogous to the ALL IDs threshold in the Sun Java System
303       * Directory Server. If this is specified, its value overrides the JE
304       * backend-wide configuration. For no limit, use 0 for the value.
305       *
306       * @return Returns the "index-entry-limit" property definition.
307       */
308      public IntegerPropertyDefinition getIndexEntryLimitPropertyDefinition() {
309        return PD_INDEX_ENTRY_LIMIT;
310      }
311    
312    
313    
314      /**
315       * Get the "index-type" property definition.
316       * <p>
317       * Specifies the type(s) of indexing that should be performed for
318       * the associated attribute.
319       * <p>
320       * For equality, presence, and substring index types, the associated
321       * attribute type must have a corresponding matching rule.
322       *
323       * @return Returns the "index-type" property definition.
324       */
325      public EnumPropertyDefinition<IndexType> getIndexTypePropertyDefinition() {
326        return PD_INDEX_TYPE;
327      }
328    
329    
330    
331      /**
332       * Get the "substring-length" property definition.
333       * <p>
334       * The length of substrings in a substring index.
335       *
336       * @return Returns the "substring-length" property definition.
337       */
338      public IntegerPropertyDefinition getSubstringLengthPropertyDefinition() {
339        return PD_SUBSTRING_LENGTH;
340      }
341    
342    
343    
344      /**
345       * Managed object client implementation.
346       */
347      private static class LocalDBIndexCfgClientImpl implements
348        LocalDBIndexCfgClient {
349    
350        // Private implementation.
351        private ManagedObject<? extends LocalDBIndexCfgClient> impl;
352    
353    
354    
355        // Private constructor.
356        private LocalDBIndexCfgClientImpl(
357            ManagedObject<? extends LocalDBIndexCfgClient> impl) {
358          this.impl = impl;
359        }
360    
361    
362    
363        /**
364         * {@inheritDoc}
365         */
366        public AttributeType getAttribute() {
367          return impl.getPropertyValue(INSTANCE.getAttributePropertyDefinition());
368        }
369    
370    
371    
372        /**
373         * {@inheritDoc}
374         */
375        public void setAttribute(AttributeType value) throws PropertyIsReadOnlyException {
376          impl.setPropertyValue(INSTANCE.getAttributePropertyDefinition(), value);
377        }
378    
379    
380    
381        /**
382         * {@inheritDoc}
383         */
384        public Integer getIndexEntryLimit() {
385          return impl.getPropertyValue(INSTANCE.getIndexEntryLimitPropertyDefinition());
386        }
387    
388    
389    
390        /**
391         * {@inheritDoc}
392         */
393        public void setIndexEntryLimit(Integer value) {
394          impl.setPropertyValue(INSTANCE.getIndexEntryLimitPropertyDefinition(), value);
395        }
396    
397    
398    
399        /**
400         * {@inheritDoc}
401         */
402        public SortedSet<IndexType> getIndexType() {
403          return impl.getPropertyValues(INSTANCE.getIndexTypePropertyDefinition());
404        }
405    
406    
407    
408        /**
409         * {@inheritDoc}
410         */
411        public void setIndexType(Collection<IndexType> values) {
412          impl.setPropertyValues(INSTANCE.getIndexTypePropertyDefinition(), values);
413        }
414    
415    
416    
417        /**
418         * {@inheritDoc}
419         */
420        public int getSubstringLength() {
421          return impl.getPropertyValue(INSTANCE.getSubstringLengthPropertyDefinition());
422        }
423    
424    
425    
426        /**
427         * {@inheritDoc}
428         */
429        public void setSubstringLength(Integer value) {
430          impl.setPropertyValue(INSTANCE.getSubstringLengthPropertyDefinition(), value);
431        }
432    
433    
434    
435        /**
436         * {@inheritDoc}
437         */
438        public ManagedObjectDefinition<? extends LocalDBIndexCfgClient, ? extends LocalDBIndexCfg> definition() {
439          return INSTANCE;
440        }
441    
442    
443    
444        /**
445         * {@inheritDoc}
446         */
447        public PropertyProvider properties() {
448          return impl;
449        }
450    
451    
452    
453        /**
454         * {@inheritDoc}
455         */
456        public void commit() throws ManagedObjectAlreadyExistsException,
457            MissingMandatoryPropertiesException, ConcurrentModificationException,
458            OperationRejectedException, AuthorizationException,
459            CommunicationException {
460          impl.commit();
461        }
462    
463      }
464    
465    
466    
467      /**
468       * Managed object server implementation.
469       */
470      private static class LocalDBIndexCfgServerImpl implements
471        LocalDBIndexCfg {
472    
473        // Private implementation.
474        private ServerManagedObject<? extends LocalDBIndexCfg> impl;
475    
476        // The value of the "attribute" property.
477        private final AttributeType pAttribute;
478    
479        // The value of the "index-entry-limit" property.
480        private final Integer pIndexEntryLimit;
481    
482        // The value of the "index-type" property.
483        private final SortedSet<IndexType> pIndexType;
484    
485        // The value of the "substring-length" property.
486        private final int pSubstringLength;
487    
488    
489    
490        // Private constructor.
491        private LocalDBIndexCfgServerImpl(ServerManagedObject<? extends LocalDBIndexCfg> impl) {
492          this.impl = impl;
493          this.pAttribute = impl.getPropertyValue(INSTANCE.getAttributePropertyDefinition());
494          this.pIndexEntryLimit = impl.getPropertyValue(INSTANCE.getIndexEntryLimitPropertyDefinition());
495          this.pIndexType = impl.getPropertyValues(INSTANCE.getIndexTypePropertyDefinition());
496          this.pSubstringLength = impl.getPropertyValue(INSTANCE.getSubstringLengthPropertyDefinition());
497        }
498    
499    
500    
501        /**
502         * {@inheritDoc}
503         */
504        public void addChangeListener(
505            ConfigurationChangeListener<LocalDBIndexCfg> listener) {
506          impl.registerChangeListener(listener);
507        }
508    
509    
510    
511        /**
512         * {@inheritDoc}
513         */
514        public void removeChangeListener(
515            ConfigurationChangeListener<LocalDBIndexCfg> listener) {
516          impl.deregisterChangeListener(listener);
517        }
518    
519    
520    
521        /**
522         * {@inheritDoc}
523         */
524        public AttributeType getAttribute() {
525          return pAttribute;
526        }
527    
528    
529    
530        /**
531         * {@inheritDoc}
532         */
533        public Integer getIndexEntryLimit() {
534          return pIndexEntryLimit;
535        }
536    
537    
538    
539        /**
540         * {@inheritDoc}
541         */
542        public SortedSet<IndexType> getIndexType() {
543          return pIndexType;
544        }
545    
546    
547    
548        /**
549         * {@inheritDoc}
550         */
551        public int getSubstringLength() {
552          return pSubstringLength;
553        }
554    
555    
556    
557        /**
558         * {@inheritDoc}
559         */
560        public Class<? extends LocalDBIndexCfg> configurationClass() {
561          return LocalDBIndexCfg.class;
562        }
563    
564    
565    
566        /**
567         * {@inheritDoc}
568         */
569        public DN dn() {
570          return impl.getDN();
571        }
572    
573      }
574    }