|
@@ -1,34 +1,24 @@
|
|
-/*
|
|
|
|
- * Copyright (c) 2011-2019, hubin (jobob@qq.com).
|
|
|
|
- * <p>
|
|
|
|
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
- * use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
- * the License at
|
|
|
|
- * <p>
|
|
|
|
- * https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
- * <p>
|
|
|
|
- * Unless required by applicable law or agreed to in writing, software
|
|
|
|
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
- * License for the specific language governing permissions and limitations under
|
|
|
|
- * the License.
|
|
|
|
- */
|
|
|
|
-package com.baomidou.mybatisplus.test;
|
|
|
|
|
|
+package com.baomidou.mybatisplus.core.conditions;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
|
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
|
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
|
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
|
+import com.baomidou.mybatisplus.test.User;
|
|
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
|
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
|
-import org.assertj.core.api.Assertions;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
-class WrapperTest {
|
|
|
|
|
|
+import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author miemie
|
|
|
|
+ * @since 2021-01-27
|
|
|
|
+ */
|
|
|
|
+class QueryWrapperTest {
|
|
|
|
|
|
private void log(String message) {
|
|
private void log(String message) {
|
|
System.out.println(message);
|
|
System.out.println(message);
|
|
@@ -38,7 +28,7 @@ class WrapperTest {
|
|
System.out.printf(" ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ->(%s)<- ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓%n", explain);
|
|
System.out.printf(" ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ->(%s)<- ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓%n", explain);
|
|
System.out.println(wrapper.getSqlSegment());
|
|
System.out.println(wrapper.getSqlSegment());
|
|
System.out.println(wrapper.getTargetSql());
|
|
System.out.println(wrapper.getTargetSql());
|
|
- Assertions.assertThat(wrapper.getTargetSql().trim()).isEqualTo(targetSql);
|
|
|
|
|
|
+ assertThat(wrapper.getTargetSql().trim()).isEqualTo(targetSql);
|
|
}
|
|
}
|
|
|
|
|
|
private <T> void logParams(QueryWrapper<T> wrapper) {
|
|
private <T> void logParams(QueryWrapper<T> wrapper) {
|
|
@@ -170,7 +160,7 @@ class WrapperTest {
|
|
void testFunc() {
|
|
void testFunc() {
|
|
QueryWrapper<User> queryWrapper = new QueryWrapper<User>()
|
|
QueryWrapper<User> queryWrapper = new QueryWrapper<User>()
|
|
.isNull("nullColumn").or().isNotNull("notNullColumn")
|
|
.isNull("nullColumn").or().isNotNull("notNullColumn")
|
|
- .orderByAsc("id").orderByDesc("name","name2")
|
|
|
|
|
|
+ .orderByAsc("id").orderByDesc("name", "name2")
|
|
.groupBy("id").groupBy("name", "id2", "name2")
|
|
.groupBy("id").groupBy("name", "id2", "name2")
|
|
.in("inColl", getList()).or().notIn("notInColl", getList())
|
|
.in("inColl", getList()).or().notIn("notInColl", getList())
|
|
.in("inArray").notIn("notInArray", 1, 2, 3)
|
|
.in("inArray").notIn("notInArray", 1, 2, 3)
|
|
@@ -249,18 +239,4 @@ class WrapperTest {
|
|
map.put("nullColumn", null);
|
|
map.put("nullColumn", null);
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
-
|
|
|
|
-// public void test() {
|
|
|
|
-// String sql = new QueryWrapper()
|
|
|
|
-// .where("b.age > 18", condition ->
|
|
|
|
-// condition.and("b.type = 'rabid'")
|
|
|
|
-// .or(nested -> nested.apply("name='12'").and("age=1"))
|
|
|
|
-// .notIn("ads,2112,212")
|
|
|
|
-// .last("LIMIT 1")
|
|
|
|
-// ).sqlSegment();
|
|
|
|
-//
|
|
|
|
-// log(sql);
|
|
|
|
-// assertEquals("WHERE b.age > 18 AND b.type = 'rabid' OR ( name='12' AND age=1 ) NOT IN ( ads,2112,212 ) LIMIT 1", sql);
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
}
|
|
}
|