view flys-aft/src/main/java/de/intevation/db/ConnectedStatements.java @ 4074:100c4e0a45e1

Improved infrastructure for prepared statements. flys-aft/trunk@3407 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 13 Dec 2011 14:32:55 +0000
parents
children ee0c60757a94
line wrap: on
line source
package de.intevation.db;

import java.util.HashMap;
import java.util.Map;

import java.sql.Connection;
import java.sql.SQLException;

public class ConnectedStatements
{
    protected Connection connection;

    protected Map<String, SymbolicStatement> statements;

    protected Map<String, SymbolicStatement.Instance> boundStatements;

    public ConnectedStatements(
        Connection connection,
        Map<String, SymbolicStatement> statements
    ) {
        this.connection = connection;
        this.statements = statements;

        boundStatements = new HashMap<String, SymbolicStatement.Instance>();
    }

    public SymbolicStatement.Instance getStatement(String key) 
    throws SQLException
    {
        SymbolicStatement.Instance stmnt = boundStatements.get(key);
        if (stmnt != null) {
            return stmnt;
        }

        SymbolicStatement ss = statements.get(key);
        if (ss == null) {
            return null;
        }

        stmnt = ss.new Instance(connection);
        boundStatements.put(key, stmnt);
        return stmnt;
    }

    public void close() {
        for (SymbolicStatement.Instance s: boundStatements.values()) {
            s.close();
        }

        try {
            connection.close();
        }
        catch (SQLException sqle) {
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org