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

SpiNNakerManchester / JavaSpiNNaker / 13070643287

31 Jan 2025 10:04AM UTC coverage: 38.643% (+0.01%) from 38.633%
13070643287

push

github

rowleya
Fix line length

0 of 1 new or added line in 1 file covered. (0.0%)

281 existing lines in 9 files now uncovered.

9175 of 23743 relevant lines covered (38.64%)

1.16 hits per line

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

61.11
/SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/db/SQL.java
1
/*
2
 * Copyright (c) 2025 The University of Manchester
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package uk.ac.manchester.spinnaker.alloc.db;
17

18
import static java.nio.charset.StandardCharsets.UTF_8;
19

20
import java.io.IOException;
21
import java.util.List;
22

23
import org.apache.commons.io.IOUtils;
24
import org.springframework.core.io.Resource;
25

26
import com.google.errorprone.annotations.CompileTimeConstant;
27

28
/**
29
 * Some sort of SQL that can be executed as part of a query or an update.
30
 */
31
public class SQL {
32

33
        private final String sql;
34

35
        /**
36
         * Create a new SQL string.
37
         *
38
         * @param sql The String containing SQL
39
         */
40
        public SQL(@CompileTimeConstant String sql) {
×
41
                this.sql = sql;
×
42
        }
×
43

44
        /**
45
         * Create a new SQL string from a resource.
46
         *
47
         * @param resource The resource containing
48
         */
49
        public SQL(Resource resource) {
50
                this(readResource(resource));
×
51
        }
×
52

53
        /**
54
         * Create a new SQL string with parameters that can be replaced.
55
         *
56
         * @param sql The String containing SQL with replaceable parts
57
         * @param parameters The parameters that are to be replaced
58
         * @param values The values that the parameters are to be replaced with
59
         */
60
        public SQL(String sql, List<String> parameters, List<String> values) {
3✔
61

62
                // Translate the string
63
                var sqlString = sql;
3✔
64

65
                // Replace the parameters with the values
66
                for (int i = 0; i < parameters.size(); i++) {
3✔
67
                        sqlString = sqlString.replace(parameters.get(i), values.get(i));
3✔
68
                }
69
                this.sql = sqlString;
3✔
70
        }
3✔
71

72
        /**
73
         * Create a new SQL string with parameters that can be replaced.
74
         *
75
         * @param resource The resource containing SQL with replaceable parts
76
         * @param parameters The parameters that are to be replaced
77
         * @param values The values that the parameters are to be replaced with
78
         */
79
        public SQL(Resource resource, List<String> parameters,
80
                        List<String> values) {
81
                this(readResource(resource), parameters, values);
3✔
82
        }
3✔
83

84
        private static String readResource(Resource resource) {
85
                try (var is = resource.getInputStream()) {
3✔
86
                        return IOUtils.toString(is, UTF_8);
3✔
UNCOV
87
                } catch (IOException e) {
×
88
                        throw new RuntimeException("Failed to read SQL resource", e);
×
89
                }
90
        }
91

92
        /**
93
         * Get the SQL to be executed.
94
         *
95
         * @return The SQL.
96
         */
97
        public String getSQL() {
98
                return sql;
3✔
99
        }
100
}
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