1

为什么 activejdbc 类 ConnectionSpecWrapper 在最近的版本中消失了?

在 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

在 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

我在过滤器中像这样使用它:

@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());
        }
    }
}

我正在考虑升级 Gazzetta dello Sport 的梦幻足球网站,该网站已经运行了 8 年并且运行良好。它位于 Java 7/Activeweb 1.10/Activejdbc 1.4.9

4

1 回答 1

0

正如您正确注意到的,“包装器”类已重命名为“规范”类。通常不使用这些类。如果您想继续使用它们,当然可以(相应地重命名)。但是,更好的方法是在文件中定义您的连接:

https://javalite.io/database_configuration#property-file-configuration 并简单地使用https://javalite.io/controller_filters#dbconnectionfilter

我假设您编写了一个自定义控制器过滤器并且正在使用ActiveWeb

更新:

既然我们已经确定您使用 ActivewWeb,请考虑删除您的代码并简单地使用 a DBConnectionFilter,这是一个完美的示例:https ://github.com/javalite/javalite-examples/blob/master/activeweb-simple/src/main/java /app/config/AppControllerConfig.java#L31

于 2020-04-27T20:58:46.877 回答