Added a search function by the name of the table to which you need to add a MapStore

This commit is contained in:
psemenkov 2022-09-28 18:02:14 +03:00
parent 7a2fbe5b79
commit b7ae9b69bc

View file

@ -6,6 +6,17 @@ import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import ru.spcex.clearing.imdg.base.BusinessObjectMapStore;
import ru.spcex.clearing.imdg.base.DictionaryMapStore;
import ru.spcex.clearing.imdg.base.TemplateEventMapStore;
import ru.spcex.clearing.imdg.base.TemplateMapStore;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
@SpringBootApplication
public class IMDGApplication {
@ -14,12 +25,35 @@ public class IMDGApplication {
try {
SpringApplicationBuilder builder = new SpringApplicationBuilder(IMDGApplication.class);
ConfigurableApplicationContext configurableApplicationContext = builder.run(args);
List<String> nameTables = new ArrayList<>();
Connection jdbcConnection = DriverManager.getConnection("jdbc:postgresql://10.200.200.133:5432/postgres", "clearing", "Aa111111");
DatabaseMetaData md = jdbcConnection.getMetaData();
ResultSet rs = md.getTables(null, "clearing", "%", new String[]{"TABLE"});
while (rs.next()) {
nameTables.add(rs.getString(3));
}
HazelcastInstance hazelcastInstance = configurableApplicationContext.getBean(HazelcastInstance.class);
hazelcastInstance.getMap("");
for (String mapName : hazelcastInstance.getConfig().getMapConfigs().keySet()) {
MapStoreConfig mapStoreConfig = hazelcastInstance.getConfig().getMapConfig(mapName).getMapStoreConfig();
Object mapStore = mapStoreConfig.getImplementation();
String tableName = mapStore == null ? "Не получилось сопоставить mapStore: is null" : "Не получилось сопоставить: " + mapStore.getClass() + " с таблицей";
if (mapStore instanceof TemplateMapStore) {
tableName = ((TemplateMapStore<?>) mapStore).getTableName();
} else if (mapStore instanceof DictionaryMapStore) {
tableName = ((DictionaryMapStore<?>) mapStore).getTableName();
} else if (mapStore instanceof TemplateEventMapStore) {
tableName = ((TemplateEventMapStore<?>) mapStore).getTableName();
} else if (mapStore instanceof BusinessObjectMapStore) {
tableName = ((BusinessObjectMapStore<?>) mapStore).getTableName();
} else if (mapName.equals("default")) {
continue;
}
nameTables.remove(tableName.toLowerCase());
}
nameTables.forEach(System.out::println);
} catch (Throwable e) {
LoggerFactory.getLogger(IMDGApplication.class).error("STORAGE start failed: {} -> {}", e.getClass().getSimpleName(), e.getMessage());