Skip to content

Allow customize a ReflectorFactory using mybatis configuration xml file #675 #677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

/**
* @author Clinton Begin
* @author Kazuki Shimizu
*/
public class XMLConfigBuilder extends BaseBuilder {

Expand Down Expand Up @@ -108,7 +109,7 @@ private void parseConfiguration(XNode root) {
pluginElement(root.evalNode("plugins"));
objectFactoryElement(root.evalNode("objectFactory"));
objectWrapperFactoryElement(root.evalNode("objectWrapperFactory"));
reflectionFactoryElement(root.evalNode("reflectionFactory"));
reflectorFactoryElement(root.evalNode("reflectorFactory"));
settingsElement(settings);
// read it after objectFactory and objectWrapperFactory issue #631
environmentsElement(root.evalNode("environments"));
Expand Down Expand Up @@ -203,7 +204,7 @@ private void objectWrapperFactoryElement(XNode context) throws Exception {
}
}

private void reflectionFactoryElement(XNode context) throws Exception {
private void reflectorFactoryElement(XNode context) throws Exception {
if (context != null) {
String type = context.getStringAttribute("type");
ReflectorFactory factory = (ReflectorFactory) resolveClass(type).newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
limitations under the License.

-->
<!ELEMENT configuration (properties?, settings?, typeAliases?, typeHandlers?, objectFactory?, objectWrapperFactory?, plugins?, environments?, databaseIdProvider?, mappers?)>
<!ELEMENT configuration (properties?, settings?, typeAliases?, typeHandlers?, objectFactory?, objectWrapperFactory?, reflectorFactory?, plugins?, environments?, databaseIdProvider?, mappers?)>

<!ELEMENT databaseIdProvider (property*)>
<!ATTLIST databaseIdProvider
Expand Down Expand Up @@ -70,6 +70,11 @@ type CDATA #REQUIRED
type CDATA #REQUIRED
>

<!ELEMENT reflectorFactory EMPTY>
<!ATTLIST reflectorFactory
type CDATA #REQUIRED
>

<!ELEMENT plugins (plugin+)>

<!ELEMENT plugin (property*)>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright 2009-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ibatis.builder;

import org.apache.ibatis.reflection.DefaultReflectorFactory;

public class CustomReflectorFactory extends DefaultReflectorFactory {

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
</objectFactory>

<objectWrapperFactory type="org.apache.ibatis.builder.CustomObjectWrapperFactory" />

<reflectorFactory type="org.apache.ibatis.builder.CustomReflectorFactory"/>

<plugins>
<plugin interceptor="org.apache.ibatis.builder.ExamplePlugin">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ public void shouldSuccessfullyLoadXMLConfigFile() throws Exception {

assertThat(config.getObjectWrapperFactory(), is(instanceOf(CustomObjectWrapperFactory.class)));

assertThat(config.getReflectorFactory(), is(instanceOf(CustomReflectorFactory.class)));

ExamplePlugin plugin = (ExamplePlugin)config.getInterceptors().get(0);
assertThat(plugin.getProperties().size(), is(1));
assertThat(plugin.getProperties().getProperty("pluginProperty"), is("100"));
Expand Down