TeslaCN commented on code in PR #2184:
URL:
https://github.com/apache/shardingsphere-elasticjob/pull/2184#discussion_r1136462977
##########
elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBJobEventStorage.java:
##########
@@ -55,26 +58,63 @@ public final class RDBJobEventStorage {
private static final String TASK_ID_STATE_INDEX = "TASK_ID_STATE_INDEX";
private static final Map<String, DatabaseType> DATABASE_TYPES = new
HashMap<>();
-
+
+ private static final Map<DataSource, RDBJobEventStorage> STORAGE_MAP = new
ConcurrentHashMap<>();
+
private final DataSource dataSource;
-
+
private final DatabaseType databaseType;
-
+
private final RDBStorageSQLMapper sqlMapper;
-
+
static {
for (DatabaseType each : ServiceLoader.load(DatabaseType.class)) {
DATABASE_TYPES.put(each.getType(), each);
}
}
-
- public RDBJobEventStorage(final DataSource dataSource) throws SQLException
{
+
+ private RDBJobEventStorage(final DataSource dataSource) throws
SQLException {
this.dataSource = dataSource;
databaseType = getDatabaseType(dataSource);
sqlMapper = new
RDBStorageSQLMapper(databaseType.getSQLPropertiesFile());
initTablesAndIndexes();
}
-
+
+ /**
+ * the same dataSource always return the same RDBJobEventStorage instance.
+ *
+ * @param dataSource dataSource
+ * @return RDBJobEventStorage instance
+ * @throws SQLException SQLException
+ */
+ public static RDBJobEventStorage getInstance(final DataSource dataSource)
throws SQLException {
+ return wrapException(() -> STORAGE_MAP.computeIfAbsent(dataSource, ds
-> {
+ try {
+ return new RDBJobEventStorage(ds);
+ } catch (SQLException e) {
+ throw new WrapException(e);
+ }
+ }));
+ }
+
+ /**
+ * wrapException util method.
Review Comment:
```suggestion
* WrapException util method.
```
##########
elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBJobEventStorage.java:
##########
@@ -55,26 +58,63 @@ public final class RDBJobEventStorage {
private static final String TASK_ID_STATE_INDEX = "TASK_ID_STATE_INDEX";
private static final Map<String, DatabaseType> DATABASE_TYPES = new
HashMap<>();
-
+
+ private static final Map<DataSource, RDBJobEventStorage> STORAGE_MAP = new
ConcurrentHashMap<>();
+
private final DataSource dataSource;
-
+
private final DatabaseType databaseType;
-
+
private final RDBStorageSQLMapper sqlMapper;
-
+
static {
for (DatabaseType each : ServiceLoader.load(DatabaseType.class)) {
DATABASE_TYPES.put(each.getType(), each);
}
}
-
- public RDBJobEventStorage(final DataSource dataSource) throws SQLException
{
+
+ private RDBJobEventStorage(final DataSource dataSource) throws
SQLException {
this.dataSource = dataSource;
databaseType = getDatabaseType(dataSource);
sqlMapper = new
RDBStorageSQLMapper(databaseType.getSQLPropertiesFile());
initTablesAndIndexes();
}
-
+
+ /**
+ * the same dataSource always return the same RDBJobEventStorage instance.
Review Comment:
```suggestion
* The same dataSource always return the same RDBJobEventStorage
instance.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]