+ * Note: Intended for internal usage only.
+ *
+ * @author Michael J. Simons
+ */
+public class Neo4jResourceHolder extends ResourceHolderSupport {
+
+ private final Session session;
+
+ private final Transaction transaction;
+
+ public Neo4jResourceHolder(Session session) {
+ this(session, TransactionConfig.empty());
+ }
+
+ public Neo4jResourceHolder(Session session, TransactionConfig transactionConfig) {
+ this.session = session;
+
+ this.transaction = this.session.beginTransaction(transactionConfig);
+ }
+
+ Transaction getTransaction() {
+ return transaction;
+ }
+
+ public void commit() {
+
+ Assert.state(hasActiveTransaction(), "Transaction must be open, but has already been closed.");
+ Assert.state(!isRollbackOnly(), "Resource msut not be marked as rollback only.");
+
+ transaction.success();
+ transaction.close();
+ }
+
+ public void rollback() {
+
+ Assert.state(hasActiveTransaction(), "Transaction must be open, but has already been closed.");
+
+ transaction.failure();
+ transaction.close();
+ }
+
+ public void close() {
+
+ Assert.state(hasActiveSession(), "Session must be open, but has already been closed.");
+
+ if (hasActiveTransaction()) {
+ transaction.close();
+ }
+ session.close();
+ }
+
+ @Override
+ public void setRollbackOnly() {
+ super.setRollbackOnly();
+ }
+
+ @Override
+ public void resetRollbackOnly() {
+
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean hasActiveSession() {
+
+ return session.isOpen();
+ }
+
+ public boolean hasActiveTransaction() {
+
+ return transaction.isOpen();
+ }
+}
diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/core/transaction/Neo4jSessionSynchronization.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/core/transaction/Neo4jSessionSynchronization.java
new file mode 100644
index 000000000..6b6022756
--- /dev/null
+++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/core/transaction/Neo4jSessionSynchronization.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2019 "Neo4j,"
+ * Neo4j Sweden AB [http://neo4j.com]
+ *
+ * This file is part of Neo4j.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.neo4j.core.transaction;
+
+import org.neo4j.driver.v1.Driver;
+import org.springframework.transaction.support.ResourceHolderSynchronization;
+import org.springframework.transaction.support.TransactionSynchronization;
+
+/**
+ * Neo4j specific {@link ResourceHolderSynchronization} for resource cleanup at the end of a transaction when
+ * participating in a non-native Neoj4 transaction, such as a Jta transaction.
+ */
+class Neo4jSessionSynchronization
+ extends ResourceHolderSynchronization
+ * Note: Intended for internal usage only.
*
* @author Michael J. Simons
*/
-public interface Neo4jSessionFactory {
-
- Session getSession();
+@FunctionalInterface
+public interface StatementRunnerSupplier S save(S entity) {
throw new UnsupportedOperationException("Not there yet.");
}
@Override
+ @Transactional
public Iterable saveAll(Iterable entities) {
throw new UnsupportedOperationException("Not there yet.");
}
@@ -86,23 +93,31 @@ class SimpleNeo4jRepository