From 419b8ef2f970fb7f8817aefbe11023a8a063e166 Mon Sep 17 00:00:00 2001 From: richie Date: Fri, 16 Aug 2019 11:32:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=BB?= =?UTF-8?q?=E5=86=99=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fanruan/api/conf/BaseConfiguration.java | 12 +++++ .../com/fanruan/api/conf/BaseUniqueKey.java | 12 +++++ .../fanruan/api/conf/ConfigContextKit.java | 21 +++++++++ .../com/fanruan/api/security/SecurityKit.java | 10 +++++ .../api/conf/BaseConfigurationTest.java | 44 +++++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 src/main/java/com/fanruan/api/conf/BaseConfiguration.java create mode 100644 src/main/java/com/fanruan/api/conf/BaseUniqueKey.java create mode 100644 src/main/java/com/fanruan/api/conf/ConfigContextKit.java create mode 100644 src/main/java/com/fanruan/api/security/SecurityKit.java create mode 100644 src/test/java/com/fanruan/api/conf/BaseConfigurationTest.java diff --git a/src/main/java/com/fanruan/api/conf/BaseConfiguration.java b/src/main/java/com/fanruan/api/conf/BaseConfiguration.java new file mode 100644 index 0000000..422d3de --- /dev/null +++ b/src/main/java/com/fanruan/api/conf/BaseConfiguration.java @@ -0,0 +1,12 @@ +package com.fanruan.api.conf; + +import com.fr.config.DefaultConfiguration; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-16 + */ +public abstract class BaseConfiguration extends DefaultConfiguration { + +} diff --git a/src/main/java/com/fanruan/api/conf/BaseUniqueKey.java b/src/main/java/com/fanruan/api/conf/BaseUniqueKey.java new file mode 100644 index 0000000..c21cfc2 --- /dev/null +++ b/src/main/java/com/fanruan/api/conf/BaseUniqueKey.java @@ -0,0 +1,12 @@ +package com.fanruan.api.conf; + +import com.fr.config.utils.UniqueKey; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-16 + * 需要存入fine_conf_entity配置库中的属性对象,需要继承此抽象类 + */ +public abstract class BaseUniqueKey extends UniqueKey { +} diff --git a/src/main/java/com/fanruan/api/conf/ConfigContextKit.java b/src/main/java/com/fanruan/api/conf/ConfigContextKit.java new file mode 100644 index 0000000..9ce6c58 --- /dev/null +++ b/src/main/java/com/fanruan/api/conf/ConfigContextKit.java @@ -0,0 +1,21 @@ +package com.fanruan.api.conf; + +import com.fr.config.ConfigContext; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-16 + */ +public class ConfigContextKit { + + /** + * 从配置对象池中创建或者获取配置对象实例 + * @param clazz 配置实例类型 + * @param 类型 + * @return 配置对象 + */ + public static T getConfigInstance(final Class clazz) { + return ConfigContext.getConfigInstance(clazz); + } +} diff --git a/src/main/java/com/fanruan/api/security/SecurityKit.java b/src/main/java/com/fanruan/api/security/SecurityKit.java new file mode 100644 index 0000000..517182b --- /dev/null +++ b/src/main/java/com/fanruan/api/security/SecurityKit.java @@ -0,0 +1,10 @@ +package com.fanruan.api.security; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-16 + * 文本加密解密相关的工具类 + */ +public class SecurityKit { +} diff --git a/src/test/java/com/fanruan/api/conf/BaseConfigurationTest.java b/src/test/java/com/fanruan/api/conf/BaseConfigurationTest.java new file mode 100644 index 0000000..d57dcd4 --- /dev/null +++ b/src/test/java/com/fanruan/api/conf/BaseConfigurationTest.java @@ -0,0 +1,44 @@ +package com.fanruan.api.conf; + +import com.fanruan.api.Prepare; +import com.fr.config.holder.Conf; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-16 + */ +public class BaseConfigurationTest extends Prepare { + + @Test + public void testGet() { + MyConf conf = MyConf.getInstance(); + Assert.assertEquals(10, conf.getCount()); + conf.setCount(100); + Assert.assertEquals(100, conf.getCount()); + } + + private static class MyConf extends BaseConfiguration { + + private static volatile MyConf instance = null; + + public static MyConf getInstance() { + if (instance == null) { + instance = ConfigContextKit.getConfigInstance(MyConf.class); + } + return instance; + } + + private Conf count = HolderKit.simple(10); + + public int getCount() { + return count.get(); + } + + public void setCount(int count) { + this.count.set(count); + } + } +} \ No newline at end of file