Jeremy Coleman
Jeremy Coleman

Reputation: 11

ConnectionSpecWrapper no longer present in recent releases

Why the activejdbc class ConnectionSpecWrapper has disappeared in recent releases?

in the 3.0 (and also 2.3.2-j8) activejdbc jar we have:

org/javalite/activejdbc/connection_config/ConnectionJndiConfig.class
org/javalite/activejdbc/connection_config/ConnectionConfig.class
org/javalite/activejdbc/connection_config/ConnectionJdbcConfig.class
org/javalite/activejdbc/connection_config/ConnectionDataSourceConfig.class
org/javalite/activejdbc/connection_config/DBConfiguration.class

In 2.3 jar we have

org/javalite/activejdbc/connection_config/ConnectionSpecWrapper.class
org/javalite/activejdbc/connection_config/DbConfiguration.class
org/javalite/activejdbc/connection_config/ConnectionJdbcSpec.class
org/javalite/activejdbc/connection_config/ConnectionSpec.class
org/javalite/activejdbc/connection_config/ConnectionDataSourceSpec.class
org/javalite/activejdbc/connection_config/ConnectionJndiSpec.class

I am using it like this, in a filter:

@Override
public void before() {

    if(Configuration.isTesting())
        return;

    List<ConnectionSpecWrapper> connectionWrappers = getConnectionWrappers();

    if (connectionWrappers.isEmpty()) {
        throw new InitException("There are no connection specs in '" + Configuration.getEnv() + "' environment");
    }

    for (ConnectionSpecWrapper connectionWrapper : connectionWrappers) {
        DB db = new DB(connectionWrapper.getDbName());
        db.open(connectionWrapper.getConnectionSpec());
        log.debug("Opened connection: " + connectionWrapper.getDbName() + " envname " + connectionWrapper.getEnvironment());
        if(manageTransaction){
            db.openTransaction();
        }
    }
}

@Override
public void after() {
    if(Configuration.isTesting())
        return;

    List<ConnectionSpecWrapper> connectionWrappers = getConnectionWrappers();
    if (connectionWrappers != null && !connectionWrappers.isEmpty()) {
        for (ConnectionSpecWrapper connectionWrapper : connectionWrappers) {
            DB db = new DB(connectionWrapper.getDbName());
            if(manageTransaction){
                db.commitTransaction();
            }
            db.close();
            log.debug("Closed connection: " + connectionWrapper.getDbName() + " envname " + connectionWrapper.getEnvironment());
        }
    }
}

I'm thinking of upgrading the Gazzetta dello Sport's fantasy football site which has been live for something like 8 years and working really well. It is on Java 7/Activeweb 1.10/Activejdbc 1.4.9

Upvotes: 1

Views: 55

Answers (1)

ipolevoy
ipolevoy

Reputation: 5518

The "wrapper" classes have been renamed into "Spec" classes, as you rightly noticed. Generally these classes are not used. If you want to continue using them you can of course (rename accordingly). However, a better approach is to define your connections in a file:

https://javalite.io/database_configuration#property-file-configuration and simply use https://javalite.io/controller_filters#dbconnectionfilter.

I'm assuming you wrote a custom controller filter and are using ActiveWeb.

Update:

Now that we established you use ActivewWeb, consider removing your code and simply using a DBConnectionFilter, here is a perfect example: https://github.com/javalite/javalite-examples/blob/master/activeweb-simple/src/main/java/app/config/AppControllerConfig.java#L31

Upvotes: 0

Related Questions