Need To Use Dynamic Custom Connection Class for connection pooling in java

57 Views Asked by At

I am thinking of implementing connection pool for DB Connections using dbcp2.

But I am using different types of custom connection classes.

How can I override the Datasource class to use dynamic custom connection classes(Say MyConnectionClass1, MyConnectionClass2, etc..) based on the input?

1

There are 1 best solutions below

7
On

What you you mean by input? It's possible you are needed same DatasourceFactory?

public DatasourceFactory {
   public Datasource instance(Object sameParameter) {
      if(// condition one for sameParameter) {
         return new MyConnectionClass1DataSource();
      } else {
         return new MyConnectionClass2DataSource();
      }
   }
}