mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-03 05:20:50 +00:00
ref[storage]: refactor lambda of storage
This commit is contained in:
1 parent
592523a3bd
commit
a6fe28d518
7 files changed
+135
-178
No files matched your search
@@ -16,7 +16,6 @@ import com.zfoo.protocol.ProtocolManager;
|
||||
import com.zfoo.protocol.buffer.ByteBufUtils;
|
||||
import com.zfoo.protocol.generate.GenerateOperation;
|
||||
import com.zfoo.protocol.serializer.CodeLanguage;
|
||||
import com.zfoo.protocol.util.FieldUtils;
|
||||
import com.zfoo.protocol.util.FileUtils;
|
||||
import com.zfoo.protocol.util.JsonUtils;
|
||||
import com.zfoo.storage.anno.AliasFieldName;
|
||||
@@ -27,8 +26,6 @@ import com.zfoo.storage.config.StorageConfig;
|
||||
import com.zfoo.storage.manager.StorageInt;
|
||||
import com.zfoo.storage.manager.StorageManager;
|
||||
import com.zfoo.storage.util.ExportUtils;
|
||||
import com.zfoo.storage.util.LambdaUtils;
|
||||
import com.zfoo.storage.util.function.Func1;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.buffer.UnpooledHeapByteBuf;
|
||||
import org.junit.Ignore;
|
||||
@@ -112,13 +109,6 @@ public class ExportBinaryTesting {
|
||||
var bytes = ByteBufUtils.readAllBytes(buffer);
|
||||
FileUtils.writeInputStreamToFile(new File("D:/github/godot-bird/binary_data.cfg"), new ByteArrayInputStream(bytes));
|
||||
|
||||
Func1<StudentResource, Integer> ageFunc = StudentResource::age;
|
||||
String methodName = LambdaUtils.extract(ageFunc).getImplMethodName();
|
||||
String fieldName = FieldUtils.methodToProperty(methodName);
|
||||
System.out.println(methodName);
|
||||
System.out.println(fieldName);
|
||||
|
||||
|
||||
//获取storage对象
|
||||
var storage = storageManager.getStorage(StudentResource.class);
|
||||
//获取唯一索引的对象
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.zfoo.storage.util;
|
||||
|
||||
import com.zfoo.protocol.util.FieldUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author veione
|
||||
*/
|
||||
public class FieldUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testPropertyName() {
|
||||
//前三种主要用于普通的POJO,第四种用于是record类型,方法名就是属性名
|
||||
String getName = FieldUtils.methodToProperty("getName");
|
||||
assertEquals(getName, "name");
|
||||
String setName = FieldUtils.methodToProperty("setName");
|
||||
assertEquals(setName, "name");
|
||||
String isName = FieldUtils.methodToProperty("isName");
|
||||
assertEquals(isName, "name");
|
||||
String name = FieldUtils.methodToProperty("name");
|
||||
assertEquals(name, "name");
|
||||
name = FieldUtils.methodToProperty("Name");
|
||||
assertEquals(name, "name");
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The zfoo Authors
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.zfoo.storage.util;
|
||||
|
||||
import com.zfoo.storage.resource.StudentResource;
|
||||
import com.zfoo.storage.util.function.Func1;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author veione
|
||||
*/
|
||||
public class LambdaFunctionCacheTest {
|
||||
|
||||
@Test
|
||||
public void testFunctionCache() {
|
||||
Func1<StudentResource, Object> nameFunc = StudentResource::getName;
|
||||
System.out.println(LambdaUtils.getMethodName(nameFunc));
|
||||
System.out.println(LambdaUtils.getMethodName(nameFunc));
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,10 @@
|
||||
|
||||
package com.zfoo.storage.util;
|
||||
|
||||
import com.zfoo.storage.resource.StudentResource;
|
||||
import com.zfoo.storage.resource.TeacherResource;
|
||||
import com.zfoo.storage.util.function.Func1;
|
||||
import com.zfoo.storage.util.lambda.LambdaMeta;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -24,6 +25,8 @@ import java.lang.reflect.Method;
|
||||
* @author veione
|
||||
*/
|
||||
public class LambdaFunctionTest {
|
||||
|
||||
|
||||
// https://blog.csdn.net/iteye_19045/article/details/119299015
|
||||
@Test
|
||||
public void testFuncSerialization() throws Exception {
|
||||
@@ -35,15 +38,20 @@ public class LambdaFunctionTest {
|
||||
Method writeReplace = clazz.getDeclaredMethod("writeReplace");
|
||||
System.out.println(writeReplace);
|
||||
|
||||
LambdaMeta meta = LambdaUtils.extract(func);
|
||||
System.out.println(meta);
|
||||
|
||||
// Function<StudentResource, String> func2 = StudentResource::name;
|
||||
// Method method = func2.getClass().getDeclaredMethod("writeReplace");
|
||||
// object = method.invoke(func2);
|
||||
// System.out.println(object);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFunctionCache() {
|
||||
Func1<StudentResource, Object> nameFunc1 = StudentResource::getName;
|
||||
Func1<StudentResource, Object> nameFunc2 = StudentResource::getName;
|
||||
Assert.assertNotEquals(nameFunc1, nameFunc2);
|
||||
}
|
||||
|
||||
private static Object getObject(Serializable func) throws Exception {
|
||||
Method method = func.getClass().getDeclaredMethod("writeReplace");
|
||||
Object object = method.invoke(func);
|
||||
|
||||
Reference in new issue
Block a user