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

future-architect / uroborosql / #767

26 Aug 2024 05:08PM UTC coverage: 90.274% (-0.9%) from 91.21%
#767

push

HidekiSugimoto189
各Logger用のインタフェースを作成し必要なクラスがimplementsするように修正。そのうえでSLF4J 2.xのAPIを利用するように変更(性能改善)

360 of 568 new or added lines in 32 files covered. (63.38%)

9 existing lines in 7 files now uncovered.

8864 of 9819 relevant lines covered (90.27%)

0.9 hits per line

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

79.41
/src/main/java/jp/co/future/uroborosql/client/command/GenerateCommand.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.command;
8

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

12
import org.jline.reader.LineReader;
13
import org.jline.terminal.Terminal;
14

15
import jp.co.future.uroborosql.client.completer.SqlKeywordCompleter;
16
import jp.co.future.uroborosql.client.completer.SqlKeywordCompleter.SqlKeyword;
17
import jp.co.future.uroborosql.client.completer.TableNameCompleter;
18
import jp.co.future.uroborosql.config.SqlConfig;
19
import jp.co.future.uroborosql.mapping.MetaTable;
20
import jp.co.future.uroborosql.mapping.TableMetadata;
21

22
/**
23
 * Generate sql template Command
24
 *
25
 * @author H.Sugimoto
26
 */
27
public class GenerateCommand extends ReplCommand {
28
        /**
29
         * Constructor
30
         */
31
        @SuppressWarnings("unchecked")
32
        public GenerateCommand() {
33
                super(false, SqlKeywordCompleter.class, TableNameCompleter.class);
1✔
34
        }
1✔
35

36
        /**
37
         * {@inheritDoc}
38
         *
39
         * @see jp.co.future.uroborosql.client.command.ReplCommand#execute(org.jline.reader.LineReader, java.lang.String[], jp.co.future.uroborosql.config.SqlConfig, java.util.Properties)
40
         */
41
        @Override
42
        public boolean execute(final LineReader reader, final String[] parts, final SqlConfig sqlConfig,
43
                        final Properties props) {
44
                var writer = reader.getTerminal().writer();
1✔
45

46
                if (parts.length < 3) {
1✔
47
                        writer.println(toString() + " parameter missing. " + toString() + " [SQL_KEYWORD] [TABLE NAME].");
×
48
                        return true;
×
49
                }
50

51
                try (var agent = sqlConfig.agent()) {
1✔
52
                        var sqlKeyword = SqlKeyword.of(parts[1]);
1✔
53
                        var tableName = parts[2];
1✔
54
                        var versionColumnName = props.getProperty("sql.versionColumnName");
1✔
55
                        var optimisticLockSupplier = props
1✔
56
                                        .getProperty("sql.optimisticLockSupplier",
1✔
57
                                                        "jp.co.future.uroborosql.mapping.LockVersionOptimisticLockSupplier");
58

59
                        var table = new MetaTable(tableName, null, versionColumnName, optimisticLockSupplier);
1✔
60
                        var metadata = TableMetadata.createTableEntityMetadata(agent, table);
1✔
61
                        metadata.setSchema(null);
1✔
62

63
                        var ctx = sqlKeyword.map(keyword -> {
1✔
64
                                switch (keyword) {
1✔
65
                                case INSERT:
66
                                        return sqlConfig.getEntityHandler().createInsertContext(agent, metadata, null);
1✔
67
                                case UPDATE:
68
                                        return sqlConfig.getEntityHandler().createUpdateContext(agent, metadata, null, true);
1✔
69
                                case DELETE:
70
                                        return sqlConfig.getEntityHandler().createDeleteContext(agent, metadata, null, true);
1✔
71
                                default:
72
                                        return sqlConfig.getEntityHandler().createSelectContext(agent, metadata, null, true);
1✔
73
                                }
74
                        }).orElseGet(() -> sqlConfig.getEntityHandler().createSelectContext(agent, metadata, null, true));
1✔
75
                        writer.println(ctx.getSql());
1✔
76
                } catch (SQLException ex) {
×
NEW
77
                        REPL_LOG.atError()
×
NEW
78
                                        .setMessage(ex.getMessage())
×
NEW
79
                                        .setCause(ex)
×
NEW
80
                                        .log();
×
81
                }
1✔
82

83
                writer.flush();
1✔
84

85
                return true;
1✔
86
        }
87

88
        /**
89
         * {@inheritDoc}
90
         *
91
         * @see jp.co.future.uroborosql.client.command.ReplCommand#showHelp(org.jline.terminal.Terminal)
92
         */
93
        @Override
94
        public void showHelp(final Terminal terminal) {
95
                terminal.writer().println("\t" + this.toString() + ": generate sql to access the table.");
1✔
96
                terminal.writer().println(
1✔
97
                                "\t\tex) generate [select/insert/update/delete] [table name]<Enter> : Show sql to access tables according to keywords.");
98
        }
1✔
99
}
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

© 2025 Coveralls, Inc