diff --git a/orm/src/main/java/com/zfoo/orm/accessor/IAccessor.java b/orm/src/main/java/com/zfoo/orm/accessor/IAccessor.java index 4f015bb46..b74caaf6d 100644 --- a/orm/src/main/java/com/zfoo/orm/accessor/IAccessor.java +++ b/orm/src/main/java/com/zfoo/orm/accessor/IAccessor.java @@ -34,8 +34,6 @@ public interface IAccessor { , E extends IEntity> void batchUpdate(List entities); - , E extends IEntity> void batchUpdateNode(List> entities); - , E extends IEntity> boolean delete(E entity); , E extends IEntity> boolean delete(PK pk, Class entityClazz); diff --git a/orm/src/main/java/com/zfoo/orm/accessor/MongodbAccessor.java b/orm/src/main/java/com/zfoo/orm/accessor/MongodbAccessor.java index f580086cc..0036cd174 100644 --- a/orm/src/main/java/com/zfoo/orm/accessor/MongodbAccessor.java +++ b/orm/src/main/java/com/zfoo/orm/accessor/MongodbAccessor.java @@ -104,37 +104,6 @@ public , E extends IEntity> void batchUpdate(List< } } - @Override - public , E extends IEntity> void batchUpdateNode(List> nodes) { - if (CollectionUtils.isEmpty(nodes)) { - return; - } - - try { - @SuppressWarnings("unchecked") - var entityClazz = (Class) nodes.get(0).getClass(); - var collection = OrmContext.getOrmManager().getCollection(entityClazz); - List entities = nodes.stream().map(PNode::getEntity).toList(); - var batchList = entities.stream() - .map(it -> new ReplaceOneModel(Filters.eq("_id", it.id()), it)) - .toList(); - - var result = collection.bulkWrite(batchList, new BulkWriteOptions().ordered(false)); - - //设置修改时间 - long currentTime = TimeUtils.currentTimeMillis(); - nodes.forEach(k->k.resetTime(currentTime)); - - if (result.getMatchedCount() != entities.size()) { - // 在数据库的批量更新操作中需要更新的数量和最终更新的数量不相同 - logger.warn("database:[{}] update size:[{}] not equal with matched size:[{}](some entity of id not exist in database)" - , entityClazz.getSimpleName(), entities.size(), result.getMatchedCount()); - } - } catch (Throwable t) { - logger.error("batchUpdate unknown exception", t); - } - } - @Override public , E extends IEntity> boolean delete(E entity) { @SuppressWarnings("unchecked") diff --git a/orm/src/main/java/com/zfoo/orm/cache/EntityCache.java b/orm/src/main/java/com/zfoo/orm/cache/EntityCache.java index 1bcc85ffb..72ecff7e2 100644 --- a/orm/src/main/java/com/zfoo/orm/cache/EntityCache.java +++ b/orm/src/main/java/com/zfoo/orm/cache/EntityCache.java @@ -309,7 +309,29 @@ private void doPersistNoVersion(List> updateList) { for (var currentPage = 1; currentPage <= maxPageSize; currentPage++) { page.setPage(currentPage); var currentUpdateList = page.currentPageList(updateList); - OrmContext.getAccessor().batchUpdateNode(currentUpdateList); + try { + @SuppressWarnings("unchecked") + var entityClazz = (Class) currentUpdateList.get(0).getClass(); + var collection = OrmContext.getOrmManager().getCollection(entityClazz); + List entities = currentUpdateList.stream().map(PNode::getEntity).toList(); + var batchList = entities.stream() + .map(it -> new ReplaceOneModel(Filters.eq("_id", it.id()), it)) + .toList(); + + var result = collection.bulkWrite(batchList, new BulkWriteOptions().ordered(false)); + + //设置修改时间 + long currentTime = TimeUtils.currentTimeMillis(); + currentUpdateList.forEach(k->k.resetTime(currentTime)); + + if (result.getMatchedCount() != entities.size()) { + // 在数据库的批量更新操作中需要更新的数量和最终更新的数量不相同 + logger.warn("database:[{}] update size:[{}] not equal with matched size:[{}](some entity of id not exist in database)" + , entityClazz.getSimpleName(), entities.size(), result.getMatchedCount()); + } + } catch (Throwable t) { + logger.error("batchUpdate unknown exception", t); + } } }