REQ-3540: move codes to precise location

This commit is contained in:
yanglin 2025-03-31 17:07:40 +08:00
parent 736cb827f7
commit 7a00e9173f
2 changed files with 12 additions and 12 deletions

View File

@ -57,13 +57,13 @@ public class IndexManager {
@BizTransactional
public IndexNode createDatabase(NodeCreate create) {
ensureChildNameNotUsed(create, IndexNodeType.DATABASE, true);
indexSupport.ensureChildNameNotUsed(create, IndexNodeType.DATABASE, true);
return indexSupport.createNode(create, IndexNodeType.DATABASE);
}
@BizTransactional
public IndexNode createDir(NodeCreate create) {
ensureChildNameNotUsed(create, IndexNodeType.DIRECTORY, true);
indexSupport.ensureChildNameNotUsed(create, IndexNodeType.DIRECTORY, true);
return indexSupport.createNode(create, IndexNodeType.DIRECTORY);
}
@ -71,7 +71,7 @@ public class IndexManager {
BizAssertions.assertTrue(format.creatable(), "无法创建: {}", format.readableName());
BizAssertions.assertFalse(TransactionSynchronizationManager.isActualTransactionActive(), "不能在事务中使用");
// check without lock
ensureChildNameNotUsed(create, IndexNodeType.FILE, false);
indexSupport.ensureChildNameNotUsed(create, IndexNodeType.FILE, false);
String fullFileName = String.format("%s.%s", create.name(), format.createFileExtension());
String emptyOssFileKey = format == FileFormat.WORD //
? docProps.getCreateFileOssFileKeyWord() //
@ -107,7 +107,7 @@ public class IndexManager {
return transaction.execute(unused -> {
try {
// check with lock
ensureChildNameNotUsed(create, IndexNodeType.FILE, true);
indexSupport.ensureChildNameNotUsed(create, IndexNodeType.FILE, true);
}
catch (NameUsedException e) {
deleteOssFile.set(true);
@ -130,14 +130,6 @@ public class IndexManager {
}
}
private void ensureChildNameNotUsed(NodeCreate create, IndexNodeType nodeType, boolean withLock) {
if (indexSupport.childrenNameDuplicatable(create))
return;
if (withLock)
indexSupport.lockParentAndReleaseOnCommit(create);
indexSupport.ensureChildNameNotUsed(create, nodeType, create.name());
}
@BizTransactional
public void rename(String code, String newName) {
IndexNode indexNode = getOrThrow(code);

View File

@ -134,6 +134,14 @@ public class IndexSupport {
indexNodeDao.rename(rename.getCode(), newName);
}
void ensureChildNameNotUsed(NodeCreate create, IndexNodeType nodeType, boolean withLock) {
if (childrenNameDuplicatable(create))
return;
if (withLock)
lockParentAndReleaseOnCommit(create);
ensureChildNameNotUsed(create, nodeType, create.name());
}
void ensureChildNameNotUsed(IndexNodeParentScope parentScope, IndexNodeType nodeType, String childName) {
IndexNode child = indexNodeDao.findValidChildByName(parentScope, nodeType, childName);
// don't use BizAssertions.assertNull