
org.neo4j.gds.procedures.KernelTransactionAccessor Maven / Gradle / Ivy
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package org.neo4j.gds.procedures;
import org.neo4j.internal.kernel.api.exceptions.ProcedureException;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.procedure.Context;
/**
* We encapsulate the code for getting the kernel transaction out of a procedure context.
* That in turn makes it easy to stub out should you want to do that.
*/
public class KernelTransactionAccessor {
public KernelTransaction getKernelTransaction(Context context) {
try {
// this is not opening something new that we should close
// it only fetches the current transaction
// compare to what Neo4j does in: https://github.com/neo-technology/neo4j/blame/5.7.0/public/community/neo4j/src/main/java/org/neo4j/graphdb/facade/DatabaseManagementServiceFactory.java#L368-L369
// newer Neo4j versions offer a more direct method: https://github.com/neo-technology/neo4j/blob/e6a228f60efac4fd2584f5ec00de0207aad944ff/public/community/neo4j/src/main/java/org/neo4j/graphdb/facade/DatabaseManagementServiceFactory.java#L356
// we should make sure we do this in a compatible way
return context.internalTransaction().kernelTransaction();
} catch (ProcedureException e) {
// Neo4j itself throws a different exception here; see https://github.com/neo-technology/neo4j/blob/340b40bb956d077b3127c8ba8eb33f2d288bc844/public/community/procedure/src/main/java/org/neo4j/procedure/impl/FieldSetter.java#L44-L49
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy