5

I want to create Oracle UCP using this code:

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);

I'm using

<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>

But when I start the code in a standalone bundle I get this error message:

    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)

Maybe I'm not configured the UCP correctly. Can you help to fix this issue?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

1 Answers1

2

Peter, I have not worked on UCP. Hence I may not be able to give you a full solution but few hints:

  1. Try using Apache Commons DBCP available as OSGi bundle.
  2. Try removing the Import-Package directive from your BND configuration. BND is intelligent to identify this. Then possible refine your imports later on.
  3. Try putting a DynamicImport-Package: * directive to your BND configuration.:

    <DynamicImport-Package>*</DynamicImport-Package>

Try the above steps, and possible combine 2 & 3 above, and report back if this works.

Thomas Joseph
  • 281
  • 1
  • 5
  • Hi Peter, I have put together a small demo application quickly with bundles driver, ucp and the client code, all separately as a Maven project at http://static.ethomasjoseph.com/osgi-project.zip Let me know if this would help. – Thomas Joseph Jun 22 '14 at 08:26
  • Could you please investigate this? – Peter Penzov Jun 23 '14 at 07:32
  • Hi Peter, I investigated a bit on this (based on your pastebin code). The real issue here is at runtime, the OracleDriver is still not visible to the UCP. We may have to bridge this. Since the source code for UCP is not available readily, debugging is a bit messy. In the past often I have patched the library with my own, where the "dynamic" driver lookup happens. – Thomas Joseph Jun 23 '14 at 16:05
  • So there is no solution? – Peter Penzov Jun 23 '14 at 16:29
  • The solution is to find the code where the driver class lookup happens, and ensure that UCP is able to find the driver. If you can point me to that class, it would help me to give you a fix quicker. – Thomas Joseph Jun 23 '14 at 17:21
  • Did you had any chance to test this? – Peter Penzov May 25 '15 at 14:24