This commit is contained in:
meiwei committed 2022-10-09 14:19:22 +08:00
commit 606c7d617d
39 files changed
+89 -79

No files matched your search

@@ -14,9 +14,9 @@ package com.zfoo.boot;
import com.zfoo.orm.OrmContext;
import com.zfoo.orm.manager.OrmManager;
import com.zfoo.orm.model.accessor.MongodbAccessor;
import com.zfoo.orm.accessor.MongodbAccessor;
import com.zfoo.orm.model.config.OrmConfig;
import com.zfoo.orm.model.query.MongodbQuery;
import com.zfoo.orm.query.MongodbQuery;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
+9
View File
@@ -78,3 +78,12 @@ SignalAttachment的signalId就是用于RPC的同步和异步的信号,通过
- icon使用的material font,mdi 5.3.45,https://pictogrammers.github.io/@mdi/font/5.3.45/
---
#### orm为什么不选择Spring的官方驱动SpringData mongodb
- SpringData mongodb 里面会生成一个class字段,比较占内存,而且你移动class类的时候体验不友好,不知道现在版本改了没有
- mongodb的官方驱动轻量,mongodb的官方驱动基本上什么功能都有,SpringData mongodb这个封装太重了
- zfoo的orm接近0封装,简单的封装可以极大提高上层的自由度
---
@@ -16,10 +16,10 @@ package com.zfoo.orm;
import com.mongodb.client.MongoClient;
import com.zfoo.orm.manager.IOrmManager;
import com.zfoo.orm.manager.OrmManager;
import com.zfoo.orm.model.accessor.IAccessor;
import com.zfoo.orm.accessor.IAccessor;
import com.zfoo.orm.model.entity.IEntity;
import com.zfoo.orm.model.query.IQuery;
import com.zfoo.orm.model.query.IQueryBuilder;
import com.zfoo.orm.query.IQuery;
import com.zfoo.orm.query.IQueryBuilder;
import com.zfoo.protocol.util.ReflectionUtils;
import com.zfoo.scheduler.SchedulerContext;
import com.zfoo.scheduler.model.StopWatch;
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.model.accessor;
package com.zfoo.orm.accessor;
import com.zfoo.orm.model.entity.IEntity;
import org.springframework.lang.Nullable;
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.model.accessor;
package com.zfoo.orm.accessor;
import com.mongodb.client.model.BulkWriteOptions;
import com.mongodb.client.model.Filters;
@@ -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
*
@@ -11,7 +10,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.model.cache;
package com.zfoo.orm.cache;
import com.github.benmanes.caffeine.cache.*;
import com.mongodb.WriteConcern;
@@ -20,9 +19,9 @@ import com.mongodb.client.model.Filters;
import com.mongodb.client.model.ReplaceOneModel;
import com.zfoo.orm.OrmContext;
import com.zfoo.orm.model.entity.IEntity;
import com.zfoo.orm.model.persister.IOrmPersister;
import com.zfoo.orm.model.persister.PNode;
import com.zfoo.orm.model.query.Page;
import com.zfoo.orm.cache.persister.IOrmPersister;
import com.zfoo.orm.cache.persister.PNode;
import com.zfoo.orm.query.Page;
import com.zfoo.orm.model.vo.EntityDef;
import com.zfoo.protocol.collection.CollectionUtils;
import com.zfoo.protocol.util.AssertionUtils;
@@ -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
*
@@ -11,7 +10,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.model.cache;
package com.zfoo.orm.cache;
import com.zfoo.orm.model.entity.IEntity;
@@ -11,9 +11,9 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.model.persister;
package com.zfoo.orm.cache.persister;
import com.zfoo.orm.model.cache.EntityCaches;
import com.zfoo.orm.cache.EntityCaches;
import com.zfoo.orm.model.vo.EntityDef;
/**
@@ -11,11 +11,11 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.model.persister;
package com.zfoo.orm.cache.persister;
import com.zfoo.event.manager.EventBus;
import com.zfoo.orm.OrmContext;
import com.zfoo.orm.model.cache.EntityCaches;
import com.zfoo.orm.cache.EntityCaches;
import com.zfoo.orm.model.vo.EntityDef;
import com.zfoo.protocol.exception.ExceptionUtils;
import com.zfoo.scheduler.manager.SchedulerBus;
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.model.persister;
package com.zfoo.orm.cache.persister;
/**
* @author godotg
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.model.persister;
package com.zfoo.orm.cache.persister;
import com.zfoo.orm.model.entity.IEntity;
import com.zfoo.scheduler.util.TimeUtils;
@@ -11,11 +11,11 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.model.persister;
package com.zfoo.orm.cache.persister;
import com.zfoo.event.manager.EventBus;
import com.zfoo.orm.OrmContext;
import com.zfoo.orm.model.cache.EntityCaches;
import com.zfoo.orm.cache.EntityCaches;
import com.zfoo.orm.model.vo.EntityDef;
import com.zfoo.protocol.util.StringUtils;
import com.zfoo.scheduler.manager.SchedulerBus;
@@ -15,7 +15,7 @@ package com.zfoo.orm.manager;
import com.mongodb.client.ClientSession;
import com.mongodb.client.MongoCollection;
import com.zfoo.orm.model.cache.IEntityCaches;
import com.zfoo.orm.cache.IEntityCaches;
import com.zfoo.orm.model.entity.IEntity;
import org.bson.Document;
@@ -21,8 +21,8 @@ import com.mongodb.client.model.IndexOptions;
import com.mongodb.client.model.Indexes;
import com.zfoo.orm.OrmContext;
import com.zfoo.orm.model.anno.*;
import com.zfoo.orm.model.cache.EntityCaches;
import com.zfoo.orm.model.cache.IEntityCaches;
import com.zfoo.orm.cache.EntityCaches;
import com.zfoo.orm.cache.IEntityCaches;
import com.zfoo.orm.model.config.OrmConfig;
import com.zfoo.orm.model.entity.IEntity;
import com.zfoo.orm.model.vo.EntityDef;
@@ -13,10 +13,10 @@
package com.zfoo.orm.model.config;
import com.zfoo.orm.model.cache.EntityCaches;
import com.zfoo.orm.model.persister.CronOrmPersister;
import com.zfoo.orm.model.persister.IOrmPersister;
import com.zfoo.orm.model.persister.TimeOrmPersister;
import com.zfoo.orm.cache.EntityCaches;
import com.zfoo.orm.cache.persister.CronOrmPersister;
import com.zfoo.orm.cache.persister.IOrmPersister;
import com.zfoo.orm.cache.persister.TimeOrmPersister;
import com.zfoo.orm.model.vo.EntityDef;
import com.zfoo.protocol.util.StringUtils;
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.model.query;
package com.zfoo.orm.query;
import com.zfoo.orm.model.entity.IEntity;
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.model.query;
package com.zfoo.orm.query;
import com.zfoo.orm.model.entity.IEntity;
import com.zfoo.protocol.model.Pair;
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.model.query;
package com.zfoo.orm.query;
import com.mongodb.client.model.Filters;
import com.zfoo.orm.OrmContext;
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.model.query;
package com.zfoo.orm.query;
import com.zfoo.orm.model.entity.IEntity;
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.model.query;
package com.zfoo.orm.query;
import com.zfoo.protocol.collection.CollectionUtils;
import com.zfoo.protocol.util.StringUtils;
@@ -15,12 +15,12 @@ package com.zfoo.orm.schema;
import com.zfoo.orm.OrmContext;
import com.zfoo.orm.manager.OrmManager;
import com.zfoo.orm.model.accessor.MongodbAccessor;
import com.zfoo.orm.accessor.MongodbAccessor;
import com.zfoo.orm.model.config.CacheStrategy;
import com.zfoo.orm.model.config.HostConfig;
import com.zfoo.orm.model.config.OrmConfig;
import com.zfoo.orm.model.config.PersisterStrategy;
import com.zfoo.orm.model.query.MongodbQuery;
import com.zfoo.orm.query.MongodbQuery;
import com.zfoo.protocol.util.DomUtils;
import com.zfoo.protocol.util.StringUtils;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
@@ -16,7 +16,6 @@ package com.zfoo.orm.cache;
import com.mongodb.client.model.Filters;
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.bson.Document;
import org.junit.Ignore;
-1
View File
@@ -15,7 +15,6 @@ package com.zfoo.orm.cache;
import com.zfoo.orm.entity.UserEntity;
import com.zfoo.orm.model.anno.EntityCachesInjection;
import com.zfoo.orm.model.cache.IEntityCaches;
import org.springframework.stereotype.Component;
/**
@@ -13,7 +13,6 @@
package com.zfoo.orm.query;
import com.zfoo.orm.model.query.Page;
import org.junit.Assert;
import org.junit.Test;
@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.lpmap;
package com.zfoo.protocol.collection.lpmap;
import com.zfoo.protocol.IPacket;
@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.lpmap;
package com.zfoo.protocol.collection.lpmap;
import com.zfoo.protocol.IPacket;
@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.lpmap;
package com.zfoo.protocol.collection.lpmap;
import com.zfoo.protocol.IPacket;
@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.lpmap;
package com.zfoo.protocol.collection.lpmap;
import com.zfoo.protocol.IPacket;
@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.lpmap;
package com.zfoo.protocol.collection.lpmap;
import com.zfoo.protocol.IPacket;
import com.zfoo.protocol.ProtocolManager;
@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.lpmap;
package com.zfoo.protocol.collection.lpmap;
import com.zfoo.protocol.IPacket;
import com.zfoo.protocol.ProtocolManager;
@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.lpmap;
package com.zfoo.protocol.collection.lpmap;
import com.zfoo.protocol.IPacket;
import io.netty.util.collection.LongObjectHashMap;
@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.lpmap;
package com.zfoo.protocol.collection.lpmap;
import com.zfoo.protocol.IPacket;
import com.zfoo.protocol.exception.RunException;
@@ -26,13 +26,14 @@ import java.util.concurrent.CountDownLatch;
@Ignore
public class ConcurrentTest {
private static final int EXECUTOR_SIZE = Runtime.getRuntime().availableProcessors();
@Test
public void test() throws InterruptedException {
var map = new CopyOnWriteHashMapLongObject<Integer>();
var num = 1_0000;
var executorSize = Runtime.getRuntime().availableProcessors();
var countDownLatch = new CountDownLatch(executorSize);
for (var i = 0; i < executorSize; i++) {
var countDownLatch = new CountDownLatch(EXECUTOR_SIZE);
for (var i = 0; i < EXECUTOR_SIZE; i++) {
new Thread(new Runnable() {
@Override
public void run() {
@@ -46,8 +47,8 @@ public class ConcurrentTest {
countDownLatch.await();
Assert.assertEquals(map.size(), num);
var countDownLatch2 = new CountDownLatch(executorSize);
for (var i = 0; i < executorSize; i++) {
var countDownLatch2 = new CountDownLatch(EXECUTOR_SIZE);
for (var i = 0; i < EXECUTOR_SIZE; i++) {
new Thread(new Runnable() {
@Override
public void run() {
@@ -10,11 +10,10 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.lpmap;
package com.zfoo.protocol.collection.lpmap;
import com.zfoo.event.manager.EventBus;
import com.zfoo.orm.lpmap.model.MyPacket;
import com.zfoo.protocol.ProtocolManager;
import com.zfoo.protocol.collection.lpmap.model.MyPacket;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
@@ -31,6 +30,8 @@ import java.util.concurrent.atomic.AtomicInteger;
@Ignore
public class ConcurrentFileChannelMapTest {
private static final int EXECUTOR_SIZE = Runtime.getRuntime().availableProcessors();
@Test
public void benchmarkTest() throws IOException, InterruptedException {
ProtocolManager.initProtocol(Set.of(MyPacket.class));
@@ -39,9 +40,9 @@ public class ConcurrentFileChannelMapTest {
var atomicInt = new AtomicInteger(0);
var count = 1000_0000;
var countdown = new CountDownLatch(EventBus.EXECUTORS_SIZE);
for (int i = 0; i < EventBus.EXECUTORS_SIZE; i++) {
EventBus.asyncExecute(new Runnable() {
var countdown = new CountDownLatch(EXECUTOR_SIZE);
for (int i = 0; i < EXECUTOR_SIZE; i++) {
new Thread(new Runnable() {
@Override
public void run() {
var key = atomicInt.getAndIncrement();
@@ -52,7 +53,7 @@ public class ConcurrentFileChannelMapTest {
}
countdown.countDown();
}
});
}).start();
}
countdown.await();
for (var i = 0; i < count; i++) {
@@ -10,10 +10,9 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.lpmap;
package com.zfoo.protocol.collection.lpmap;
import com.zfoo.event.manager.EventBus;
import com.zfoo.orm.lpmap.model.MyPacket;
import com.zfoo.protocol.collection.lpmap.model.MyPacket;
import com.zfoo.protocol.ProtocolManager;
import org.junit.Assert;
import org.junit.Ignore;
@@ -31,6 +30,8 @@ import java.util.concurrent.atomic.AtomicInteger;
@Ignore
public class ConcurrentHeapMapTest {
private static final int EXECUTOR_SIZE = Runtime.getRuntime().availableProcessors();
@Test
public void putIfAbsentTest() {
ProtocolManager.initProtocol(Set.of(MyPacket.class));
@@ -56,17 +57,20 @@ public class ConcurrentHeapMapTest {
var atomicInt = new AtomicInteger(0);
var count = 1000_0000;
var countdown = new CountDownLatch(EventBus.EXECUTORS_SIZE);
for (int i = 0; i < EventBus.EXECUTORS_SIZE; i++) {
EventBus.asyncExecute(() -> {
var key = atomicInt.getAndIncrement();
while (key < count) {
var myPacket = MyPacket.valueOf(key, String.valueOf(key));
map.put(key, myPacket);
key = atomicInt.getAndIncrement();
var countdown = new CountDownLatch(EXECUTOR_SIZE);
for (int i = 0; i < EXECUTOR_SIZE; i++) {
new Thread(new Runnable() {
@Override
public void run() {
var key = atomicInt.getAndIncrement();
while (key < count) {
var myPacket = MyPacket.valueOf(key, String.valueOf(key));
map.put(key, myPacket);
key = atomicInt.getAndIncrement();
}
countdown.countDown();
}
countdown.countDown();
});
}).start();
}
countdown.await();
for (var i = 0; i < count; i++) {
@@ -10,9 +10,9 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.lpmap;
package com.zfoo.protocol.collection.lpmap;
import com.zfoo.orm.lpmap.model.MyPacket;
import com.zfoo.protocol.collection.lpmap.model.MyPacket;
import com.zfoo.protocol.ProtocolManager;
import org.junit.Assert;
import org.junit.Ignore;
@@ -10,9 +10,9 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.lpmap;
package com.zfoo.protocol.collection.lpmap;
import com.zfoo.orm.lpmap.model.MyPacket;
import com.zfoo.protocol.collection.lpmap.model.MyPacket;
import com.zfoo.protocol.ProtocolManager;
import org.junit.Assert;
import org.junit.Ignore;
@@ -10,9 +10,9 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.lpmap;
package com.zfoo.protocol.collection.lpmap;
import com.zfoo.orm.lpmap.model.MyPacket;
import com.zfoo.protocol.collection.lpmap.model.MyPacket;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
@@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.orm.lpmap.model;
package com.zfoo.protocol.collection.lpmap.model;
import com.zfoo.protocol.IPacket;