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

SpiNNakerManchester / JavaSpiNNaker / 13068443665

31 Jan 2025 07:38AM UTC coverage: 37.377% (+0.08%) from 37.299%
13068443665

push

github

rowleya
Check that a job is possible before entering the queue

45 of 62 new or added lines in 4 files covered. (72.58%)

15 existing lines in 4 files now uncovered.

8873 of 23739 relevant lines covered (37.38%)

1.12 hits per line

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

63.16
/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
         */
NEW
40
        public SQL(@CompileTimeConstant String sql) {
×
NEW
41
                this.sql = sql;
×
NEW
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) {
NEW
50
                this(readResource(resource));
×
NEW
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
                System.err.println(sqlString);
3✔
70
                this.sql = sqlString;
3✔
71
        }
3✔
72

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

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

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