Skip to content

Commit 6ab4616

Browse files
authored
Merge branch 'master' into master
2 parents 68be874 + 290afb5 commit 6ab4616

File tree

148 files changed

+2891
-996
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+2891
-996
lines changed

src/main/java/org/apache/ibatis/annotations/Arg.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,4 +46,9 @@
4646
String resultMap() default "";
4747

4848
String name() default "";
49+
50+
/**
51+
* @since 3.5.0
52+
*/
53+
String columnPrefix() default "";
4954
}

src/main/java/org/apache/ibatis/annotations/Options.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public enum FlushCachePolicy {
4848

4949
FlushCachePolicy flushCache() default FlushCachePolicy.DEFAULT;
5050

51-
ResultSetType resultSetType() default ResultSetType.FORWARD_ONLY;
51+
ResultSetType resultSetType() default ResultSetType.DEFAULT;
5252

5353
StatementType statementType() default StatementType.PREPARED;
5454

src/main/java/org/apache/ibatis/binding/MapperMethod.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
import org.apache.ibatis.mapping.MappedStatement;
2222
import org.apache.ibatis.mapping.SqlCommandType;
2323
import org.apache.ibatis.mapping.StatementType;
24-
import org.apache.ibatis.reflection.Jdk;
2524
import org.apache.ibatis.reflection.MetaObject;
26-
import org.apache.ibatis.reflection.OptionalUtil;
2725
import org.apache.ibatis.reflection.ParamNameResolver;
2826
import org.apache.ibatis.reflection.TypeParameterResolver;
2927
import org.apache.ibatis.session.Configuration;
@@ -86,7 +84,7 @@ public Object execute(SqlSession sqlSession, Object[] args) {
8684
result = sqlSession.selectOne(command.getName(), param);
8785
if (method.returnsOptional() &&
8886
(result == null || !method.getReturnType().equals(result.getClass()))) {
89-
result = OptionalUtil.ofNullable(result);
87+
result = Optional.ofNullable(result);
9088
}
9189
}
9290
break;
@@ -296,7 +294,7 @@ public MethodSignature(Configuration configuration, Class<?> mapperInterface, Me
296294
this.returnsVoid = void.class.equals(this.returnType);
297295
this.returnsMany = configuration.getObjectFactory().isCollection(this.returnType) || this.returnType.isArray();
298296
this.returnsCursor = Cursor.class.equals(this.returnType);
299-
this.returnsOptional = Jdk.optionalExists && Optional.class.equals(this.returnType);
297+
this.returnsOptional = Optional.class.equals(this.returnType);
300298
this.mapKey = getMapKey(method);
301299
this.returnsMap = this.mapKey != null;
302300
this.rowBoundsIndex = getUniqueParamIndex(method, RowBounds.class);

src/main/java/org/apache/ibatis/binding/MapperProxy.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.lang.reflect.Modifier;
2424
import java.util.Map;
2525

26-
import org.apache.ibatis.lang.UsesJava7;
2726
import org.apache.ibatis.reflection.ExceptionUtil;
2827
import org.apache.ibatis.session.SqlSession;
2928

@@ -63,7 +62,6 @@ private MapperMethod cachedMapperMethod(Method method) {
6362
return methodCache.computeIfAbsent(method, k -> new MapperMethod(mapperInterface, method, sqlSession.getConfiguration()));
6463
}
6564

66-
@UsesJava7
6765
private Object invokeDefaultMethod(Object proxy, Method method, Object[] args)
6866
throws Throwable {
6967
final Constructor<MethodHandles.Lookup> constructor = MethodHandles.Lookup.class

src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
import org.apache.ibatis.mapping.SqlSource;
8282
import org.apache.ibatis.mapping.StatementType;
8383
import org.apache.ibatis.parsing.PropertyParser;
84-
import org.apache.ibatis.reflection.Jdk;
8584
import org.apache.ibatis.reflection.TypeParameterResolver;
8685
import org.apache.ibatis.scripting.LanguageDriver;
8786
import org.apache.ibatis.session.Configuration;
@@ -167,11 +166,15 @@ private void loadXmlResource() {
167166
// this flag is set at XMLMapperBuilder#bindMapperForNamespace
168167
if (!configuration.isResourceLoaded("namespace:" + type.getName())) {
169168
String xmlResource = type.getName().replace('.', '/') + ".xml";
170-
InputStream inputStream = null;
171-
try {
172-
inputStream = Resources.getResourceAsStream(type.getClassLoader(), xmlResource);
173-
} catch (IOException e) {
174-
// ignore, resource is not required
169+
// #1347
170+
InputStream inputStream = type.getResourceAsStream("/" + xmlResource);
171+
if (inputStream == null) {
172+
// Search XML mapper that is not in the module but in the classpath.
173+
try {
174+
inputStream = Resources.getResourceAsStream(type.getClassLoader(), xmlResource);
175+
} catch (IOException e2) {
176+
// ignore, resource is not required
177+
}
175178
}
176179
if (inputStream != null) {
177180
XMLMapperBuilder xmlParser = new XMLMapperBuilder(inputStream, assistant.getConfiguration(), xmlResource, configuration.getSqlFragments(), type.getName());
@@ -298,7 +301,7 @@ void parseStatement(Method method) {
298301
Integer fetchSize = null;
299302
Integer timeout = null;
300303
StatementType statementType = StatementType.PREPARED;
301-
ResultSetType resultSetType = ResultSetType.FORWARD_ONLY;
304+
ResultSetType resultSetType = null;
302305
SqlCommandType sqlCommandType = getSqlCommandType(method);
303306
boolean isSelect = sqlCommandType == SqlCommandType.SELECT;
304307
boolean flushCache = !isSelect;
@@ -451,7 +454,7 @@ private Class<?> getReturnType(Method method) {
451454
returnType = (Class<?>) ((ParameterizedType) returnTypeParameter).getRawType();
452455
}
453456
}
454-
} else if (Jdk.optionalExists && Optional.class.equals(rawType)) {
457+
} else if (Optional.class.equals(rawType)) {
455458
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
456459
Type returnTypeParameter = actualTypeArguments[0];
457460
if (returnTypeParameter instanceof Class<?>) {
@@ -610,7 +613,7 @@ private void applyConstructorArgs(Arg[] args, Class<?> resultType, List<ResultMa
610613
nullOrEmpty(arg.select()),
611614
nullOrEmpty(arg.resultMap()),
612615
null,
613-
null,
616+
nullOrEmpty(arg.columnPrefix()),
614617
typeHandler,
615618
flags,
616619
null,

src/main/java/org/apache/ibatis/builder/xml/XMLMapperEntityResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2016 the original author or authors.
2+
* Copyright 2009-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ public class XMLMapperEntityResolver implements EntityResolver {
4040
private static final String MYBATIS_CONFIG_DTD = "org/apache/ibatis/builder/xml/mybatis-3-config.dtd";
4141
private static final String MYBATIS_MAPPER_DTD = "org/apache/ibatis/builder/xml/mybatis-3-mapper.dtd";
4242

43-
/*
43+
/**
4444
* Converts a public DTD into a local one
4545
*
4646
* @param publicId The public id that is what comes after "PUBLIC"

src/main/java/org/apache/ibatis/builder/xml/mybatis-3-mapper.dtd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<!--
33
4-
Copyright 2009-2017 the original author or authors.
4+
Copyright 2009-2018 the original author or authors.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -90,6 +90,7 @@ typeHandler CDATA #IMPLIED
9090
select CDATA #IMPLIED
9191
resultMap CDATA #IMPLIED
9292
name CDATA #IMPLIED
93+
columnPrefix CDATA #IMPLIED
9394
>
9495

9596
<!ELEMENT arg EMPTY>
@@ -101,6 +102,7 @@ typeHandler CDATA #IMPLIED
101102
select CDATA #IMPLIED
102103
resultMap CDATA #IMPLIED
103104
name CDATA #IMPLIED
105+
columnPrefix CDATA #IMPLIED
104106
>
105107

106108
<!ELEMENT collection (constructor?,id*,result*,association*,collection*, discriminator?)>
@@ -172,7 +174,7 @@ parameterMap CDATA #IMPLIED
172174
parameterType CDATA #IMPLIED
173175
resultMap CDATA #IMPLIED
174176
resultType CDATA #IMPLIED
175-
resultSetType (FORWARD_ONLY | SCROLL_INSENSITIVE | SCROLL_SENSITIVE) #IMPLIED
177+
resultSetType (FORWARD_ONLY | SCROLL_INSENSITIVE | SCROLL_SENSITIVE | DEFAULT) #IMPLIED
176178
statementType (STATEMENT|PREPARED|CALLABLE) #IMPLIED
177179
fetchSize CDATA #IMPLIED
178180
timeout CDATA #IMPLIED

src/main/java/org/apache/ibatis/cache/decorators/SerializedCache.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -91,12 +91,10 @@ public boolean equals(Object obj) {
9191
}
9292

9393
private byte[] serialize(Serializable value) {
94-
try {
95-
ByteArrayOutputStream bos = new ByteArrayOutputStream();
96-
ObjectOutputStream oos = new ObjectOutputStream(bos);
94+
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
95+
ObjectOutputStream oos = new ObjectOutputStream(bos)) {
9796
oos.writeObject(value);
9897
oos.flush();
99-
oos.close();
10098
return bos.toByteArray();
10199
} catch (Exception e) {
102100
throw new CacheException("Error serializing object. Cause: " + e, e);
@@ -105,11 +103,9 @@ private byte[] serialize(Serializable value) {
105103

106104
private Serializable deserialize(byte[] value) {
107105
Serializable result;
108-
try {
109-
ByteArrayInputStream bis = new ByteArrayInputStream(value);
110-
ObjectInputStream ois = new CustomObjectInputStream(bis);
106+
try (ByteArrayInputStream bis = new ByteArrayInputStream(value);
107+
ObjectInputStream ois = new CustomObjectInputStream(bis)) {
111108
result = (Serializable) ois.readObject();
112-
ois.close();
113109
} catch (Exception e) {
114110
throw new CacheException("Error deserializing object. Cause: " + e, e);
115111
}

0 commit comments

Comments
 (0)