diff --git a/doc/视频教程.md b/doc/视频教程.md index c69e4b37..5adf2151 100644 --- a/doc/视频教程.md +++ b/doc/视频教程.md @@ -56,4 +56,18 @@ cron表达式的用法 spring自带的Scheduled和zfoo的Scheduler java的线程池,SingleThreadScheduledExecutor,SingleThreadExecutor 通过spring自带的CronExpression计算下一次cron表达式要执行的时间 -``` \ No newline at end of file +``` + +### [第六讲](https://www.bilibili.com/video/BV1to4y1C77Y) + +- scheduler原理讲解 +- 知识点 + +``` +Mysql中的数据库,表,一条数据,在Mongodb分别叫做,数据库,集合,文档 +Elastic Search的全文搜索引擎 +Java的缓存框架guava cache,还有它的升级版本caffeine +mongodb的map reduce操作 +分布式唯一Id,Java自带的UUID,雪花算法(SnowFlake),Redis分布式唯一Id实现,Mongodb分布式唯一Id实现,Zookeeper分布式唯一Id实现 +``` + diff --git a/orm/src/test/java/com/zfoo/orm/accessor/DeleteTest.java b/orm/src/test/java/com/zfoo/orm/accessor/DeleteTest.java deleted file mode 100644 index dac5ebf0..00000000 --- a/orm/src/test/java/com/zfoo/orm/accessor/DeleteTest.java +++ /dev/null @@ -1,53 +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.orm.accessor; - -import com.zfoo.orm.OrmContext; -import com.zfoo.orm.entity.UserEntity; -import com.zfoo.orm.model.cache.IEntityCaches; -import com.zfoo.util.ThreadUtils; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -/** - * @author jaysunxiao - * @version 3.0 - */ -@Ignore -public class DeleteTest { - - private static final Logger logger = LoggerFactory.getLogger(InsertTest.class); - - - @Test - public void test() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); - - IEntityCaches userEntityCaches = (IEntityCaches) OrmContext.getOrmManager().getEntityCaches(UserEntity.class); - - for (int i = 0; i < 10; i++) { - UserEntity userEntity = new UserEntity(i, (byte) 1, (short) i, i, true, "helloOrm" + i, "helloOrm" + i); - - OrmContext.getAccessor().delete(userEntity); - logger.debug("thread2执行移除[{}]", i); - } - - ThreadUtils.sleep(Long.MAX_VALUE); - } - - -} diff --git a/orm/src/test/java/com/zfoo/orm/accessor/IndexTextTest.java b/orm/src/test/java/com/zfoo/orm/accessor/IndexTextTest.java index 30b9c996..e10a289c 100644 --- a/orm/src/test/java/com/zfoo/orm/accessor/IndexTextTest.java +++ b/orm/src/test/java/com/zfoo/orm/accessor/IndexTextTest.java @@ -22,7 +22,6 @@ import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import java.util.ArrayList; -import java.util.List; import java.util.function.Consumer; /** @@ -34,8 +33,8 @@ public class IndexTextTest { @Test public void insertTest() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); - List listUser = new ArrayList<>(); + var context = new ClassPathXmlApplicationContext("application.xml"); + var listUser = new ArrayList(); var userEntity = new UserEntity(1, (byte) 1, (short) 1, 1, true, "两个黄鹂鸣翠柳,一行白鹭上青天。窗含西岭千秋雪,门泊东吴万里船。", null); listUser.add(userEntity); userEntity = new UserEntity(2, (byte) 2, (short) 2, 2, true, "床前明月光,疑是地上霜。 举头望明月,低头思故乡。", null); @@ -49,7 +48,7 @@ public class IndexTextTest { @Test public void queryTest() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); + var context = new ClassPathXmlApplicationContext("application.xml"); var collection = OrmContext.getOrmManager().getCollection(UserEntity.class); collection.find(Filters.text("窗含西岭千秋雪")).forEach(new Consumer() { @Override diff --git a/orm/src/test/java/com/zfoo/orm/accessor/InsertTest.java b/orm/src/test/java/com/zfoo/orm/accessor/InsertTest.java deleted file mode 100644 index 10a65dea..00000000 --- a/orm/src/test/java/com/zfoo/orm/accessor/InsertTest.java +++ /dev/null @@ -1,46 +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.orm.accessor; - -import com.zfoo.orm.OrmContext; -import com.zfoo.orm.entity.UserEntity; -import com.zfoo.orm.model.cache.IEntityCaches; -import com.zfoo.util.ThreadUtils; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -/** - * @author jaysunxiao - * @version 3.0 - */ -@Ignore -public class InsertTest { - - @SuppressWarnings("unchecked") - @Test - public void test() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); - - IEntityCaches userEntityCaches = (IEntityCaches) OrmContext.getOrmManager().getEntityCaches(UserEntity.class); - - for (int i = 0; i < 10; i++) { - UserEntity userEntity = new UserEntity(i, (byte) 1, (short) i, i, true, "helloOrm" + i, "helloOrm" + i); - OrmContext.getAccessor().insert(userEntity); - } - - ThreadUtils.sleep(Long.MAX_VALUE); - } - -} diff --git a/orm/src/test/java/com/zfoo/orm/accessor/TransactionTest.java b/orm/src/test/java/com/zfoo/orm/accessor/TransactionTest.java index 3373be7f..c7f3724d 100644 --- a/orm/src/test/java/com/zfoo/orm/accessor/TransactionTest.java +++ b/orm/src/test/java/com/zfoo/orm/accessor/TransactionTest.java @@ -35,7 +35,7 @@ public class TransactionTest { @Test public void transactionTest() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); + var context = new ClassPathXmlApplicationContext("application.xml"); /* Step 1: Start a client session. */ var clientSession = OrmContext.getOrmManager().getClientSession(); @@ -71,6 +71,7 @@ public class TransactionTest { clientSession.withTransaction(txnBody, txnOptions); } catch (RuntimeException e) { // some error handling + e.printStackTrace(); } finally { clientSession.close(); } diff --git a/orm/src/test/java/com/zfoo/orm/accessor/UpdateTest.java b/orm/src/test/java/com/zfoo/orm/cache/EntityCachesTest.java similarity index 69% rename from orm/src/test/java/com/zfoo/orm/accessor/UpdateTest.java rename to orm/src/test/java/com/zfoo/orm/cache/EntityCachesTest.java index 395d4037..7d0c772e 100644 --- a/orm/src/test/java/com/zfoo/orm/accessor/UpdateTest.java +++ b/orm/src/test/java/com/zfoo/orm/cache/EntityCachesTest.java @@ -1,6 +1,5 @@ /* * 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 * @@ -9,9 +8,10 @@ * 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.orm.accessor; +package com.zfoo.orm.cache; import com.mongodb.client.model.Filters; import com.zfoo.orm.OrmContext; @@ -29,20 +29,21 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; * @version 3.0 */ @Ignore -public class UpdateTest { +public class EntityCachesTest { @Test public void test() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); + var context = new ClassPathXmlApplicationContext("application.xml"); - IEntityCaches userEntityCaches = (IEntityCaches) OrmContext.getOrmManager().getEntityCaches(UserEntity.class); + // 动态去拿到UserEntity的EntityCaches + var userEntityCaches = (IEntityCaches) OrmContext.getOrmManager().getEntityCaches(UserEntity.class); - for (int i = 0; i < 10; i++) { - var userEnt = userEntityCaches.load((long) i); - userEnt.setE("update" + i); - userEnt.setC(i); - userEntityCaches.update(userEnt); + for (var i = 1; i <= 10; i++) { + var entity = userEntityCaches.load((long) i); + entity.setE("update" + i); + entity.setC(i); + userEntityCaches.update(entity); } ThreadUtils.sleep(Long.MAX_VALUE); @@ -51,7 +52,7 @@ public class UpdateTest { @Test public void collectionTest() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); + var context = new ClassPathXmlApplicationContext("application.xml"); var collection = OrmContext.getOrmManager().getCollection(UserEntity.class); var result = collection.updateOne(Filters.eq("_id", 1), new Document("$inc", new Document("c", 1L))); diff --git a/orm/src/test/java/com/zfoo/orm/cache/OrmTest.java b/orm/src/test/java/com/zfoo/orm/cache/OrmTest.java index 14a967cf..9ff12ffa 100644 --- a/orm/src/test/java/com/zfoo/orm/cache/OrmTest.java +++ b/orm/src/test/java/com/zfoo/orm/cache/OrmTest.java @@ -28,18 +28,16 @@ public class OrmTest { @Test public void test() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); + var context = new ClassPathXmlApplicationContext("application.xml"); - UserManager mainOrm = context.getBean(UserManager.class); + // 通过注解自动注入的方式去拿到UserEntity的EntityCaches + var userEntityCaches = context.getBean(UserManager.class).userEntityCaches; for (int i = 0; i <= 10; i++) { - var entity = mainOrm.getEntityCaches().load((long) i); - entity.setA((byte) i); - entity.setB((short) i); + var entity = userEntityCaches.load((long) i); + entity.setE("update" + i); entity.setC(i); - entity.setD(true); - entity.setE("helloOrm" + i); - mainOrm.getEntityCaches().update(entity); + userEntityCaches.update(entity); } OrmContext.getOrmManager().getAllEntityCaches().forEach(it -> System.out.println(it.recordStatus())); diff --git a/orm/src/test/java/com/zfoo/orm/cache/UserManager.java b/orm/src/test/java/com/zfoo/orm/cache/UserManager.java index 54123606..9a81a4f4 100644 --- a/orm/src/test/java/com/zfoo/orm/cache/UserManager.java +++ b/orm/src/test/java/com/zfoo/orm/cache/UserManager.java @@ -26,10 +26,6 @@ import org.springframework.stereotype.Component; public class UserManager { @EntityCachesInjection - private IEntityCaches entityCaches; - - public IEntityCaches getEntityCaches() { - return entityCaches; - } + public IEntityCaches userEntityCaches; } diff --git a/orm/src/test/java/com/zfoo/orm/query/QueryTest.java b/orm/src/test/java/com/zfoo/orm/query/QueryTest.java index f8a1ef64..5c4611ca 100644 --- a/orm/src/test/java/com/zfoo/orm/query/QueryTest.java +++ b/orm/src/test/java/com/zfoo/orm/query/QueryTest.java @@ -19,7 +19,6 @@ import org.junit.Ignore; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; -import java.util.List; /** * @author jaysunxiao @@ -30,15 +29,15 @@ public class QueryTest { @Test public void queryAllTest() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); - List list = OrmContext.getQuery().queryAll(UserEntity.class); + var context = new ClassPathXmlApplicationContext("application.xml"); + var list = OrmContext.getQuery().queryAll(UserEntity.class); System.out.println(list); } @Test public void queryByFieldTest() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); - List list = OrmContext.getQuery().queryFieldEqual("a", 1, UserEntity.class); + var context = new ClassPathXmlApplicationContext("application.xml"); + var list = OrmContext.getQuery().queryFieldEqual("a", 1, UserEntity.class); System.out.println(list); } diff --git a/orm/src/test/java/com/zfoo/orm/util/MongoIdUtilsTest.java b/orm/src/test/java/com/zfoo/orm/util/MongoIdUtilsTest.java index 0b083651..4a0061b3 100644 --- a/orm/src/test/java/com/zfoo/orm/util/MongoIdUtilsTest.java +++ b/orm/src/test/java/com/zfoo/orm/util/MongoIdUtilsTest.java @@ -19,6 +19,8 @@ import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; /** + * MongoDB分布式唯一Id测试 + * * @author jaysunxiao * @version 3.0 */