use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class Begin method exec.
@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
String lineWithoutApp = parser.getLineWithoutApp();
if (!acceptableText(lineWithoutApp)) {
out.println("Error: To open a transaction, write BEGIN TRANSACTION");
return Continuation.INPUT_COMPLETE;
}
KernelTransaction tx = currentTransaction(getServer());
// This is a "begin" app so it will leave a transaction open. Don't close it in here
getServer().getDb().beginTx();
Integer txCount = session.getCommitCount();
int count;
if (txCount == null) {
if (tx == null) {
count = 0;
out.println("Transaction started");
} else {
count = 1;
out.println("Warning: transaction found that was not started by the shell.");
}
} else {
count = txCount;
out.println(String.format("Nested transaction started (Tx count: %d)", count + 1));
}
session.setCommitCount(++count);
return Continuation.INPUT_COMPLETE;
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class Commit method exec.
@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
if (parser.getLineWithoutApp().trim().length() > 0) {
out.println("Error: COMMIT should be run without trailing arguments");
return Continuation.INPUT_COMPLETE;
}
Integer txCount = session.getCommitCount();
KernelTransaction tx = Begin.currentTransaction(getServer());
if (txCount == null || txCount.equals(0)) {
if (tx != null) {
out.println("Warning: committing a transaction not started by the shell");
txCount = 1;
} else {
throw new ShellException("Not in a transaction");
}
}
if (txCount.equals(1)) {
if (tx == null) {
throw fail(session, "Not in a transaction");
}
try {
tx.success();
tx.close();
session.remove(Variables.TX_COUNT);
out.println("Transaction committed");
return Continuation.INPUT_COMPLETE;
} catch (Exception e) {
throw fail(session, e.getMessage());
}
} else {
session.set(Variables.TX_COUNT, --txCount);
out.println(String.format("Nested transaction committed (Tx count: %d)", txCount));
return Continuation.INPUT_COMPLETE;
}
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class Rollback method exec.
@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
if (parser.getLineWithoutApp().trim().length() > 0) {
out.println("Error: ROLLBACK should be run without trailing arguments");
return Continuation.INPUT_COMPLETE;
}
KernelTransaction tx = Begin.currentTransaction(getServer());
if (tx == null) {
throw Commit.fail(session, "Not in a transaction");
}
session.remove(Variables.TX_COUNT);
tx.failure();
try {
tx.close();
} catch (TransactionFailureException e) {
throw new ShellException(e.getMessage());
}
out.println("Transaction rolled back");
return Continuation.INPUT_COMPLETE;
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class ClusterMembershipChangeIT method discoverClusterMembers.
private List<Object[]> discoverClusterMembers(GraphDatabaseFacade db) throws TransactionFailureException, org.neo4j.kernel.api.exceptions.ProcedureException {
KernelAPI kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
KernelTransaction transaction = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
Statement statement = transaction.acquireStatement();
// when
return asList(statement.procedureCallOperations().procedureCallRead(procedureName(GET_SERVERS_V1.fullyQualifiedProcedureName()), new Object[0]));
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class ClusterOverviewIT method clusterOverview.
private List<MemberInfo> clusterOverview(GraphDatabaseFacade db) throws TransactionFailureException, ProcedureException {
KernelAPI kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
KernelTransaction transaction = kernel.newTransaction(Type.implicit, AnonymousContext.read());
List<MemberInfo> infos = new ArrayList<>();
try (Statement statement = transaction.acquireStatement()) {
RawIterator<Object[], ProcedureException> itr = statement.procedureCallOperations().procedureCallRead(procedureName("dbms", "cluster", ClusterOverviewProcedure.PROCEDURE_NAME), null);
while (itr.hasNext()) {
Object[] row = itr.next();
Object[] addresses = (Object[]) row[1];
infos.add(new MemberInfo(Arrays.copyOf(addresses, addresses.length, String[].class), Role.valueOf((String) row[2])));
}
}
return infos;
}
Aggregations