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

future-architect / uroborosql / #743

28 Jun 2024 04:17PM UTC coverage: 90.988% (+0.5%) from 90.484%
#743

push

web-flow
add paramIfNotEmpty method (#318)

* v0.x to master merge

* fix nanoseconds diff (java8 to java11)

* eclipse cleanup and  optimize import

* eclipse format

* optimize Imports

* remove unused annotation

* library version up

* migrate v0.x to master
- update java version 8 to 11
- update junit4 to junit5
- library version update

* fix test failed

* remove unused annotation

* fixed bug

* use var

* fix java8 coding style

* Refactoring TransactionContextManager

* Refactoring SqlAgent

* 途中コミット

* fix testcase

* fix review

* fix javadoc comments

* merge v0.x PR

* cleanup code

* cleanup test code

* change build status badge

* - agent.query, update, proc, batch にそれぞれSupplierを引数にとるメソッドを追加
- SqlQuery.paramとSqlEntityUpdate.setにFunctionを受け取るメソッドを追加

* testcaseの整形

* - SqlFluent と ExtractionCondition の分離
- Arrays.asList -> List.of への変更
- テストの整形

* - v0.x系の不具合対応の追いつき
- ログ出力の整理

* - SqlKindの整理(ENTITY_XXXの追加)
- REPL_LOGの追加
- Deprecatedメソッドの削除(SqlAgent)
- SqlAgent, ExecutionContextでsetterをfluent APIに変更

* DB接続URLの修正

* add and fix testcases.

* add event testcases.

* fix typo

* add paramIfNotEmpty method and StringUtils rename ObjectUtils

* fix review comments.

* remove unused import

1695 of 1958 new or added lines in 97 files covered. (86.57%)

26 existing lines in 10 files now uncovered.

8249 of 9066 relevant lines covered (90.99%)

0.91 hits per line

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

86.84
/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
import org.slf4j.Logger;
15
import org.slf4j.LoggerFactory;
16

17
import jp.co.future.uroborosql.client.completer.SqlKeywordCompleter;
18
import jp.co.future.uroborosql.client.completer.SqlKeywordCompleter.SqlKeyword;
19
import jp.co.future.uroborosql.client.completer.TableNameCompleter;
20
import jp.co.future.uroborosql.config.SqlConfig;
21
import jp.co.future.uroborosql.context.ExecutionContext;
22
import jp.co.future.uroborosql.mapping.MetaTable;
23
import jp.co.future.uroborosql.mapping.Table;
24
import jp.co.future.uroborosql.mapping.TableMetadata;
25

26
/**
27
 * Generate sql template Command
28
 *
29
 * @author H.Sugimoto
30
 */
31
public class GenerateCommand extends ReplCommand {
32
        /** REPLロガー */
33
        private static final Logger REPL_LOG = LoggerFactory.getLogger("jp.co.future.uroborosql.repl");
1✔
34

35
        /**
36
         * Constructor
37
         */
38
        @SuppressWarnings("unchecked")
39
        public GenerateCommand() {
40
                super(false, SqlKeywordCompleter.class, TableNameCompleter.class);
1✔
41
        }
1✔
42

43
        /**
44
         * {@inheritDoc}
45
         *
46
         * @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)
47
         */
48
        @Override
49
        public boolean execute(final LineReader reader, final String[] parts, final SqlConfig sqlConfig,
50
                        final Properties props) {
51
                var writer = reader.getTerminal().writer();
1✔
52

53
                if (parts.length < 3) {
1✔
54
                        writer.println(toString() + " parameter missing. " + toString() + " [SQL_KEYWORD] [TABLE NAME].");
×
55
                        return true;
×
56
                }
57

58
                try (var agent = sqlConfig.agent()) {
1✔
59
                        var sqlKeyword = SqlKeyword.of(parts[1]);
1✔
60
                        var tableName = parts[2];
1✔
61
                        var versionColumnName = props.getProperty("sql.versionColumnName");
1✔
62
                        var optimisticLockSupplier = props
1✔
63
                                        .getProperty("sql.optimisticLockSupplier",
1✔
64
                                                        "jp.co.future.uroborosql.mapping.LockVersionOptimisticLockSupplier");
65

66
                        Table table = new MetaTable(tableName, null, versionColumnName, optimisticLockSupplier);
1✔
67
                        var metadata = TableMetadata.createTableEntityMetadata(agent, table);
1✔
68
                        metadata.setSchema(null);
1✔
69

70
                        ExecutionContext ctx = null;
1✔
71
                        if (sqlKeyword.isPresent()) {
1✔
72
                                var keyword = sqlKeyword.get();
1✔
73
                                switch (keyword) {
1✔
74
                                case INSERT:
75
                                        ctx = sqlConfig.getEntityHandler().createInsertContext(agent, metadata, null);
1✔
76
                                        break;
1✔
77

78
                                case UPDATE:
79
                                        ctx = sqlConfig.getEntityHandler().createUpdateContext(agent, metadata, null, true);
1✔
80
                                        break;
1✔
81

82
                                case DELETE:
83
                                        ctx = sqlConfig.getEntityHandler().createDeleteContext(agent, metadata, null, true);
1✔
84
                                        break;
1✔
85

86
                                default:
87
                                        ctx = sqlConfig.getEntityHandler().createSelectContext(agent, metadata, null, true);
1✔
88
                                        break;
89
                                }
90
                        } else {
1✔
91
                                ctx = sqlConfig.getEntityHandler().createSelectContext(agent, metadata, null, true);
×
92
                        }
93
                        writer.println(ctx.getSql());
1✔
NEW
94
                } catch (SQLException ex) {
×
NEW
95
                        REPL_LOG.error(ex.getMessage(), ex);
×
96
                }
1✔
97

98
                writer.flush();
1✔
99

100
                return true;
1✔
101
        }
102

103
        /**
104
         * {@inheritDoc}
105
         *
106
         * @see jp.co.future.uroborosql.client.command.ReplCommand#showHelp(org.jline.terminal.Terminal)
107
         */
108
        @Override
109
        public void showHelp(final Terminal terminal) {
110
                terminal.writer().println("\t" + this.toString() + ": generate sql to access the table.");
1✔
111
                terminal.writer().println(
1✔
112
                                "\t\tex) generate [select/insert/update/delete] [table name]<Enter> : Show sql to access tables according to keywords.");
113
        }
1✔
114
}
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