I’m trying to have my IDEA plugin run a simple SQL select query from a defined datasource (i.e. one configured in the project).
I’ve followed some of the instructions on other posts, and they seem to recommend this approach:
- Create session by using
com.intellij.database.console.session.DatabaseSessionManager#getSession(project: Project, connectionPoint: DatabaseConnectionPoint)
. - Create request
com.intellij.database.datagrid.DataRequest.RawRequest
and overrideprocessRaw
method. Here you can get the connection from the second argument -com.intellij.database.dataSource.DatabaseConnectionCore#getRemoteConnection
. - Send the request for execution
session.getMessageBus().getDataProducer().processRequest(request)
.
Following this, I have the following:
com.intellij.database.dataSource.LocalDataSource dataSource = LocalDataSourceManager
.getInstance(project)
.getDataSources().get(0); // just as example
DatabaseSession session = com.intellij.database.console.session.DatabaseSessionManager.getSession(project, dataSource);
com.intellij.database.datagrid.DataRequest.RawRequest req = new DataRequest.RawRequest(session)
{
@Override
public void processRaw(Context context, DatabaseConnectionCore databaseConnectionCore) throws Exception
{
RemoteConnection conn = databaseConnectionCore.getRemoteConnection();
RemotePreparedStatement stmt = conn.prepareStatement("select 1 from dual");
stmt.execute();
RemoteResultSet resultSet = stmt.getResultSet();
while (resultSet.next())
{
String out = resultSet.getString(1);
System.out.println(out);
}
}
};
session.getMessageBus().getDataProducer().processRequest(req);
Yet the processRaw method is never invoked; debugging shows it stepping over the call to processRequest, but it seems to be ignored/nixed.
Could you please point me in the right direction?
My actual scenario that I’m working towards is to run a prebuilt select query and retrieve all the records in it, then do some processing based on the results.