Skip to content

Commit

Permalink
Convert Strings to Text Blocks (a Java 15 feature) (#2141)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored May 29, 2023
1 parent 48ddf8c commit 1348b07
Show file tree
Hide file tree
Showing 77 changed files with 881 additions and 774 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public boolean isOffline() {
public synchronized void setOnline(boolean isOnline) {
if (this.isOnline != isOnline) {
this.isOnline = isOnline;

EventBuilder.from(this.parent.getEventAdmin(), Events.ON_SET_ONLINE) //
.addArg(Events.OnSetOnline.EDGE_ID, this.getId()) //
.addArg(Events.OnSetOnline.IS_ONLINE, isOnline) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ public Optional<String> getSerialNumberForEdge(Edge edge) {
}

@Override
public Map<String, Role> getPageDevice(User user, PaginationOptions paginationOptions) throws OpenemsNamedException {
public Map<String, Role> getPageDevice(User user, PaginationOptions paginationOptions)
throws OpenemsNamedException {
throw new UnsupportedOperationException("Unsupported by Dummy Class");
}

@Override
public Role getRoleForEdge(User user, String edgeId) throws OpenemsNamedException {
throw new UnsupportedOperationException("Unsupported by Dummy Class");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ public class FieldTypeConflictHandlerTest {
public void testHandleExceptionMessage() {
var influx = new InfluxImpl();
var sut = new FieldTypeConflictHandler(influx);
assertTrue(sut.handleExceptionMessage("HTTP status code: 400; Message: partial write: field type conflict: " //
+ "input field \"foo/bar\" on measurement \"data\" is type integer, " //
+ "already exists as type float dropped=2"));
assertTrue(sut.handleExceptionMessage("""
HTTP status code: 400; Message: partial write: field type conflict: \
input field "foo/bar" on measurement "data" is type integer, \
already exists as type float dropped=2"""));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,47 @@ private final String generate() {
}

private String createEdgeTable() {
return "CREATE TABLE IF NOT EXISTS edge (\n" //
+ " id SERIAL primary key,\n" //
+ " name text NOT NULL,\n" //
+ " UNIQUE(name)\n" //
+ ");\n\n";
return """
CREATE TABLE IF NOT EXISTS edge (
id SERIAL primary key,
name text NOT NULL,
UNIQUE(name)
);
""";
}

private String createComponentTable() {
return "CREATE TABLE IF NOT EXISTS component (\n" //
+ " id SERIAL primary key,\n" //
+ " name text NOT NULL,\n" //
+ " UNIQUE(name)\n" //
+ ");\n\n";
return """
CREATE TABLE IF NOT EXISTS component (
id SERIAL primary key,
name text NOT NULL,
UNIQUE(name)
);
""";
}

private String createChannelTable() {
return "CREATE TABLE IF NOT EXISTS channel (\n" //
+ " id SERIAL primary key,\n" //
+ " component_id INTEGER NOT NULL REFERENCES component,\n" //
+ " name text NOT NULL,\n" //
+ " priority INTEGER NOT NULL,\n" //
+ " UNIQUE(component_id, name)\n" //
+ ");\n\n";
return """
CREATE TABLE IF NOT EXISTS channel (
id SERIAL primary key,
component_id INTEGER NOT NULL REFERENCES component,
name text NOT NULL,
priority INTEGER NOT NULL,
UNIQUE(component_id, name)
);
""";
}

private String createEdgeChannelTable() {
return "CREATE TABLE IF NOT EXISTS edge_channel (\n" //
+ " id SERIAL primary key,\n" //
+ " edge_id INTEGER NOT NULL REFERENCES edge,\n" //
+ " channel_id INTEGER NOT NULL REFERENCES channel,\n" //
+ " type INTEGER NOT NULL,\n" //
+ " available_since TIMESTAMPTZ\n" //
+ ");\n\n";
return """
CREATE TABLE IF NOT EXISTS edge_channel (
id SERIAL primary key,
edge_id INTEGER NOT NULL REFERENCES edge,
channel_id INTEGER NOT NULL REFERENCES channel,
type INTEGER NOT NULL,
available_since TIMESTAMPTZ
);
""";
}

private String createEdgeChannelIndex() {
Expand Down Expand Up @@ -177,132 +185,140 @@ private String addContinuousAggregate(Type type, Priority priority) {
}

private String createFunctionGetOrCreateEdgeId() {
return "CREATE OR REPLACE FUNCTION openems_get_or_create_edge_id(\n" //
+ " _edge text,\n" //
+ " OUT _edge_id int\n" //
+ ") LANGUAGE plpgsql AS \n" + "$$\n" //
+ "BEGIN\n" //
+ " LOOP\n" //
+ " SELECT id\n" //
+ " FROM edge\n" //
+ " WHERE edge.name = _edge\n" //
+ " INTO _edge_id;\n" //
+ "\n" //
+ " EXIT WHEN FOUND;\n" //
+ "\n" //
+ " INSERT INTO edge (name)\n" //
+ " VALUES (_edge)\n" //
+ " ON CONFLICT DO NOTHING\n" //
+ " RETURNING id\n" //
+ " INTO _edge_id;\n" //
+ "\n" //
+ " EXIT WHEN FOUND;\n" //
+ " END LOOP;\n" //
+ "END;\n" //
+ "$$;\n\n";
return """
CREATE OR REPLACE FUNCTION openems_get_or_create_edge_id(
_edge text,
OUT _edge_id int
) LANGUAGE plpgsql AS
$$
BEGIN
LOOP
SELECT id
FROM edge
WHERE edge.name = _edge
INTO _edge_id;
EXIT WHEN FOUND;
INSERT INTO edge (name)
VALUES (_edge)
ON CONFLICT DO NOTHING
RETURNING id
INTO _edge_id;
EXIT WHEN FOUND;
END LOOP;
END;
$$;
""";
}

private String createFunctionGetOrCreateComponentId() {
return "CREATE OR REPLACE FUNCTION openems_get_or_create_component_id(\n" //
+ " _component text, \n" //
+ " OUT _component_id int\n" //
+ ") LANGUAGE plpgsql AS \n" //
+ "$$\n" //
+ "BEGIN \n" //
+ " loop\n" //
+ " SELECT component.id\n" //
+ " FROM component\n" //
+ " WHERE component.name = _component\n" //
+ " INTO _component_id; \n" //
+ "\n" //
+ " EXIT WHEN FOUND;\n" //
+ "\n" //
+ " INSERT INTO component (name)\n" //
+ " VALUES (_component) \n" //
+ " ON CONFLICT DO nothing\n" //
+ " RETURNING id INTO _component_id;\n" //
+ "\n" //
+ " EXIT WHEN FOUND;\n" //
+ " END LOOP;\n" //
+ "END;\n" //
+ "$$;\n\n";
return """
CREATE OR REPLACE FUNCTION openems_get_or_create_component_id(
_component text,
OUT _component_id int
) LANGUAGE plpgsql AS\
$$
BEGIN
loop
SELECT component.id
FROM component
WHERE component.name = _component
INTO _component_id;
EXIT WHEN FOUND;
INSERT INTO component (name)
VALUES (_component)
ON CONFLICT DO nothing
RETURNING id INTO _component_id;
EXIT WHEN FOUND;
END LOOP;
END;
$$;
""";
}

private String createFunctionGetOrCreateChannelId() {
return "CREATE OR REPLACE FUNCTION openems_get_or_create_channel_id(\n" //
+ " _component text,\n" //
+ " _channel text,\n" //
+ " OUT _channel_id int,\n" //
+ " OUT _priority int\n" //
+ ") LANGUAGE plpgsql AS \n" //
+ "$$ \n" //
+ "BEGIN\n" //
+ " LOOP\n" //
+ " SELECT channel.id, channel.priority\n" //
+ " FROM channel\n" //
+ " LEFT JOIN component\n" //
+ " ON channel.component_id = component.id \n" //
+ " WHERE component.name = _component AND channel.name = _channel\n" //
+ " INTO _channel_id, _priority;\n" //
+ "\n" //
+ " EXIT WHEN FOUND;\n" //
+ "\n" //
+ " INSERT INTO channel (component_id, name, priority)\n" //
+ " VALUES ((SELECT _component_id FROM openems_get_or_create_component_id(_component)), _channel, "
+ Priority.LOW.getId() + "" + ")\n" //
+ " ON CONFLICT DO NOTHING\n" //
+ " RETURNING id, priority\n" //
+ " INTO _channel_id, _priority;\n" //
+ "\n" //
+ " EXIT WHEN FOUND;\n" //
+ " END LOOP;\n" //
+ "END;\n" //
+ "$$;\n\n";
return """
CREATE OR REPLACE FUNCTION openems_get_or_create_channel_id(
_component text,
_channel text,
OUT _channel_id int,
OUT _priority int
) LANGUAGE plpgsql AS
$$
BEGIN
LOOP
SELECT channel.id, channel.priority
FROM channel
LEFT JOIN component
ON channel.component_id = component.id
WHERE component.name = _component AND channel.name = _channel
INTO _channel_id, _priority;
EXIT WHEN FOUND;
INSERT INTO channel (component_id, name, priority)
VALUES ((SELECT _component_id FROM openems_get_or_create_component_id(_component)), _channel,
""" + Priority.LOW.getId() + "" + ")" + """
ON CONFLICT DO NOTHING
RETURNING id, priority
INTO _channel_id, _priority;
EXIT WHEN FOUND;
END LOOP;
END;
$$;
""";
}

private String createFunctionGetOrCreateEdgeChannelId() {
return "CREATE OR REPLACE FUNCTION openems_get_or_create_edge_channel_id(\n" //
+ " _edge text,\n" //
+ " _component text,\n" //
+ " _channel text,\n" //
+ " _type int,\n" //
+ " OUT _channel_id int,\n" //
+ " OUT _channel_type int,\n" //
+ " OUT _priority int,\n" //
+ " OUT _available_since TIMESTAMPTZ\n" //
+ ") LANGUAGE plpgsql AS \n" //
+ "$$ \n" //
+ "BEGIN\n" //
+ " LOOP\n" //
+ " SELECT edge_channel.id, edge_channel.type, channel.priority, edge_channel.available_since\n" //
+ " FROM edge_channel\n" //
+ " LEFT JOIN edge\n" //
+ " ON edge_channel.edge_id = edge.id \n" //
+ " LEFT JOIN channel\n" //
+ " ON edge_channel.channel_id = channel.id\n" //
+ " LEFT JOIN component\n" //
+ " ON channel.component_id = component.id \n" //
+ " WHERE edge.name = _edge AND component.name = _component AND channel.name = _channel\n" //
+ " INTO _channel_id, _channel_type, _priority, _available_since;\n" //
+ "\n" //
+ " EXIT WHEN FOUND;\n" //
+ "\n" //
+ " SELECT c._channel_id, c._priority\n" //
+ " FROM openems_get_or_create_channel_id(_component, _channel) c\n" //
+ " INTO _channel_id, _priority;\n" //
+ "\n" //
+ " INSERT INTO edge_channel (edge_id, channel_id, type, available_since)\n" //
+ " VALUES ((SELECT _edge_id FROM openems_get_or_create_edge_id(_edge)),\n" //
+ " _channel_id,\n" //
+ " _type,\n" //
+ " now())\n" //
+ " ON CONFLICT DO NOTHING\n" //
+ " RETURNING id, type\n" //
+ " INTO _channel_id, _channel_type;\n" //
+ "\n" //
+ " EXIT WHEN FOUND;\n" //
+ " END LOOP;\n" //
+ "END;\n" //
+ "$$;\n\n";
return """
CREATE OR REPLACE FUNCTION openems_get_or_create_edge_channel_id(
_edge text,
_component text,
_channel text,
_type int,
OUT _channel_id int,
OUT _channel_type int,
OUT _priority int,
OUT _available_since TIMESTAMPTZ
) LANGUAGE plpgsql AS\s
$$\s
BEGIN
LOOP
SELECT edge_channel.id, edge_channel.type, channel.priority, edge_channel.available_since
FROM edge_channel
LEFT JOIN edge
ON edge_channel.edge_id = edge.id\s
LEFT JOIN channel
ON edge_channel.channel_id = channel.id
LEFT JOIN component
ON channel.component_id = component.id\s
WHERE edge.name = _edge AND component.name = _component AND channel.name = _channel
INTO _channel_id, _channel_type, _priority, _available_since;
EXIT WHEN FOUND;
SELECT c._channel_id, c._priority
FROM openems_get_or_create_channel_id(_component, _channel) c
INTO _channel_id, _priority;
INSERT INTO edge_channel (edge_id, channel_id, type, available_since)
VALUES ((SELECT _edge_id FROM openems_get_or_create_edge_id(_edge)),
_channel_id,
_type,
now())
ON CONFLICT DO NOTHING
RETURNING id, type
INTO _channel_id, _channel_type;
EXIT WHEN FOUND;
END LOOP;
END;
$$;
""";
}
}
Loading

0 comments on commit 1348b07

Please sign in to comment.