【问题标题】:How to read connection pool settings from resource adapter?如何从资源适配器读取连接池设置?
【发布时间】:2015-02-02 04:36:17
【问题描述】:

我正在为 Glassfish 开发新的资源适配器。 它使用在管理控制台中设置了属性的连接池。 连接器连接池 -> 附加属性 -> name=url, value=127.0.0.1 我想从资源适配器中读取这个属性。 (以我的托管连接实现类为例)

我尝试查看文档和在线示例,但不知道如何操作。

【问题讨论】:

    标签: java jakarta-ee glassfish connection-pooling jca


    【解决方案1】:

    这是几乎所有带有连接池的 j2ee 容器上的 Web 应用程序的通用方式。

        InitialContext ctx = new InitialContext();
        //The JDBC Data source that we just created
        DataSource ds = (DataSource) ctx.lookup("url here");
        Connection connection = ds.getConnection();
    

    【讨论】:

    • 感谢您的回复。我没有提到它,但我使用会话 bean 而不是 Web 应用程序。问题是如何访问配置属性而不是资源适配器。
    【解决方案2】:
    @Connector(reauthenticationSupport = false, transactionSupport = TransactionSupport.TransactionSupportLevel.NoTransaction)
    public class SocketResourceAdapter implements ResourceAdapter {
    
    /** The logger */
    private static Logger log = Logger.getLogger("SocketResourceAdapter");
    
    /** Name property */
    @ConfigProperty(defaultValue = "DefaultMessage", supportsDynamicUpdates = true)
    private String name;
    
    @ConfigProperty(defaultValue = "---", type = String.class)
    private String url;
    
    @ConfigProperty(type = Integer.class)
    private Integer port;
    
    
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    
    public Integer getPort() {
        return port;
    }
    public void setPort(Integer port) {
        this.port = port;
    }
    

    然后我可以在资源适配器中使用 getUrl() 。 起初它不起作用,因为我正在为连接工厂而不是资源适配器设置属性。

    【讨论】:

      猜你喜欢
      • 2014-08-20
      • 1970-01-01
      • 2015-03-29
      • 1970-01-01
      • 1970-01-01
      • 2017-03-10
      • 2011-02-08
      • 2018-03-18
      • 2019-10-22
      相关资源
      最近更新 更多