How to read connection pool settings from resource adapter?

251 views Asked by At

I am working on a new resource adapter for Glassfish. It uses a connection pool that has a property set in the admin console. Connector Connection Pools -> Additional Properties -> name=url, value=127.0.0.1 I would like to read this property from the resource adapter. (from my managed connection implementation class for example)

I tried checking the documentation and online examples but did not find out how to do it.

2

There are 2 answers

1
anonymous On

This is the common way for almost all web apps on j2ee containers with connection pools.

    InitialContext ctx = new InitialContext();
    //The JDBC Data source that we just created
    DataSource ds = (DataSource) ctx.lookup("url here");
    Connection connection = ds.getConnection();
0
Severin On
@Connector(reauthenticationSupport = false, transactionSupport = TransactionSupport.TransactionSupportLevel.NoTransaction)
public class SocketResourceAdapter implements ResourceAdapter {

/** The logger */
private static Logger log = Logger.getLogger("SocketResourceAdapter");

/** Name property */
@ConfigProperty(defaultValue = "DefaultMessage", supportsDynamicUpdates = true)
private String name;

@ConfigProperty(defaultValue = "---", type = String.class)
private String url;

@ConfigProperty(type = Integer.class)
private Integer port;


public String getUrl() {
    return url;
}
public void setUrl(String url) {
    this.url = url;
}

public Integer getPort() {
    return port;
}
public void setPort(Integer port) {
    this.port = port;
}

And then I can just use getUrl() in the resource adapter. At first it did not work because I was setting the properties for the connection factory and not the resource adapter.