`
wangdf_jee
  • 浏览: 113621 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

SqlMapClientBuilder

阅读更多
/*
*  Copyright 2004 Clinton Begin
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.ibatis.sqlmap.client;

import com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser;

import java.io.InputStream;
import java.io.Reader;
import java.util.Properties;

/**
* Builds SqlMapClient instances from a supplied resource (e.g. XML configuration file)
* <p/>
* The SqlMapClientBuilder class is responsible for parsing configuration documents
* and building the SqlMapClient instance.  Its current implementation works with
* XML configuration files (e.g. sql-map-config.xml).
* <p/>
* Example:
* <pre>
* Reader reader = Resources.getResourceAsReader("properties/sql-map-config.xml");
* SqlMapClient client = SqlMapClientBuilder.buildSqlMapClient (reader);
* </pre>
* <p/>
* Examples of the XML document structure used by SqlMapClientBuilder can
* be found at the links below.
* <p/>
* Note: They might look big, but they're mostly comments!
* <ul>
* <li> <a href="sql-map-config.txt">The SQL Map Config File</a>
* <li> <a href="sql-map.txt">An SQL Map File</a>
* <ul>
*/
public class SqlMapClientBuilder {

  /**
   * No instantiation allowed.
   */
  protected SqlMapClientBuilder() {
  }

  /**
   * Builds an SqlMapClient using the specified reader.
   *
   * @param reader A Reader instance that reads an sql-map-config.xml file.
   *               The reader should read an well formed sql-map-config.xml file.
   * @return An SqlMapClient instance.
   */
  public static SqlMapClient buildSqlMapClient(Reader reader) {
//    return new XmlSqlMapClientBuilder().buildSqlMap(reader);
    return new SqlMapConfigParser().parse(reader);
  }

  /**
   * Builds an SqlMapClient using the specified reader and properties file.
   * <p/>
   *
   * @param reader A Reader instance that reads an sql-map-config.xml file.
   *               The reader should read an well formed sql-map-config.xml file.
   * @param props  Properties to be used to provide values to dynamic property tokens
   *               in the sql-map-config.xml configuration file.  This provides an easy way to
   *               achieve some level of programmatic configuration.
   * @return An SqlMapClient instance.
   */
  public static SqlMapClient buildSqlMapClient(Reader reader, Properties props) {
//    return new XmlSqlMapClientBuilder().buildSqlMap(reader, props);
    return new SqlMapConfigParser().parse(reader, props);
  }

  /**
   * Builds an SqlMapClient using the specified input stream.
   *
   * @param inputStream An InputStream instance that reads an sql-map-config.xml file.
   *               The stream should read a well formed sql-map-config.xml file.
   * @return An SqlMapClient instance.
   */
  public static SqlMapClient buildSqlMapClient(InputStream inputStream) {
    return new SqlMapConfigParser().parse(inputStream);
  }

  /**
   * Builds an SqlMapClient using the specified input stream and properties file.
   * <p/>
   *
   * @param inputStream An InputStream instance that reads an sql-map-config.xml file.
   *               The stream should read an well formed sql-map-config.xml file.
   * @param props  Properties to be used to provide values to dynamic property tokens
   *               in the sql-map-config.xml configuration file.  This provides an easy way to
   *               achieve some level of programmatic configuration.
   * @return An SqlMapClient instance.
   */
  public static SqlMapClient buildSqlMapClient(InputStream inputStream, Properties props) {
    return new SqlMapConfigParser().parse(inputStream, props);
  }
}
分享到:
评论

相关推荐

    传智播客ibatis视频教程源代码

    sqlMapClient = com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(reader); reader.close(); } catch (IOException e) { e.printStackTrace(); } } public void addStudent(Student ...

    iBatis-设置缓存模式-Java源码(下载)

    SqlMapClient sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader); reader.close(); return sqlMapper; } public void executeSQLCommand(String sql) throws Exception { st.executeUpdate(sql...

    ibatis源码 例子

    sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader); reader.close(); } catch (IOException e) { throw new RuntimeException("Exception!" + e, e); } } public List&lt;Employee&gt; ...

    ibatis学习笔记.txt

    - **iBatis** 使用 SqlMapClientBuilder 从配置文件(如 SqlMapConfig.xml)构建 SqlMapClient 对象。 - **示例代码**: ```java String resource = "SqlMapConfig.xml"; Reader reader = Resources....

    ibatis简易使用 ibatis简易使用 ibatis简易使用

    - 使用`SqlMapClientBuilder`构建`SqlMapClient`对象,这一步是初始化iBATIS的核心,通过读取`SqlMapConfig.xml`来建立与数据库的连接。代码示例: ```java Reader reader = Resources.getResourceAsReader(...

    proxool实例

    orgproxool.SqlMapClientBuilder builder = new SqlMapClientBuilder(); SqlMapClient sqlMap = builder.buildSqlMapClient(ppp); ``` 最后,在应用程序中使用Proxool就像使用普通的数据库连接一样,但实际上是通过...

    记一次Ibatis的意外发生.docx

    这个类中import了多个包,包括com.ibatis.common.xml.NodeletException、com.ibatis.sqlmap.client.SqlMapClient、com.ibatis.sqlmap.client.SqlMapClientBuilder等。需要注意的是,IBatis的包声明是org.apache....

    ibatis学习笔记

    在Java代码中,通常通过`SqlMapClientBuilder`构建实例。 2. 类型别名(Type Alias):`typeAlias`元素用于简化Java类型引用,例如`&lt;typeAlias alias="Student" type="entity.Student"/&gt;`,之后可以直接用"Student...

    Ibatis资料ibatai sql map iBATIS使用$和#的一些理解

    在使用iBATIS(现已被MyBatis取代)进行数据库操作时,我们常常需要传递参数到SQL语句中。在iBATIS中,有两种主要的方式来处理这些参数:使用`$`和`#`。这两种方式在不同的场景下有不同的效果。...

    Ibatis增删改简单应用配置示例说明实例

    在Ibatis2中,我们通过SqlMapClientBuilder构建SqlMapClient对象,然后通过它可以生成DAO的动态代理对象,实现业务逻辑。 ```java SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(Resources....

    ibatis 使用简单配置

    sqlMapClient = SqlMapClientBuilder.buildSqlMapClient( Resources.getResourceAsReader("SqlMapConfig.xml")); } catch (IOException e1) { e1.printStackTrace(); } return sqlMapClient; } } ``` 4. *...

    iBatis教程中文版

    SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(Resources.getResourceAsStream("SqlMapConfig.xml")); List&lt;Contact&gt; contacts = sqlMap.queryForList("Contact.selectAllContacts"); for (Contact ...

    SqlMapClient对象.pdf

    利用`Resources.getResourceAsReader()`方法读取配置文件,然后通过`SqlMapClientBuilder.buildSqlMapClient()`方法创建SqlMapClient实例。这个过程通常放在一个静态代码块中,以确保在类加载时就完成初始化。 2. *...

    ibatis配置文件信息

    - **SqlMapClientBuilder**:用于构建`SqlMapClient`实例。 - **异常处理**:捕获并处理可能发生的`IOException`。 #### 四、总结 通过对ibatis配置文件的解析,我们可以看到ibatis的强大之处在于它能够灵活地配置...

    ibatis标签

    在源码方面,iBATIS的实现中,`&lt;iterate&gt;`标签的解析和执行是通过SqlMapConfig.xml配置文件加载后,由SqlMapClientBuilder解析,并由Executor执行器来处理。在处理动态SQL时,iBATIS会将`&lt;iterate&gt;`标签转换成对应的...

    ibatis 学习小结笔记

    通过 `SqlMapClientBuilder` 创建 `SqlMapClient` 实例,并传入配置文件路径。这样就可以通过 `SqlMapClient` 来执行 SQL 操作了。 #### 四、ibatis 与 Hibernate 的对比 - **SQL 控制**:ibatis 相比 Hibernate ...

    Ibatis应用事例

    - **SqlMapClient 实例化**:通过 `SqlMapClientBuilder` 创建 `SqlMapClient` 实例,这是Ibatis的核心组件之一。 - **QueryForList 方法**:用于查询所有记录,其中 `"queryAll"` 是映射文件中 `&lt;select&gt;` 元素的 `...

Global site tag (gtag.js) - Google Analytics