0

I need to override the JdbcDataSource class getConnection() method to unlock Data direct driver.

When solr is executing the sql queries present in solr-data-config.xml inside solr cores, it is unable to execute the sql queries. It is failing with error "this driver is locked for use with embedded applications".

I could override the getConnection() method & unlock the driver by extending the JdbcDataSource class. But solr is not picking up my extended class. How to configure solr with extended JdbcDataSource.

  • 2
    I think the easiest way would be to create a new class that extends the old one, override `getConnection()` call, include the class in a .jar-file, add the .jar-file to the libraries being loaded by Solr, then use the new name in your data source definition - `dataSource type="NewAndImprovedJdbcDataSource"`. If it doesn't allow overriding getConnection, you might have to copy the content to a new file and create a "new", separate datasource instead. – MatsLindh Apr 10 '20 at 10:26
  • I overriden the getConnection method. Where can i add the feild dataSource type = "NewAndImprovedJdbcDataSource"? And where can i place the jar in solr installation directory? I am not sure in which location I can add my jar file. – adiraju uttej Apr 10 '20 at 13:13
  • 1
    You add the .jar file to the `lib` elements in `solrconfig.xml`: https://lucene.apache.org/solr/guide/6_6/lib-directives-in-solrconfig.html - You reference the datasource in the data-config.xml file: https://lucene.apache.org/solr/guide/6_6/uploading-structured-data-store-data-with-the-data-import-handler.html#fieldreaderdatasource – MatsLindh Apr 10 '20 at 16:11
  • Thanks for sharing the configuration steps. I followed the steps. But, after I wrote a custom data source which extends JdbcDataSource, after running the solr, i am facing this error. java.lang.NoClassDefFoundError: org/apache/solr/handler/dataimport/JdbcDataSource – adiraju uttej Apr 10 '20 at 16:18
  • 1
    You still have to load the libraries for the JdbcDataSource if you're extending it. The Solr log will show you all the jars being loaded. – MatsLindh Apr 10 '20 at 16:22
  • SolrDataImportHandler is loaded as part of solr-config.xml. Am I going in the right way? – adiraju uttej Apr 10 '20 at 16:39
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/211384/discussion-between-adiraju-uttej-and-matslindh). – adiraju uttej Apr 10 '20 at 16:39
  • Thanks a lot. It worked. – adiraju uttej Apr 10 '20 at 17:23

1 Answers1

1

I think the easiest way would be to create a new class that extends the old one, override getConnection() call, include the class in a .jar-file, add the .jar-file to the libraries being loaded by Solr, then use the new name in your data source definition - dataSource type="NewAndImprovedJdbcDataSource".

You must the .jar file to the lib elements in solrconfig.xml:

<lib dir="../../../<path>/" regex="my-library\.jar" />

You then reference the datasource in the data-config.xml file:

<dataSource name="<name>" type="YourCustomClass" />
MatsLindh
  • 49,529
  • 4
  • 53
  • 84