简体   繁体   English

使用带有C3P0的Hibernate的分布式Web模块的连接池

[英]Connection pool for Distributed Web modules using Hibernate with C3P0

I have a Web Service ( model-layer ) which communicates with Database. 我有一个与数据库通信的Web服务( model-layer )。 This module is responsible of saving and retrieving the data and managing the transaction. 该模块负责保存和检索数据以及管理事务。 Also many BL are defined her. 她也定义了许多BL。 The other isolated web modules use this service to save and retrieve their required data. 其他隔离的Web模块使用此服务来保存和检索其所需的数据。

Right now the model-layer is becoming bottle neck. 现在, model-layer正在成为瓶颈。 I need to change the architecture. 我需要改变架构。

I want to move the Hibernate Entity classes and BL to their respected web modules. 我想将Hibernate Entity类和BL移至它们受尊重的Web模块。 So each web module will communicate to same Database. 因此,每个Web模块将与同一数据库通信。 But I do not want a distributed connection pool and transaction maintained on each module. 但是我不希望在每个模块上维护分布式连接池和事务。

I know that there should be a way to use a Single Connection Pool for all the distributed web modules. 我知道应该为所有分布式Web模块使用单一连接池。 But I need a professional opinion that how should I do that. 但是我需要专业的意见,我应该怎么做。

I do not want to use the Spring framework, which is already been denied solution by the organization. 我不想使用Spring框架,该框架已被组织拒绝解决。

Right now I am trying find the solution by saving the serialized object of connection on LDAP and all the modules will use that connection pool. 现在,我正在尝试通过将连接的序列化对象保存在LDAP上来找到解决方案,所有模块都将使用该连接池。 And right now I am scratching my head wondering if I am going in the right direction. 现在,我挠头想知道我是否朝着正确的方向前进。

Please guide me to correct path. 请指导我正确的路径。 If spring is the only option then please advise me that as well. 如果春季是唯一的选择,那么也请告知我。 I will try to convince my company. 我会说服我的公司。

I guess I have found the Answer. 我想我已经找到答案了。

I have used a shared DataSource (*-ds.xml) on a single JBoss server. 我在单个JBoss服务器上使用了共享的数据源 (*-ds.xml)

Datasource file is as follows 数据源文件如下

<datasources>
  <local-tx-datasource>
    <jndi-name>jdbc/wc-mysql</jndi-name>
    <connection-url>jdbc:mysql://MyPC-IP:3306/DB</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>xUser</user-name>
    <password>xXxXx</password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>

    <use-java-context>false</use-java-context>

    <metadata>
       <type-mapping>mySQL</type-mapping>
    </metadata>
  </local-tx-datasource>
</datasources>

This DS is available to all the JBoss servers running on different location. 该DS适用于在不同位置运行的所有JBoss服务器。

One thing to make sure that <use-java-context>false</use-java-context> will make the DS publicly available so you need to do the security handshake yourself. 确保<use-java-context>false</use-java-context>将使DS公开可用的一件事,因此您需要自己进行安全性握手。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM