OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 142 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
Line 22... Line 22...
22
import org.openconcerto.sql.model.SQLField;
22
import org.openconcerto.sql.model.SQLField;
23
import org.openconcerto.sql.model.SQLField.Properties;
23
import org.openconcerto.sql.model.SQLField.Properties;
24
import org.openconcerto.sql.model.SQLRow;
24
import org.openconcerto.sql.model.SQLRow;
25
import org.openconcerto.sql.model.SQLSchema;
25
import org.openconcerto.sql.model.SQLSchema;
26
import org.openconcerto.sql.model.SQLServer;
26
import org.openconcerto.sql.model.SQLServer;
-
 
27
import org.openconcerto.sql.model.SQLSyntax;
27
import org.openconcerto.sql.model.SQLSyntax.ConstraintType;
28
import org.openconcerto.sql.model.SQLSyntax.ConstraintType;
28
import org.openconcerto.sql.model.SQLSystem;
29
import org.openconcerto.sql.model.SQLSystem;
29
import org.openconcerto.sql.model.SQLTable;
30
import org.openconcerto.sql.model.SQLTable;
30
import org.openconcerto.sql.model.SQLTable.Index;
31
import org.openconcerto.sql.model.SQLTable.Index;
31
import org.openconcerto.sql.model.graph.Link;
32
import org.openconcerto.sql.model.graph.Link;
Line 177... Line 178...
177
                return null;
178
                return null;
178
            else {
179
            else {
179
                final AlterTable alterTable = new AlterTable(aT);
180
                final AlterTable alterTable = new AlterTable(aT);
180
                final SQLSystem aSystem = aT.getServer().getSQLSystem();
181
                final SQLSystem aSystem = aT.getServer().getSQLSystem();
181
                final SQLSystem bSystem = bT.getServer().getSQLSystem();
182
                final SQLSystem bSystem = bT.getServer().getSQLSystem();
-
 
183
                final SQLSyntax bSyntax = bT.getDBSystemRoot().getSyntax();
182
                {
184
                {
183
                    final Set<String> aFields = aT.getFieldsName();
185
                    final Set<String> aFields = aT.getFieldsName();
184
                    final Set<String> bFields = bT.getFieldsName();
186
                    final Set<String> bFields = bT.getFieldsName();
185
                    for (final String rm : CollectionUtils.substract(aFields, bFields)) {
187
                    for (final String rm : CollectionUtils.substract(aFields, bFields)) {
186
                        alterTable.dropColumn(rm);
188
                        alterTable.dropColumn(rm);
Line 189... Line 191...
189
                        alterTable.addColumn(bT.getField(added));
191
                        alterTable.addColumn(bT.getField(added));
190
                    }
192
                    }
191
                    for (final String common : CollectionUtils.inter(aFields, bFields)) {
193
                    for (final String common : CollectionUtils.inter(aFields, bFields)) {
192
                        final SQLField aF = aT.getField(common);
194
                        final SQLField aF = aT.getField(common);
193
                        final SQLField bF = bT.getField(common);
195
                        final SQLField bF = bT.getField(common);
194
                        final Map<Properties, String> diff = aF.getDiffMap(bF, bSystem, true);
196
                        final Map<Properties, String> diff = aF.getDiffMap(bF, bSyntax, true);
195
                        alterTable.alterColumn(common, bF, diff.keySet());
197
                        alterTable.alterColumn(common, bF, diff.keySet());
196
                    }
198
                    }
197
                }
199
                }
198
                final List<String> aPKNames = aT.getPKsNames();
200
                final List<String> aPKNames = aT.getPKsNames();
199
                final List<String> bPKNames = bT.getPKsNames();
201
                final List<String> bPKNames = bT.getPKsNames();
Line 257... Line 259...
257
                }
259
                }
258
 
260
 
259
                if (alterTable.isEmpty()) {
261
                if (alterTable.isEmpty()) {
260
                    final String exactDiff = aT.equalsDesc(bT, null, true);
262
                    final String exactDiff = aT.equalsDesc(bT, null, true);
261
                    assert exactDiff != null : "Why bother if exactly equals";
263
                    assert exactDiff != null : "Why bother if exactly equals";
262
                    final String lenientDiff = aT.equalsDesc(bT, bT.getServer().getSQLSystem(), true);
264
                    final String lenientDiff = aT.equalsDesc(bT, bSyntax, true);
263
                    if (lenientDiff == null)
265
                    if (lenientDiff == null)
264
                        Log.get().info("Tables " + aT.getSQLName() + " and " + bT.getSQLName() + " are not exactly equal, but due to diferring DB system features can't be :\n" + exactDiff);
266
                        Log.get().info("Tables " + aT.getSQLName() + " and " + bT.getSQLName() + " are not exactly equal, but due to diferring DB system features can't be :\n" + exactDiff);
265
                    else
267
                    else
266
                        throw new IllegalStateException("Unequal tables with no ALTER TABLE : " + aT.getSQLName() + " and " + bT.getSQLName() + "\n" + lenientDiff);
268
                        throw new IllegalStateException("Unequal tables with no ALTER TABLE : " + aT.getSQLName() + " and " + bT.getSQLName() + "\n" + lenientDiff);
267
                }
269
                }