/** * Print the contents of the given tableName to system.out<br> * <br> * Call this from any {@link BaseContextSensitiveTest} child by: * TestUtil.printOutTableContents(getConnection(), "encounter"); * * @param sqlConnection the connection to use * @param tableNames the name(s) of the table(s) to print out * @throws Exception */ public static void printOutTableContents(Connection sqlConnection, String... tableNames) throws Exception { for (String tableName : tableNames) { System.out.println("The contents of table: " + tableName); IDatabaseConnection connection = new DatabaseConnection(sqlConnection); DatabaseConfig config = connection.getConfig(); config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory()); QueryDataSet outputSet = new QueryDataSet(connection); outputSet.addTable(tableName); FlatXmlDataSet.write(outputSet, System.out); } }
private IDataSet dbUnitDataSet(InputStream stream) { try { ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(stream)); dataSet.addReplacementObject("[null]", null); dataSet.addReplacementObject("[false]", Boolean.FALSE); dataSet.addReplacementObject("[true]", Boolean.TRUE); return dataSet; } catch (Exception e) { throw translateException("Could not read the dataset stream", e); } }
@Test @SkipBaseSetup public void createConceptDictionaryDataSet() throws Exception { IDatabaseConnection connection = new DatabaseConnection(getConnection()); DatabaseConfig config = connection.getConfig(); config.setProperty(DatabaseConfig.PROPERTY_RESULTSET_TABLE_FACTORY, new ForwardOnlyResultSetTableFactory()); String[] tableNames = new String[] { "concept_class", "concept_datatype", "concept_map_type", "concept_reference_source", "concept", "concept_numeric", "concept_description", "concept_name", "concept_reference_term", "concept_reference_map", "concept_reference_term_map", "concept_set", "concept_complex", "concept_answer", "concept_stop_word" }; IDataSet dataSet = connection.createDataSet(tableNames); FlatXmlDataSet.write(dataSet, new FileOutputStream("target/conceptDictionaryDataSet.xml")); } }
public void executeDataset(String path) throws IOException, SQLException { InputStream inputStream = getClass().getResourceAsStream(path); ReplacementDataSet replacementDataSet; try { replacementDataSet = new ReplacementDataSet(new FlatXmlDataSet(new InputStreamReader(inputStream), false, true, false)); inputStream.close(); } catch (DataSetException e) { throw new IOException(e); } finally { IOUtils.closeQuietly(inputStream); } replacementDataSet.addReplacementObject("[NULL]", null); try { DatabaseOperation.REFRESH.execute(dbUnitConnection, replacementDataSet); connection.commit(); } catch (DatabaseUnitException e) { throw new IOException(e); } }
public static void exportDataSet(IDataSet dataSet, String fileName) throws DataSetException, FileNotFoundException, IOException { FlatXmlDataSet.write(dataSet, new FileOutputStream(fileName)); }
new FlatXmlDataSet(reader, false, true, false)); replacementDataSet.addReplacementObject("[NULL]", null); xmlDataSetToRun = replacementDataSet;
public void exportDbUnitDataSetToFile(IDataSet dataset, File file) throws IOException, DataSetException { FlatXmlDataSet.write( dataset, new FileOutputStream(file)); } }
ps.close(); IDataSet dataset = new FlatXmlDataSet(fileOrDirectoryStream);
private DataDump createDataDump(final String path, final IDataSet dbContent) throws IOException, DataSetException { StringWriter stringWriter = new StringWriter(); FlatXmlDataSet.write(dbContent, stringWriter); DataDump dumpData = new DataDump(stringWriter.toString(), path); stringWriter.close(); return dumpData; }
DatabaseOperation.CLEAN_INSERT.execute(conn, new FlatXmlDataSet(new File(file)));
private DataDump createDataDump(final String path, final IDataSet dbContent) throws IOException, DataSetException { StringWriter stringWriter = new StringWriter(); FlatXmlDataSet.write(dbContent, stringWriter); DataDump dumpData = new DataDump(stringWriter.toString(), path); stringWriter.close(); return dumpData; }
InputStream is = this.getClass().getClassLoader().getResourceAsStream("input.xml") if(is != null) loadedDataSet = new FlatXmlDataSet(is); else System.out.println("Can't find input.xml :(");
private DataDump createDataDump(final String path, final IDataSet dbContent) throws IOException, DataSetException { StringWriter stringWriter = new StringWriter(); FlatXmlDataSet.write(dbContent, stringWriter); DataDump dumpData = new DataDump(stringWriter.toString(), path); stringWriter.close(); return dumpData; }
loadedDataSet = new FlatXmlDataSet(this.getClass().getClassLoader().getResourceAsStream("input.xml"));
private DataDump createDataDump(final String path, final IDataSet dbContent) throws IOException, DataSetException { StringWriter stringWriter = new StringWriter(); FlatXmlDataSet.write(dbContent, stringWriter); DataDump dumpData = new DataDump(stringWriter.toString(), path); stringWriter.close(); return dumpData; }
protected IDataSet getFlatXmlDataSetFromRawResrouce(int id) throws DataSetException { InputStream in = getContext().getResources().openRawResource(id); FlatXmlProducer producer = new FlatXmlProducer(new InputSource(in), false); return new FlatXmlDataSet(producer); }
/** * Converts the supplied dataSet to a FlatXmlDataSet which, in turn, is written to a String. * * @param dataSet The IDataSet to convert. * @return The string representation of the supplied IDataSet. */ protected final String extractFlatXmlDataSet(@NotNull final IDataSet dataSet) { // Check sanity Validate.notNull(dataSet, "dataset"); // Convert and return. final StringWriter out = new StringWriter(); try { FlatXmlDataSet.write(dataSet, out); } catch (Exception e) { throw new IllegalArgumentException("Could not write FlatXmlDataSet.", e); } // All done. return out.toString(); }
protected IDataSet getFlatXmlDataSetFromRawResrouce(int id) throws DataSetException { InputStream in = getContext().getResources().openRawResource(id); FlatXmlProducer producer = new FlatXmlProducer(new InputSource(in), false); return new FlatXmlDataSet(producer); }
public static void logDb(IDatabaseConnection connection) { try { ITableFilter filter = new DatabaseSequenceFilter(connection); IDataSet dataset = new FilteredDataSet(filter, connection.createDataSet()); StringWriter out = new StringWriter(); FlatXmlDataSet.write(dataset, out); log.info(out.getBuffer().toString()); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
protected IDataSet getDataSet() throws Exception { ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(this.getClass().getClassLoader() .getResourceAsStream(getDataSetFile()))); dataSet.addReplacementObject("[NULL]", null); return dataSet; }