/** * Loads the table names from the specified dataset XML resource and uses it as a template * of how to case any table name that will be exported. * <p> * Note that calling this method doesn't actually ADD a table. * @param resourcePath Resource path to dataset XML * @return ExportBuilder to allow for chaining */ public ExportBuilder setTableNamesCasingByDataSet(String resourcePath) { try { this.exportItems.setCasedTableNames(new XPathGetter(XmlUtils.loadXml( JuUrl.resource().relativeTo(DbDataUtil.class).get(resourcePath))).getNodeNames("dataset/*")); } catch (Exception ex) { throw new JuDbException("Couldn't load table names data set " + resourcePath, ex); } return this; }
/** * Adds the data of the tables contained in the specified data set. * <p> * It doesn't matter what kind of dataset we got, we're just extracting the table names. * @param resourceUrl * @param sortedByPrimaryKey If true, the entries will be sorted by primary key * @return ExportBuilder to allow for chaining */ public ExportBuilder addTablesByDataSet(URL resourceUrl, boolean sortedByPrimaryKey) { try { Set<String> tableNames = JuCollectionUtils.asSameOrderSet(new XPathGetter(XmlUtils.loadXml(resourceUrl)).getNodeNames("dataset/*")); for (String tableName : tableNames) { if (sortedByPrimaryKey) { this.addTableSorted(tableName); } else { this.addTable(tableName); } } return this; } catch (Exception ex) { throw new JuDbException("Couldn't add tables by dataset " + resourceUrl, ex); } }
@Test public void canGetNodeNames() throws Exception { XPathGetter xg = XmlUtils.loadXmlAsXPathGetter(JuUrl.resource().relativeTo(XPathGetterTest.class).get("simple.xml")); List<String> nodeNames = xg.getNodeNames("root/element/*"); TestUtils.assertCollectionEquals(nodeNames, "childElement", "childElement", "textElement"); } }