⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configurationimpl.java

📁 羽量级数据持久层开发框架
💻 JAVA
字号:
package org.speedframework.configuration;

//~--- non-JDK imports --------------------------------------------------------

import org.apache.log4j.Logger;

import org.speedframework.connection.ConnectionAdaptorPool;
import org.speedframework.connection.IConnectionAdaptor;
import org.speedframework.exception.SpeedFrameworkException;

//~--- JDK imports ------------------------------------------------------------

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

/**
 *  类描述信息,描述类的主要职责和用处。
 *
 *
 * @version    $LastChangedRevision: 1945 $, 2007.09.29 at 02:14:27 CST
 * @author     <a href="mailto:falcon8848@gmail.com">piginzoo </a>
 */
public class ConfigurationImpl implements IConfiguration
 {

    /** 属性描述信息 */
    private static final Logger log = Logger.getLogger(ConfigurationImpl.class);

    // private static Hashtable pool = new Hashtable();

    /** 属性描述信息 */
    private static ConfigurationImpl config = new ConfigurationImpl();

    /**
     * Constructs ...
     *
     */
    private ConfigurationImpl() {}

    /**
     * 方法描述信息,
     * 描述方法是做什么的,
     * 如何调用,最好给出调用代码示例。
     *
     * @param id
     *
     * @return
     *
     * @throws SpeedFrameworkException
     */
    public synchronized IConnectionAdaptor getConnectionAdaptor(String id) throws SpeedFrameworkException {

        // ca=new SpeedConnectionAdaptor();
        // SpeedConnectionAdaptor ca = null;
        // try {
        // log.debug(id);
        // ca = (SpeedConnectionAdaptor) get(id);
        // if (ca == null) {
        // ca = new SpeedConnectionAdaptor();
        // this.setConnection(ca, id);
        // this.put(id, ca);
        // } else {
        // this.setConnection(ca, id);
        // }
        //
        // } catch (Exception e) {
        // e.printStackTrace();
        // throw new SpeedFrameworkException(e);
        // }
        // return ca;
        IConnectionAdaptor adaptor = null;

        try {
            adaptor = ConnectionAdaptorPool.getPoolById(id).getConnectionAdapter();
            adaptor.take().setAutoCommit(false);

            return adaptor;
        } catch (Exception e) {
            throw new SpeedFrameworkException(e);
        }
    }

    /**
     * 方法描述信息,
     * 描述方法是做什么的,
     * 如何调用,最好给出调用代码示例。
     *
     * @return
     */
    public static ConfigurationImpl newInstance() {
        return config;
    }

    // private void put(String name, Object value) {
    // pool.put(name, value);
    // }
    // private IConnectionAdaptor get(String name) {
    // return (IConnectionAdaptor) pool.get(name);
    // }
    // private IConnectionAdaptor setConnection(SpeedConnectionAdaptor ca,
    // String id) throws SpeedFrameworkException, SQLException {
    // Connection con=null;
    // if (ca.take() == null || ca.take().isClosed() ) {
    //
    // String type = ConfigureUtility.getConnectionType( id);
    // con=ConfigureUtility.ConnectionManager(id, type);
    // con.setAutoCommit(false);
    // ca.setConnection(con);
    // }
    // return ca;
    // }

    /**
     * 方法描述信息,
     * 描述方法是做什么的,
     * 如何调用,最好给出调用代码示例。
     *
     * @param args
     */
    public static void main(String[] args) {
        IConnectionAdaptor ad   = ConfigurationImpl.newInstance().getConnectionAdaptor("link_mysql");
        Connection         conn = ad.take();

        try {
            Statement stmt = conn.createStatement();

            stmt.executeUpdate("insert into testexecute (name) values ('new')");

            // ResultSet rs=stmt.executeQuery("select * from testexecute");
            conn.commit();
            conn.close();
        } catch (SQLException e) {

            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -