Skip to content

Conversation

epochcoder
Copy link
Contributor

Supported via the InputStream/Reader constructors

Default constructors will keep using a new configuration

Supported via the InputStream/Reader constructors

Default constructors will keep using a new configuration
@harawata
Copy link
Member

harawata commented Oct 27, 2022

Thanks for the PR, @epochcoder !

The purpose of XMLConfigBuilder is to build a new Configuration, so accepting an existing instance of Configuration bothers me a little bit.
Also, some settings (e.g. VFS) must be loaded before other settings, but this change makes it impossible to enforce the order.

If XMLConfigBuilder takes Class<? extends Configuration> and instantiates it in the constructor, it still satisfies your need, right?
It would look something like this:

private XMLConfigBuilder(Class<? extends Configuration> configClass, XPathParser parser, String environment, Properties props) {
  super(newConfig(configClass));
  ...
}

private static Configuration newConfig(Class<? extends Configuration> configClass) {
  try {
    return configClass.getConstructor().newInstance();
  } catch (Exception e) {
    throw new BuilderException("Failed to create a new Configuration instance.", e);
  }
}

If the custom Configuration has extra properties, they must be set to the instance returned from the parse() method.

Cc: @brucelwl @zeimao77

@epochcoder
Copy link
Contributor Author

epochcoder commented Oct 28, 2022 via email

…Builder

to use a specific implementation when creating the configuration
@coveralls
Copy link

Coverage Status

Coverage increased (+0.008%) to 87.305% when pulling d7826d7 on epochcoder:feature/2724-pass-subclassed-configuration-xmlconfigbuilder into 043aaaa on mybatis:master.

@harawata harawata self-assigned this Oct 31, 2022
@harawata harawata added the enhancement Improve a feature or add a new feature label Oct 31, 2022
@harawata harawata merged commit 350ac91 into mybatis:master Oct 31, 2022
@kazuki43zoo kazuki43zoo modified the milestone: 3.5.12 May 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improve a feature or add a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants