Skip to content

Commit

Permalink
Merge pull request #2966 from taoyect/minor-refine
Browse files Browse the repository at this point in the history
just minor refine
  • Loading branch information
hazendaz committed Oct 9, 2023
2 parents 21dee5d + c0901d7 commit 6e84c85
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 47 deletions.
6 changes: 2 additions & 4 deletions src/main/java/org/apache/ibatis/reflection/MetaClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ public boolean hasSetter(String name) {
if (reflector.hasSetter(prop.getName())) {
MetaClass metaProp = metaClassForProperty(prop.getName());
return metaProp.hasSetter(prop.getChildren());
} else {
return false;
}
return false;
}

public boolean hasGetter(String name) {
Expand All @@ -153,9 +152,8 @@ public boolean hasGetter(String name) {
if (reflector.hasGetter(prop.getName())) {
MetaClass metaProp = metaClassForProperty(prop);
return metaProp.hasGetter(prop.getChildren());
} else {
return false;
}
return false;
}

public Invoker getGetInvoker(String name) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/apache/ibatis/reflection/MetaObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ public Object getValue(String name) {
MetaObject metaValue = metaObjectForProperty(prop.getIndexedName());
if (metaValue == SystemMetaObject.NULL_META_OBJECT) {
return null;
} else {
return metaValue.getValue(prop.getChildren());
}
return metaValue.getValue(prop.getChildren());
}

public void setValue(String name, Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ public Class<?> getSetterType(String name) {
MetaObject metaValue = metaObject.metaObjectForProperty(prop.getIndexedName());
if (metaValue == SystemMetaObject.NULL_META_OBJECT) {
return metaClass.getSetterType(name);
} else {
return metaValue.getSetterType(prop.getChildren());
}
return metaValue.getSetterType(prop.getChildren());
}

@Override
Expand All @@ -97,9 +96,8 @@ public Class<?> getGetterType(String name) {
MetaObject metaValue = metaObject.metaObjectForProperty(prop.getIndexedName());
if (metaValue == SystemMetaObject.NULL_META_OBJECT) {
return metaClass.getGetterType(name);
} else {
return metaValue.getGetterType(prop.getChildren());
}
return metaValue.getGetterType(prop.getChildren());
}

@Override
Expand All @@ -112,12 +110,10 @@ public boolean hasSetter(String name) {
MetaObject metaValue = metaObject.metaObjectForProperty(prop.getIndexedName());
if (metaValue == SystemMetaObject.NULL_META_OBJECT) {
return metaClass.hasSetter(name);
} else {
return metaValue.hasSetter(prop.getChildren());
}
} else {
return false;
return metaValue.hasSetter(prop.getChildren());
}
return false;
}

@Override
Expand All @@ -130,12 +126,10 @@ public boolean hasGetter(String name) {
MetaObject metaValue = metaObject.metaObjectForProperty(prop.getIndexedName());
if (metaValue == SystemMetaObject.NULL_META_OBJECT) {
return metaClass.hasGetter(name);
} else {
return metaValue.hasGetter(prop.getChildren());
}
} else {
return false;
return metaValue.hasGetter(prop.getChildren());
}
return false;
}

@Override
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
49 changes: 22 additions & 27 deletions src/main/java/org/apache/ibatis/scripting/xmltags/TrimSqlNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,40 +122,35 @@ public String getSql() {
}

private void applyPrefix(StringBuilder sql, String trimmedUppercaseSql) {
if (!prefixApplied) {
prefixApplied = true;
if (prefixesToOverride != null) {
for (String toRemove : prefixesToOverride) {
if (trimmedUppercaseSql.startsWith(toRemove)) {
sql.delete(0, toRemove.trim().length());
break;
}
}
}
if (prefix != null) {
sql.insert(0, " ");
sql.insert(0, prefix);
}
if (prefixApplied) {
return;
}
prefixApplied = true;
if (prefixesToOverride != null) {
prefixesToOverride.stream().filter(trimmedUppercaseSql::startsWith).findFirst()
.ifPresent(toRemove -> sql.delete(0, toRemove.trim().length()));
}
if (prefix != null) {
sql.insert(0, " ").insert(0, prefix);
}
}

private void applySuffix(StringBuilder sql, String trimmedUppercaseSql) {
if (!suffixApplied) {
suffixApplied = true;
if (suffixesToOverride != null) {
for (String toRemove : suffixesToOverride) {
if (trimmedUppercaseSql.endsWith(toRemove) || trimmedUppercaseSql.endsWith(toRemove.trim())) {
if (suffixApplied) {
return;
}
suffixApplied = true;
if (suffixesToOverride != null) {
suffixesToOverride.stream()
.filter(toRemove -> trimmedUppercaseSql.endsWith(toRemove) || trimmedUppercaseSql.endsWith(toRemove.trim()))
.findFirst().ifPresent(toRemove -> {
int start = sql.length() - toRemove.trim().length();
int end = sql.length();
sql.delete(start, end);
break;
}
}
}
if (suffix != null) {
sql.append(" ");
sql.append(suffix);
}
});
}
if (suffix != null) {
sql.append(" ").append(suffix);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/site/es/xdoc/statement-builders.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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

0 comments on commit 6e84c85

Please sign in to comment.