/** {@inheritDoc} */ protected IDataSet fromResource(Resource resource, DataSetFormatOptions options) throws DataSetException, IOException { FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder(); builder.setColumnSensing(options.isColumnSensing()); builder.setDtdMetadata(options.isDtdMetadata()); builder.setCaseSensitiveTableNames(options.isCaseSensitiveTableNames()); if (StringUtils.hasText(options.getDtdLocation())) { IDataSet metaDataSet = FLAT_DTD.loadUnique(null, options.getDtdLocation()); builder.setMetaDataSet(metaDataSet); } return builder.build(resource.getInputStream()); }
public static void reload() throws Exception { if (dbReloaded) { return; } Connection jdbcConn = null; IDatabaseConnection dbunitConn = null; try { jdbcConn = DriverManager.getConnection(URL, USERNAME, PASSWORD); boolean caseSensitiveTableNames = false; if (URL.contains("postgres")) { dbunitConn = new DatabaseConnection(jdbcConn, SCHEMA); dbunitConn .getConfig() .setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new PostgresqlDataTypeFactory()); caseSensitiveTableNames = true; } else if (URL.contains("mysql")) { dbunitConn = new MySqlConnection(jdbcConn, null); if (System.getProperty("os.name").contains("Linux")) { caseSensitiveTableNames = true; } } // else if (URL.contains("oracle")) { // dbunitConn = new OracleConnection(jdbcConn, SCHEMA); // } // else if (URL.contains("sqlserver")) { // dbunitConn = new MsSqlConnection(jdbcConn, SCHEMA); // } // else if (URL.contains("db2")) { // dbunitConn = new Db2Connection(jdbcConn, SCHEMA); // if (System.getProperty("os.name").contains("Linux")) { // caseSensitiveTableNames = true; // } // } else { throw new IllegalStateException("Die Datenbank-URL " + URL + " wird nicht unterstuetzt"); } final ClassLoader cl = Thread.currentThread().getContextClassLoader(); final FlatXmlDataSetBuilder flatXmlDataSetBuilder = new FlatXmlDataSetBuilder(); flatXmlDataSetBuilder.setCaseSensitiveTableNames(caseSensitiveTableNames); FlatXmlDataSet xmlDataset = flatXmlDataSetBuilder.build(cl.getResource(XML_FLAT_DATASET)); DatabaseOperation dbOp = CLEAN_INSERT; // if (URL != null && URL.contains("sqlserver")) { // // Fuer SQL Server ist ein spezieller INSERT-Modus notwendig, // // damit IDENTITY-Spalten eingefuegt werden koennen // dbOp = InsertIdentityOperation.CLEAN_INSERT; // } dbOp.execute(dbunitConn, xmlDataset); } finally { if (dbunitConn != null) dbunitConn.close(); if (jdbcConn != null) jdbcConn.close(); } dbReloaded = true; System.out.println("Die Datenbank " + URL + " wurde neu geladen"); }