Skip to content

Commit

Permalink
Merge pull request mybatis#270 from hazendaz/master
Browse files Browse the repository at this point in the history
Lots of Sonar and Java 6 plus Pretty Readme
  • Loading branch information
emacarron committed Sep 22, 2014
2 parents d3a073f + 90b09f7 commit c967452
Show file tree
Hide file tree
Showing 115 changed files with 588 additions and 244 deletions.
6 changes: 0 additions & 6 deletions README

This file was deleted.

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
MYBATIS Data Mapper Framework
=============================

[![Build Status](https://travis-ci.org/mybatis/mybatis-3.svg?branch=master)](https://travis-ci.org/mybatis/mybatis-3)
[![Maven central](https://maven-badges.herokuapp.com/maven-central/org.mybatis/mybatis/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.mybatis/mybatis)

![mybatis](http://mybatis.github.io/images/mybatis-logo.png)

The MyBatis data mapper framework makes it easier to use a relational database with object-oriented applications.
MyBatis couples objects with stored procedures or SQL statements using a XML descriptor or annotations.
Simplicity is the biggest advantage of the MyBatis data mapper over object relational mapping tools.

Essentials
----------

* [See the docs](http://mybatis.github.io/mybatis-3)
* [Download Latest](https://github.com/mybatis/mybatis-3/releases)
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
</distributionManagement>

<properties>
<clirr.comparisonVersion>3.2.7</clirr.comparisonVersion>
<findbugs.onlyAnalyze>org.apache.ibatis.*</findbugs.onlyAnalyze>
<clirr.comparisonVersion>3.2.6</clirr.comparisonVersion>
<osgi.export>org.apache.ibatis.*;version=${project.version};-noimport:=true</osgi.export>
<osgi.import>*;resolution:=optional</osgi.import>
<osgi.dynamicImport>*</osgi.dynamicImport>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/apache/ibatis/annotations/Many.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@Target(ElementType.METHOD)
public @interface Many {
String select() default "";

FetchType fetchType() default FetchType.DEFAULT;

}
2 changes: 1 addition & 1 deletion src/main/java/org/apache/ibatis/annotations/One.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@Target(ElementType.METHOD)
public @interface One {
String select() default "";

FetchType fetchType() default FetchType.DEFAULT;

}
14 changes: 7 additions & 7 deletions src/main/java/org/apache/ibatis/binding/MapperMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ private Object rowCountResult(int rowCount) {
if (method.returnsVoid()) {
result = null;
} else if (Integer.class.equals(method.getReturnType()) || Integer.TYPE.equals(method.getReturnType())) {
result = rowCount;
result = Integer.valueOf(rowCount);
} else if (Long.class.equals(method.getReturnType()) || Long.TYPE.equals(method.getReturnType())) {
result = (long) rowCount;
result = Long.valueOf(rowCount);
} else if (Boolean.class.equals(method.getReturnType()) || Boolean.TYPE.equals(method.getReturnType())) {
result = (rowCount > 0);
result = Boolean.valueOf(rowCount > 0);
} else {
throw new BindingException("Mapper method '" + command.getName() + "' has an unsupported return type: " + method.getReturnType());
}
Expand Down Expand Up @@ -174,7 +174,7 @@ public static class SqlCommand {
private final String name;
private final SqlCommandType type;

public SqlCommand(Configuration configuration, Class<?> mapperInterface, Method method) throws BindingException {
public SqlCommand(Configuration configuration, Class<?> mapperInterface, Method method) {
String statementName = mapperInterface.getName() + "." + method.getName();
MappedStatement ms = null;
if (configuration.hasStatement(statementName)) {
Expand Down Expand Up @@ -216,7 +216,7 @@ public static class MethodSignature {
private final SortedMap<Integer, String> params;
private final boolean hasNamedParameters;

public MethodSignature(Configuration configuration, Method method) throws BindingException {
public MethodSignature(Configuration configuration, Method method) {
this.returnType = method.getReturnType();
this.returnsVoid = void.class.equals(this.returnType);
this.returnsMany = (configuration.getObjectFactory().isCollection(this.returnType) || this.returnType.isArray());
Expand All @@ -233,12 +233,12 @@ public Object convertArgsToSqlCommandParam(Object[] args) {
if (args == null || paramCount == 0) {
return null;
} else if (!hasNamedParameters && paramCount == 1) {
return args[params.keySet().iterator().next()];
return args[params.keySet().iterator().next().intValue()];
} else {
final Map<String, Object> param = new ParamMap<Object>();
int i = 0;
for (Map.Entry<Integer, String> entry : params.entrySet()) {
param.put(entry.getValue(), args[entry.getKey()]);
param.put(entry.getValue(), args[entry.getKey().intValue()]);
// issue #71, add param names as param1, param2...but ensure backward compatibility
final String genericParamName = "param" + String.valueOf(i + 1);
if (!param.containsKey(genericParamName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public List<ParameterMapping> getParameterMappings() {
return parameterMappings;
}

@Override
public String handleToken(String content) {
parameterMappings.add(buildParameterMapping(content));
return "?";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public StaticSqlSource(Configuration configuration, String sql, List<ParameterMa
this.configuration = configuration;
}

@Override
public BoundSql getBoundSql(Object parameterObject) {
return new BoundSql(configuration, sql, parameterMappings, parameterObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ private void applyResultMap(String resultMapId, Class<?> returnType, Arg[] args,
applyConstructorArgs(args, returnType, resultMappings);
applyResults(results, returnType, resultMappings);
Discriminator disc = applyDiscriminator(resultMapId, returnType, discriminator);
assistant.addResultMap(resultMapId, returnType, null, disc, resultMappings, null); // TODO add AutoMappingBehaviour
// TODO add AutoMappingBehaviour
assistant.addResultMap(resultMapId, returnType, null, disc, resultMappings, null);
createDiscriminatorResultMaps(resultMapId, returnType, discriminator);
}

Expand All @@ -219,9 +220,11 @@ private void createDiscriminatorResultMaps(String resultMapId, Class<?> resultTy
for (Case c : discriminator.cases()) {
String caseResultMapId = resultMapId + "-" + c.value();
List<ResultMapping> resultMappings = new ArrayList<ResultMapping>();
applyConstructorArgs(c.constructArgs(), resultType, resultMappings); // issue #136
// issue #136
applyConstructorArgs(c.constructArgs(), resultType, resultMappings);
applyResults(c.results(), resultType, resultMappings);
assistant.addResultMap(caseResultMapId, c.type(), resultMapId, null, resultMappings, null); // TODO add AutoMappingBehaviour
// TODO add AutoMappingBehaviour
assistant.addResultMap(caseResultMapId, c.type(), resultMapId, null, resultMappings, null);
}
}
}
Expand Down Expand Up @@ -312,19 +315,23 @@ void parseStatement(Method method) {
sqlCommandType,
fetchSize,
timeout,
null, // ParameterMapID
// ParameterMapID
null,
parameterTypeClass,
resultMapId, // ResultMapID
resultMapId,
getReturnType(method),
resultSetType,
flushCache,
useCache,
false, // TODO issue #577
// TODO issue #577
false,
keyGenerator,
keyProperty,
keyColumn,
// DatabaseID
null,
languageDriver,
// ResultSets
null);
}
}
Expand All @@ -346,7 +353,8 @@ private Class<?> getParameterType(Method method) {
if (parameterType == null) {
parameterType = parameterTypes[i];
} else {
parameterType = ParamMap.class; // issue #135
// issue #135
parameterType = ParamMap.class;
}
}
}
Expand All @@ -355,7 +363,8 @@ private Class<?> getParameterType(Method method) {

private Class<?> getReturnType(Method method) {
Class<?> returnType = method.getReturnType();
if (void.class.equals(returnType)) { // issue #508
// issue #508
if (void.class.equals(returnType)) {
ResultType rt = method.getAnnotation(ResultType.class);
if (rt != null) {
returnType = rt.value();
Expand All @@ -368,11 +377,13 @@ private Class<?> getReturnType(Method method) {
returnTypeParameter = actualTypeArguments[0];
if (returnTypeParameter instanceof Class) {
returnType = (Class<?>) returnTypeParameter;
} else if (returnTypeParameter instanceof ParameterizedType) { // (issue #443) actual type can be a also a parametrized type
} else if (returnTypeParameter instanceof ParameterizedType) {
// (issue #443) actual type can be a also a parameterized type
returnType = (Class<?>) ((ParameterizedType) returnTypeParameter).getRawType();
} else if (returnTypeParameter instanceof GenericArrayType) {
Class<?> componentType = (Class<?>) ((GenericArrayType) returnTypeParameter).getGenericComponentType();
returnType = Array.newInstance(componentType, 0).getClass(); // (issue #525) support List<byte[]>
// (issue #525) support List<byte[]>
returnType = Array.newInstance(componentType, 0).getClass();
}
}
}
Expand All @@ -385,7 +396,8 @@ private Class<?> getReturnType(Method method) {
returnTypeParameter = actualTypeArguments[1];
if (returnTypeParameter instanceof Class) {
returnType = (Class<?>) returnTypeParameter;
} else if (returnTypeParameter instanceof ParameterizedType) { // (issue 443) actual type can be a also a parametrized type
} else if (returnTypeParameter instanceof ParameterizedType) {
// (issue 443) actual type can be a also a parameterized type
returnType = (Class<?>) ((ParameterizedType) returnTypeParameter).getRawType();
}
}
Expand Down Expand Up @@ -504,7 +516,7 @@ private String nestedSelectId(Result result) {
}

private boolean isLazy(Result result) {
Boolean isLazy = configuration.isLazyLoadingEnabled();
boolean isLazy = configuration.isLazyLoadingEnabled();
if (result.one().select().length() > 0 && FetchType.DEFAULT != result.one().fetchType()) {
isLazy = (result.one().fetchType() == FetchType.LAZY);
} else if (result.many().select().length() > 0 && FetchType.DEFAULT != result.many().fetchType()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public ProviderSqlSource(Configuration config, Object provider) {
}
}

@Override
public BoundSql getBoundSql(Object parameterObject) {
SqlSource sqlSource = createSqlSource(parameterObject);
return sqlSource.getBoundSql(parameterObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ public Configuration parse() {

private void parseConfiguration(XNode root) {
try {
propertiesElement(root.evalNode("properties")); //issue #117 read properties first
//issue #117 read properties first
propertiesElement(root.evalNode("properties"));
typeAliasesElement(root.evalNode("typeAliases"));
pluginElement(root.evalNode("plugins"));
objectFactoryElement(root.evalNode("objectFactory"));
objectWrapperFactoryElement(root.evalNode("objectWrapperFactory"));
settingsElement(root.evalNode("settings"));
environmentsElement(root.evalNode("environments")); // read it after objectFactory and objectWrapperFactory issue #631
// read it after objectFactory and objectWrapperFactory issue #631
environmentsElement(root.evalNode("environments"));
databaseIdProviderElement(root.evalNode("databaseIdProvider"));
typeHandlerElement(root.evalNode("typeHandlers"));
mapperElement(root.evalNode("mappers"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ private Node findSqlFragment(String refid) {
refid = builderAssistant.applyCurrentNamespace(refid, true);
try {
XNode nodeToInclude = configuration.getSqlFragments().get(refid);
Node result = nodeToInclude.getNode().cloneNode(true);
return result;
return nodeToInclude.getNode().cloneNode(true);
} catch (IllegalArgumentException e) {
throw new IncompleteElementException("Could not find SQL statement to include with refid '" + refid + "'", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void setSize(final int size) {
keyMap = new LinkedHashMap<Object, Object>(size, .75F, true) {
private static final long serialVersionUID = 4267176411845948333L;

@Override
protected boolean removeEldestEntry(Map.Entry<Object, Object> eldest) {
boolean tooBig = size() > size;
if (tooBig) {
Expand Down Expand Up @@ -84,6 +85,7 @@ public void clear() {
keyMap.clear();
}

@Override
public ReadWriteLock getReadWriteLock() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ public void putObject(Object key, Object object) {

@Override
public Object getObject(Object key) {
if (clearWhenStale()) {
return null;
} else {
return delegate.getObject(key);
}
return clearWhenStale() ? null : delegate.getObject(key);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private void removeGarbageCollectedItems() {
private static class SoftEntry extends SoftReference<Object> {
private final Object key;

private SoftEntry(Object key, Object value, ReferenceQueue<Object> garbageCollectionQueue) {
SoftEntry(Object key, Object value, ReferenceQueue<Object> garbageCollectionQueue) {
super(value, garbageCollectionQueue);
this.key = key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public int getSize() {
@Override
public Object getObject(Object key) {
// issue #146
if (clearOnCommit) {
return null;
}
return delegate.getObject(key);
return clearOnCommit ? null : delegate.getObject(key);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void clear() {
delegate.clear();
}

@Override
public ReadWriteLock getReadWriteLock() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class JndiDataSourceFactory implements DataSourceFactory {

private DataSource dataSource;

@Override
public void setProperties(Properties properties) {
try {
InitialContext initCtx = null;
Expand All @@ -60,6 +61,7 @@ public void setProperties(Properties properties) {
}
}

@Override
public DataSource getDataSource() {
return dataSource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@ public Connection getProxyConnection() {
* @return The hashcode of the real connection (or 0 if it is null)
*/
public int getRealHashCode() {
if (realConnection == null) {
return 0;
} else {
return realConnection.hashCode();
}
return realConnection == null ? 0 : realConnection.hashCode();
}

/*
Expand Down Expand Up @@ -203,6 +199,7 @@ public long getCheckoutTime() {
return System.currentTimeMillis() - checkoutTimestamp;
}

@Override
public int hashCode() {
return hashCode;
}
Expand All @@ -213,6 +210,7 @@ public int hashCode() {
* @param obj - the other connection to test for equality
* @see Object#equals(Object)
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof PooledConnection) {
return realConnection.hashCode() == (((PooledConnection) obj).realConnection.hashCode());
Expand All @@ -231,6 +229,7 @@ public boolean equals(Object obj) {
* @param args - the parameters to be passed to the method
* @see java.lang.reflect.InvocationHandler#invoke(Object, java.lang.reflect.Method, Object[])
*/
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
if (CLOSE.hashCode() == methodName.hashCode() && CLOSE.equals(methodName)) {
Expand Down
Loading

0 comments on commit c967452

Please sign in to comment.