You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.1 KiB

7 years ago
  1. package hsfulda.de;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5. import java.util.HashMap;
  6. public class FedConnection implements FedConnectionInterface {
  7. HashMap<Integer, Connection> connections = new HashMap<Integer, Connection>();
  8. String connectionStrings[] = {
  9. "jdbc:oracle:thin:@pinatubo.informatik.hs-fulda.de:1521:ORALV8A",
  10. "jdbc:oracle:thin:@mtsthelens.informatik.hs-fulda.de:1521:ORALV9A",
  11. "jdbc:oracle:thin:@krakatau.informatik.hs-fulda.de:1521:ORALV10A" };
  12. public FedConnection(String username, String password) throws FedException {
  13. try {
  14. DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
  15. for (int i = 0; i < connectionStrings.length; i++) {
  16. connections.put(i, DriverManager.getConnection(connectionStrings[i], username, password));
  17. }
  18. } catch (SQLException sqlException) {
  19. throw new FedException(sqlException);
  20. }
  21. }
  22. public void setAutoCommit(boolean autoCommit) throws FedException {
  23. try {
  24. for (Object i : connections.keySet()) {
  25. connections.get(i).setAutoCommit(autoCommit);
  26. }
  27. } catch (SQLException sqlException) {
  28. throw new FedException(sqlException);
  29. }
  30. }
  31. public boolean getAutoCommit() throws FedException {
  32. boolean autoCommit = false;
  33. try {
  34. autoCommit = connections.get(0).getAutoCommit();
  35. } catch (SQLException sqlException) {
  36. throw new FedException(sqlException);
  37. }
  38. return autoCommit;
  39. }
  40. public void commit() throws FedException {
  41. try {
  42. for (Object i : connections.keySet()) {
  43. connections.get(i).commit();
  44. }
  45. } catch (SQLException sqlException) {
  46. throw new FedException(sqlException);
  47. }
  48. }
  49. public void rollback() throws FedException {
  50. try {
  51. for (Object i : connections.keySet()) {
  52. connections.get(i).rollback();
  53. }
  54. } catch (SQLException sqlException) {
  55. throw new FedException(sqlException);
  56. }
  57. }
  58. public void close() throws FedException {
  59. try {
  60. for (Object i : connections.keySet()) {
  61. connections.get(i).close();
  62. }
  63. } catch (SQLException sqlException) {
  64. throw new FedException(sqlException);
  65. }
  66. }
  67. public FedStatement getStatement() {
  68. return new FedStatement(this);
  69. }
  70. }