简体   繁体   English

ConnectionSpecWrapper 在最近的版本中不再存在

[英]ConnectionSpecWrapper no longer present in recent releases

Why the activejdbc class ConnectionSpecWrapper has disappeared in recent releases?为什么 activejdbc class ConnectionSpecWrapper 在最近的版本中消失了?

in the 3.0 (and also 2.3.2-j8) activejdbc jar we have:在 3.0(以及 2.3.2-j8)activejdbc jar 中,我们有:

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在 2.3 jar 我们有

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.我正在考虑升级 Gazzetta dello Sport 的梦幻足球网站,该网站已经运行了 8 年并且运行良好。 It is on Java 7/Activeweb 1.10/Activejdbc 1.4.9它位于 Java 7/Activeweb 1.10/Activejdbc 1.4.9

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 . https://javalite.io/database_configuration#property-file-configuration并简单地使用https://javalite.io/controller_filters#dbconnectionfilter

I'm assuming you wrote a custom controller filter and are using ActiveWeb .我假设您编写了一个自定义 controller 过滤器并且正在使用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既然我们已经确定您使用 ActivewWeb,请考虑删除您的代码并简单地使用DBConnectionFilter ,这是一个完美的示例: https://github.com/javalite/javalite-examples/blob/master/activeweb-simple/src/main/ java/app/config/AppControllerConfig.java#L31

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM