2013-12-20 81 views
4

我想使用此代碼來創建甲骨文UCP:不能在甲骨文UCP找到oracle.ucp.jdbc.PoolDataSourceFactory

import oracle.ucp.jdbc.PoolDataSource; 
import oracle.ucp.jdbc.PoolDataSourceFactory; 

System.out.println("***** OracleDS_UCP -> start init of PoolDataSource"); 

      PoolDataSource pool = PoolDataSourceFactory.getPoolDataSource(); 
      pool.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource"); 
      pool.setURL("jdbc:oracle:thin:@localhost:1521:XE"); 
      pool.setUser("test"); 
      pool.setPassword("test"); 
      pool.setMaxStatements(10); // the maximum number of statements that may be pooled or cached on a connection. 
      pool.setInitialPoolSize(2); 
      pool.setMinPoolSize(1); 
      pool.setMaxPoolSize(50); 
      pool.setLoginTimeout(60); // one minute 
      pool.setConnectionWaitTimeout(60); // one minute 
      pool.setAbandonedConnectionTimeout(30 * 60); // thirty minutes 
      pool.setMaxIdleTime(60 * 60); // one hour and kill inactive or idle connections 
      pool.setInactiveConnectionTimeout(60 * 60); // one hour and kill inactive or idle connections 
      pool.setConnectionWaitTimeout(0); // do not wait for a used connection to be released by a client. 
      pool.setConnectionHarvestTriggerCount(40); 
      pool.setConnectionHarvestMaxCount(10); 

我使用

<plugin> 
      <groupId>org.apache.felix</groupId> 
      <artifactId>maven-bundle-plugin</artifactId> 
      <version>2.4.0</version> 
      <extensions>true</extensions> 
      <configuration> 
       <instructions> 
        <Embed-Dependency>ucp,ojdbc6</Embed-Dependency> 
        <Import-Package> 
         org.osgi.framework, 
         javax.sql, 
         javax.naming, 
         oracle.jdbc.pool.OracleDataSource, 
         oracle.ucp.jdbc.PoolDataSourceFactory, 
         oracle.ucp.jdbc.PoolDataSourceImpl, 
         javax.naming.spi, 
         javax.management, 
         javax.management.modelmbean, 
         oracle.jdbc.pool 
        </Import-Package> 
        <Include-Resource> 
         ucp-11.2.0.3.jar, 
         ojdbc6-11.2.0.3.jar 
        </Include-Resource> 
        <Bundle-ClassPath> 
         ucp-11.2.0.3.jar, 
         ojdbc6-11.2.0.3.jar, 
         . 
        </Bundle-ClassPath> 
        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> 
        <Bundle-Activator>org.test.ucp.activator.Activator</Bundle-Activator> 
       </instructions> 
      </configuration> 
     </plugin> 

但是,當我開始在代碼一個獨立的包我得到這個錯誤信息:

Test Oracle UCP 
ERROR: Bundle ucpTest [21] Error starting inputstream:ucpTest-1.0.jar (org.osgi.framework.BundleExce 
ption: Activator start error in bundle ucpTest [21].) 
java.lang.IllegalArgumentException: interface oracle.ucp.jdbc.LabelableConnection is not visible fro 
m class loader 
     at java.lang.reflect.Proxy$ProxyClassFactory.apply(Unknown Source) 
     at java.lang.reflect.Proxy$ProxyClassFactory.apply(Unknown Source) 
     at java.lang.reflect.WeakCache$Factory.get(Unknown Source) 
     at java.lang.reflect.WeakCache.get(Unknown Source) 
     at java.lang.reflect.Proxy.getProxyClass0(Unknown Source) 
     at java.lang.reflect.Proxy.newProxyInstance(Unknown Source) 
     at oracle.ucp.jdbc.proxy.ConnectionProxyFactory.createConnectionProxy(ConnectionProxyFactory 
.java:78) 
     at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:919) 
     at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:863) 
     at oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:855) 
     at org.test.osgi.ucp.impl.OracleDS_UCP.getConnection(OracleDS_UCP.java:26) 
     at org.test.ucp.activator.Activator.testOracleUCP(Activator.java:41) 
     at org.test.ucp.activator.Activator.start(Activator.java:17) 
     at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645) 
     at org.apache.felix.framework.Felix.activateBundle(Felix.java:1977) 
     at org.apache.felix.framework.Felix.startBundle(Felix.java:1895) 
     at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1191) 
     at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:295) 
     at java.lang.Thread.run(Unknown Source) 

也許我沒有正確配置UCP。你能幫助解決這個問題嗎?

+0

這是您收到異常的完整堆棧跟蹤嗎?這是一個Web /企業應用程序還是獨立應用程序? –

+0

已更新。這是一個獨立的應用程序。 –

+0

在pom.xml中包含LabelableConnection – TrungTran05T3

回答

2

彼得,我還沒有在UCP工作過。因此,我可能無法給你一個完整的解決方案,但一些提示:使用Apache下議院DBCP可作爲OSGi bundle

  1. 嘗試。
  2. 嘗試從BND配置中刪除Import-Package指令。 BND很聰明地識別這一點。然後可以稍後改進您的導入。
  3. 嘗試把一個DynamicImport-Package:*指令您的BND配置:

    < DynamicImport-包裝> * </DynamicImport-包裝>

試試上面的步驟,並結合可能2 & 3以上,如果這有效,請回報。

+0

步驟2和步驟3不起作用。 –

+0

嗨,彼得,我已經用捆綁驅動程序,ucp和客戶端代碼快速地將一個小型演示應用程序放在一起,它們分別在http://static.ethomasjoseph.com/osgi-project.zip中作爲Maven項目單獨發佈。有助於。 –

+0

由於某種原因,我得到NPE http://pastebin.com/3ytURu2G –