Uploaded image for project: 'Karaf'
  1. Karaf
  2. KARAF-3261

jdbc command (using JdbcConnector.java) does not honour service ranking and throws IllegalArgumentException instead

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.0.1
    • 3.0.3, 2.4.1, 2.3.9, 4.0.0.M2, 4.0.0.M3
    • None
    • None

    Description

      Given two datasources are defined with the same jndi name
      and different service_rankings are defined
      when jdbc:datasources is used on the command line
      then the IllegalArgumentException("Multiple JDBC datasource found for " + name) is thrown
      instead of the highest ranked service being listed

      Requirements:
      Features: jpa, jndi, jdbc
      Bundle: derby library and oracle JDBC drivers

      Datasource 1: Derby (condensed)
      <?xml version="1.0" encoding="UTF-8"?>
      <blueprint>
      <bean id="dataSource" class="org.apache.derby.jdbc.EmbeddedXADataSource">
      <property name="databaseName" value="database"/>
      <property name="createDatabase" value="create" />
      </bean>
      <service ref="dataSource" interface="javax.sql.DataSource" >
      <service-properties>
      <entry key="osgi.jndi.service.name" value="jdbc/database"/>
      </service-properties>
      </service>
      </blueprint>

      Datasource 2: Oracle
      <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      default-activation="eager" >
      <bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
      <property name="URL" value="jdbc:oracle:thin:@localhost:1521/ORCL" />
      <property name="user" value="scott"/>
      <property name="password" value="tiger"/>
      </bean>
      <service ref="dataSource" interface="javax.sql.DataSource" ranking="90" >
      <service-properties>
      <entry key="osgi.jndi.service.name" value="jdbc/database"/>
      </service-properties>
      </service>
      </blueprint>

      karaf@root()> service:list javax.sql.DataSource
      [javax.sql.DataSource]
      ----------------------
      osgi.jndi.service.name = jdbc/database
      osgi.service.blueprint.compname = dataSource
      service.id = 802
      service.ranking = 90
      Provided by :
      Bundle 167
      Used by:
      Test Bundle (171)

      [javax.sql.DataSource]
      ----------------------
      osgi.jndi.service.name = jdbc/database
      osgi.service.blueprint.compname = dataSource
      service.id = 804
      Provided by :
      Test Bundle (171)

      In karaf:
      karaf@root()> jdbc:datasources
      Error executing command: Multiple JDBC datasource found for jdbc/database
      karaf@root()> exception-display
      java.lang.IllegalArgumentException: Multiple JDBC datasource found for jdbc/database
      at org.apache.karaf.jdbc.internal.JdbcConnector.lookupDataSource(JdbcConnector.java:133)
      at org.apache.karaf.jdbc.internal.JdbcConnector.connect(JdbcConnector.java:49)
      at org.apache.karaf.jdbc.internal.JdbcServiceImpl.info(JdbcServiceImpl.java:213)
      at Proxyd62a7e80_cc25_47ad_b3a2_9976b9f06424.info(Unknown Source)
      at Proxy3ab1f1e7_eaa9_4281_9b24_3b7d97868ed3.info(Unknown Source)
      at org.apache.karaf.jdbc.command.DataSourcesCommand.doExecute(DataSourcesCommand.java:38)
      at org.apache.karaf.shell.console.AbstractAction.execute(AbstractAction.java:33)
      at org.apache.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:39)
      at org.apache.karaf.shell.commands.basic.AbstractCommand.execute(AbstractCommand.java:33)
      at sun.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_51]
      at java.lang.reflect.Method.invoke(Method.java:606)[:1.7.0_51]
      at org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler.java:54)
      at org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:119)
      at org.apache.karaf.shell.console.commands.$BlueprintCommand30051229.execute(Unknown Source)[37:org.apache.karaf.shell.console:3.0.1]

      Preferred behaviour would be to return all datasources, including their service ranking. As a minimum would be to return the message as a warning, and return the highest ranked service.

      Attachments

        Activity

          People

            gnodet Guillaume Nodet
            barrymw Mark Barry
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: