Skip to content

Commit

Permalink
Do not create new object and immediately return
Browse files Browse the repository at this point in the history
Just return objects directly rather than creating another one.
  • Loading branch information
hazendaz committed Sep 22, 2014
1 parent 7f8ee70 commit 2e043d9
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 20 deletions.
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 @@ -118,8 +118,7 @@ public TypeHandler<?> getTypeHandler(Class<?> propertyType, String columnName) {

private Class<?> resolveClass(String className) {
try {
final Class<?> clazz = Resources.classForName(className);
return clazz;
return Resources.classForName(className);
} catch (ClassNotFoundException e) {
return null;
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/apache/ibatis/mapping/MappedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ private static String[] delimitedStringtoArray(String in) {
if (in == null || in.trim().length() == 0) {
return null;
} else {
String[] answer = in.split(",");
return answer;
return in.split(",");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ public <T> T create(Class<T> type) {
return create(type, null, null);
}

@SuppressWarnings("unchecked")
@Override
public <T> T create(Class<T> type, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
Class<?> classToCreate = resolveInterface(type);
@SuppressWarnings("unchecked")
// we know types are assignable
T created = (T) instantiateClass(classToCreate, constructorArgTypes, constructorArgs);
return created;
return (T) instantiateClass(classToCreate, constructorArgTypes, constructorArgs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,8 @@ public Object get(Object key) {
}

if (parameterMetaObject != null) {
Object object = parameterMetaObject.getValue(strKey);
// issue #61 do not modify the context when reading
// if (object != null) {
// super.put(strKey, object);
// }

return object;
return parameterMetaObject.getValue(strKey);
}

return null;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/apache/ibatis/session/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,7 @@ public V get(Object key) {

private String getShortName(String key) {
final String[] keyparts = key.split("\\.");
final String shortKey = keyparts[keyparts.length - 1];
return shortKey;
return keyparts[keyparts.length - 1];
}

protected static class Ambiguity {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/apache/ibatis/type/TypeHandlerRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public <T> TypeHandler<T> getTypeHandler(TypeReference<T> javaTypeReference, Jdb
return getTypeHandler(javaTypeReference.getRawType(), jdbcType);
}

@SuppressWarnings("unchecked")
private <T> TypeHandler<T> getTypeHandler(Type type, JdbcType jdbcType) {
Map<JdbcType, TypeHandler<?>> jdbcHandlerMap = TYPE_HANDLER_MAP.get(type);
TypeHandler<?> handler = null;
Expand All @@ -177,10 +178,8 @@ private <T> TypeHandler<T> getTypeHandler(Type type, JdbcType jdbcType) {
if (handler == null && type != null && type instanceof Class && Enum.class.isAssignableFrom((Class<?>) type)) {
handler = new EnumTypeHandler((Class<?>) type);
}
@SuppressWarnings("unchecked")
// type drives generics here
TypeHandler<T> returned = (TypeHandler<T>) handler;
return returned;
return (TypeHandler<T>) handler;
}

public TypeHandler<Object> getUnknownTypeHandler() {
Expand Down

0 comments on commit 2e043d9

Please sign in to comment.