@Override public void existingTableDetected( Connection connection, Table table, Model model, Database database) throws SQLException { if (Model.ANCESTORS_TABLE_NAME.equals(table.getKey())) { if (!pathOptimizationsEnabled) { log.info("Path optimizations disabled"); return; } // check if we want to initialize the descendants table now, or log // a warning if the hierarchy table is too big String sql = "SELECT id FROM ancestors LIMIT 1"; Statement s = connection.createStatement(); ResultSet rs = s.executeQuery(sql); boolean empty = !rs.next(); rs.close(); s.close(); if (empty) { pathOptimizationsEnabled = false; log.error( "Table ANCESTORS empty, must be upgraded by hand by calling: " + "SELECT nx_init_ancestors()"); log.info("Path optimizations disabled"); } } }
@Override public List<String> getPostCreateTableSqls(Table table, Model model, Database database) { if (Model.ANCESTORS_TABLE_NAME.equals(table.getKey())) { List<String> sqls = new ArrayList<String>(); if (pathOptimizationsEnabled) { sqls.add("SELECT nx_init_ancestors()"); } else { log.info("Path optimizations disabled"); } return sqls; } return Collections.emptyList(); }