package hsfulda.de; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import java.util.HashMap; public class FedStatement implements FedStatementInterface { private FedConnection fedConnection; private HashMap statements = new HashMap(); public FedStatement(FedConnection fedConnection) { this.fedConnection = fedConnection; } public int executeUpdate(String sql) throws FedException { int count = 0; String cleanSql = sql.replaceAll("HORIZONTAL\\ \\([^(]*\\([^)]*\\)\\)", ""); try { for (Integer i : fedConnection.connections.keySet()) { Connection connection = fedConnection.connections.get(i); Statement statement = connection.createStatement(); statements.put(i, statement); count += statement.executeUpdate(cleanSql); } return count; } catch (SQLException e) { throw new FedException(e); } } public FedResultSet executeQuery(String sql) throws FedException { FedResultSet fedResultSet = new FedResultSet(this); try { for (Integer i : fedConnection.connections.keySet()) { Connection connection = fedConnection.connections.get(i); Statement statement = connection.createStatement(); statements.put(i, statement); fedResultSet.setResultSet(i, statement.executeQuery(sql)); } return fedResultSet; } catch (SQLException e) { throw new FedException(e); } } public void close() throws FedException { try { for (Object i : statements.keySet()) { statements.get(i).close(); } } catch (SQLException e) { throw new FedException(e); } } public FedConnection getConnection() throws FedException { return fedConnection; } }