Missed Team ’24? Catch up on announcements here.

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

Execute SQL in Plugin

Simon Martinelli August 18, 2014

I've built my own REST Plugin.

Now I need to execute a SQL query inside the plugin. How do I do that?

Thanks, Simon

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Alexey_Rjeutski__Polontech_
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.
August 18, 2014

That highly depends on database engine, but as an example - see https://answers.atlassian.com/questions/12868/third-party-dependency-in-jira-plugin for sql server

Simon Martinelli August 18, 2014

Thanks.

You mean there is no way to get the database connection trough the JIRA API?

Alexey_Rjeutski__Polontech_
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.
August 18, 2014

No, but you can use regular java methods.

Also please look into https://answers.atlassian.com/questions/154862/use-jira-connection-pool-for-plugin - but as for my experience - I've used external methods...

Like Milyausha likes this
2 votes
JamieA
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.
August 18, 2014
Alexey_Rjeutski__Polontech_
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.
August 18, 2014

Good catch.

I think you need mostly

ComponentManager componentManager = ComponentManager.getInstance()
delegator = (DelegatorInterface) componentManager.getComponentInstanceOfType(DelegatorInterface.class)
String helperName = delegator.getGroupHelperName("default");

Connection conn = ConnectionFactory.getConnection(helperName);

and then use connection with regular java methods - no need to use the groovy ones.

JamieA
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.
August 18, 2014

yeah, it was just an example of the relevant APIs. groovy.sql not available in java (of course).

1 vote
Marcin Urbański August 18, 2014

You could follow this tutorial https://developer.atlassian.com/display/JIRADEV/JIRA+Issue+CRUD+Servlet+and+Issue+Search. The query will be inside REST module.

Alexey_Rjeutski__Polontech_
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.
August 18, 2014

How would it help? It uses standart jira API, not the sql query (jql query is not sql query)

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 18, 2014

Executing SQL directly in a plugin is a bad idea, you should try to use the API whereever possible.

Simon Martinelli August 18, 2014

I know but I need the worklog incl. remaining estimate from change history.

This can be done in one SQL statement. When using the API I will have the n+1 problem. So the API is not an option.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 18, 2014

What n+1 problem? Pulling worklogs from an issue is a standard function in the API.

SQL is slow and clunky and easy to break.

Simon Martinelli August 18, 2014

Using the API I must search for all Issues (1 query) then for every Issue I must get the History (n query).

For example if I get 1200 issues back using the API I will have 1201 queries and many objects created for no use.

0 votes
Simon Martinelli August 18, 2014

You mean there is no way to get the database connection trough the JIRA API?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events