1

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

1 Answers1

0

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

ipolevoy
  • 5,432
  • 2
  • 31
  • 46
  • Yes it's a custom controller filter and i'm using active web. – Jeremy Coleman Apr 27 '20 at 21:17
  • But I need to do an equivalent thing on the latest releases, which do not have those classe. – Jeremy Coleman Apr 27 '20 at 21:19
  • These are the classe in the latest releases: – Jeremy Coleman Apr 27 '20 at 21:20
  • 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 – Jeremy Coleman Apr 27 '20 at 21:20
  • you can just rename these classes min your custom controller. The rest should work as before. – ipolevoy Apr 28 '20 at 13:03
  • Hi Igor, thanks, but what should I rename the ConnectionSpecWrapper class to? – Jeremy Coleman Apr 28 '20 at 15:38
  • I reckon there is a mismatch between the java docs and the actual jar in the repo. The javadoc: http://javalite.github.io/3.0-SNAPSHOT/org/javalite/activejdbc/connection_config/ConnectionSpecWrapper.html mentions the class "org.javalite.activejdbc.connection_config.ConnectionSpecWrapper", but it is not present in the jar. – Jeremy Coleman Apr 29 '20 at 17:43
  • @JeremyColeman, sorry about JavaDoc, it was not updated. It is now updated, so your link is dead. Instead of replicating the code in DBConnectionFilter, why can't you just use the filter? In case you still want to do this, you can borrow code from: https://github.com/javalite/javalite/blob/master/activeweb/src/main/java/org/javalite/activeweb/controller_filters/DBConnectionFilter.java. In all seriosness, why not delete all this code and just do it the way we recommend: https://github.com/javalite/javalite-examples/blob/master/activeweb-simple/src/main/java/app/config/AppControllerConfig.java? – ipolevoy Apr 29 '20 at 21:52
  • Hi Igor, thanks for that. I think I will delete that custom filter, because I don't need it any more. Was using it in the past to connect to different oracle schemas. If I remember well, I think you helped me do it. But now I'm no longer using it because the requirement for opening different schemas is no longer current. I'll check out your links. – Jeremy Coleman May 02 '20 at 14:53
  • @JeremyColeman, in that case, feel free to upvote and mark this answer as correct. Also, keep in mind, that you can in fact access multiple databases without writing custom code. You can add multiple `DBControllerFilter` configurations. – ipolevoy May 03 '20 at 17:51