Skip to content

Commit 1348b07

Browse files
saeednikojEnKoChOlOsfeilmeier
authored
Convert Strings to Text Blocks (a Java 15 feature) (OpenEMS#2141)
* Convert all Text Blocks to Java 15 * Apply Eclipse Autoformat globally --------- Co-authored-by: Saeid Nikoubin <[email protected]> Co-authored-by: Stefan Feilmeier <[email protected]>
1 parent 48ddf8c commit 1348b07

File tree

77 files changed

+881
-774
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+881
-774
lines changed

io.openems.backend.common/src/io/openems/backend/common/metadata/Edge.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public boolean isOffline() {
101101
public synchronized void setOnline(boolean isOnline) {
102102
if (this.isOnline != isOnline) {
103103
this.isOnline = isOnline;
104-
104+
105105
EventBuilder.from(this.parent.getEventAdmin(), Events.ON_SET_ONLINE) //
106106
.addArg(Events.OnSetOnline.EDGE_ID, this.getId()) //
107107
.addArg(Events.OnSetOnline.IS_ONLINE, isOnline) //

io.openems.backend.common/src/io/openems/backend/common/test/DummyMetadata.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,14 @@ public Optional<String> getSerialNumberForEdge(Edge edge) {
138138
}
139139

140140
@Override
141-
public Map<String, Role> getPageDevice(User user, PaginationOptions paginationOptions) throws OpenemsNamedException {
141+
public Map<String, Role> getPageDevice(User user, PaginationOptions paginationOptions)
142+
throws OpenemsNamedException {
142143
throw new UnsupportedOperationException("Unsupported by Dummy Class");
143144
}
144145

145146
@Override
146147
public Role getRoleForEdge(User user, String edgeId) throws OpenemsNamedException {
147148
throw new UnsupportedOperationException("Unsupported by Dummy Class");
148149
}
149-
150+
150151
}

io.openems.backend.timedata.influx/test/io/openems/backend/timedata/influx/FieldTypeConflictHandlerTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ public class FieldTypeConflictHandlerTest {
1010
public void testHandleExceptionMessage() {
1111
var influx = new InfluxImpl();
1212
var sut = new FieldTypeConflictHandler(influx);
13-
assertTrue(sut.handleExceptionMessage("HTTP status code: 400; Message: partial write: field type conflict: " //
14-
+ "input field \"foo/bar\" on measurement \"data\" is type integer, " //
15-
+ "already exists as type float dropped=2"));
13+
assertTrue(sut.handleExceptionMessage("""
14+
HTTP status code: 400; Message: partial write: field type conflict: \
15+
input field "foo/bar" on measurement "data" is type integer, \
16+
already exists as type float dropped=2"""));
1617
}
1718

1819
}

io.openems.backend.timedata.timescaledb/test/io/openems/backend/timedata/timescaledb/internal/SchemaGenerator.java

+158-142
Original file line numberDiff line numberDiff line change
@@ -38,39 +38,47 @@ private final String generate() {
3838
}
3939

4040
private String createEdgeTable() {
41-
return "CREATE TABLE IF NOT EXISTS edge (\n" //
42-
+ " id SERIAL primary key,\n" //
43-
+ " name text NOT NULL,\n" //
44-
+ " UNIQUE(name)\n" //
45-
+ ");\n\n";
41+
return """
42+
CREATE TABLE IF NOT EXISTS edge (
43+
id SERIAL primary key,
44+
name text NOT NULL,
45+
UNIQUE(name)
46+
);
47+
""";
4648
}
4749

4850
private String createComponentTable() {
49-
return "CREATE TABLE IF NOT EXISTS component (\n" //
50-
+ " id SERIAL primary key,\n" //
51-
+ " name text NOT NULL,\n" //
52-
+ " UNIQUE(name)\n" //
53-
+ ");\n\n";
51+
return """
52+
CREATE TABLE IF NOT EXISTS component (
53+
id SERIAL primary key,
54+
name text NOT NULL,
55+
UNIQUE(name)
56+
);
57+
""";
5458
}
5559

5660
private String createChannelTable() {
57-
return "CREATE TABLE IF NOT EXISTS channel (\n" //
58-
+ " id SERIAL primary key,\n" //
59-
+ " component_id INTEGER NOT NULL REFERENCES component,\n" //
60-
+ " name text NOT NULL,\n" //
61-
+ " priority INTEGER NOT NULL,\n" //
62-
+ " UNIQUE(component_id, name)\n" //
63-
+ ");\n\n";
61+
return """
62+
CREATE TABLE IF NOT EXISTS channel (
63+
id SERIAL primary key,
64+
component_id INTEGER NOT NULL REFERENCES component,
65+
name text NOT NULL,
66+
priority INTEGER NOT NULL,
67+
UNIQUE(component_id, name)
68+
);
69+
""";
6470
}
6571

6672
private String createEdgeChannelTable() {
67-
return "CREATE TABLE IF NOT EXISTS edge_channel (\n" //
68-
+ " id SERIAL primary key,\n" //
69-
+ " edge_id INTEGER NOT NULL REFERENCES edge,\n" //
70-
+ " channel_id INTEGER NOT NULL REFERENCES channel,\n" //
71-
+ " type INTEGER NOT NULL,\n" //
72-
+ " available_since TIMESTAMPTZ\n" //
73-
+ ");\n\n";
73+
return """
74+
CREATE TABLE IF NOT EXISTS edge_channel (
75+
id SERIAL primary key,
76+
edge_id INTEGER NOT NULL REFERENCES edge,
77+
channel_id INTEGER NOT NULL REFERENCES channel,
78+
type INTEGER NOT NULL,
79+
available_since TIMESTAMPTZ
80+
);
81+
""";
7482
}
7583

7684
private String createEdgeChannelIndex() {
@@ -177,132 +185,140 @@ private String addContinuousAggregate(Type type, Priority priority) {
177185
}
178186

179187
private String createFunctionGetOrCreateEdgeId() {
180-
return "CREATE OR REPLACE FUNCTION openems_get_or_create_edge_id(\n" //
181-
+ " _edge text,\n" //
182-
+ " OUT _edge_id int\n" //
183-
+ ") LANGUAGE plpgsql AS \n" + "$$\n" //
184-
+ "BEGIN\n" //
185-
+ " LOOP\n" //
186-
+ " SELECT id\n" //
187-
+ " FROM edge\n" //
188-
+ " WHERE edge.name = _edge\n" //
189-
+ " INTO _edge_id;\n" //
190-
+ "\n" //
191-
+ " EXIT WHEN FOUND;\n" //
192-
+ "\n" //
193-
+ " INSERT INTO edge (name)\n" //
194-
+ " VALUES (_edge)\n" //
195-
+ " ON CONFLICT DO NOTHING\n" //
196-
+ " RETURNING id\n" //
197-
+ " INTO _edge_id;\n" //
198-
+ "\n" //
199-
+ " EXIT WHEN FOUND;\n" //
200-
+ " END LOOP;\n" //
201-
+ "END;\n" //
202-
+ "$$;\n\n";
188+
return """
189+
CREATE OR REPLACE FUNCTION openems_get_or_create_edge_id(
190+
_edge text,
191+
OUT _edge_id int
192+
) LANGUAGE plpgsql AS
193+
$$
194+
BEGIN
195+
LOOP
196+
SELECT id
197+
FROM edge
198+
WHERE edge.name = _edge
199+
INTO _edge_id;
200+
201+
EXIT WHEN FOUND;
202+
203+
INSERT INTO edge (name)
204+
VALUES (_edge)
205+
ON CONFLICT DO NOTHING
206+
RETURNING id
207+
INTO _edge_id;
208+
209+
EXIT WHEN FOUND;
210+
END LOOP;
211+
END;
212+
$$;
213+
""";
203214
}
204215

205216
private String createFunctionGetOrCreateComponentId() {
206-
return "CREATE OR REPLACE FUNCTION openems_get_or_create_component_id(\n" //
207-
+ " _component text, \n" //
208-
+ " OUT _component_id int\n" //
209-
+ ") LANGUAGE plpgsql AS \n" //
210-
+ "$$\n" //
211-
+ "BEGIN \n" //
212-
+ " loop\n" //
213-
+ " SELECT component.id\n" //
214-
+ " FROM component\n" //
215-
+ " WHERE component.name = _component\n" //
216-
+ " INTO _component_id; \n" //
217-
+ "\n" //
218-
+ " EXIT WHEN FOUND;\n" //
219-
+ "\n" //
220-
+ " INSERT INTO component (name)\n" //
221-
+ " VALUES (_component) \n" //
222-
+ " ON CONFLICT DO nothing\n" //
223-
+ " RETURNING id INTO _component_id;\n" //
224-
+ "\n" //
225-
+ " EXIT WHEN FOUND;\n" //
226-
+ " END LOOP;\n" //
227-
+ "END;\n" //
228-
+ "$$;\n\n";
217+
return """
218+
CREATE OR REPLACE FUNCTION openems_get_or_create_component_id(
219+
_component text,
220+
OUT _component_id int
221+
) LANGUAGE plpgsql AS\
222+
$$
223+
BEGIN
224+
loop
225+
SELECT component.id
226+
FROM component
227+
WHERE component.name = _component
228+
INTO _component_id;
229+
230+
EXIT WHEN FOUND;
231+
232+
INSERT INTO component (name)
233+
VALUES (_component)
234+
ON CONFLICT DO nothing
235+
RETURNING id INTO _component_id;
236+
237+
EXIT WHEN FOUND;
238+
END LOOP;
239+
END;
240+
$$;
241+
""";
229242
}
230243

231244
private String createFunctionGetOrCreateChannelId() {
232-
return "CREATE OR REPLACE FUNCTION openems_get_or_create_channel_id(\n" //
233-
+ " _component text,\n" //
234-
+ " _channel text,\n" //
235-
+ " OUT _channel_id int,\n" //
236-
+ " OUT _priority int\n" //
237-
+ ") LANGUAGE plpgsql AS \n" //
238-
+ "$$ \n" //
239-
+ "BEGIN\n" //
240-
+ " LOOP\n" //
241-
+ " SELECT channel.id, channel.priority\n" //
242-
+ " FROM channel\n" //
243-
+ " LEFT JOIN component\n" //
244-
+ " ON channel.component_id = component.id \n" //
245-
+ " WHERE component.name = _component AND channel.name = _channel\n" //
246-
+ " INTO _channel_id, _priority;\n" //
247-
+ "\n" //
248-
+ " EXIT WHEN FOUND;\n" //
249-
+ "\n" //
250-
+ " INSERT INTO channel (component_id, name, priority)\n" //
251-
+ " VALUES ((SELECT _component_id FROM openems_get_or_create_component_id(_component)), _channel, "
252-
+ Priority.LOW.getId() + "" + ")\n" //
253-
+ " ON CONFLICT DO NOTHING\n" //
254-
+ " RETURNING id, priority\n" //
255-
+ " INTO _channel_id, _priority;\n" //
256-
+ "\n" //
257-
+ " EXIT WHEN FOUND;\n" //
258-
+ " END LOOP;\n" //
259-
+ "END;\n" //
260-
+ "$$;\n\n";
245+
return """
246+
CREATE OR REPLACE FUNCTION openems_get_or_create_channel_id(
247+
_component text,
248+
_channel text,
249+
OUT _channel_id int,
250+
OUT _priority int
251+
) LANGUAGE plpgsql AS
252+
$$
253+
BEGIN
254+
LOOP
255+
SELECT channel.id, channel.priority
256+
FROM channel
257+
LEFT JOIN component
258+
ON channel.component_id = component.id
259+
WHERE component.name = _component AND channel.name = _channel
260+
INTO _channel_id, _priority;
261+
262+
EXIT WHEN FOUND;
263+
264+
INSERT INTO channel (component_id, name, priority)
265+
VALUES ((SELECT _component_id FROM openems_get_or_create_component_id(_component)), _channel,
266+
""" + Priority.LOW.getId() + "" + ")" + """
267+
ON CONFLICT DO NOTHING
268+
RETURNING id, priority
269+
INTO _channel_id, _priority;
270+
EXIT WHEN FOUND;
271+
END LOOP;
272+
END;
273+
$$;
274+
""";
261275
}
262276

263277
private String createFunctionGetOrCreateEdgeChannelId() {
264-
return "CREATE OR REPLACE FUNCTION openems_get_or_create_edge_channel_id(\n" //
265-
+ " _edge text,\n" //
266-
+ " _component text,\n" //
267-
+ " _channel text,\n" //
268-
+ " _type int,\n" //
269-
+ " OUT _channel_id int,\n" //
270-
+ " OUT _channel_type int,\n" //
271-
+ " OUT _priority int,\n" //
272-
+ " OUT _available_since TIMESTAMPTZ\n" //
273-
+ ") LANGUAGE plpgsql AS \n" //
274-
+ "$$ \n" //
275-
+ "BEGIN\n" //
276-
+ " LOOP\n" //
277-
+ " SELECT edge_channel.id, edge_channel.type, channel.priority, edge_channel.available_since\n" //
278-
+ " FROM edge_channel\n" //
279-
+ " LEFT JOIN edge\n" //
280-
+ " ON edge_channel.edge_id = edge.id \n" //
281-
+ " LEFT JOIN channel\n" //
282-
+ " ON edge_channel.channel_id = channel.id\n" //
283-
+ " LEFT JOIN component\n" //
284-
+ " ON channel.component_id = component.id \n" //
285-
+ " WHERE edge.name = _edge AND component.name = _component AND channel.name = _channel\n" //
286-
+ " INTO _channel_id, _channel_type, _priority, _available_since;\n" //
287-
+ "\n" //
288-
+ " EXIT WHEN FOUND;\n" //
289-
+ "\n" //
290-
+ " SELECT c._channel_id, c._priority\n" //
291-
+ " FROM openems_get_or_create_channel_id(_component, _channel) c\n" //
292-
+ " INTO _channel_id, _priority;\n" //
293-
+ "\n" //
294-
+ " INSERT INTO edge_channel (edge_id, channel_id, type, available_since)\n" //
295-
+ " VALUES ((SELECT _edge_id FROM openems_get_or_create_edge_id(_edge)),\n" //
296-
+ " _channel_id,\n" //
297-
+ " _type,\n" //
298-
+ " now())\n" //
299-
+ " ON CONFLICT DO NOTHING\n" //
300-
+ " RETURNING id, type\n" //
301-
+ " INTO _channel_id, _channel_type;\n" //
302-
+ "\n" //
303-
+ " EXIT WHEN FOUND;\n" //
304-
+ " END LOOP;\n" //
305-
+ "END;\n" //
306-
+ "$$;\n\n";
278+
return """
279+
CREATE OR REPLACE FUNCTION openems_get_or_create_edge_channel_id(
280+
_edge text,
281+
_component text,
282+
_channel text,
283+
_type int,
284+
OUT _channel_id int,
285+
OUT _channel_type int,
286+
OUT _priority int,
287+
OUT _available_since TIMESTAMPTZ
288+
) LANGUAGE plpgsql AS\s
289+
$$\s
290+
BEGIN
291+
LOOP
292+
SELECT edge_channel.id, edge_channel.type, channel.priority, edge_channel.available_since
293+
FROM edge_channel
294+
LEFT JOIN edge
295+
ON edge_channel.edge_id = edge.id\s
296+
LEFT JOIN channel
297+
ON edge_channel.channel_id = channel.id
298+
LEFT JOIN component
299+
ON channel.component_id = component.id\s
300+
WHERE edge.name = _edge AND component.name = _component AND channel.name = _channel
301+
INTO _channel_id, _channel_type, _priority, _available_since;
302+
303+
EXIT WHEN FOUND;
304+
305+
SELECT c._channel_id, c._priority
306+
FROM openems_get_or_create_channel_id(_component, _channel) c
307+
INTO _channel_id, _priority;
308+
309+
INSERT INTO edge_channel (edge_id, channel_id, type, available_since)
310+
VALUES ((SELECT _edge_id FROM openems_get_or_create_edge_id(_edge)),
311+
_channel_id,
312+
_type,
313+
now())
314+
ON CONFLICT DO NOTHING
315+
RETURNING id, type
316+
INTO _channel_id, _channel_type;
317+
318+
EXIT WHEN FOUND;
319+
END LOOP;
320+
END;
321+
$$;
322+
""";
307323
}
308324
}

0 commit comments

Comments
 (0)