PArent context must be get with the same current DB

This commit is contained in:
Luca Frosini 2024-07-09 12:02:25 +02:00
parent fb7ca52744
commit 99980cc20c
1 changed files with 34 additions and 1 deletions

View File

@ -153,16 +153,41 @@ public class ContextUtility {
}
}
// private OVertex getParentOfContextVertexByUUID(UUID uuid) throws ResourceRegistryException {
// ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
// ODatabaseDocument oDatabaseDocument = null;
// try {
// oDatabaseDocument = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER);
// OVertex oVertex = OrientDBUtility.getElementByUUID(oDatabaseDocument, Context.NAME, uuid,
// OVertex.class);
// return oVertex;
// } finally {
// if(oDatabaseDocument!=null) {
// oDatabaseDocument.close();
// }
//
// if(current!=null) {
// current.activateOnCurrentThread();
// }
// }
// }
private SecurityContext getSecurityContextByUUID(UUID uuid, OVertex contextVertex) throws ResourceRegistryException {
SecurityContext securityContext = contexts.get(uuid);
if(securityContext == null) {
securityContext = new SecurityContext(uuid);
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
ODatabaseDocument oDatabaseDocument = null;
try {
if(contextVertex == null) {
contextVertex = getContextVertexByUUID(uuid);
oDatabaseDocument = getAdminSecurityContext().getDatabaseDocument(PermissionMode.READER);
contextVertex = OrientDBUtility.getElementByUUID(oDatabaseDocument, Context.NAME, uuid, OVertex.class);
}
OVertex parentVertex = contextVertex.getVertices(ODirection.IN, IsParentOf.NAME).iterator().next();
if(parentVertex != null) {
@ -172,6 +197,14 @@ public class ContextUtility {
} catch(NoSuchElementException e) {
// No parent
} finally {
if(oDatabaseDocument!=null) {
oDatabaseDocument.close();
}
if(current!=null) {
current.activateOnCurrentThread();
}
}
contexts.put(uuid, securityContext);