FilterNode优化
This commit is contained in:
@@ -2,18 +2,18 @@
|
||||
*/
|
||||
package org.redkale.test.convert.protobuf;
|
||||
|
||||
import org.redkale.convert.protobuf.ProtobufObjectEncoder;
|
||||
import org.redkale.convert.protobuf.ProtobufReader;
|
||||
import org.redkale.convert.protobuf.ProtobufObjectDecoder;
|
||||
import org.redkale.convert.protobuf.ProtobufConvert;
|
||||
import java.lang.annotation.*;
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import java.lang.annotation.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.*;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.convert.protobuf.ProtobufConvert;
|
||||
import org.redkale.convert.protobuf.ProtobufObjectDecoder;
|
||||
import org.redkale.convert.protobuf.ProtobufObjectEncoder;
|
||||
import org.redkale.convert.protobuf.ProtobufReader;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
@@ -34,7 +34,9 @@ public class PBCustMessage2Test {
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
final BiFunction<Attribute, Object, Object> objFieldFunc = (Attribute t, Object u) -> {
|
||||
if (t.field().equals("retinfo")) return null;
|
||||
if (t.field().equals("retinfo")) {
|
||||
return null;
|
||||
}
|
||||
return t.get(u);
|
||||
};
|
||||
OnPlayerLeaveMessage msg1 = new OnPlayerLeaveMessage(100, "haha");
|
||||
@@ -43,19 +45,25 @@ public class PBCustMessage2Test {
|
||||
byte[] bs2 = ProtobufConvert.root().convertTo(msg2);
|
||||
System.out.println(Arrays.toString(bs1));
|
||||
System.out.println(Arrays.toString(bs2));
|
||||
if (!main) Assertions.assertEquals(Arrays.toString(bs1), Arrays.toString(bs2));
|
||||
if (!main) {
|
||||
Assertions.assertEquals(Arrays.toString(bs1), Arrays.toString(bs2));
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
OnPlayerLeaveMessage2 newmsg2 = ProtobufConvert.root().convertFrom(OnPlayerLeaveMessage2.class, bs1);
|
||||
byte[] newbs2 = ProtobufConvert.root().convertTo(newmsg2);
|
||||
System.out.println(Arrays.toString(newbs2));
|
||||
if (!main) Assertions.assertEquals(Arrays.toString(bs1), Arrays.toString(newbs2));
|
||||
if (!main) {
|
||||
Assertions.assertEquals(Arrays.toString(bs1), Arrays.toString(newbs2));
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
ProtobufConvert convert = ProtobufConvert.root().newConvert(objFieldFunc);
|
||||
System.out.println(Arrays.toString(convert.convertTo(msg1)));
|
||||
System.out.println(Arrays.toString(convert.convertTo(msg2)));
|
||||
if (!main) Assertions.assertEquals(Arrays.toString(convert.convertTo(msg1)), Arrays.toString(convert.convertTo(msg2)));
|
||||
if (!main) {
|
||||
Assertions.assertEquals(Arrays.toString(convert.convertTo(msg1)), Arrays.toString(convert.convertTo(msg2)));
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@@ -72,7 +80,9 @@ public class PBCustMessage2Test {
|
||||
|
||||
public static String getMessageName(Class<?> clazz) {
|
||||
MessageName mn = clazz.getAnnotation(MessageName.class);
|
||||
if (mn != null) return mn.value();
|
||||
if (mn != null) {
|
||||
return mn.value();
|
||||
}
|
||||
char[] fieldChars = clazz.getSimpleName().toCharArray();
|
||||
fieldChars[0] = Character.toLowerCase(fieldChars[0]);
|
||||
return new String(fieldChars);
|
||||
@@ -165,8 +175,10 @@ public class PBCustMessage2Test {
|
||||
|
||||
public static class OnPlayerLeaveMessage {
|
||||
|
||||
@ConvertColumn(index = 1)
|
||||
private String event = "onPlayerLeaveMessage";
|
||||
|
||||
@ConvertColumn(index = 2)
|
||||
private OnPlayerLeaveContent result;
|
||||
|
||||
public OnPlayerLeaveMessage() {
|
||||
|
||||
@@ -2,11 +2,6 @@
|
||||
*/
|
||||
package org.redkale.test.convert.protobuf;
|
||||
|
||||
import org.redkale.convert.protobuf.ProtobufObjectEncoder;
|
||||
import org.redkale.convert.protobuf.ProtobufReader;
|
||||
import org.redkale.convert.protobuf.ProtobufFactory;
|
||||
import org.redkale.convert.protobuf.ProtobufObjectDecoder;
|
||||
import org.redkale.convert.protobuf.ProtobufConvert;
|
||||
import java.lang.annotation.*;
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
@@ -15,6 +10,11 @@ import java.util.function.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.*;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.convert.protobuf.ProtobufConvert;
|
||||
import org.redkale.convert.protobuf.ProtobufFactory;
|
||||
import org.redkale.convert.protobuf.ProtobufObjectDecoder;
|
||||
import org.redkale.convert.protobuf.ProtobufObjectEncoder;
|
||||
import org.redkale.convert.protobuf.ProtobufReader;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
@@ -148,6 +148,7 @@ public class PBCustMessageTest {
|
||||
|
||||
public static class OnPlayerLeaveMessage {
|
||||
|
||||
@ConvertColumn(index = 1)
|
||||
private OnPlayerLeaveContent onPlayerLeaveMessage;
|
||||
|
||||
public OnPlayerLeaveMessage() {
|
||||
|
||||
@@ -42,12 +42,12 @@ public class CacheTestBean {
|
||||
System.out.println(cache.queryColumnMap("pkgid", FilterFunc.MAX, "price", null));
|
||||
System.out.println(cache.queryColumnMap("pkgid", FilterFunc.MIN, "price", null));
|
||||
|
||||
System.out.println(cache.find(null, FilterNode.create("name", FilterExpress.EQUAL, "BB")));
|
||||
System.out.println(cache.find(null, FilterNode.create("name", FilterExpress.IGNORECASEEQUAL, "BB")));
|
||||
System.out.println(cache.querySheet(null, null, FilterNode.create("name", FilterExpress.IGNORECASENOTLIKE, "B")));
|
||||
System.out.println(cache.find(null, FilterNode.create(CacheTestBean::getName, FilterExpress.EQUAL, "BB")));
|
||||
System.out.println(cache.find(null, FilterNode.create(CacheTestBean::getName, FilterExpress.IGNORECASEEQUAL, "BB")));
|
||||
System.out.println(cache.querySheet(null, null, FilterNode.create(CacheTestBean::getName, FilterExpress.IGNORECASENOTLIKE, "B")));
|
||||
System.out.println(cache.find(null, FilterNodes.eq("name", "BB")));
|
||||
System.out.println(cache.find(null, FilterNodes.igEq("name", "BB")));
|
||||
System.out.println(cache.querySheet(null, null, FilterNodes.igNotLike("name", "B")));
|
||||
System.out.println(cache.find(null, FilterNodes.eq(CacheTestBean::getName, "BB")));
|
||||
System.out.println(cache.find(null, FilterNodes.igEq(CacheTestBean::getName, "BB")));
|
||||
System.out.println(cache.querySheet(null, null, FilterNodes.igNotLike(CacheTestBean::getName, "B")));
|
||||
}
|
||||
|
||||
public CacheTestBean() {
|
||||
|
||||
@@ -5,22 +5,18 @@
|
||||
*/
|
||||
package org.redkale.test.source;
|
||||
|
||||
import org.redkale.persistence.Cacheable;
|
||||
import org.redkale.persistence.Id;
|
||||
import org.redkale.persistence.Transient;
|
||||
import org.redkale.source.*;
|
||||
import org.redkale.annotation.AutoLoad;
|
||||
|
||||
import static org.redkale.source.FilterExpress.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.*;
|
||||
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.annotation.AutoLoad;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.persistence.Cacheable;
|
||||
import org.redkale.persistence.Id;
|
||||
import org.redkale.persistence.Transient;
|
||||
import org.redkale.source.*;
|
||||
import static org.redkale.source.FilterExpress.*;
|
||||
|
||||
/**
|
||||
* @author zhangjx
|
||||
@@ -105,9 +101,9 @@ public class FilterNodeTest {
|
||||
public void run() throws Exception {
|
||||
final CarTestBean bean = CarTestBean.create();
|
||||
FilterNode joinNode1 = FilterJoinNode.create(UserTestTable.class, new String[]{"userid", "username"}, "username", LIKE, bean.username)
|
||||
.or(FilterJoinNode.create(UserTestTable.class, new String[]{"userid", "username"}, "createtime", GREATERTHAN, bean.createtime));
|
||||
.or(FilterJoinNode.create(UserTestTable.class, new String[]{"userid", "username"}, "createtime", GT, bean.createtime));
|
||||
FilterNode joinNode2 = FilterJoinNode.create(CarTypeTestTable.class, "cartype", "typename", LIKE, bean.typename);
|
||||
final FilterNode node = CarTestBean.caridTransient() ? (joinNode2.or(joinNode1)) : FilterNode.create("carid", GREATERTHAN, bean.carid).and(joinNode1).or(joinNode2);
|
||||
final FilterNode node = CarTestBean.caridTransient() ? (joinNode2.or(joinNode1)) : FilterNodes.gt("carid", bean.carid).and(joinNode1).or(joinNode2);
|
||||
final FilterNode beanNode = FilterNodeBean.createFilterNode(bean);
|
||||
System.out.println("node.string = " + node);
|
||||
System.out.println("bean.string = " + beanNode);
|
||||
@@ -136,7 +132,7 @@ public class FilterNodeTest {
|
||||
public static class CarTestBean implements FilterBean {
|
||||
|
||||
@FilterGroup("[OR].[AND]a")
|
||||
@FilterColumn(express = GREATERTHAN)
|
||||
@FilterColumn(express = GT)
|
||||
@Transient
|
||||
public long carid;
|
||||
|
||||
@@ -146,7 +142,7 @@ public class FilterNodeTest {
|
||||
public String username;
|
||||
|
||||
@FilterGroup("[OR].[AND]a.[OR]c")
|
||||
@FilterColumn(express = GREATERTHAN)
|
||||
@FilterColumn(express = GT)
|
||||
@FilterJoinColumn(table = UserTestTable.class, columns = {"userid", "username"})
|
||||
public long createtime;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class TestSourceCache {
|
||||
|
||||
public static class TestEntityBean implements FilterBean {
|
||||
|
||||
@FilterColumn(express = FilterExpress.GREATERTHAN)
|
||||
@FilterColumn(express = FilterExpress.GT)
|
||||
public int userid;
|
||||
|
||||
@FilterColumn(express = FilterExpress.LIKE)
|
||||
@@ -60,9 +60,9 @@ public class TestSourceCache {
|
||||
|
||||
final Flipper flipper = new Flipper(2);
|
||||
flipper.setSort("userid DESC, createtime DESC");
|
||||
final FilterNode node = FilterNode.create("userid", FilterExpress.GREATERTHAN, 1000).and("username", FilterExpress.LIKE, "用户");
|
||||
final FilterNode node = FilterNodes.gt("userid", 1000).like("username", "用户");
|
||||
System.out.println("node = " + node);
|
||||
final FilterNode node2 = FilterNode.create(TestEntity::getUserid, FilterExpress.GREATERTHAN, 1000).and("username", FilterExpress.LIKE, "用户");
|
||||
final FilterNode node2 = FilterNodes.gt(TestEntity::getUserid, 1000).like("username", "用户");
|
||||
Assertions.assertEquals(node.toString(), node2.toString());
|
||||
Sheet<TestEntity> sheet = info.getCache().querySheet(null, flipper, node);
|
||||
System.out.println(sheet);
|
||||
|
||||
Reference in New Issue
Block a user