Skip to content
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

[ci] Formatting #2794

Merged
merged 1 commit into from
Feb 4, 2023
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
70 changes: 22 additions & 48 deletions src/main/java/org/apache/ibatis/builder/MapperBuilderAssistant.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,32 +347,26 @@ public MappedStatement addMappedStatement(String id, SqlSource sqlSource, Statem
String resultMap, Class<?> resultType, ResultSetType resultSetType, boolean flushCache, boolean useCache,
boolean resultOrdered, KeyGenerator keyGenerator, String keyProperty, String keyColumn, String databaseId,
LanguageDriver lang, String resultSets) {
return addMappedStatement(
id, sqlSource, statementType, sqlCommandType, fetchSize, timeout,
parameterMap, parameterType, resultMap, resultType, resultSetType,
flushCache, useCache, resultOrdered, keyGenerator, keyProperty,
keyColumn, databaseId, lang, null, false);
return addMappedStatement(id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, parameterMap,
parameterType, resultMap, resultType, resultSetType, flushCache, useCache, resultOrdered, keyGenerator,
keyProperty, keyColumn, databaseId, lang, null, false);
}

public MappedStatement addMappedStatement(String id, SqlSource sqlSource, StatementType statementType,
SqlCommandType sqlCommandType, Integer fetchSize, Integer timeout, String parameterMap, Class<?> parameterType,
String resultMap, Class<?> resultType, ResultSetType resultSetType, boolean flushCache, boolean useCache,
boolean resultOrdered, KeyGenerator keyGenerator, String keyProperty, String keyColumn, String databaseId,
LanguageDriver lang) {
return addMappedStatement(
id, sqlSource, statementType, sqlCommandType, fetchSize, timeout,
parameterMap, parameterType, resultMap, resultType, resultSetType,
flushCache, useCache, resultOrdered, keyGenerator, keyProperty,
keyColumn, databaseId, lang, null);
return addMappedStatement(id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, parameterMap,
parameterType, resultMap, resultType, resultSetType, flushCache, useCache, resultOrdered, keyGenerator,
keyProperty, keyColumn, databaseId, lang, null);
}

private <T> T valueOrDefault(T value, T defaultValue) {
return value == null ? defaultValue : value;
}

private ParameterMap getStatementParameterMap(
String parameterMapName,
Class<?> parameterTypeClass,
private ParameterMap getStatementParameterMap(String parameterMapName, Class<?> parameterTypeClass,
String statementId) {
parameterMapName = applyCurrentNamespace(parameterMapName, true);
ParameterMap parameterMap = null;
Expand All @@ -384,19 +378,13 @@ private ParameterMap getStatementParameterMap(
}
} else if (parameterTypeClass != null) {
List<ParameterMapping> parameterMappings = new ArrayList<>();
parameterMap = new ParameterMap.Builder(
configuration,
statementId + "-Inline",
parameterTypeClass,
parameterMap = new ParameterMap.Builder(configuration, statementId + "-Inline", parameterTypeClass,
parameterMappings).build();
}
return parameterMap;
}

private List<ResultMap> getStatementResultMaps(
String resultMap,
Class<?> resultType,
String statementId) {
private List<ResultMap> getStatementResultMaps(String resultMap, Class<?> resultType, String statementId) {
resultMap = applyCurrentNamespace(resultMap, true);

List<ResultMap> resultMaps = new ArrayList<>();
Expand All @@ -406,35 +394,21 @@ private List<ResultMap> getStatementResultMaps(
try {
resultMaps.add(configuration.getResultMap(resultMapName.trim()));
} catch (IllegalArgumentException e) {
throw new IncompleteElementException("Could not find result map '" + resultMapName + "' referenced from '" + statementId + "'", e);
throw new IncompleteElementException(
"Could not find result map '" + resultMapName + "' referenced from '" + statementId + "'", e);
}
}
} else if (resultType != null) {
ResultMap inlineResultMap = new ResultMap.Builder(
configuration,
statementId + "-Inline",
resultType,
new ArrayList<>(),
null).build();
ResultMap inlineResultMap = new ResultMap.Builder(configuration, statementId + "-Inline", resultType,
new ArrayList<>(), null).build();
resultMaps.add(inlineResultMap);
}
return resultMaps;
}

public ResultMapping buildResultMapping(
Class<?> resultType,
String property,
String column,
Class<?> javaType,
JdbcType jdbcType,
String nestedSelect,
String nestedResultMap,
String notNullColumn,
String columnPrefix,
Class<? extends TypeHandler<?>> typeHandler,
List<ResultFlag> flags,
String resultSet,
String foreignColumn,
public ResultMapping buildResultMapping(Class<?> resultType, String property, String column, Class<?> javaType,
JdbcType jdbcType, String nestedSelect, String nestedResultMap, String notNullColumn, String columnPrefix,
Class<? extends TypeHandler<?>> typeHandler, List<ResultFlag> flags, String resultSet, String foreignColumn,
boolean lazy) {
Class<?> javaTypeClass = resolveResultJavaType(resultType, property, javaType);
TypeHandler<?> typeHandlerInstance = resolveTypeHandler(javaTypeClass, typeHandler);
Expand Down Expand Up @@ -490,9 +464,8 @@ public ResultMapping buildResultMapping(
public ResultMapping buildResultMapping(Class<?> resultType, String property, String column, Class<?> javaType,
JdbcType jdbcType, String nestedSelect, String nestedResultMap, String notNullColumn, String columnPrefix,
Class<? extends TypeHandler<?>> typeHandler, List<ResultFlag> flags) {
return buildResultMapping(
resultType, property, column, javaType, jdbcType, nestedSelect,
nestedResultMap, notNullColumn, columnPrefix, typeHandler, flags, null, null, configuration.isLazyLoadingEnabled());
return buildResultMapping(resultType, property, column, javaType, jdbcType, nestedSelect, nestedResultMap,
notNullColumn, columnPrefix, typeHandler, flags, null, null, configuration.isLazyLoadingEnabled());
}

/**
Expand Down Expand Up @@ -533,8 +506,8 @@ private List<ResultMapping> parseCompositeColumnName(String columnName) {
while (parser.hasMoreTokens()) {
String property = parser.nextToken();
String column = parser.nextToken();
ResultMapping complexResultMapping = new ResultMapping.Builder(
configuration, property, column, configuration.getTypeHandlerRegistry().getUnknownTypeHandler()).build();
ResultMapping complexResultMapping = new ResultMapping.Builder(configuration, property, column,
configuration.getTypeHandlerRegistry().getUnknownTypeHandler()).build();
composites.add(complexResultMapping);
}
}
Expand All @@ -556,7 +529,8 @@ private Class<?> resolveResultJavaType(Class<?> resultType, String property, Cla
return javaType;
}

private Class<?> resolveParameterJavaType(Class<?> resultType, String property, Class<?> javaType, JdbcType jdbcType) {
private Class<?> resolveParameterJavaType(Class<?> resultType, String property, Class<?> javaType,
JdbcType jdbcType) {
if (javaType == null) {
if (JdbcType.CURSOR.equals(jdbcType)) {
javaType = java.sql.ResultSet.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,9 @@ private KeyGenerator handleSelectKeyAnnotation(SelectKey selectKeyAnnotation, St
SqlSource sqlSource = buildSqlSource(selectKeyAnnotation, parameterTypeClass, languageDriver, null);
SqlCommandType sqlCommandType = SqlCommandType.SELECT;

assistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass, resultSetTypeEnum,
flushCache, useCache, false,
keyGenerator, keyProperty, keyColumn, databaseId, languageDriver, null, false);
assistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, parameterMap,
parameterTypeClass, resultMap, resultTypeClass, resultSetTypeEnum, flushCache, useCache, false, keyGenerator,
keyProperty, keyColumn, databaseId, languageDriver, null, false);

id = assistant.applyCurrentNamespace(id, false);

Expand Down Expand Up @@ -657,9 +657,9 @@ private Optional<AnnotationWrapper> getAnnotationWrapper(Method method, boolean
Map<String, AnnotationWrapper> statementAnnotations = targetTypes.stream()
.flatMap(x -> Arrays.stream(method.getAnnotationsByType(x))).map(AnnotationWrapper::new)
.collect(Collectors.toMap(AnnotationWrapper::getDatabaseId, x -> x, (existing, duplicate) -> {
throw new BuilderException(String.format("Detected conflicting annotations '%s' and '%s' on '%s'.",
existing.getAnnotation(), duplicate.getAnnotation(),
method.getDeclaringClass().getName() + "." + method.getName()));
throw new BuilderException(
String.format("Detected conflicting annotations '%s' and '%s' on '%s'.", existing.getAnnotation(),
duplicate.getAnnotation(), method.getDeclaringClass().getName() + "." + method.getName()));
}));
AnnotationWrapper annotationWrapper = null;
if (databaseId != null) {
Expand All @@ -670,10 +670,9 @@ private Optional<AnnotationWrapper> getAnnotationWrapper(Method method, boolean
}
if (errorIfNoMatch && annotationWrapper == null && !statementAnnotations.isEmpty()) {
// Annotations exist, but there is no matching one for the specified databaseId
throw new BuilderException(
String.format(
"Could not find a statement annotation that correspond a current database or default statement on method '%s.%s'. Current database id is [%s].",
method.getDeclaringClass().getName(), method.getName(), databaseId));
throw new BuilderException(String.format(
"Could not find a statement annotation that correspond a current database or default statement on method '%s.%s'. Current database id is [%s].",
method.getDeclaringClass().getName(), method.getName(), databaseId));
}
return Optional.ofNullable(annotationWrapper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ public interface ProviderMethodResolver {
*/
default Method resolveMethod(ProviderContext context) {
List<Method> sameNameMethods = Arrays.stream(getClass().getMethods())
.filter(m -> m.getName().equals(context.getMapperMethod().getName()))
.collect(Collectors.toList());
.filter(m -> m.getName().equals(context.getMapperMethod().getName())).collect(Collectors.toList());
if (sameNameMethods.isEmpty()) {
throw new BuilderException("Cannot resolve the provider method because '" + context.getMapperMethod().getName()
+ "' not found in SqlProvider '" + getClass().getName() + "'.");
}
List<Method> targetMethods = sameNameMethods.stream()
.filter(m -> CharSequence.class.isAssignableFrom(m.getReturnType()))
.collect(Collectors.toList());
.filter(m -> CharSequence.class.isAssignableFrom(m.getReturnType())).collect(Collectors.toList());
if (targetMethods.size() == 1) {
return targetMethods.get(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,8 @@ private ResultMap resultMapElement(XNode resultMapNode) {
private ResultMap resultMapElement(XNode resultMapNode, List<ResultMapping> additionalResultMappings,
Class<?> enclosingType) {
ErrorContext.instance().activity("processing " + resultMapNode.getValueBasedIdentifier());
String type = resultMapNode.getStringAttribute("type",
resultMapNode.getStringAttribute("ofType",
resultMapNode.getStringAttribute("resultType",
resultMapNode.getStringAttribute("javaType"))));
String type = resultMapNode.getStringAttribute("type", resultMapNode.getStringAttribute("ofType",
resultMapNode.getStringAttribute("resultType", resultMapNode.getStringAttribute("javaType"))));
Class<?> typeClass = resolveClass(type);
if (typeClass == null) {
typeClass = inheritEnclosingType(resultMapNode, enclosingType);
Expand Down Expand Up @@ -391,18 +389,20 @@ private ResultMapping buildResultMappingFromContext(XNode context, Class<?> resu
String javaType = context.getStringAttribute("javaType");
String jdbcType = context.getStringAttribute("jdbcType");
String nestedSelect = context.getStringAttribute("select");
String nestedResultMap = context.getStringAttribute("resultMap", () ->
processNestedResultMappings(context, Collections.emptyList(), resultType));
String nestedResultMap = context.getStringAttribute("resultMap",
() -> processNestedResultMappings(context, Collections.emptyList(), resultType));
String notNullColumn = context.getStringAttribute("notNullColumn");
String columnPrefix = context.getStringAttribute("columnPrefix");
String typeHandler = context.getStringAttribute("typeHandler");
String resultSet = context.getStringAttribute("resultSet");
String foreignColumn = context.getStringAttribute("foreignColumn");
boolean lazy = "lazy".equals(context.getStringAttribute("fetchType", configuration.isLazyLoadingEnabled() ? "lazy" : "eager"));
boolean lazy = "lazy"
.equals(context.getStringAttribute("fetchType", configuration.isLazyLoadingEnabled() ? "lazy" : "eager"));
Class<?> javaTypeClass = resolveClass(javaType);
Class<? extends TypeHandler<?>> typeHandlerClass = resolveClass(typeHandler);
JdbcType jdbcTypeEnum = resolveJdbcType(jdbcType);
return builderAssistant.buildResultMapping(resultType, property, column, javaTypeClass, jdbcTypeEnum, nestedSelect, nestedResultMap, notNullColumn, columnPrefix, typeHandlerClass, flags, resultSet, foreignColumn, lazy);
return builderAssistant.buildResultMapping(resultType, property, column, javaTypeClass, jdbcTypeEnum, nestedSelect,
nestedResultMap, notNullColumn, columnPrefix, typeHandlerClass, flags, resultSet, foreignColumn, lazy);
}

private String processNestedResultMappings(XNode context, List<ResultMapping> resultMappings,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 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.
Expand Down Expand Up @@ -66,7 +66,8 @@ public synchronized long getClaimedOverdueConnectionCount() {
}

public synchronized long getAverageOverdueCheckoutTime() {
return claimedOverdueConnectionCount == 0 ? 0 : accumulatedCheckoutTimeOfOverdueConnections / claimedOverdueConnectionCount;
return claimedOverdueConnectionCount == 0 ? 0
: accumulatedCheckoutTimeOfOverdueConnections / claimedOverdueConnectionCount;
}

public synchronized long getAverageCheckoutTime() {
Expand All @@ -88,7 +89,8 @@ public synchronized String toString() {
builder.append("\n jdbcDriver ").append(dataSource.getDriver());
builder.append("\n jdbcUrl ").append(dataSource.getUrl());
builder.append("\n jdbcUsername ").append(dataSource.getUsername());
builder.append("\n jdbcPassword ").append(dataSource.getPassword() == null ? "NULL" : "************");
builder.append("\n jdbcPassword ")
.append(dataSource.getPassword() == null ? "NULL" : "************");
builder.append("\n poolMaxActiveConnections ").append(dataSource.poolMaximumActiveConnections);
builder.append("\n poolMaxIdleConnections ").append(dataSource.poolMaximumIdleConnections);
builder.append("\n poolMaxCheckoutTime ").append(dataSource.poolMaximumCheckoutTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ private PooledConnection popConnection(String username, String password) throws
state.accumulatedRequestTime += System.currentTimeMillis() - t;
} else {
if (log.isDebugEnabled()) {
log.debug("A bad connection (" + conn.getRealHashCode() + ") was returned from the pool, getting another connection.");
log.debug("A bad connection (" + conn.getRealHashCode()
+ ") was returned from the pool, getting another connection.");
}
state.badConnectionCount++;
localBadConnectionCount++;
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/org/apache/ibatis/executor/BaseExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,8 @@ private static class DeferredLoad {
private final ResultExtractor resultExtractor;

// issue #781
public DeferredLoad(MetaObject resultObject,
String property,
CacheKey key,
PerpetualCache localCache,
Configuration configuration,
Class<?> targetType) {
public DeferredLoad(MetaObject resultObject, String property, CacheKey key, PerpetualCache localCache,
Configuration configuration, Class<?> targetType) {
this.resultObject = resultObject;
this.property = property;
this.key = key;
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/org/apache/ibatis/executor/BatchExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,10 @@ public List<BatchResult> doFlushStatements(boolean isRollback) throws SQLExcepti
closeStatement(stmt);
} catch (BatchUpdateException e) {
StringBuilder message = new StringBuilder();
message.append(batchResult.getMappedStatement().getId())
.append(" (batch index #")
.append(i + 1)
.append(")")
message.append(batchResult.getMappedStatement().getId()).append(" (batch index #").append(i + 1).append(")")
.append(" failed.");
if (i > 0) {
message.append(" ")
.append(i)
message.append(" ").append(i)
.append(" prior sub executor(s) completed successfully, but will be rolled back.");
}
throw new BatchExecutorException(message.toString(), e, results, batchResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ public class BatchExecutorException extends ExecutorException {
private final BatchUpdateException batchUpdateException;
private final BatchResult batchResult;

public BatchExecutorException(String message,
BatchUpdateException cause,
List<BatchResult> successfulBatchResults,
BatchResult batchResult) {
public BatchExecutorException(String message, BatchUpdateException cause, List<BatchResult> successfulBatchResults,
BatchResult batchResult) {
super(message + " Cause: " + cause, cause);
this.batchUpdateException = cause;
this.successfulBatchResults = successfulBatchResults;
Expand Down
Loading