Commit adbfe3a2 authored by hewei's avatar hewei

[issues#20]:selectByExampleSelective 不支持 distinct

parent f3d2a6fd
......@@ -189,6 +189,13 @@ public class SelectSelectivePlugin extends BasePlugin {
if (stringHasValue(introspectedTable.getSelectByExampleQueryId())) {
selectByExampleSelectiveEle.addElement(new TextElement("'" + introspectedTable.getSelectByExampleQueryId() + "' as QUERYID,"));
}
// issues#20
XmlElement ifDistinctElement = new XmlElement("if");
ifDistinctElement.addAttribute(new Attribute("test", "example.distinct"));
ifDistinctElement.addElement(new TextElement("distinct"));
selectByExampleSelectiveEle.addElement(ifDistinctElement);
selectByExampleSelectiveEle.addElement(columnsEle);
selectByExampleSelectiveEle.addElement(new TextElement("from " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()));
......
......@@ -79,7 +79,7 @@ public class SelectSelectivePluginTest {
// 2. 执行sql
List list = (List) tbMapper.invoke("selectByExampleSelective", tbExample.getObject(), columns1);
Assert.assertEquals(list.size(), 3);
Assert.assertEquals(list.size(), 4);
int index = 0;
for (Object obj : list) {
if (index == 1) {
......@@ -99,6 +99,13 @@ public class SelectSelectivePluginTest {
index++;
}
// 3. 测试 distinct
tbExample.invoke("setDistinct", true);
String sql1 = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExampleSelective", tbExample.getObject(), columns1);
Assert.assertEquals(sql1, "select distinct field1 from tb WHERE ( id < '100' ) order by field2 asc");
List list1 = (List) tbMapper.invoke("selectByExampleSelective", tbExample.getObject(), columns1);
Assert.assertEquals(list1.size(), 3);
}
});
}
......@@ -228,7 +235,7 @@ public class SelectSelectivePluginTest {
// 2. 执行sql
List list = (List) tbMapper.invoke("selectByExampleSelective", tbExample.getObject(), columns1);
Assert.assertEquals(list.size(), 3);
Assert.assertEquals(list.size(), 4);
int index = 0;
for (Object obj : list) {
if (index == 0) {
......@@ -282,7 +289,7 @@ public class SelectSelectivePluginTest {
// 2. 执行sql
List list = (List) tbMapper.invoke("selectByExampleSelective", tbExample.getObject(), columns1);
Assert.assertEquals(list.size(), 3);
Assert.assertEquals(list.size(), 4);
int index = 0;
for (Object obj : list) {
if (index == 0) {
......
......@@ -32,6 +32,7 @@ CREATE TABLE `tb` (
INSERT INTO `tb` VALUES ('1', 'fd1', null);
INSERT INTO `tb` VALUES ('2', null, '2');
INSERT INTO `tb` VALUES ('3', 'fd3', '3');
INSERT INTO `tb` VALUES ('4', 'fd3', '4');
-- ----------------------------
-- Table structure for tb_blobs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment