OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 144 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.utils.ChangeTable.DeferredClause;
22
import org.openconcerto.sql.utils.ChangeTable.DeferredClause;
23
import org.openconcerto.sql.utils.SQLUtils;
23
import org.openconcerto.sql.utils.SQLUtils;
24
import org.openconcerto.sql.utils.SQLUtils.SQLFactory;
24
import org.openconcerto.sql.utils.SQLUtils.SQLFactory;
25
import org.openconcerto.utils.CollectionUtils;
25
import org.openconcerto.utils.CollectionUtils;
26
import org.openconcerto.utils.ListMap;
26
import org.openconcerto.utils.ListMap;
-
 
27
import org.openconcerto.utils.NumberUtils;
27
import org.openconcerto.utils.StringUtils;
28
import org.openconcerto.utils.StringUtils;
28
import org.openconcerto.utils.Tuple2;
29
import org.openconcerto.utils.Tuple2;
29
import org.openconcerto.utils.cc.ITransformer;
30
import org.openconcerto.utils.cc.ITransformer;
-
 
31
import org.openconcerto.xml.XMLCodecUtils;
30
 
32
 
-
 
33
import java.beans.DefaultPersistenceDelegate;
31
import java.io.BufferedReader;
34
import java.io.BufferedReader;
32
import java.io.BufferedWriter;
35
import java.io.BufferedWriter;
33
import java.io.File;
36
import java.io.File;
34
import java.io.FileInputStream;
37
import java.io.FileInputStream;
35
import java.io.FileOutputStream;
38
import java.io.FileOutputStream;
Line 99... Line 102...
99
        CAST_TYPES.put(Timestamp.class, "datetime");
102
        CAST_TYPES.put(Timestamp.class, "datetime");
100
        CAST_TYPES.put(java.sql.Date.class, "date");
103
        CAST_TYPES.put(java.sql.Date.class, "date");
101
        CAST_TYPES.put(java.sql.Time.class, "time");
104
        CAST_TYPES.put(java.sql.Time.class, "time");
102
        CAST_TYPES.put(Blob.class, "binary");
105
        CAST_TYPES.put(Blob.class, "binary");
103
        CAST_TYPES.put(String.class, "char");
106
        CAST_TYPES.put(String.class, "char");
-
 
107
 
-
 
108
        XMLCodecUtils.register(SQLSyntaxMySQL.class, new DefaultPersistenceDelegate(new String[] { "noBackslashEscapes" }));
104
    }
109
    }
105
 
110
 
106
    private final boolean noBackslashEscapes;
111
    private final boolean noBackslashEscapes;
107
 
112
 
108
    public SQLSyntaxMySQL(final boolean noBackslashEscapes) {
113
    public SQLSyntaxMySQL(final boolean noBackslashEscapes) {
Line 121... Line 126...
121
        this.typeNames.addAll(Blob.class, "blob", "tinyblob", "mediumblob", "longblob", "varbinary", "binary");
126
        this.typeNames.addAll(Blob.class, "blob", "tinyblob", "mediumblob", "longblob", "varbinary", "binary");
122
        this.typeNames.addAll(Clob.class, "text", "tinytext", "mediumtext", "longtext", "varchar", "char");
127
        this.typeNames.addAll(Clob.class, "text", "tinytext", "mediumtext", "longtext", "varchar", "char");
123
        this.typeNames.addAll(String.class, "varchar", "char");
128
        this.typeNames.addAll(String.class, "varchar", "char");
124
    }
129
    }
125
 
130
 
-
 
131
    public final boolean isNoBackslashEscapes() {
-
 
132
        return this.noBackslashEscapes;
-
 
133
    }
-
 
134
 
126
    @Override
135
    @Override
127
    public final String quoteString(String s) {
136
    public final String quoteString(String s) {
128
        final String res = super.quoteString(s);
137
        final String res = super.quoteString(s);
129
        if (s == null)
138
        if (s == null)
130
            return res;
139
            return res;
Line 280... Line 289...
280
    public boolean isDeadLockException(SQLException exn) {
289
    public boolean isDeadLockException(SQLException exn) {
281
        return SQLUtils.findWithSQLState(exn).getErrorCode() == 1213;
290
        return SQLUtils.findWithSQLState(exn).getErrorCode() == 1213;
282
    }
291
    }
283
 
292
 
284
    @Override
293
    @Override
-
 
294
    public boolean isTableNotFoundException(Exception exn) {
-
 
295
        return SQLUtils.findWithSQLState(exn).getErrorCode() == 1146;
-
 
296
    }
-
 
297
 
-
 
298
    @Override
-
 
299
    public String getSetLockTimeoutQuery(int millis) {
-
 
300
        // Wait at least the passed amount.
-
 
301
        // 0ms -> 0s, 1ms -> 1s, 1000ms -> 1s, 1001ms -> 2s
-
 
302
        return "set innodb_lock_wait_timeout = " + NumberUtils.divideRoundUp(millis, 1000);
-
 
303
    }
-
 
304
 
-
 
305
    @Override
-
 
306
    public String getShowLockTimeoutQuery() {
-
 
307
        return "select @@SESSION.innodb_lock_wait_timeout * 1000";
-
 
308
    }
-
 
309
 
-
 
310
    @Override
285
    public Map<ClauseType, List<String>> getAlterField(SQLField f, Set<Properties> toAlter, String type, String defaultVal, Boolean nullable) {
311
    public Map<ClauseType, List<String>> getAlterField(SQLField f, Set<Properties> toAlter, String type, String defaultVal, Boolean nullable) {
286
        final boolean newNullable = toAlter.contains(Properties.NULLABLE) ? nullable : getNullable(f);
312
        final boolean newNullable = toAlter.contains(Properties.NULLABLE) ? nullable : getNullable(f);
287
        final String newType = toAlter.contains(Properties.TYPE) ? type : getType(f);
313
        final String newType = toAlter.contains(Properties.TYPE) ? type : getType(f);
288
        String newDef = toAlter.contains(Properties.DEFAULT) ? defaultVal : getDefault(f, newType);
314
        String newDef = toAlter.contains(Properties.DEFAULT) ? defaultVal : getDefault(f, newType);
289
        // MySQL doesn't support "NOT NULL DEFAULT NULL" so use the equivalent "NOT NULL"
315
        // MySQL doesn't support "NOT NULL DEFAULT NULL" so use the equivalent "NOT NULL"
Line 606... Line 632...
606
            protected String asString(ChangeTable<?> ct, SQLName tableName) {
632
            protected String asString(ChangeTable<?> ct, SQLName tableName) {
607
                return "ALTER TABLE " + tableName.quote() + " COMMENT = " + ct.getSyntax().quoteString(comment) + ";";
633
                return "ALTER TABLE " + tableName.quote() + " COMMENT = " + ct.getSyntax().quoteString(comment) + ";";
608
            }
634
            }
609
        };
635
        };
610
    }
636
    }
-
 
637
 
-
 
638
    @Override
-
 
639
    public String getSessionIDExpression() {
-
 
640
        return "CONNECTION_ID()";
-
 
641
    }
-
 
642
 
-
 
643
    @Override
-
 
644
    public String getSessionsQuery(final DBSystemRoot sysRoot, final boolean includeSelf) {
-
 
645
        final String allRows = "SELECT \"ID\", \"Info\" as \"QUERY\", \"USER\" as \"USER_NAME\" FROM INFORMATION_SCHEMA.PROCESSLIST";
-
 
646
        if (includeSelf)
-
 
647
            return allRows;
-
 
648
        return allRows + " WHERE \"ID\" != " + this.getSessionIDExpression();
-
 
649
    }
-
 
650
 
-
 
651
    @Override
-
 
652
    protected String getAllUsersForGrant() {
-
 
653
        return "'%'@'%'";
-
 
654
    }
-
 
655
 
-
 
656
    @Override
-
 
657
    public String getAllowConnectionsQuery(String sysRootName, final boolean allow) {
-
 
658
        return null;
-
 
659
        // MAYBE use this (but still allow super users)
-
 
660
        // https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_offline_mode
-
 
661
        // return "set GLOBAL offline_mode = " + (allow ? "off" : "on");
-
 
662
    }
611
}
663
}