Search code examples
javaconnection-poolingeclipselink

How to alter connection in EclipseLink


I use EclipseLink in my application. EclipseLink uses some connection pool. I use EclipseLink internal one. Connection pool creates connection when it is needed and then keeps it for future use.

I need to make one specific SQL call on each connection when it is created, but only once. What I need to do is to grant user specific role on oracle. For security this user has this role, but disabled, and needs to enable it.

I don't want to do it each time connection is taken from the pool, only when it is created.

How can I do it?


Solution

  • I found better solution. I'll put it here in case anybody in future looks for this.

    I use my own SessionCustomizer. In which I have:

    public void customize(Session session) throws Exception {
        DatabaseLogin login = session.getLogin();
        Connector connector = login.getConnector();
    
        login.setConnector(new ConnectorWrapper(connector, m_onCreationQuery));
    }
    

    So there is my own ConnectorWrapper, which in turn wraps original Connector and when creating Connection, uses original one to create it, then calls SQL query on it, then returns it.