Expand my Community achievements bar.

SOLVED

DataSourcePool in WorkflowProcess - unsolved

Avatar

Level 7

Don't know how my answer was accepted because I didn't accept it

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/datasourcepool-in-workflow...

 

I'll give some more detail because I have RTFM as was answered (and accepted mysteriously).

 

This is my code for injecting the DataSourcePool Reference.

The SIADB is not found.

 

public class queryForSingleRow implements WorkflowProcess {
    private static final Logger log = LoggerFactory.getLogger(queryForSingleRow.class);

    @reference
    private DataSourcePool dsp;
    
    @Override
    public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
		     
        String dataSourceName = "SIADB";

    	Connection connection = null;
		DataSource ds = null;
		try {
			
			log.info("Checking datasources");
			for(Iterator<String> it = dsp.getAllJndiDataSourceNames().iterator(); it.hasNext();) {
				String dsname = it.next();
				log.info("Found datasource " + dsname);
			}
	        log.info("Using DataSourcePool service lookup to get connection pool " + dataSourceName); 
            ds = (DataSource) dsp.getDataSource(dataSourceName);
			connection = ds.getConnection();				

//More code after

Log file output:

 2021-05-27 13:41:21.737 INFO [com.s360g.aem.workflowcomponent.custom.queryForSingleRow] Checking datasources
2021-05-27 13:41:21.737 INFO [com.s360g.aem.workflowcomponent.custom.queryForSingleRow] Using DataSourcePool service lookup to get connection pool SIADB
2021-05-27 13:41:21.737 INFO [com.s360g.aem.workflowcomponent.custom.queryForSingleRow] Unable to find datasource SIADB.
com.day.commons.datasource.poolservice.DataSourceNotFoundException: No data source found with name 'SIADB' (after asking 0 providers)

 

I have this in CRX - /apps/source360/com.day.commons.datasource.jdbcpool.JdbcPoolService-SIADB

 

crich2784_0-1622141532084.png

 

I know it's probably something simple like permissions or proper placement of the sling:OsgiConfig.

 

Help is appreciated.

 

 

1 Accepted Solution

Avatar

Correct answer by
Employee

Just a quick note, @reference should be @Reference (capital R).

 

Then, OSGi configs in the JCR must be in folder named "config" (or "config.<runmode>") that is no more than 4 levels from the root; So it should be at: /apps/source360/config/com.day.commons.datasource.jdbcpool.JdbcPoolService-SIADB

 

Lastly, you should be able to do away with your lookup logic and let OSGi annotations do all the hard work...

 

@Reference(target="(datasource.name=SIADB)")

private DataSourcePool dsp;

View solution in original post

4 Replies

Avatar

Level 7

Ok, I figured it out.

 

Making an sling:OsgiConfig node in CRX manually does not work as the instructions imply.

 

Go to ConfigMgr

Search for jdbcpool

Add new configuration.  

The datasource.name is waaay at the bottom - I missed that.

Save it and it works.

Avatar

Correct answer by
Employee

Just a quick note, @reference should be @Reference (capital R).

 

Then, OSGi configs in the JCR must be in folder named "config" (or "config.<runmode>") that is no more than 4 levels from the root; So it should be at: /apps/source360/config/com.day.commons.datasource.jdbcpool.JdbcPoolService-SIADB

 

Lastly, you should be able to do away with your lookup logic and let OSGi annotations do all the hard work...

 

@Reference(target="(datasource.name=SIADB)")

private DataSourcePool dsp;

Avatar

Level 7
David - Awesome. Thanks. I'm trying to pass the datasource name as a parameter from dialog thus, not putting it in the code. But, this explains why my stuff wasn't working also. The documentation doesn't mention the config directory part. All good. Thanks for replying.
Gotcha! If the datasource.name is variable based on a dialog then i'd continue to do what youre doing! looks good!