Package com.dci.intellij.dbn.object.common.loader

Source Code of com.dci.intellij.dbn.object.common.loader.DBSourceCodeLoader

package com.dci.intellij.dbn.object.common.loader;

import com.dci.intellij.dbn.common.util.StringUtil;
import com.dci.intellij.dbn.connection.ConnectionHandler;
import com.dci.intellij.dbn.connection.ConnectionUtil;
import com.dci.intellij.dbn.object.common.DBObject;
import com.intellij.openapi.diagnostic.Logger;

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

public abstract class DBSourceCodeLoader {
    protected Logger logger = Logger.getInstance(getClass().getName());

    private DBObject object;
    private boolean lenient;

    protected DBSourceCodeLoader(DBObject object, boolean lenient) {
        this.object = object;
        this.lenient = lenient;
    }

    public String load() throws SQLException {
        Connection connection = null;
        ResultSet resultSet = null;
        ConnectionHandler connectionHandler = object.getConnectionHandler();
        try {
            connection = connectionHandler.getPoolConnection();
            resultSet = loadSourceCode(connection);
                                                
            StringBuilder sourceCode = new StringBuilder();
            while (resultSet.next()) {
                String codeLine = resultSet.getString(1);
                sourceCode.append(codeLine);
            }

            if (sourceCode.length() == 0 && !lenient)
                throw new SQLException("Object not found in database.");

            return StringUtil.removeCharacter(sourceCode.toString(), '\r');
        } finally {
            ConnectionUtil.closeResultSet(resultSet);
            connectionHandler.freePoolConnection(connection);
        }
    }

    public abstract ResultSet loadSourceCode(Connection connection) throws SQLException;
}
TOP

Related Classes of com.dci.intellij.dbn.object.common.loader.DBSourceCodeLoader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.