@@ -0,0 +1,3030 @@
+/*%0A * Copyright 2014 Codenvy, S.A.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.codenvy.ide.ext.datasource.client.store;%0A%0Aimport java.util.SortedMap;%0Aimport java.util.TreeMap;%0A%0Aimport javax.inject.Inject;%0Aimport javax.validation.constraints.NotNull;%0A%0Aimport com.codenvy.ide.dto.DtoFactory;%0Aimport com.codenvy.ide.ext.datasource.shared.ColumnDTO;%0Aimport com.codenvy.ide.ext.datasource.shared.DatabaseDTO;%0Aimport com.codenvy.ide.ext.datasource.shared.SchemaDTO;%0Aimport com.codenvy.ide.ext.datasource.shared.TableDTO;%0A%0A/**%0A * %7B@link PreStoreProcessor%7D that sorts schemas, tables and columns in lexicographical order.%0A * %0A * @author %22Micka%C3%ABl Leduque%22%0A */%0Apublic class SortMetadataProcessor implements PreStoreProcessor %7B%0A%0A    /** The client version of the DTO factory. */%0A    private final DtoFactory dtoFactory;%0A%0A    @Inject%0A    public SortMetadataProcessor(final @NotNull DtoFactory dtoFactory) %7B%0A        this.dtoFactory = dtoFactory;%0A    %7D%0A%0A    @Override%0A    public DatabaseDTO execute(final DatabaseDTO databaseDto) throws PreStoreProcessorException %7B%0A        // create a copy%0A        final String json = this.dtoFactory.toJson(databaseDto);%0A        final DatabaseDTO modified = this.dtoFactory.createDtoFromJson(json, DatabaseDTO.class);%0A%0A        sortSchemas(modified);%0A%0A        return modified;%0A    %7D%0A%0A    /**%0A     * Sort the schemas in the database metadata DTO.%0A     * %0A     * @param database the metadata DTO.%0A     */%0A    private void sortSchemas(final DatabaseDTO database) %7B%0A        for (final SchemaDTO schema : database.getSchemas().values()) %7B%0A            sortTables(schema);%0A        %7D%0A%0A        SortedMap%3CString, SchemaDTO%3E sortedSchemas = new TreeMap%3CString, SchemaDTO%3E(database.getSchemas());%0A        database.setSchemas(sortedSchemas);%0A    %7D%0A%0A    /**%0A     * Sort the tables in the schema metadata DTO.%0A     * %0A     * @param schema the metadata DTO%0A     */%0A    private void sortTables(final SchemaDTO schema) %7B%0A        for (final TableDTO table : schema.getTables().values()) %7B%0A            sortColumns(table);%0A        %7D%0A%0A        SortedMap%3CString, TableDTO%3E sortedTables = new TreeMap%3CString, TableDTO%3E(schema.getTables());%0A        schema.setTables(sortedTables);%0A    %7D%0A%0A    /**%0A     * Sort the columns in the table metadata DTO.%0A     * %0A     * @param table the metadata DTO%0A     */%0A    private void sortColumns(final TableDTO table) %7B%0A        SortedMap%3CString, ColumnDTO%3E sortedColumn = new TreeMap%3CString, ColumnDTO%3E(table.getColumns());%0A        table.setColumns(sortedColumn);%0A    %7D%0A%7D%0A

Add a processor that sorts the metadata entities - #166