List of usage examples for org.hibernate.boot Metadata collectTableMappings
java.util.Collection<Table> collectTableMappings();
From source file:com.evolveum.midpoint.repo.sql.schemacheck.SchemaChecker.java
License:Apache License
private boolean areSomeTablesPresent(Metadata metadata) { Collection<String> presentTables = new ArrayList<>(); Collection<String> missingTables = new ArrayList<>(); for (Table table : metadata.collectTableMappings()) { String tableName = table.getName(); try (Session session = baseHelper.beginReadOnlyTransaction()) { List<?> result = session.createNativeQuery("select count(*) from " + tableName).list(); LOGGER.debug("Table {} seems to be present; number of records is {}", tableName, result); presentTables.add(tableName); } catch (Throwable t) { LOGGER.debug("Table {} seems to be missing: {}", tableName, t.getMessage(), t); missingTables.add(tableName); }//from www . j av a 2s .co m } LOGGER.info("The following midPoint tables are present (not necessarily well-defined): {}", presentTables); LOGGER.info("Couldn't find the following midPoint tables: {}", missingTables); return !presentTables.isEmpty(); }