Skip to content

Instantly share code, notes, and snippets.

@handersonbf
Created September 19, 2012 18:50
Show Gist options
  • Select an option

  • Save handersonbf/3751455 to your computer and use it in GitHub Desktop.

Select an option

Save handersonbf/3751455 to your computer and use it in GitHub Desktop.
DbUnitManagerFactory.java
package base.dbunit;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
@Component
public class DbUnitManagerFactory {
DataSource dataSource;
@Autowired
public DbUnitManagerFactory(DataSource dataSource) {
this.dataSource = dataSource;
}
@Bean
public DbUnitManager getDbUnitManager() {
boolean oracle = isOracleDataBase();
if (oracle)
return new DbUnitManagerOracle(dataSource);
return new DbUnitManagerMSSqlServer(dataSource);
}
private boolean isOracleDataBase() {
try {
DatabaseMetaData metadata = dataSource.getConnection().getMetaData();
String databaseName = metadata.getDatabaseProductName().toLowerCase();
return databaseName.contains("oracle");
} catch (SQLException e) {
throw new IllegalStateException("Impossível descobrir informações sobre o banco de dados.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment