Skip to content

Commit

Permalink
[#307]支持修改为mappingStrategy默认property_first
Browse files Browse the repository at this point in the history
  • Loading branch information
xuejmnet committed Jan 26, 2025
1 parent 4fb5218 commit 9af831e
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 47 deletions.
2 changes: 1 addition & 1 deletion sql-test/src/main/java/com/easy/query/test/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static void initEasyQuery() {
.replaceService(JdbcExecutorListener.class, myJdbcListener)
.replaceService(QueryConfiguration.class, MyQueryConfiguration.class)
// .replaceService(EntityMappingRule.class, PropertyEntityMappingRule.class)
// .replaceService(EntityMappingRule.class, PropertyFirstEntityMappingRule.class)
.replaceService(EntityMappingRule.class, PropertyFirstEntityMappingRule.class)
// .replaceService(SQLKeyword.class, DefaultSQLKeyword.class)
// .replaceService(BeanValueCaller.class, ReflectBeanValueCaller.class)
.build();
Expand Down
34 changes: 19 additions & 15 deletions sql-test/src/main/java/com/easy/query/test/QueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,8 @@ public void query39() {
.select(BlogEntityTest2.class);
String sql = queryable.toSQL();
// Assert.assertEquals("SELECT t.`title`,t.`content`,t.`star`,t.`publish_time`,t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top` FROM `t_blog` t WHERE t.`deleted` = ?", sql);
Assert.assertEquals("SELECT t.`title`,t.`content`,t.`star`,t.`publish_time`,t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top` FROM `t_blog` t WHERE t.`deleted` = ?", sql);
// Assert.assertEquals("SELECT t.`title`,t.`content`,t.`star`,t.`publish_time`,t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top` FROM `t_blog` t WHERE t.`deleted` = ?", sql);
Assert.assertEquals("SELECT t.`title`,t.`content`,t.`url` AS `my_url`,t.`star`,t.`publish_time`,t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top` FROM `t_blog` t WHERE t.`deleted` = ?", sql);
List<BlogEntityTest2> blogEntityTest2s = easyQuery.queryable(BlogEntity.class)
.select(BlogEntityTest2.class).toList();
Assert.assertTrue(blogEntityTest2s.size() >= 100);
Expand All @@ -1050,7 +1051,7 @@ public void query39() {
Queryable<BlogEntityTest2> queryable = easyQuery.queryable(BlogEntity.class)
.select(BlogEntityTest2.class, o -> o.columnAll());
String sql = queryable.toSQL();
Assert.assertEquals("SELECT t.`title`,t.`content`,t.`star`,t.`publish_time`,t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top` FROM `t_blog` t WHERE t.`deleted` = ?", sql);
Assert.assertEquals("SELECT t.`title`,t.`content`,t.`url` AS `my_url`,t.`star`,t.`publish_time`,t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top` FROM `t_blog` t WHERE t.`deleted` = ?", sql);
List<BlogEntityTest2> blogEntityTest2s = easyQuery.queryable(BlogEntity.class)
.select(BlogEntityTest2.class, o -> o.columnAll()).toList();
Assert.assertTrue(blogEntityTest2s.size() >= 100);
Expand All @@ -1060,7 +1061,7 @@ public void query39() {
Queryable<BlogEntityTest2> queryable = easyQuery.queryable(BlogEntity.class)
.select(BlogEntityTest2.class, o -> o.columnAll().columnAs(BlogEntity::getUrl, BlogEntityTest2::getUrl));
String sql = queryable.toSQL();
Assert.assertEquals("SELECT t.`title`,t.`content`,t.`star`,t.`publish_time`,t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top`,t.`url` AS `my_url` FROM `t_blog` t WHERE t.`deleted` = ?", sql);
Assert.assertEquals("SELECT t.`title`,t.`content`,t.`url` AS `my_url`,t.`star`,t.`publish_time`,t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top`,t.`url` AS `my_url` FROM `t_blog` t WHERE t.`deleted` = ?", sql);
List<BlogEntityTest2> blogEntityTest2s = easyQuery.queryable(BlogEntity.class)
.select(BlogEntityTest2.class, o -> o.columnAll().columnAs(BlogEntity::getUrl, BlogEntityTest2::getUrl)).toList();
Assert.assertTrue(blogEntityTest2s.size() >= 100);
Expand All @@ -1070,7 +1071,7 @@ public void query39() {
Queryable<BlogEntityTest2> queryable = easyQuery.queryable(BlogEntity.class)
.select(BlogEntityTest2.class, o -> o.columnAll().columnIgnore(BlogEntity::getTitle).columnAs(BlogEntity::getUrl, BlogEntityTest2::getUrl));
String sql = queryable.toSQL();
Assert.assertEquals("SELECT t.`content`,t.`star`,t.`publish_time`,t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top`,t.`url` AS `my_url` FROM `t_blog` t WHERE t.`deleted` = ?", sql);
Assert.assertEquals("SELECT t.`content`,t.`url` AS `my_url`,t.`star`,t.`publish_time`,t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top`,t.`url` AS `my_url` FROM `t_blog` t WHERE t.`deleted` = ?", sql);
List<BlogEntityTest2> blogEntityTest2s = easyQuery.queryable(BlogEntity.class)
.select(BlogEntityTest2.class, o -> o.columnAll().columnIgnore(BlogEntity::getTitle).columnAs(BlogEntity::getUrl, BlogEntityTest2::getUrl)).toList();
Assert.assertTrue(blogEntityTest2s.size() >= 100);
Expand Down Expand Up @@ -1624,7 +1625,7 @@ public void query65() {


String sql = q1.union(q2, q3).where(o -> o.eq(Topic::getId, "123321")).toSQL();

System.out.println(sql);
Assert.assertEquals("SELECT t7.`id`,t7.`stars`,t7.`title`,t7.`create_time` FROM ( (SELECT t.`id`,t.`stars`,t.`title`,t.`create_time` FROM `t_topic` t WHERE t.`id` = ?) UNION (SELECT t1.`id`,t1.`stars`,t1.`title`,t1.`create_time` FROM `t_topic` t1 WHERE t1.`create_time` >= ?) UNION (SELECT t2.`id`,t2.`stars`,t2.`title`,t2.`create_time` FROM `t_topic` t2 LEFT JOIN `t_blog` t3 ON t3.`deleted` = ? AND t2.`id` = t3.`id` WHERE t3.`content` IS NOT NULL AND t2.`stars` IS NOT NULL) ) t7 WHERE t7.`id` = ?", sql);
}

Expand All @@ -1646,9 +1647,10 @@ public void query66() {


String sql = q1.union(q2, q3).where(o -> o.eq(TopicUnion::getId, "123321")).toSQL();

System.out.println(sql);
// Assert.assertEquals("SELECT t8.`id`,t8.`stars`,t8.`title` FROM ( (SELECT t.`id`,t.`stars`,t.`title` FROM `t_topic` t WHERE t.`id` = ?) UNION (SELECT t8.`id`,t8.`stars`,t8.`title` FROM `t_topic` t8 WHERE t8.`create_time` >= ?) UNION (SELECT t8.`id`,t8.`stars`,t8.`title` FROM `t_topic` t8 LEFT JOIN `t_blog` t8 ON t8.`deleted` = ? AND t8.`id` = t8.`id` WHERE t8.`content` IS NOT NULL AND t8.`stars` IS NOT NULL) ) t8 WHERE t8.`id` = ?", sql);
Assert.assertEquals("SELECT t8.`id`,t8.`stars`,t8.`title` FROM ( (SELECT t.`id`,t.`stars`,t.`title` FROM `t_topic` t WHERE t.`id` = ?) UNION (SELECT t2.`id`,t2.`stars`,t2.`title` FROM `t_topic` t2 WHERE t2.`create_time` >= ?) UNION (SELECT t4.`id`,t4.`stars`,t4.`title` FROM `t_topic` t4 LEFT JOIN `t_blog` t5 ON t5.`deleted` = ? AND t4.`id` = t5.`id` WHERE t5.`content` IS NOT NULL AND t4.`stars` IS NOT NULL) ) t8 WHERE t8.`id` = ?", sql);
// Assert.assertEquals("SELECT t8.`id`,t8.`stars`,t8.`title` FROM ( (SELECT t.`id`,t.`stars`,t.`title` FROM `t_topic` t WHERE t.`id` = ?) UNION (SELECT t2.`id`,t2.`stars`,t2.`title` FROM `t_topic` t2 WHERE t2.`create_time` >= ?) UNION (SELECT t4.`id`,t4.`stars`,t4.`title` FROM `t_topic` t4 LEFT JOIN `t_blog` t5 ON t5.`deleted` = ? AND t4.`id` = t5.`id` WHERE t5.`content` IS NOT NULL AND t4.`stars` IS NOT NULL) ) t8 WHERE t8.`id` = ?", sql);
Assert.assertEquals("SELECT t8.`id`,t8.`stars`,t8.`abc` AS `abc` FROM ( (SELECT t.`id`,t.`stars`,t.`title` AS `abc` FROM `t_topic` t WHERE t.`id` = ?) UNION (SELECT t2.`id`,t2.`stars`,t2.`title` AS `abc` FROM `t_topic` t2 WHERE t2.`create_time` >= ?) UNION (SELECT t4.`id`,t4.`stars`,t4.`title` AS `abc` FROM `t_topic` t4 LEFT JOIN `t_blog` t5 ON t5.`deleted` = ? AND t4.`id` = t5.`id` WHERE t5.`content` IS NOT NULL AND t4.`stars` IS NOT NULL) ) t8 WHERE t8.`id` = ?", sql);
}

@Test
Expand All @@ -1660,15 +1662,17 @@ public void query67() {
.where(o -> o.ge(BlogEntity::getCreateTime, LocalDateTime.of(2020, 1, 1, 1, 1)))
.select(TopicUnion.class, o -> o.columnAs(BlogEntity::getId, TopicUnion::getId)
.columnAs(BlogEntity::getStar, TopicUnion::getStars)
.columnAs(BlogEntity::getContent, TopicUnion::getAbc)
.columnAs(BlogEntity::getContent, TopicUnion::getTitle)
);
List<TopicUnion> list = q1.unionAll(q2).where(o -> o.eq(TopicUnion::getId, "123321")).toList();
Assert.assertEquals(0, list.size());


String sql = q1.union(q2).where(o -> o.eq(TopicUnion::getId, "123321")).toSQL();

Assert.assertEquals("SELECT t5.`id`,t5.`stars`,t5.`title` FROM ( (SELECT t.`id`,t.`stars`,t.`title` FROM `t_topic` t WHERE t.`id` = ?) UNION (SELECT t2.`id` AS `id`,t2.`star` AS `stars`,t2.`content` AS `title` FROM `t_blog` t2 WHERE t2.`deleted` = ? AND t2.`create_time` >= ?) ) t5 WHERE t5.`id` = ?", sql);
System.out.println(sql);
// Assert.assertEquals("SELECT t5.`id`,t5.`stars`,t5.`title` FROM ( (SELECT t.`id`,t.`stars`,t.`title` FROM `t_topic` t WHERE t.`id` = ?) UNION (SELECT t2.`id` AS `id`,t2.`star` AS `stars`,t2.`content` AS `title` FROM `t_blog` t2 WHERE t2.`deleted` = ? AND t2.`create_time` >= ?) ) t5 WHERE t5.`id` = ?", sql);
// Assert.assertEquals("SELECT t4.`id`,t4.`stars`,t4.`abc` AS `abc` FROM ( (SELECT t.`id`,t.`stars`,t.`title` AS `abc` FROM `t_topic` t WHERE t.`id` = ?) UNION ALL (SELECT t2.`id` AS `id`,t2.`star` AS `stars`,t2.`content` AS `abc` FROM `t_blog` t2 WHERE t2.`deleted` = ? AND t2.`create_time` >= ?) ) t4 WHERE t4.`id` = ?", sql);
Assert.assertEquals("SELECT t5.`id`,t5.`stars`,t5.`abc` AS `abc` FROM ( (SELECT t.`id`,t.`stars`,t.`title` AS `abc` FROM `t_topic` t WHERE t.`id` = ?) UNION (SELECT t2.`id` AS `id`,t2.`star` AS `stars`,t2.`content` AS `abc` FROM `t_blog` t2 WHERE t2.`deleted` = ? AND t2.`create_time` >= ?) ) t5 WHERE t5.`id` = ?", sql);
}

@Test
Expand Down Expand Up @@ -1711,7 +1715,7 @@ public void query69() {
System.out.println(topicTypeVO);
Assert.assertNotNull(topicTypeVO);

Assert.assertEquals(TopicTypeEnum.TEACHER, topicTypeVO.getTopicType1());
Assert.assertEquals(TopicTypeEnum.TEACHER, topicTypeVO.getTopicType());

}

Expand Down Expand Up @@ -1821,7 +1825,7 @@ public void query72() {
String sql = easyQuery.queryable(BlogEntity.class)
.where(o -> o.eq(BlogEntity::getId, "2"))
.select(BlogEntityVO1.class).limit(1).toSQL();
Assert.assertEquals("SELECT t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top` FROM `t_blog` t WHERE t.`deleted` = ? AND t.`id` = ? LIMIT 1", sql);
Assert.assertEquals("SELECT t.`score`,t.`status` AS `status1`,t.`order`,t.`is_top`,t.`top` FROM `t_blog` t WHERE t.`deleted` = ? AND t.`id` = ? LIMIT 1", sql);
}

@Test
Expand All @@ -1834,7 +1838,7 @@ public void query73() {
String sql = easyQuery.queryable(BlogEntity.class)
.where(o -> o.eq(BlogEntity::getId, "2"))
.select(BlogEntityVO1.class, o -> o.columnAll()).limit(1).toSQL();
Assert.assertEquals("SELECT t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top` FROM `t_blog` t WHERE t.`deleted` = ? AND t.`id` = ? LIMIT 1", sql);
Assert.assertEquals("SELECT t.`score`,t.`status` AS `status1`,t.`order`,t.`is_top`,t.`top` FROM `t_blog` t WHERE t.`deleted` = ? AND t.`id` = ? LIMIT 1", sql);
}

@Test
Expand All @@ -1847,7 +1851,7 @@ public void query74() {
String sql = easyQuery.queryable(BlogEntity.class)
.where(o -> o.eq(BlogEntity::getId, "2"))
.select(BlogEntityVO1.class, o -> o.columnIgnore(BlogEntity::getId)).limit(1).toSQL();
Assert.assertEquals("SELECT t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top` FROM `t_blog` t WHERE t.`deleted` = ? AND t.`id` = ? LIMIT 1", sql);
Assert.assertEquals("SELECT t.`score`,t.`status` AS `status1`,t.`order`,t.`is_top`,t.`top` FROM `t_blog` t WHERE t.`deleted` = ? AND t.`id` = ? LIMIT 1", sql);
}

@Test
Expand All @@ -1874,7 +1878,7 @@ public void query76() {
String sql = easyQuery.queryable(BlogEntity.class)
.where(o -> o.eq(BlogEntity::getId, "2"))
.select(BlogEntityVO1.class, o -> o.columnAll().columnIgnore(BlogEntity::getScore)).limit(1).toSQL();
Assert.assertEquals("SELECT t.`status`,t.`order`,t.`is_top`,t.`top` FROM `t_blog` t WHERE t.`deleted` = ? AND t.`id` = ? LIMIT 1", sql);
Assert.assertEquals("SELECT t.`status` AS `status1`,t.`order`,t.`is_top`,t.`top` FROM `t_blog` t WHERE t.`deleted` = ? AND t.`id` = ? LIMIT 1", sql);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void testx2() {
r.url().set(o.url());
}));
String sql1 = queryable.toSQL();
Assert.assertEquals("SELECT t.`content`,t.`star`,t.`publish_time`,t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top`,t.`url` AS `my_url` FROM `t_blog` t WHERE t.`deleted` = ?", sql1);
Assert.assertEquals("SELECT t.`content`,t.`url` AS `my_url`,t.`star`,t.`publish_time`,t.`score`,t.`status`,t.`order`,t.`is_top`,t.`top`,t.`url` AS `my_url` FROM `t_blog` t WHERE t.`deleted` = ?", sql1);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TopicTypeVO {
private String id;
private Integer stars;
private String title;
@Column(value = "topic_type",conversion = EnumConverter.class)
private TopicTypeEnum topicType1;
@Column(value = "topic_type1",conversion = EnumConverter.class)
private TopicTypeEnum topicType;
private LocalDateTime createTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
public class TopicUnion {
private String id;
private Integer stars;
@Column("title")
private String abc;
@Column("abc")
private String title;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public class BlogEntityVO1 {
/**
* 状态
*/
@Column(value = "status")
private Integer abc;
@Column(value = "status1")
private Integer status;
/**
* 排序
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
package com.easy.query.test.vo.proxy;

import com.easy.query.core.expression.parser.core.available.TableAvailable;
import com.easy.query.core.proxy.AbstractProxyEntity;
import com.easy.query.core.proxy.SQLColumn;
import com.easy.query.core.proxy.SQLSelectAsExpression;
import com.easy.query.core.proxy.columns.SQLBooleanColumn;
import com.easy.query.core.proxy.columns.SQLNumberColumn;
import com.easy.query.core.proxy.fetcher.AbstractFetcher;
import com.easy.query.core.proxy.core.EntitySQLContext;
import com.easy.query.test.vo.BlogEntityVO1;

import java.util.function.Consumer;
import com.easy.query.core.proxy.columns.types.SQLBigDecimalTypeColumn;
import com.easy.query.core.proxy.columns.types.SQLIntegerTypeColumn;
import com.easy.query.core.proxy.columns.types.SQLBooleanTypeColumn;

/**
* this file automatically generated by easy-query, don't modify it
* 当前文件是easy-query自动生成的请不要随意修改
* 如果出现属性冲突请使用@ProxyProperty进行重命名
*
* @author xuejiaming
* @author easy-query
*/
public class BlogEntityVO1Proxy extends AbstractProxyEntity<BlogEntityVO1Proxy, BlogEntityVO1> {

private static final Class<BlogEntityVO1> entityClass = BlogEntityVO1.class;

public static final BlogEntityVO1Proxy TABLE = createTable().createEmpty();

public static BlogEntityVO1Proxy createTable() {
return new BlogEntityVO1Proxy();
}
Expand All @@ -31,40 +35,40 @@ public BlogEntityVO1Proxy() {
* 评分
* {@link BlogEntityVO1#getScore}
*/
public SQLNumberColumn<BlogEntityVO1Proxy, java.math.BigDecimal> score() {
return getNumberColumn("score" , java.math.BigDecimal.class);
public SQLBigDecimalTypeColumn<BlogEntityVO1Proxy> score() {
return getBigDecimalTypeColumn("score");
}

/**
* 状态
* {@link BlogEntityVO1#getAbc}
* {@link BlogEntityVO1#getStatus}
*/
public SQLNumberColumn<BlogEntityVO1Proxy, Integer> abc() {
return getNumberColumn("abc" , Integer.class);
public SQLIntegerTypeColumn<BlogEntityVO1Proxy> status() {
return getIntegerTypeColumn("status");
}

/**
* 排序
* {@link BlogEntityVO1#getOrder}
*/
public SQLNumberColumn<BlogEntityVO1Proxy, java.math.BigDecimal> order() {
return getNumberColumn("order" , java.math.BigDecimal.class);
public SQLBigDecimalTypeColumn<BlogEntityVO1Proxy> order() {
return getBigDecimalTypeColumn("order");
}

/**
* 是否置顶
* {@link BlogEntityVO1#getIsTop}
*/
public SQLBooleanColumn<BlogEntityVO1Proxy, Boolean> isTop() {
return getBooleanColumn("isTop" , Boolean.class);
public SQLBooleanTypeColumn<BlogEntityVO1Proxy> isTop() {
return getBooleanTypeColumn("isTop");
}

/**
* 是否置顶
* {@link BlogEntityVO1#getTop}
*/
public SQLBooleanColumn<BlogEntityVO1Proxy, Boolean> top() {
return getBooleanColumn("top" , Boolean.class);
public SQLBooleanTypeColumn<BlogEntityVO1Proxy> top() {
return getBooleanTypeColumn("top");
}


Expand Down Expand Up @@ -99,10 +103,10 @@ public BlogEntityVO1ProxyFetcher score() {

/**
* 状态
* {@link BlogEntityVO1#getAbc}
* {@link BlogEntityVO1#getStatus}
*/
public BlogEntityVO1ProxyFetcher abc() {
return add(getProxy().abc());
public BlogEntityVO1ProxyFetcher status() {
return add(getProxy().status());
}

/**
Expand Down Expand Up @@ -131,11 +135,7 @@ public BlogEntityVO1ProxyFetcher top() {


@Override
protected BlogEntityVO1ProxyFetcher createFetcher(
BlogEntityVO1Proxy cp,
AbstractFetcher<BlogEntityVO1Proxy, BlogEntityVO1, BlogEntityVO1ProxyFetcher> prev,
SQLSelectAsExpression sqlSelectExpression
) {
protected BlogEntityVO1ProxyFetcher createFetcher(BlogEntityVO1Proxy cp, AbstractFetcher<BlogEntityVO1Proxy, BlogEntityVO1, BlogEntityVO1ProxyFetcher> prev, SQLSelectAsExpression sqlSelectExpression) {
return new BlogEntityVO1ProxyFetcher(cp, this, sqlSelectExpression);
}
}
Expand Down

0 comments on commit 9af831e

Please sign in to comment.