Skip to content

Commit 802d4d2

Browse files
committed
fixing Sonarqube
1 parent 62564e2 commit 802d4d2

File tree

4 files changed

+18
-45
lines changed

4 files changed

+18
-45
lines changed

src/main/java/edu/ie3/datamodel/io/SqlUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public class SqlUtils {
1313

1414
protected static final Logger log = LoggerFactory.getLogger(SqlUtils.class);
15-
private static final String endQueryCreateTable =
15+
private static final String END_QUERY_CREATE_TABLE =
1616
")\n \t WITHOUT OIDS\n \t TABLESPACE pg_default;";
1717

1818
private SqlUtils() {
@@ -27,7 +27,7 @@ private static String beginQueryCreateTable(String schemaName, String tableName)
2727
public static String queryCreateGridTable(String schemaName) {
2828
return beginQueryCreateTable(schemaName, DbGridMetadata.GRID_TABLE_COLUMN)
2929
+ "\tuuid uuid PRIMARY KEY,\n\tname TEXT NOT NULL\n"
30-
+ endQueryCreateTable;
30+
+ END_QUERY_CREATE_TABLE;
3131
}
3232

3333
/**

src/main/java/edu/ie3/datamodel/io/connectors/SqlConnector.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -160,28 +160,4 @@ public Map<String, String> extractFieldMap(ResultSet rs) {
160160
}
161161
return insensitiveFieldsToAttributes;
162162
}
163-
164-
/**
165-
* Executes a query to check if a table exists
166-
*
167-
* @param tableName Name of the table, that should be checked
168-
* @return True, if the table exists
169-
*/
170-
public boolean tableExistsSQL(String tableName) {
171-
String query =
172-
"SELECT count(*) "
173-
+ "FROM information_schema.tables "
174-
+ "WHERE table_name = ?"
175-
+ "LIMIT 1;";
176-
try (PreparedStatement ps = getConnection().prepareStatement(query)) {
177-
ps.setString(1, tableName);
178-
179-
ResultSet resultSet = ps.executeQuery();
180-
resultSet.next();
181-
return resultSet.getInt(1) != 0;
182-
} catch (SQLException e) {
183-
log.error("Error during execution of query {}", query, e);
184-
}
185-
return false;
186-
}
187163
}

src/main/java/edu/ie3/datamodel/io/sink/SqlSink.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,7 @@ private <C extends Entity, E extends TimeSeriesEntry<V>, V extends Value> void p
193193
} else if (ResultEntity.class.isAssignableFrom(cls)) {
194194
insertListIgnoreNested(entities, cls, identifier, false);
195195
} else if (TimeSeries.class.isAssignableFrom(cls)) {
196-
entities.forEach(
197-
ts -> {
198-
persistTimeSeries((TimeSeries<E, V>) ts, identifier);
199-
});
196+
entities.forEach(ts -> persistTimeSeries((TimeSeries<E, V>) ts, identifier));
200197
} else {
201198
log.error("I don't know how to handle an entity of class {}", cls.getSimpleName());
202199
}
@@ -262,20 +259,24 @@ private <E extends TimeSeriesEntry<V>, V extends Value> void persistTimeSeries(
262259
identifier,
263260
timeSeries.getUuid().toString()))
264261
.collect(Collectors.joining(",\n", "", ";"));
265-
try {
266-
connector.executeUpdate(query);
267-
} catch (SQLException e) {
268-
throw new RuntimeException(
269-
String.format(
270-
"An error occurred during extraction of the time series, SQLReason: '%s'",
271-
e.getMessage()),
272-
e);
273-
}
262+
executeQueryToPersist(query);
274263
} catch (ProcessorProviderException e) {
275264
throw new ProcessorProviderException("Exception occurred during processor request: ", e);
276265
}
277266
}
278267

268+
private void executeQueryToPersist(String query) {
269+
try {
270+
connector.executeUpdate(query);
271+
} catch (SQLException e) {
272+
throw new RuntimeException(
273+
String.format(
274+
"An error occurred during extraction of the time series, SQLReason: '%s'",
275+
e.getMessage()),
276+
e);
277+
}
278+
}
279+
279280
/** Persists a whole {@link JointGridContainer}. */
280281
public void persistJointGrid(JointGridContainer jointGridContainer, UUID gridUUID) {
281282
DbGridMetadata identifier = new DbGridMetadata(jointGridContainer.getGridName(), gridUUID);
@@ -427,13 +428,13 @@ private String queryTimeSeriesValueLine(
427428
Map<String, String> entityFieldData,
428429
String[] headerElements,
429430
DbGridMetadata identifier,
430-
String TSuuid) {
431+
String tsUuid) {
431432
return writeOneLine(
432433
Stream.concat(
433434
Stream.concat(
434435
Arrays.stream(headerElements).map(entityFieldData::get),
435436
identifier.getStreamForQuery()),
436-
Stream.of(quote(TSuuid, "'"))));
437+
Stream.of(quote(tsUuid, "'"))));
437438
}
438439

439440
private LinkedHashMap<String, String> sqlEntityFieldData(

src/main/java/edu/ie3/datamodel/io/source/sql/SqlDataSource.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,4 @@ protected Stream<Map<String, String>> executeQuery(String query, AddParams addPa
190190
protected Stream<Map<String, String>> executeQuery(String query) {
191191
return executeQuery(query, x -> {});
192192
}
193-
194-
public boolean checkExistingTable(String tableName) throws SQLException {
195-
return connector.tableExistsSQL(tableName);
196-
}
197193
}

0 commit comments

Comments
 (0)