Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

DataSourcePool in WorkflowProcess

Avatar

Avatar
Affirm 3
Level 2
crich2784
Level 2

Likes

4 likes

Total Posts

32 posts

Correct Reply

2 solutions
Top badges earned
Affirm 3
Boost 3
Give Back
Validate 1
Boost 1
View profile

Avatar
Affirm 3
Level 2
crich2784
Level 2

Likes

4 likes

Total Posts

32 posts

Correct Reply

2 solutions
Top badges earned
Affirm 3
Boost 3
Give Back
Validate 1
Boost 1
View profile
crich2784
Level 2

26-05-2021

I am trying to dynamically connect to a datasource.  I'm using the AEM archetype.

 

public class mystuff implements WorkflowProcess {
private static final Logger log = LoggerFactory.getLogger(mystuff.class);
@reference
private DataSourcePool dsp;

@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {

String dataSourceName = "MYDB";
DataSource ds = null;
Connection connection = null;
try {

if (dsp == null ) {
   log.info("DataSourcePool is null");
} else {
   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);

 

 

No datasources are being found and no connection made.  

I have the MYDB configured just fine.  I am using it in a Servlet by doing this annotation.

 

@reference(target = "(&(objectclass=javax.sql.DataSource)(datasource.name=MYDB))")
private DataSource ds;

 

However, i do not want to hard-code the datasource.name.  Any ideas!!??

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

570 likes

Total Posts

687 posts

Correct Reply

197 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

570 likes

Total Posts

687 posts

Correct Reply

197 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile
asutosh_jena
Level 10

26-05-2021

Hi @crich2784 

 

Did you create the OSGi config with com.day.commons.datasource.jdbcpool.JdbcPoolService and added the DB details into it?

The JDBC Connections Pool service is a factory. Therefore, if you use a sling:OsgiConfig node to configure the connection service, the name of the node must include the factory service PID followed by -alias. The alias that you use must be unique for all configuration nodess for that PID. An example node name is com.day.commons.datasource.jdbcpool.JdbcPoolService-mydb

Please have a look here:

https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/jdbc.html?lang=en

Thanks!

Answers (0)