/*
 * 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 XbLinkbaseArcDAO {

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

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

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

        return singleton;
    }

    protected int insert(XbLinkbaseArcObj obj)
        throws XbException {

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

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

            int index = 1;
            stmt.setLong(index++, obj.getArc_id());
            stmt.setLong(index++, obj.getLinkbaseref_id());
            stmt.setString(index++, obj.getArc_show());
            stmt.setString(index++, obj.getArc_title());
            stmt.setString(index++, obj.getArc_from());
            stmt.setString(index++, obj.getArc_to());
            stmt.setString(index++, obj.getArc_arcrole());
            stmt.setString(index++, obj.getArc_use());
            stmt.setLong(index++, obj.getArc_priority());
            stmt.setDouble(index++, obj.getCalculation_weight());
            stmt.setDouble(index++, obj.getPresentation_order());

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

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

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