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.

59 lines
1.7 KiB

7 years ago
  1. package hsfulda.de;
  2. import java.sql.Connection;
  3. import java.sql.SQLException;
  4. import java.sql.Statement;
  5. import java.util.HashMap;
  6. public class FedStatement implements FedStatementInterface {
  7. private FedConnection fedConnection;
  8. private HashMap<Integer, Statement> statements = new HashMap<Integer, Statement>();
  9. public FedStatement(FedConnection fedConnection) {
  10. this.fedConnection = fedConnection;
  11. }
  12. public int executeUpdate(String sql) throws FedException {
  13. int count = 0;
  14. String cleanSql = sql.replaceAll("HORIZONTAL\\ \\([^(]*\\([^)]*\\)\\)", "");
  15. try {
  16. for (Integer i : fedConnection.connections.keySet()) {
  17. Connection connection = fedConnection.connections.get(i);
  18. Statement statement = connection.createStatement();
  19. statements.put(i, statement);
  20. count += statement.executeUpdate(cleanSql);
  21. }
  22. return count;
  23. } catch (SQLException e) {
  24. throw new FedException(e);
  25. }
  26. }
  27. public FedResultSet executeQuery(String sql) throws FedException {
  28. FedResultSet fedResultSet = new FedResultSet(this);
  29. try {
  30. for (Integer i : fedConnection.connections.keySet()) {
  31. Connection connection = fedConnection.connections.get(i);
  32. Statement statement = connection.createStatement();
  33. statements.put(i, statement);
  34. fedResultSet.setResultSet(i, statement.executeQuery(sql));
  35. }
  36. return fedResultSet;
  37. } catch (SQLException e) {
  38. throw new FedException(e);
  39. }
  40. }
  41. public void close() throws FedException {
  42. try {
  43. for (Object i : statements.keySet()) {
  44. statements.get(i).close();
  45. }
  46. } catch (SQLException e) {
  47. throw new FedException(e);
  48. }
  49. }
  50. public FedConnection getConnection() throws FedException {
  51. return fedConnection;
  52. }
  53. }