Sonar plugin query the database -


i'm developing sonar plugin , have questions it. plugin need retrieve data database manipulate them , display them in page.

currently, plugin querying database using jdbc driver think problem in production. want find method connect , query database (just select query) plugin using api, or sonar object...

i know there webservice, don't give me information need, have make queries myself.

my plugin sonarqube 4.1.

i hope explication clear.

i think found solution:

i have class retrieve databasesessionfactory in constructor. read somewhere sonar uses dependency injection constructor.

    public class myclass implements webservice{          privatedatabasesessionfactory sessionfactory;          public myclass(databasesessionfactory sessionfactory) {             this.sessionfactory = sessionfactory;         }     } 

and after, in class, can use sessionfactory variable query database:

        databasesession s = sessionfactory.getsession();         string sqlquery ="select d.data " + snapshotsource.class.getname() + " d "                     + "where d.id = :id";         query query = s.createquery(sqlquery);          query.setparameter("id", 1);          list<string> queryresult = (list<string>) query.getresultlist();         //queryresult.get(0) contains source 

in example, first snapshot source in database. hope it's solution , can anybody.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -