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

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -