Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do you access other data sources starting JIRA 4.3?

Rob Baily January 19, 2012

In versions prior to 4.3 you could include a Resource in the Tomcat server.xml and then an entry in the entityEngine.xml file and access the data source through ConnectionFactory.getConnection( dataSourceName ). Per the notes at http://confluence.atlassian.com/display/JIRA/Plugin+Developer+Notes+for+JIRA+4.3#PluginDeveloperNotesforJIRA43-AccessingdelegatorsconnectionsanddatasourcesinOfBiz this is no longer supported. I cannot determine how our plugin should access a database outside of the JIRA database. Please help!

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
tier-0 grump
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 22, 2012

Yeah, sure - firstly in your server.xml, add a Resource

        <Context path="/jira" docBase="/src/jira50/classes/artifacts/jira" workDir="/src/jira50/target/work" reloadable="false" useHttpOnly="true">
           <Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction" factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="60"/>
            <Resource auth="Container" driverClassName="org.postgresql.Driver" name="jdbc/otherDS" username="jirauser" password="jirauser" maxActive="20" type="javax.sql.DataSource" url="jdbc:postgresql://localhost:5432/otherDB" />

            <Manager pathname=""/>
        </Context>

Then in your entityengine.xml simply create a datasource element that references this resource, you can see I simply ignored the dire warnings :-) As we're not going to get ofbiz to manage the connection it is important to set all the checks to false.

<!--
DATASOURCE You should no longer define a datasource in this file, the database is now configured through the UI at setup time. The only time you would want to configure it here is when you migrate from an older version and need to point the new installation at an existing db. This is considered a legacy method and will not work if dbconfig.xml exists in the home directory. --> <datasource name="otherDS" field-type-name="postgres72" schema-name="public" helper-class="org.ofbiz.core.entity.GenericHelperDAO" check-on-start="false" use-foreign-keys="false" use-foreign-key-indices="false" check-fks-on-start="false" check-fk-indices-on-start="false" add-missing-on-start="false" check-indices-on-start="false"> <jndi-jdbc jndi-server-name="default" jndi-name="java:comp/env/jdbc/otherDS"/> </datasource>

Now fro your Java code you can obtain a JDBC connection using

org.ofbiz.core.entity.ConnectionFactory.getConnection("otherDS")

Rob Baily January 24, 2012

This looks like it is working! Thank you for your time!

Nabil Sayegh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2013

Do you need to close the connection?

0 votes
tier-0 grump
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 21, 2012

Officially moving forward, we want plugin developers to use Active Objects to access databases, but this doesn't help you a great deal, as the default behaviour here is to use the JIRA database. If you want to use an external database you can still add it to a Resource section, and you still have access to the entityengine.xml, and although the documentation no longer suggests that this works, ConnectionFactory is still available to you. There are some problems with this approach though, the main JIRA database is no longer managed through the resource pool but via direct JDBC, so I'm a little unsure if you could get transactions to span from the JIRA db to your db.

Rob Baily January 21, 2012

In this case I don't need to worry about transactions. I am reading an external database to pull in data to set some custom JIRA fields so the other database is not updated in my plugin, it is read only. Could you possibly elaborate a little more on the solution of using the ConnectionFactory or how I would get another data source from the entityengine.xml? Its not very clear to me. Thanks!

TAGS
AUG Leaders

Atlassian Community Events