Access to ActiveObjects tables via JDBC?

Claudio Kirchhoff January 10, 2017

I wonder if I can get a JDBC connection to the JIRA/Confluence database from plugin code and access the tables created by the ActiveObjects plugin.

Is that possible?

If so: Would that still work reliably on a different JIRA/Confluence instance with different configuration, specifically with a different database vendor?

3 answers

1 accepted

1 vote
Answer accepted
Jobin Kuruvilla [Adaptavist]
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.
January 10, 2017

You can definitely get the DS info or Connection from plugin code and use it to access AO tables.

DatasourceInfo datasourceInfo = new DefaultOfBizConnectionFactory().getDatasourceInfo();
Connection connection = new DefaultOfBizConnectionFactory().getConnection();

AO tables follows a unique naming strategy, which you can find at https://developer.atlassian.com/docs/atlassian-platform-common-components/active-objects/developing-your-plugin-with-active-objects/active-objects-faq/table-names. The names stay the same across instances.

Having said that, it is recommended to use the ActiveObjects APIs to interact with the AO tables. 

Claudio Kirchhoff January 10, 2017

Thanks a lot, Jobin, I will try that! Are you aware of specific dangers of accessing AO tables directly view JDBC?

Jobin Kuruvilla [Adaptavist]
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.
January 10, 2017

Not really. I mostly opt for AO APIs but have done it via direct JDBC calls for complex scenarios. Other than that, it is normal JDBC!

Claudio Kirchhoff January 10, 2017

Is there a way to make that work for Confluence? I can only find DefaultOfBizConnectionFactory in the com.atlassian.jira.ofbiz package.

Marcel Nick October 24, 2017

I get null when I try accessing JDBC info 

JdbcDatasourceInfo jdbcDatasourceInfo = new DefaultOfBizConnectionFactory().getDatasourceInfo().getJdbcDatasource(); 

However the JNDI Datasource works

DefaultOfBizConnectionFactory().getDatasourceInfo().getJndiDatasource()

 

Any clues ?

I am using SDK with 

<jira.version>7.2.2</jira.version><amps.version>6.2.11</amps.version>

Marcel Nick October 24, 2017

It seems to be SDK version issue.

It works when I change JIRA & AMPS version to the one below

<jira.version>6.3.1</jira.version>
<amps.version>5.0.3</amps.version>

Sam Glaser September 21, 2023

I have a plugin that makes an AO entity, but where do I run these lines of code to find the connection?

2 votes
Daniel Wester
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.
January 10, 2017

Be very careful. AO does have some caching built in so if you mix the access algorithm (API vs direct jdbc) you might see some strange results.

0 votes
davidbalducci
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 3, 2024

 

Hi,

Is it still possible to access the db via jdbc connection?

The code above with jira version 8.4.0 does not work. How can we do otherwise?

 

Thanks

Suggest an answer

Log in or Sign up to answer