AR原始文档

Accessing more than one database

» Home » ActiveRecord » Documentation » ActiveRecord RC1 Documentation » Advanced usage » Accessing more than one database

You can use more than one database with ActiveRecord. In order to do so you must create base classes that define, based on the hierarchy, which database is being used. Those are called Root types. If you use just one database, the root type is ActiveRecordBase.

Adding a different database

Let's analyze the steps involved in getting ActiveRecord to work with more than one database.

First: Create your root type

You must create an abstract class that extends ActiveRecordBase. This class can be empty. All ActiveRecord types bound to the second database must use it as the base class.

using Castle.ActiveRecord

public abstract class LogisticDatabase : ActiveRecordBase

{

}

Second: configure the second database

On the existing configuration, you must use add another config set bound to the abstract class you have just created. For more information on it, see Xml Configuration Reference.

Xml Configuration Reference

» Home » ActiveRecord » Documentation » ActiveRecord RC1 Documentation » Reference Manual » Xml Configuration Reference

The following is the definition of the expected xml schema. Differences regarding the how it must appear in a standalone xml file or in a configuration associated with an AppDomain (web.config for instance) are also explained below.

<configuration>

<activerecord

isWeb="true|false"

isDebug="true|false"

threadinfotype="custom thread info implementation"

sessionfactoryholdertype="custom session holder implementation"

namingstrategytype="custom namingstrategy implementation">

<config>

<add key="hibernate.connection.driver_class" value="NHibernate Driver" />

<add key="hibernate.dialect" value="NHibernate Dialect" />

<add key="hibernate.connection.provider" value="NHibernate Connection Provider" />

<add key="hibernate.connection.connection_string" value="connection string" />

</config>

<config type="Full Type name to Abstract Class that defines boundaries for different database">

<add key="hibernate.connection.driver_class" value="NHibernate Driver" />

<add key="hibernate.dialect" value="NHibernate Dialect" />

<add key="hibernate.connection.provider" value="NHibernate Connection Provider" />

<add key="hibernate.connection.connection_string" value="connection string" />

</config>

</activerecord>

</configuration>

The following table explains the attributes.

翻译:

  1. 新建一个abstract类继承自ActiveRecordBase
  2. 新增一个activerecord的config

    假设新建的类为

using Castle.ActiveRecord

public abstract class LogisticDatabase : ActiveRecordBase

{

}

则新增的定义为

<config type=" LogisticDatabase ">

<add key="hibernate.connection.driver_class" value="NHibernate Driver" />

<add key="hibernate.dialect" value="NHibernate Dialect" />

<add key="hibernate.connection.provider" value="NHibernate Connection Provider" />

<add key="hibernate.connection.connection_string" value="connection string" />

</config>

让所以用到第二个数据库的domain都继承自此类。

转载于:https://www.cnblogs.com/shiningrise/archive/2007/08/30/876463.html

ActiveRecord使用多数据库相关推荐

  1. Castle ActiveRecord学习实践(1):快速入门指南

    摘要:最近几天有时间看了一下Castle,原来它的功能是如此的强大,从数据访问框架到IOC容器,再到WEB框架,基本包括了整个开发过程中的所有东西,看来得好好学习研究一下了,并且打算把自己学习过程的一 ...

  2. Castle ActiveRecord学习实践(6):延迟加载和使用Where子句

    摘要:在ActiveRecord中把数据库表之间的关联关系采用对象间的聚合关系来表现,然而这却带来一系列的性能上的问题.就像我在One-Many中用到的例子Blog,使用Blog.Find(1)查找了 ...

  3. Castle ActiveRecord学习笔记四:各种映射

    这里主要来说明ActiveRecord的属性与数据库及其字段的对应关系. 主要以ActiveRecordAttribute.PrimaryKeyAttribute.PropertyAttribute来 ...

  4. yml配置mysql自动重连_数据库和Doctrine(转载自http://www111cnnet/phper/332/85987htm) - Doctrine...

    Doctrine2压缩包的tools目录用来做一些命令行工作.这里主要说一下通过tools,把数据库的表结构自动生成yml/xml/entities,原因是写那些东西太浪费时间了有木有.1.通过Doc ...

  5. JFinal 极速开发框架--5.ActiveRecord

    5.1 概述 ActiveRecord 是 JFinal 最核心的组成部分之一,通过 ActiveRecord 来操作数据库,将极大地减少代码量,极大地提升开发效率. 5.2 ActiveRecord ...

  6. yii框架如何连接mysql数据库_php yii框架怎么连接数据库

    这篇文章主要介绍了PHP的Yii框架中使用数据库的配置和SQL操作实例教程,Yii支持绑定多种数据库,文中主要对各种查询语句在Yii中的使用给出了例子,需要的朋友可以参考下 php yii框架怎么连接 ...

  7. Laravel和Thinkphp有什么区别,哪个框架好用

    Laravel和Thinkphp这两个php框架对于php程序员都不陌生,新手可能对Thinkphp比较熟,也是国内比较出名的开源框架,更高级的Laravel一般有点经验的才使用. TP框架: Thi ...

  8. 在Idea中测试各JVM语言的交互性

    为什么80%的码农都做不了架构师?>>>    背景: 假设出现这样的场景,一个Java项目中,需要用其他语言来编写相关模块,但需要能被Java调用 测试工具:Idea12 测试语言 ...

  9. Laravel框架一:原理机制篇

    转载自http://www.cnblogs.com/XiongMaoMengNan/p/6644892.html Laravel作为在国内国外都颇为流行的PHP框架,风格优雅,其拥有自己的一些特点. ...

最新文章

  1. 基于R的混合线性模型的实现
  2. python 报错 SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:1076) 解决方法
  3. Jmeter和LoadRunner的区别
  4. 简单的计算机试题,这么简单的MS Office试题基础,一般人都不好意思看!
  5. 互联网1分钟 |1220
  6. java 不能反序列化_不能将“Java.Lang.Studio”实例反序列化到StaskObl对象令牌中
  7. php显示时间,php实现用已经过去多长时间的方式显示时间
  8. hibernate课程 初探单表映射1-2 ORM定义
  9. ansible不配置ssh免密钥,使用密码登录
  10. 部署系统到linux服务器,若依管理系统部署到linux(上)
  11. overflow鼠标拖拽显示_[翻译] 从零开始的 .Net Shell 扩展教程 (四) - Shell 拖拽处理程序
  12. 第八篇: UpdateProgress 控件--显示正在处理中的信息
  13. 一篇关于实体链接的小综述
  14. c语言编程马克思手稿 百例,清华大学出版社-图书详情-《C语言趣味编程100例》...
  15. shell 004 __小斌文档 |数组+函数
  16. TI BSL in python
  17. #444 沸腾客厅:在播客里温暖一个冬天
  18. 华为荣耀启动“二级火箭”战略,加速向线下突进
  19. 由于超过32位java限制_Java 32位Xmx vs java 64位Xmx
  20. 《智能制造》总结报告

热门文章

  1. 读取工作流程中的表单物件
  2. Amazon关键词抓取
  3. 今天是周一,又是热的天气笼罩。
  4. IE6/IE7下:inline-block解决方案
  5. php使用curl库进行ssl双向认证
  6. Android Studio 第六十五期 - Android业务组件库
  7. 2018 SaaS应用大会 掀起SaaS应用新浪潮
  8. java并发编程实践 part 01 --gt; 线程创建方式
  9. Attribute class invalid for tag present according to TLD
  10. C#多线程编程(转)