001    package org.apache.directory.shared.ldap.schema;
002    
003    
004    import java.util.Map;
005    import java.util.Set;
006    
007    import javax.naming.NamingException;
008    
009    import org.apache.directory.shared.ldap.entry.Entry;
010    import org.apache.directory.shared.ldap.name.DN;
011    import org.apache.directory.shared.ldap.schema.AttributeType;
012    import org.apache.directory.shared.ldap.schema.MatchingRule;
013    import org.apache.directory.shared.ldap.schema.ObjectClass;
014    import org.apache.directory.shared.ldap.schema.registries.Schema;
015    
016    
017    public interface SchemaDao
018    {
019    
020        /**
021         * Gets a Map of Schemas managed by a schema store.
022         *
023         * @return a Map of Schemas using the name of the Schema as the key
024         * @throws Exception if there is some problem accessing the schema data
025         */
026        Map<String, Schema> getSchemas() throws Exception;
027    
028    
029        Set<String> getSchemaNames() throws Exception;
030    
031    
032        Schema getSchema( String schemaName ) throws Exception;
033    
034    
035        boolean hasMatchingRule( String oid ) throws Exception;
036    
037    
038        boolean hasAttributeType( String oid ) throws Exception;
039    
040    
041        boolean hasObjectClass( String oid ) throws Exception;
042    
043    
044        boolean hasSyntax( String oid ) throws Exception;
045    
046    
047        boolean hasSyntaxChecker( String oid ) throws Exception;
048    
049    
050        /**
051         * Given the non-normalized name (alias) or the OID for a schema entity.  This 
052         * method finds the schema under which that entity is located. 
053         * 
054         * NOTE: this method presumes that all alias names across schemas are unique.  
055         * This should be the case for LDAP but this can potentially be violated so 
056         * we should make sure this is a unique name.
057         * 
058         * @param entityName one of the names of the entity or it's numeric id
059         * @return the name of the schema that contains that entity or null if no entity with 
060         * that alias name exists
061         * @throws NamingException if more than one entity has the name, or if there 
062         * are underlying data access problems
063         */
064        String findSchema( String entityName ) throws Exception;
065    
066    
067        DN findDn( String entityName ) throws Exception;
068    
069    
070        /**
071         * Given the non-normalized name (alias) or the OID for a schema entity.  This 
072         * method finds the entry of the schema entity. 
073         * 
074         * NOTE: this method presumes that all alias names across schemas are unique.  
075         * This should be the case for LDAP but this can potentially be violated so 
076         * we should make sure this is a unique name.
077         * 
078         * @param entityName one of the names of the entity or it's numeric id
079         * @return the search result for the entity or null if no such entity exists with 
080         * that alias or numeric oid
081         * @throws NamingException if more than one entity has the name, or if there 
082         * are underlying data access problems
083         */
084        Entry find( String entityName ) throws Exception;
085    
086    
087        /**
088         * Enables a schema by removing it's m-disabled attribute if present.
089         * 
090         * NOTE:
091         * This is a write operation and great care must be taken to make sure it
092         * is used in a limited capacity.  This method is called in two places 
093         * currently.  
094         * 
095         * (1) Within the initialization sequence to enable schemas required
096         *     for the correct operation of indices in other partitions.
097         * (2) Within the partition schema loader to auto enable schemas that are
098         *     depended on by other schemas which are enabled.
099         * 
100         * In both cases, the modifier is effectively the administrator since the 
101         * server is performing the operation directly or on behalf of a user.  In 
102         * case (1) during intialization there is no other user involved so naturally
103         * the modifier is the administrator.  In case (2) when a user enables a 
104         * schema with a dependency that is not enabled the server enables that 
105         * dependency on behalf of the user.  Again effectively it is the server that
106         * is modifying the schema entry and hence the admin is the modifier.
107         * 
108         * No need to worry about a lack of replication propagation in both cases.  In 
109         * case (1) all replicas will enable these schemas anyway on startup.  In case
110         * (2) the original operation that enabled the schema depending on the on that
111         * enableSchema() is called for itself will be replicated.  Hence the same chain 
112         * reaction will occur in a replica.
113         * 
114         * @param schemaName the name of the schema to enable
115         * @throws NamingException if there is a problem updating the schema entry
116         */
117        void enableSchema( String schemaName ) throws Exception;
118    
119    
120        /**
121         * Returns the set of matchingRules and attributeTypes which depend on the 
122         * provided syntax.
123         *
124         * @param numericOid the numeric identifier for the entity
125         * @return the set of matchingRules and attributeTypes depending on a syntax
126         * @throws NamingException if the dao fails to perform search operations
127         */
128        Set<Entry> listSyntaxDependents( String numericOid ) throws Exception;
129    
130    
131        Set<Entry> listMatchingRuleDependents( MatchingRule mr ) throws Exception;
132    
133    
134        Set<Entry> listAttributeTypeDependents( AttributeType at ) throws Exception;
135    
136    
137        /**
138         * Lists the SearchResults of metaSchema objects that depend on a schema.
139         * 
140         * @param schemaName the name of the schema to search for dependees
141         * @return a set of SearchResults over the schemas whose m-dependency attribute contains schemaName
142         * @throws NamingException if there is a problem while searching the schema partition
143         */
144        Set<Entry> listSchemaDependents( String schemaName ) throws Exception;
145    
146    
147        /**
148         * Lists the SearchResults of metaSchema objects that depend on a schema.
149         * 
150         * @param schemaName the name of the schema to search for dependencies
151         * @return a set of SearchResults over the schemas whose m-dependency attribute contains schemaName
152         * @throws NamingException if there is a problem while searching the schema partition
153         */
154        Set<Entry> listEnabledSchemaDependents( String schemaName ) throws Exception;
155    
156    
157        Set<Entry> listObjectClassDependents( ObjectClass oc ) throws Exception;
158    }