• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

future-architect / uroborosql / #771

12 Sep 2024 03:50PM UTC coverage: 90.374% (-0.8%) from 91.197%
#771

Pull #331

HidekiSugimoto189
Merge branch 'feature/add_new_dialect' of https://github.com/future-architect/uroborosql into feature/add_new_dialect
Pull Request #331: add oracle v12-23 and Mariadb 5,10 dialect

497 of 703 new or added lines in 42 files covered. (70.7%)

9 existing lines in 7 files now uncovered.

8928 of 9879 relevant lines covered (90.37%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.14
/src/main/java/jp/co/future/uroborosql/client/completer/TableNameCompleter.java
1
/**
2
 * Copyright (c) 2017-present, Future Corporation
3
 *
4
 * This source code is licensed under the MIT license found in the
5
 * LICENSE file in the root directory of this source tree.
6
 */
7
package jp.co.future.uroborosql.client.completer;
8

9
import java.sql.SQLException;
10
import java.util.List;
11

12
import org.jline.reader.Candidate;
13
import org.jline.reader.LineReader;
14
import org.jline.reader.ParsedLine;
15

16
import jp.co.future.uroborosql.client.command.ReplCommand;
17
import jp.co.future.uroborosql.connection.ConnectionSupplier;
18
import jp.co.future.uroborosql.log.support.ReplLoggingSupport;
19

20
/**
21
 * テーブル名を補完するCompleter
22
 *
23
 * @author H.Sugimoto
24
 *
25
 */
26
public class TableNameCompleter extends AbstractCompleter implements ReplLoggingSupport {
27

28
        /** Connectionサプライヤ. */
29
        private final ConnectionSupplier connectionSupplier;
30

31
        /**
32
         * Constructor
33
         *
34
         * @param commands ReplCommand List
35
         * @param connectionSupplier connectionSupplier
36
         */
37
        public TableNameCompleter(final List<ReplCommand> commands, final ConnectionSupplier connectionSupplier) {
38
                super(commands);
1✔
39
                this.connectionSupplier = connectionSupplier;
1✔
40
        }
1✔
41

42
        /**
43
         * DatabaseMetadataからテーブル名を取得して補完候補とする。
44
         *
45
         * {@inheritDoc}
46
         *
47
         * @see org.jline.reader.Completer#complete(org.jline.reader.LineReader, org.jline.reader.ParsedLine, java.util.List)
48
         */
49
        @Override
50
        public void complete(final LineReader reader, final ParsedLine line, final List<Candidate> candidates) {
51
                var buffer = line.line().substring(0, line.cursor());
1✔
52
                var parts = getLineParts(buffer);
1✔
53
                var len = parts.length;
1✔
54

55
                // コード補完する引数の番号を特定。
56
                var startArgNo = getStartArgNo(line);
1✔
57

58
                // 対象引数が-1、または開始引数にlenが満たない場合は該当なしなのでコード補完しない
59
                if (!accept(startArgNo, buffer, len)) {
1✔
60
                        return;
1✔
61
                }
62

63
                var isBlank = buffer.endsWith(" ");
1✔
64
                var tableNamePattern = "%";
1✔
65
                if (len == startArgNo && isBlank) {
1✔
66
                        tableNamePattern = "%";
1✔
67
                } else if (len == startArgNo + 1 && !isBlank) {
1✔
68
                        tableNamePattern = parts[len - 1] + "%";
1✔
69
                } else {
70
                        return;
×
71
                }
72

73
                try {
74
                        var conn = connectionSupplier.getConnection();
1✔
75
                        var md = conn.getMetaData();
1✔
76
                        try (var rs = md.getTables(conn.getCatalog(), conn.getSchema(),
1✔
77
                                        tableNamePattern.toUpperCase(), null)) {
1✔
78
                                while (rs.next()) {
1✔
79
                                        candidates.add(new Candidate(rs.getString("TABLE_NAME")));
1✔
80
                                }
81
                        }
82
                        if (candidates.isEmpty()) {
1✔
83
                                try (var rs = md.getTables(conn.getCatalog(), conn.getSchema(),
1✔
84
                                                tableNamePattern.toLowerCase(), null)) {
1✔
85
                                        while (rs.next()) {
1✔
86
                                                candidates.add(new Candidate(rs.getString("TABLE_NAME")));
×
87
                                        }
88
                                }
89
                        }
90
                } catch (SQLException ex) {
×
NEW
91
                        errorWith(REPL_LOG)
×
NEW
92
                                        .setMessage(ex.getMessage())
×
NEW
93
                                        .setCause(ex)
×
NEW
94
                                        .log();
×
UNCOV
95
                        return;
×
96
                }
1✔
97
        }
1✔
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc