You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Emmanuel Lécharny <el...@gmail.com> on 2016/02/09 15:27:10 UTC

Schema handling change

Hi guys,

I have made some modifications in the way we manage schemas in the API
and in the server. Let's me explain what are those modifications, the
reason I needed those chnages to be applied and the impact on the
existing code.

Rational
--------

I wanted to inject some new schema into an existing SchemaManager on a
client application connecting to a remote server. There is no simple way
to do it if you don't stick with the SchemaLoader the SchemaManager has
been initialized with, because the ShcemaLoader instance is the one
which holds the list of existing schemas (yes, the Schemamanager has no
clue about the Schema it manages...)

Typically, if you do something like :

SchemaManager schemaManager = new DefaultSchemaManager();

you end with a SchemaManager which depends on teh JarLdifSchemaLoader :

    public DefaultSchemaManager() throws Exception
    {
        // Default to the the root (one schemaManager for all the entries
        namingContext = Dn.ROOT_DSE;
        this.schemaLoader = new JarLdifSchemaLoader();
        ...

This is very invonvenient, because you can't inject a schema if it's not
encapsulated into a jar file.

Changes
-------

So my idea was to :
1) hide the SchemaLoader, and put the reference to it into each Schema
instance. All in all the SchemaLoader is just used to load the
SchemaObjetcts from a Schema. Once it's done, the resulting SchemaObject
instances (AT, OC, Syntaxes, etc) are stored in teh SchemaManager's
Registries.
2) Store the list of schemas in the ShcemaManager, instead of storing it
only in the SchemaLoader. Actually, that means when we load some new
schemas, we add them to the list in the SchemaManager, beside havig this
list in the associated SchemaLoader
3) Make it possible to create a SchemaManager passing a list of Schemas
to load instead of passing a SchemaLoader
4) You can now get teh list of all the schemas loaded in a SchemaManager
using the getAllSchemas() method


I already have added the SchemaLoader reference in the Schema, as it's
an orthogonal change that won't impact the code.

The LowerCaseKeyMap private class has been extracted from the
AbstractSchemaLoader to be made a public class, as we will reuse it in
the SchemaManager.

The SchemaManager now exposes a Collection<Schema> getAllSchemas()
method, that returns the list of all Schema being handled by the
SchemaManager (enabled and disabled). I have also removed the
getLoader() and setSchemaLoader() method, which are useless.


Impact
------
Adding a new Schema is just a matter of declaring a SchemaLoader, create
a Schema with this SchemaLoader, and inject this schema in teh
SchemaManager :

        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
        SchemaManager schemaManager = new DefaultSchemaManager( loader );

        Schema dummy = new DefaultSchema( loader, "dummy" );

Note that we don't even have to pass a SchemaLoader to the
DefaultSchemaManager, it will then use a different SchemaLoader
(JarLdifSchemaLoader) internally, but it will still work and load the
"dummy" schema.



Server side, this has no impact at all, excpet in the way we deal with
schema updates internally when doing so trhough a LDAP request.

I ran all the tests, most of the modifications were made in the API.