OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 153 Rev 162
Line 58... Line 58...
58
import org.openconcerto.sql.model.SQLRowAccessor;
58
import org.openconcerto.sql.model.SQLRowAccessor;
59
import org.openconcerto.sql.model.SQLRowValues;
59
import org.openconcerto.sql.model.SQLRowValues;
60
import org.openconcerto.sql.model.SQLTable;
60
import org.openconcerto.sql.model.SQLTable;
61
import org.openconcerto.sql.model.graph.PathBuilder;
61
import org.openconcerto.sql.model.graph.PathBuilder;
62
import org.openconcerto.sql.request.ListSQLRequest;
62
import org.openconcerto.sql.request.ListSQLRequest;
63
import org.openconcerto.sql.request.RowItemDesc;
-
 
64
import org.openconcerto.sql.request.SQLFieldTranslator;
63
import org.openconcerto.sql.request.SQLFieldTranslator;
65
import org.openconcerto.sql.utils.AlterTable;
64
import org.openconcerto.sql.utils.AlterTable;
66
import org.openconcerto.sql.utils.ChangeTable;
65
import org.openconcerto.sql.utils.ChangeTable;
67
import org.openconcerto.sql.utils.SQLCreateTable;
66
import org.openconcerto.sql.utils.SQLCreateTable;
68
import org.openconcerto.sql.view.EditFrame;
67
import org.openconcerto.sql.view.EditFrame;
Line 437... Line 436...
437
                createTable = new AlterTable(table);
436
                createTable = new AlterTable(table);
438
 
437
 
439
            }
438
            }
440
            // fields creation
439
            // fields creation
441
            boolean mustAdd = false;
440
            boolean mustAdd = false;
-
 
441
            final Set<String> addedFieldNames = new HashSet<>();
442
            for (FieldDescriptor fDesc : tDesc.getFields()) {
442
            for (FieldDescriptor fDesc : tDesc.getFields()) {
-
 
443
                final String fieldName = fDesc.getName();
443
                final SQLField f = (table == null) ? null : table.getFieldRaw(fDesc.getName());
444
                final SQLField f = (table == null) ? null : table.getFieldRaw(fieldName);
444
                if (f == null) {
445
                if (f == null && !addedFieldNames.contains(fieldName)) {
445
                    final String type = fDesc.getType();
446
                    final String type = fDesc.getType();
-
 
447
                    addedFieldNames.add(fieldName);
446
                    if (type.equals(FieldDescriptor.TYPE_STRING)) {
448
                    if (type.equals(FieldDescriptor.TYPE_STRING)) {
447
                        int l = 256;
449
                        int l = 256;
448
                        try {
450
                        try {
449
                            l = Integer.parseInt(fDesc.getLength());
451
                            l = Integer.parseInt(fDesc.getLength());
450
                        } catch (Exception e) {
452
                        } catch (Exception e) {
451
                            Log.get().log(Level.WARNING, "Extension: unable to parse length: " + fDesc.getLength(), e);
453
                            Log.get().log(Level.WARNING, "Extension: unable to parse length: " + fDesc.getLength(), e);
452
                        }
454
                        }
453
                        createTable.addVarCharColumn(fDesc.getName(), l);
455
                        createTable.addVarCharColumn(fieldName, l);
454
                    } else if (type.equals(FieldDescriptor.TYPE_INTEGER)) {
456
                    } else if (type.equals(FieldDescriptor.TYPE_INTEGER)) {
455
                        int defaultVal = 0;
457
                        int defaultVal = 0;
456
                        try {
458
                        try {
457
                            defaultVal = Integer.parseInt(fDesc.getDefaultValue());
459
                            defaultVal = Integer.parseInt(fDesc.getDefaultValue());
458
                        } catch (Exception e) {
460
                        } catch (Exception e) {
459
                            Log.get().log(Level.WARNING, "Extension: unable to parse default integer value : " + fDesc.getDefaultValue(), e);
461
                            Log.get().log(Level.WARNING, "Extension: unable to parse default integer value : " + fDesc.getDefaultValue(), e);
460
                        }
462
                        }
461
                        createTable.addIntegerColumn(fDesc.getName(), defaultVal);
463
                        createTable.addIntegerColumn(fieldName, defaultVal);
462
                    } else if (type.equals(FieldDescriptor.TYPE_DECIMAL)) {
464
                    } else if (type.equals(FieldDescriptor.TYPE_DECIMAL)) {
463
                        BigDecimal defaultVal = BigDecimal.ZERO;
465
                        BigDecimal defaultVal = BigDecimal.ZERO;
464
                        try {
466
                        try {
465
                            defaultVal = new BigDecimal(fDesc.getDefaultValue());
467
                            defaultVal = new BigDecimal(fDesc.getDefaultValue());
466
                        } catch (Exception e) {
468
                        } catch (Exception e) {
467
                            Log.get().log(Level.WARNING, "Extension: unable to parse default bigdecimal value : " + fDesc.getDefaultValue(), e);
469
                            Log.get().log(Level.WARNING, "Extension: unable to parse default bigdecimal value : " + fDesc.getDefaultValue(), e);
468
                        }
470
                        }
469
                        createTable.addNumberColumn(fDesc.getName(), BigDecimal.class, defaultVal, false);
471
                        createTable.addNumberColumn(fieldName, BigDecimal.class, defaultVal, false);
470
                    } else if (type.equals(FieldDescriptor.TYPE_BOOLEAN)) {
472
                    } else if (type.equals(FieldDescriptor.TYPE_BOOLEAN)) {
471
                        String defaultValue = "false";
473
                        String defaultValue = "false";
472
                        if (fDesc.getDefaultValue() != null && fDesc.getDefaultValue().equals("true")) {
474
                        if (fDesc.getDefaultValue() != null && fDesc.getDefaultValue().equals("true")) {
473
                            defaultValue = "true";
475
                            defaultValue = "true";
474
                        }
476
                        }
475
                        createTable.addColumn(fDesc.getName(), "boolean", defaultValue, false);
477
                        createTable.addColumn(fieldName, "boolean", defaultValue, false);
476
                    } else if (type.equals(FieldDescriptor.TYPE_DATE)) {
478
                    } else if (type.equals(FieldDescriptor.TYPE_DATE)) {
477
                        createTable.addColumn(fDesc.getName(), "date");
479
                        createTable.addColumn(fieldName, "date");
478
                    } else if (type.equals(FieldDescriptor.TYPE_TIME)) {
480
                    } else if (type.equals(FieldDescriptor.TYPE_TIME)) {
479
                        createTable.addColumn(fDesc.getName(), "time");
481
                        createTable.addColumn(fieldName, "time");
480
                    } else if (type.equals(FieldDescriptor.TYPE_DATETIME)) {
482
                    } else if (type.equals(FieldDescriptor.TYPE_DATETIME)) {
481
                        createTable.addDateAndTimeColumn(fDesc.getName());
483
                        createTable.addDateAndTimeColumn(fieldName);
482
                    } else if (type.equals(FieldDescriptor.TYPE_REF)) {
484
                    } else if (type.equals(FieldDescriptor.TYPE_REF)) {
483
                        // created later
485
                        // created later
484
                        mustAdd = false;
486
                        mustAdd = false;
485
                    }
487
                    }
486
                    mustAdd = true;
488
                    mustAdd = true;