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

SpiNNakerManchester / JavaSpiNNaker / 13074984160

31 Jan 2025 02:43PM UTC coverage: 38.651% (+0.09%) from 38.562%
13074984160

push

github

web-flow
Merge pull request #1215 from SpiNNakerManchester/sanity_check_jobs

Sanity check jobs

52 of 83 new or added lines in 8 files covered. (62.65%)

7 existing lines in 3 files now uncovered.

9177 of 23743 relevant lines covered (38.65%)

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
/**
27
 * Some sort of SQL that can be executed as part of a query or an update.
28
 */
29
public class SQL {
30

31
        private final String sql;
32

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

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

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

60
                // Translate the string
61
                var sqlString = sql;
3✔
62

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

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

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

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