在Glassfish JDBC连接池上设置V $ SESSION.program属性 [英] Setting V$SESSION.program property on Glassfish JDBC Connection Pool

查看:123
本文介绍了在Glassfish JDBC连接池上设置V $ SESSION.program属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Java EE应用程序部署在Glassfish 3.0.1上,并使用JDBC连接池连接到Oracle 9i数据库。我正在使用JPA读取/写入数据到数据库,它工作正常。然而,为了更好地报告这个应用程序加载到数据库的负载,我想设置V $ SESSION.program列以供oracle使用。



从各种谷歌搜索(例如 http://forums.oracle.com/forums/thread .jspa?messageID = 3271623 )它看起来像我应该能够将其添加为属性,就像您设置任何其他属性一样。因此,我通过更改GlassFish的domain.xml文件(请参阅下文)尝试了此操作,并且当我使用Glassfish管理控制台查看V $ SESSION.program属性时,现在在JDBC连接池上设置了V $ SESSION.program属性(当我启动glassfish服务器,进入管理页面,浏览到Resources-> JDBC-> Connection Pools-> MyConnectionPool-> Additional Properties我可以看到一个适当的V $ SESSION.program条目。)



但是,当我查询Oracle数据库的连接( SELECT * FROM V $ SESSION )时,它们具有与以前相同的V $ SESSION.program (它是JDBC瘦客户端),而不是我在domain.xml中设置的那个,我可以在Glassfish管理页面上看到JDBC Connection Pool的属性。



我的domain.xml的resources部分如下:

 < resources> 
< property name =datasourceNamevalue =OracleConnectionPoolDataSource/>
< property name =databaseNamevalue =mydatabasename/>
< property name =passwordvalue =mypassword/>
< property name =portNumbervalue =1521/>
< property name =serverNamevalue =myservername/>
< property name =uservalue =myuser/>
< property name =v $ session.programvalue =MyGlassfishApp/>
< / jdbc-connection-pool>
< /资源>

我的Persistence.xml如下(我已经删除了所有的 < class> ...< / class> lines):

 <?xml version =1.0encoding =UTF-8?> 
< persistence version =2.0xmlns =http://java.sun.com/xml/ns/persistencexmlns:xsi =http://www.w3.org/2001/XMLSchema-实例xsi:schemaLocation =http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd\">

< persistence-unit name =Persistence-ejbtransaction-type =RESOURCE_LOCAL>
< provider> org.eclipse.persistence.jpa.PersistenceProvider< / provider>
< jta-data-source> jdbc / mydatabasename< / jta-data-source>
< exclude-unlisted-classes> false< / exclude-unlisted-classes>
<属性>
< property name =javax.persistence.query.timeoutvalue =60/>
< property name =javax.persistence.lock.timeoutvalue =60/>
< property name =javax.persistence.target-servervalue =SunAS9/>

<! - 禁用缓存,因此我们总是直接使用数据库 - >
< property name =eclipselink.cache.shared.defaultvalue =false/>
< property name =eclipselink.query-results-cachevalue =false/>

< / properties>
< / persistence-unit>

< /持久性>

编辑:
我尝试了v $ session.program ,V $ SESSION.PROGRAM和V $ SESSION.program - 没有任何工作虽然...我也尝试设置V $ SESSION.program财产EntityManager,但没有奏效(我没有真正期望它因为据我所知,EntityManager属性只能用于JPA层,而不是与数据库的底层连接 - 但我试图用绝望的办法...)



我也尝试使用SessionCustomizer建议这里。我使用的SessionCustomizer代码如下:

  public class ProgramSessionCustomizer实现SessionCustomizer {
private static Logger logger = Logger.getLogger (ProgramSessionCustomizer.class);

@Override
public void customize(Session s)throws Exception {
logger.error(ProgramSessionCustomizer setting v $ session.program);
s.getDatasourceLogin()。setProperty(v $ session.program,MYprogramTEST);
logger.error(ProgramSessionCustomizer已设置v $ session.program);
}
}

然后,我将SessionCustomizer设置在persistence.xml中添加属性:

 < property name =eclipselink.session.customizervalue =persistence.config.ProgramSessionCustomizer/ > 

我可以看到日志行,所以Customizer肯定会被调用。但是,我没有看到数据库中设置的程序,当我浏览到Glassfish管理控制台上的JDBC连接池属性时,我甚至没有看到它设置(如上所述,我看到了当我使用glassfish domain.xml设置属性)



再一次,更多的建议将非常受欢迎,因为我不知所措!


我终于找到了如何为XA数据源在WebSphere 8中设置此连接属性。它可以在WebSphere管理控制台中设置:
资源> JDBC提供程序> [Oracle JDBC驱动程序(XA)]>数据源> [数据源名称]>定制属性



只需使用键添加一个属性: connectionProperties 及其值: v $ session.program:PUT_YOUR_NAME_HERE


my Java EE App is deployed on Glassfish 3.0.1, and uses a JDBC Connection Pool to Connect to an Oracle 9i database. I am using JPA to read/write data to the database, which is working fine. However, to get better reporting regarding the load this app is putting on the database, I want to set the V$SESSION.program column for use by oracle.

From various google searches (eg. http://forums.oracle.com/forums/thread.jspa?messageID=3271623) it looks like I should just be able to add this as a property, the same as you would set any other property. So I have tried this by changing the domain.xml file for Glassfish (see below), and the V$SESSION.program property is now set on the JDBC connection pool when I view it using the Glassfish Admin Console (When I start up the glassfish server, go to the admin page and browse to Resources->JDBC->Connection Pools->MyConnectionPool->Additional Properties I can see an entry for V$SESSION.program set appropriately).

However, when I query the Oracle Database for the connections (SELECT * FROM V$SESSION), they have the same V$SESSION.program as before (which is "JDBC Thin Client"), rather than the one I set in the domain.xml and which I can see as a property of the JDBC Connection Pool on the Glassfish Admin Page.

The resources section of my domain.xml is below:

<resources>
  <jdbc-connection-pool pool-resize-quantity="4" max-pool-size="16" datasource-classname="oracle.jdbc.pool.OracleDataSource" res-type="javax.sql.DataSource" steady-pool-size="4" name="mydatabasename">
    <property name="datasourceName" value="OracleConnectionPoolDataSource" />
    <property name="databaseName" value="mydatabasename" />
    <property name="password" value="mypassword" />
    <property name="portNumber" value="1521" />
    <property name="serverName" value="myservername" />
    <property name="url" value="jdbc:oracle:thin:@myservername:1521:mydatabasename" />
    <property name="user" value="myuser" />
    <property name="v$session.program" value="MyGlassfishApp" />
  </jdbc-connection-pool>
  <jdbc-resource pool-name="mydatabasename" jndi-name="jdbc/mydatabasename" />
</resources>

And my Persistence.xml is as below (I've deleted all the <class>...</class> lines):

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

  <persistence-unit name="Persistence-ejb" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/mydatabasename</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.query.timeout" value="60"/>
      <property name="javax.persistence.lock.timeout" value="60"/>
      <property name="javax.persistence.target-server" value="SunAS9"/>

      <!-- Disable caching so we always use the DB directly -->
      <property name="eclipselink.cache.shared.default" value="false"/>
      <property name="eclipselink.query-results-cache" value="false"/>

    </properties>
  </persistence-unit>

</persistence>

EDIT: I have tried v$session.program, V$SESSION.PROGRAM and V$SESSION.program - none have worked though... I have also tried setting the V$SESSION.program property on the EntityManager, but that didn't work (I didn't really expect it to since from what I understand the EntityManager properties are only to do with the JPA layer, not the underlying connection to the Database - but I'm trying stuff out of desperation...)

I also tried using a SessionCustomizer as suggested here. The SessionCustomizer code I used is below:

public class ProgramSessionCustomizer implements SessionCustomizer {
    private static Logger logger = Logger.getLogger(ProgramSessionCustomizer.class);

    @Override
    public void customize(Session s) throws Exception {
        logger.error("ProgramSessionCustomizer setting v$session.program");
        s.getDatasourceLogin().setProperty("v$session.program", "MYprogramTEST");
        logger.error("ProgramSessionCustomizer has set v$session.program");
    }
}

I then set the SessionCustomizer in the persistence.xml by adding the property:

<property name="eclipselink.session.customizer" value="persistence.config.ProgramSessionCustomizer"/>

I can see the log lines, so the Customizer is definitely being called. However, I don't see the program set in the database, and I don't even see it set when I browse to the JDBC connection pool properties on the Glassfish Admin Console (which, as I said above, I do see when I set the property using the glassfish domain.xml)

Again, any more suggestions would be very welcome as I'm at a loss!

解决方案

I finally found out how to set this connection property in WebSphere 8 too for a XA datasource. It can be set in the WebSphere admin console: Resources > JDBC providers > [Oracle JDBC Driver (XA)] > Data Sources > [data source name] > Custom properties

Just add there a property with a key: connectionProperties and its value: v$session.program:PUT_YOUR_NAME_HERE

这篇关于在Glassfish JDBC连接池上设置V $ SESSION.program属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆