/*
 * Copyright (c) 2007, Going Dot Com Inc. All rights reserved.
 */

package jp.co.going.xbrl.taxonomy;

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

import jp.co.going.xbrl.common.XbException;

/**
 * @author Going Dot Com Inc.
 */
public class XbLinkbaseResourceDAO {

    // singleton作成
    private static XbLinkbaseResourceDAO singleton = null;
    // Connection変数
    private static Connection conn = null;
    // ステートメントを作成
    private PreparedStatement stmt = null;

    // コンストラクタ
    private XbLinkbaseResourceDAO() {
    }

    // インスタンス取得
    public static XbLinkbaseResourceDAO getInstance(Connection connection) {
        // インスタンスを生成
        if (singleton == null) {
            conn = connection;
            singleton = new XbLinkbaseResourceDAO();
        }

        return singleton;
    }

    protected int insert(XbLinkbaseResourceObj obj)
        throws XbException {

        try {
            StringBuffer  strb_sql = new StringBuffer();
            // 問合せの実行
            strb_sql.append("insert into ");
            strb_sql.append("xb_linkbase_resource ");
            strb_sql.append("values ");
            strb_sql.append("(?, ?, ?, ?, ?, ?, ?)");

            // SQL設定
            stmt = conn.prepareStatement(strb_sql.toString());

            int index = 1;
            stmt.setLong(index++, obj.getResource_id());
            stmt.setLong(index++, obj.getLinkbaseref_id());
            stmt.setString(index++, obj.getResource_label());
            stmt.setString(index++, obj.getResource_title());
            stmt.setString(index++, obj.getLabel_role());
            stmt.setString(index++, obj.getLabel_lang());
            stmt.setString(index++, obj.getResource_value());

            // SQL　実行
            int count =stmt.executeUpdate();

            // ステートメントをクローズ
            stmt.close();

            return count;
        } catch (SQLException e) {
            throw new XbException(e, "SQLError : " + e.getMessage());
        }
    }
}