org.ow2.jotm
jotm-core
diff --git a/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/DefaultSynchronizationManager.java b/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/DefaultSynchronizationManager.java
deleted file mode 100644
index 4cca62b1d..000000000
--- a/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/DefaultSynchronizationManager.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Copyright 2011 the original author or authors.
- *
- * 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.transaction;
-
-import org.springframework.transaction.support.TransactionSynchronizationManager;
-
-/**
- * @author mh
- * @since 15.02.11
- */
-public class DefaultSynchronizationManager implements SynchronizationManager {
- @Override
- public void initSynchronization() {
- TransactionSynchronizationManager.initSynchronization();
- }
-
- @Override
- public boolean isSynchronizationActive() {
- return TransactionSynchronizationManager.isSynchronizationActive();
- }
-
- @Override
- public void clearSynchronization() {
- TransactionSynchronizationManager.clear();
- }
-}
diff --git a/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/JotmFactoryBean.java b/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/JotmFactoryBean.java
deleted file mode 100644
index 90f9ef609..000000000
--- a/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/JotmFactoryBean.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/**
- * Copyright 2011 the original author or authors.
- *
- * 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.transaction;
-
-import org.objectweb.jotm.Current;
-import org.objectweb.jotm.Jotm;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.beans.factory.InitializingBean;
-
-import javax.naming.NamingException;
-import javax.transaction.SystemException;
-
-/**
- * FactoryBean that retrieves the JTA UserTransaction/TransactionManager for
- * ObjectWeb's JOTM. Will retrieve
- * an already active JOTM instance if found (e.g. if running in JOnAS),
- * else create a new local JOTM instance.
- *
- * With JOTM, the same object implements both the
- * {@link javax.transaction.UserTransaction} and the
- * {@link javax.transaction.TransactionManager} interface,
- * as returned by this FactoryBean.
- *
- * A local JOTM instance is well-suited for working in conjunction with
- * ObjectWeb's XAPool, e.g. with bean
- * definitions like the following:
- *
- *
- * <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>
- *
- * <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
- * <property name="userTransaction" ref="jotm"/>
- * </bean>
- *
- * <bean id="innerDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">
- * <property name="transactionManager" ref="jotm"/>
- * <property name="driverName" value="..."/>
- * <property name="url" value="..."/>
- * <property name="user" value="..."/>
- * <property name="password" value="..."/>
- * </bean>
- *
- * <bean id="dataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">
- * <property name="dataSource" ref="innerDataSource"/>
- * <property name="user" value="..."/>
- * <property name="password" value="..."/>
- * <property name="maxSize" value="..."/>
- * </bean>
- *
- * Note that Spring's {@link org.springframework.transaction.jta.JtaTransactionManager} will automatically detect
- * that the passed-in UserTransaction reference also implements the
- * TransactionManager interface. Hence, it is not necessary to specify a
- * separate reference for JtaTransactionManager's "transactionManager" property.
- *
- * Implementation note: This FactoryBean uses JOTM's static access method
- * to obtain the JOTM {@link org.objectweb.jotm.Current} object, which
- * implements both the UserTransaction and the TransactionManager interface,
- * as mentioned above.
- *
- * @author Juergen Hoeller
- * @see org.springframework.transaction.jta.JtaTransactionManager#setUserTransaction
- * @see org.springframework.transaction.jta.JtaTransactionManager#setTransactionManager
- * @see org.objectweb.jotm.Current
- * @since 21.01.2004
- */
-public class JotmFactoryBean implements FactoryBean, DisposableBean, InitializingBean {
-
- private Current jotmCurrent;
-
- private Jotm jotm;
- private String jotmHome;
- private Integer defaultTimeout;
- private Boolean transactionRecovery;
-
-
- /**
- * Set the default transaction timeout for the JOTM instance.
- *
Should only be called for a local JOTM instance,
- * not when accessing an existing (shared) JOTM instance.
- */
- public void setDefaultTimeout(int defaultTimeout) {
- this.defaultTimeout = defaultTimeout;
- }
-
-
- public void setTransactionRecovery(boolean transactionRecovery) throws SystemException {
- this.transactionRecovery = transactionRecovery;
- }
-
- /**
- * @param jotmHome the directory that contains conf/jotm.properties
- */
- public void setJotmHome(String jotmHome) {
- this.jotmHome = jotmHome;
- }
-
- @Override
- public void afterPropertiesSet() throws Exception {
- createJotm();
- }
-
- private void createJotm() throws NamingException, SystemException {
- if (jotmHome!=null) {
- System.setProperty("jotm.home",jotmHome);
- }
- // Check for already active JOTM instance.
- this.jotmCurrent = Current.getCurrent();
-
- // If none found, create new local JOTM instance.
- if (this.jotmCurrent == null) {
- // Only for use within the current Spring context:
- // local, not bound to registry.
- this.jotm = new Jotm(true, false);
- this.jotmCurrent = Current.getCurrent();
- }
- if (defaultTimeout!=null) {
- this.jotmCurrent.setDefaultTimeout(defaultTimeout);
- }
- if (transactionRecovery!=null) {
- this.jotmCurrent.setTransactionRecovery(transactionRecovery);
- }
- }
-
- /**
- * Return the JOTM instance created by this factory bean, if any.
- * Will be null if an already active JOTM instance is used.
- *
Application code should never need to access this.
- */
- public Jotm getJotm() {
- return this.jotm;
- }
-
-
- public Object getObject() {
- return this.jotmCurrent;
- }
-
- public Class getObjectType() {
- return this.jotmCurrent.getClass();
- }
-
- public boolean isSingleton() {
- return true;
- }
-
-
- /**
- * Stop the local JOTM instance, if created by this FactoryBean.
- */
- public void destroy() {
- if (this.jotm != null) {
- this.jotm.stop();
- }
- }
-
-}
diff --git a/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/MultiTransactionStatus.java b/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/MultiTransactionStatus.java
deleted file mode 100644
index abb83b0fc..000000000
--- a/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/MultiTransactionStatus.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/**
- * Copyright 2011 the original author or authors.
- *
- * 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.transaction;
-
-import org.springframework.transaction.PlatformTransactionManager;
-import org.springframework.transaction.TransactionDefinition;
-import org.springframework.transaction.TransactionException;
-import org.springframework.transaction.TransactionStatus;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author mh
- * @since 14.02.11
- */
-public class MultiTransactionStatus implements TransactionStatus {
-
-
- private PlatformTransactionManager mainTransactionManager;
-
- private Map transactionStatuses =
- Collections.synchronizedMap(new HashMap());
-
- private boolean newSynchonization;
-
- public MultiTransactionStatus(PlatformTransactionManager mainTransactionManager) {
- this.mainTransactionManager = mainTransactionManager;
- }
-
-
- protected Map getTransactionStatuses() {
- return transactionStatuses;
- }
-
- private TransactionStatus getMainTransactionStatus() {
- return transactionStatuses.get(mainTransactionManager);
- }
-
-
- public void setNewSynchonization() {
- this.newSynchonization = true;
- }
-
- public boolean isNewSynchonization() {
- return newSynchonization;
- }
-
-
- @Override
- public boolean isNewTransaction() {
- return getMainTransactionStatus().isNewTransaction();
- }
-
- @Override
- public boolean hasSavepoint() {
- return getMainTransactionStatus().hasSavepoint();
- }
-
- @Override
- public void setRollbackOnly() {
- for(TransactionStatus ts : transactionStatuses.values() ){
- ts.setRollbackOnly();
- }
- }
-
- @Override
- public boolean isRollbackOnly() {
- return getMainTransactionStatus().isRollbackOnly();
- }
-
- @Override
- public boolean isCompleted() {
- return getMainTransactionStatus().isCompleted();
- }
-
-
- private static class SavePoints {
- Map savepoints=new HashMap();
-
- private void addSavePoint(TransactionStatus status, Object savepoint) {
- this.savepoints.put(status, savepoint);
- }
-
- private void save(TransactionStatus transactionStatus) {
- Object savepoint = transactionStatus.createSavepoint();
- addSavePoint(transactionStatus, savepoint);
- }
-
-
- public void rollback() {
- for (TransactionStatus transactionStatus : savepoints.keySet()) {
- transactionStatus.rollbackToSavepoint(savepointFor(transactionStatus));
- }
- }
-
- private Object savepointFor(TransactionStatus transactionStatus) {
- return savepoints.get(transactionStatus);
- }
-
- public void release() {
- for (TransactionStatus transactionStatus : savepoints.keySet()) {
- transactionStatus.releaseSavepoint(savepointFor(transactionStatus));
- }
- }
- }
-
- @Override
- public Object createSavepoint() throws TransactionException {
- SavePoints savePoints = new SavePoints();
-
- for (TransactionStatus transactionStatus : transactionStatuses.values()) {
- savePoints.save(transactionStatus);
- }
- return savePoints;
- }
-
- @Override
- public void rollbackToSavepoint(Object savepoint) throws TransactionException {
- SavePoints savePoints= (SavePoints) savepoint;
- savePoints.rollback();
- }
-
- @Override
- public void releaseSavepoint(Object savepoint) throws TransactionException {
- ((SavePoints)savepoint).release();
- }
-
- public void registerTransactionManager(TransactionDefinition definition, PlatformTransactionManager transactionManager) {
- getTransactionStatuses().put(transactionManager, transactionManager.getTransaction(definition));
- }
-
- void commit(PlatformTransactionManager transactionManager) {
- TransactionStatus transactionStatus = getTransactionStatus(transactionManager);
- transactionManager.commit(transactionStatus);
- }
-
- private TransactionStatus getTransactionStatus(PlatformTransactionManager transactionManager) {
- return this.getTransactionStatuses().get(transactionManager);
- }
-
- void rollback(PlatformTransactionManager transactionManager) {
- transactionManager.rollback(getTransactionStatus(transactionManager));
- }
-
- @Override
- public void flush() {
- for (TransactionStatus transactionStatus : transactionStatuses.values()) {
- transactionStatus.flush();
- }
- }
-}
\ No newline at end of file
diff --git a/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/SpringProvider.java b/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/SpringProvider.java
deleted file mode 100644
index 6f3462831..000000000
--- a/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/SpringProvider.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * Copyright 2011 the original author or authors.
- *
- * 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.transaction;
-
-import org.neo4j.helpers.Service;
-import org.neo4j.kernel.impl.core.KernelPanicEventGenerator;
-import org.neo4j.kernel.impl.nioneo.store.FileSystemAbstraction;
-import org.neo4j.kernel.impl.transaction.*;
-import org.neo4j.kernel.impl.util.StringLogger;
-import org.springframework.beans.factory.annotation.Configurable;
-
-@Configurable
-@Service.Implementation( TransactionManagerProvider.class )
-public class SpringProvider extends TransactionManagerProvider
-{
- public SpringProvider()
- {
- super( "spring-jta" );
- }
-
- @Override
- public AbstractTransactionManager loadTransactionManager( String txLogDir,
- XaDataSourceManager xaDataSourceManager,
- KernelPanicEventGenerator kpe,
- RemoteTxHook rollbackHook,
- StringLogger msgLog,
- FileSystemAbstraction fileSystem,
- TransactionStateFactory stateFactory ) {
- return new SpringServiceImpl(stateFactory,xaDataSourceManager);
- }
-}
diff --git a/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/SpringServiceImpl.java b/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/SpringServiceImpl.java
deleted file mode 100644
index 3288a39cd..000000000
--- a/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/SpringServiceImpl.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/**
- * Copyright 2011 the original author or authors.
- *
- * 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.transaction;
-
-import org.neo4j.kernel.api.KernelAPI;
-import org.neo4j.kernel.api.KernelTransaction;
-import org.neo4j.kernel.impl.core.TransactionState;
-import org.neo4j.kernel.impl.transaction.AbstractTransactionManager;
-import org.neo4j.kernel.impl.transaction.TransactionStateFactory;
-import org.neo4j.kernel.impl.transaction.XaDataSourceManager;
-import org.neo4j.kernel.impl.transaction.xaframework.XaDataSource;
-import org.objectweb.jotm.Current;
-import org.objectweb.jotm.TransactionResourceManager;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Configurable;
-import org.springframework.transaction.PlatformTransactionManager;
-import org.springframework.transaction.jta.JtaTransactionManager;
-
-import javax.transaction.*;
-import javax.transaction.xa.XAException;
-import javax.transaction.xa.XAResource;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-/**
- * @author Chris Gioran
- */
-@Configurable
-class SpringServiceImpl extends AbstractTransactionManager
-{
- private PlatformTransactionManager transactionManager;
-
- private TransactionManager delegate;
-
- private final Map states = new WeakHashMap();
-// private final Map kernelTransactions = new WeakHashMap();
- private final TransactionStateFactory stateFactory;
- private XaDataSourceManager xaDataSourceManager;
- private KernelAPI kernelAPI;
-
- SpringServiceImpl(TransactionStateFactory stateFactory, XaDataSourceManager xaDataSourceManager)
- {
- this.stateFactory = stateFactory;
- this.xaDataSourceManager = xaDataSourceManager;
- }
-
- @Override
- public void init() throws Throwable {
- if (transactionManager instanceof JtaTransactionManager) {
- delegate = ((JtaTransactionManager) transactionManager).getTransactionManager();
- } else {
- throw new IllegalStateException("Injected transaction manager is not of type JtaTransactionManager but "+ transactionManager.getClass().getName());
- }
- }
-
- @Override
- public void doRecovery() throws Throwable
- {
- TransactionResourceManager trm = new TransactionResourceManager()
- {
- @Override
- public void returnXAResource( String rmName, XAResource rmXares )
- {
- }
- };
-
- try
- {
- for ( XaDataSource xaDs : xaDataSourceManager.getAllRegisteredDataSources() )
- {
- Current.getTransactionRecovery().registerResourceManager( xaDs.getName(),
- xaDs.getXaConnection().getXaResource(), xaDs.getName(), trm );
- }
- Current.getTransactionRecovery().startResourceManagerRecovery();
- }
- catch ( XAException e )
- {
- throw new Error( "Error registering xa datasource", e );
- }
- }
-
- @Override
- public TransactionState getTransactionState() {
- try
- {
- TransactionState state = states.get( getTransaction() );
- return state != null ? state : TransactionState.NO_STATE;
- }
- catch ( SystemException e )
- {
- throw new RuntimeException( e );
- }
- }
-
- @Override
- public int getEventIdentifier() {
- return 0;
- }
-
- @Override
- public void start() throws Throwable {
-
- }
-
- @Override
- public void shutdown() throws Throwable {
- states.clear();
- }
-
- public void begin() throws NotSupportedException, SystemException
- {
- delegate.begin();
- Transaction tx = getTransaction();
- states.put(tx, stateFactory.create(tx));
-// kernelTransactions.put( tx, kernelAPI.newTransaction() );
- }
-
- public void commit() throws RollbackException, HeuristicMixedException,
- HeuristicRollbackException, SecurityException,
- IllegalStateException, SystemException
- {
- Transaction tx = getTransaction();
- delegate.commit();
- states.remove(tx);
- }
-
- public int getStatus() throws SystemException
- {
- return delegate.getStatus();
- }
-
- public Transaction getTransaction() throws SystemException
- {
- return delegate.getTransaction();
- }
-
- public void resume( Transaction tobj ) throws InvalidTransactionException,
- IllegalStateException, SystemException
- {
- delegate.resume( tobj );
- }
-
- public void rollback() throws IllegalStateException, SecurityException,
- SystemException
- {
- Transaction tx = getTransaction();
- delegate.rollback();
- states.remove(tx);
- }
-
- public void setRollbackOnly() throws IllegalStateException, SystemException
- {
- delegate.setRollbackOnly();
- }
-
- public void setTransactionTimeout( int seconds ) throws SystemException
- {
- delegate.setTransactionTimeout( seconds );
- }
-
- public Transaction suspend() throws SystemException
- {
- return delegate.suspend();
- }
-
- @Override
- public void stop()
- {
- // Currently a no-op
- }
-
- public PlatformTransactionManager getTransactionManager() {
- return transactionManager;
- }
-
- @Autowired
- public void setTransactionManager(PlatformTransactionManager transactionManager) {
- this.transactionManager = transactionManager;
- }
-
-// @Override
-// public void setKernel(KernelAPI kernelAPI) {
-// this.kernelAPI = kernelAPI;
-// }
-//
-// @Override
-// public KernelTransaction getKernelTransaction()
-// {
-// Transaction transaction;
-// try
-// {
-// transaction = getTransaction();
-// }
-// catch ( SystemException e )
-// {
-// return null;
-// }
-// return kernelTransactions.get( transaction );
-// }
-}
diff --git a/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/SynchronizationManager.java b/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/SynchronizationManager.java
deleted file mode 100644
index b4159ed9f..000000000
--- a/spring-data-neo4j-tx/src/main/java/org/springframework/data/neo4j/transaction/SynchronizationManager.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Copyright 2011 the original author or authors.
- *
- * 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.transaction;
-
-/**
- * @author mh
- * @since 15.02.11
- */
-public interface SynchronizationManager {
- void initSynchronization();
-
- boolean isSynchronizationActive();
-
- void clearSynchronization();
-}
diff --git a/spring-data-neo4j-tx/src/test/java/org/springframework/data/neo4j/transaction/JOTMIntegrationTests.java b/spring-data-neo4j-tx/src/test/java/org/springframework/data/neo4j/transaction/JOTMIntegrationTests.java
deleted file mode 100644
index 244f54ff4..000000000
--- a/spring-data-neo4j-tx/src/test/java/org/springframework/data/neo4j/transaction/JOTMIntegrationTests.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/**
- * Copyright 2011 the original author or authors.
- *
- * 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.transaction;
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.neo4j.graphdb.GraphDatabaseService;
-import org.neo4j.graphdb.Node;
-import org.neo4j.graphdb.NotFoundException;
-import org.neo4j.graphdb.factory.GraphDatabaseSettings;
-import org.neo4j.kernel.AbstractGraphDatabase;
-import org.neo4j.kernel.GraphDatabaseAPI;
-import org.neo4j.kernel.KernelData;
-import org.neo4j.kernel.configuration.Config;
-import org.objectweb.jotm.Current;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-import org.springframework.transaction.jta.JtaTransactionManager;
-import org.springframework.transaction.jta.ManagedTransactionAdapter;
-
-import javax.transaction.NotSupportedException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-/**
- * @author mh
- * @since 21.02.11
- */
-
-public class JOTMIntegrationTests {
- private ClassPathXmlApplicationContext ctx;
- private GraphDatabaseService gds;
-
- @Before
- public void setUp() throws Exception {
- ctx = new ClassPathXmlApplicationContext("classpath:spring-tx-text-context.xml");
- gds = ctx.getBean(GraphDatabaseService.class);
- }
-
- @After
- public void tearDown() throws Exception {
- if (ctx != null) ctx.close();
- }
-
- @Test
- public void createdNodeShouldBeFoundAfterCommit() throws Exception {
- org.neo4j.graphdb.Transaction transaction = gds.beginTx();
- Node node = null;
- try {
- node = gds.createNode();
- assertNotNull(node);
- transaction.success();
- } finally {
- transaction.finish();
- }
-
- transaction = gds.beginTx();
- try {
- Node readBackOutsideOfTx = gds.getNodeById(node.getId());
- Assert.assertEquals(node, readBackOutsideOfTx);
- } finally {
- transaction.success();
- transaction.finish();
- }
- try {
- transaction = gds.beginTx();
- Node readBackInsideOfTx = gds.getNodeById(node.getId());
- Assert.assertEquals(node, readBackInsideOfTx);
- transaction.success();
- } finally {
- transaction.finish();
- }
- }
-
- @Test
- public void indexedNodeShouldBeFound() throws Exception {
- org.neo4j.graphdb.Transaction transaction = gds.beginTx();
- Node node = null;
- try {
- node = gds.createNode();
- gds.index().forNodes("node").add(node, "name", "value");
- transaction.success();
- } finally {
- transaction.finish();
- }
- transaction = gds.beginTx();
- try {
- Node retrievedNode = gds.index().forNodes("node").get("name", "value").getSingle();
- Assert.assertEquals(node, retrievedNode);
- } finally {
- transaction.success();
- transaction.finish();
- }
- }
-
- @Test(expected = NotFoundException.class)
- public void createdNodeShouldBeNotAvailableAfterRollback() throws Exception {
- org.neo4j.graphdb.Transaction tx = gds.beginTx();
- long nodeId=0;
- try {
- Node node = gds.createNode();
- nodeId = node.getId();
- tx.failure();
- } finally {
- tx.close();
- }
- tx = gds.beginTx();
- try {
- gds.getNodeById(nodeId);
- } finally {
- tx.success();
- tx.close();
- }
- }
-
- @Test
- public void databaseConfiguredWithSpringJtaShouldUseJtaTransactionManager() throws SystemException, NotSupportedException {
- final Config config = ((GraphDatabaseAPI) gds).getDependencyResolver().resolveDependency(Config.class);
- Assert.assertEquals("spring-jta", config.getParams().get(GraphDatabaseSettings.tx_manager_impl.name()));
-
- JtaTransactionManager tm = ctx.getBean("transactionManager", JtaTransactionManager.class);
- Transaction transaction = tm.createTransaction("jotm", 1000);
-
- Assert.assertEquals(ManagedTransactionAdapter.class, transaction.getClass());
- assertEquals(Current.class, ((ManagedTransactionAdapter) transaction).getTransactionManager().getClass());
- }
-}
diff --git a/spring-data-neo4j/src/main/java/org/neo4j/graphdb/ExecutionPlanDescription.java b/spring-data-neo4j/src/main/java/org/neo4j/graphdb/ExecutionPlanDescription.java
new file mode 100644
index 000000000..afcf774b5
--- /dev/null
+++ b/spring-data-neo4j/src/main/java/org/neo4j/graphdb/ExecutionPlanDescription.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2002-2015 "Neo Technology,"
+ * Network Engine for Objects in Lund AB [http://neotechnology.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.graphdb;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Instances describe single execution steps in a Cypher query execution plan
+ *
+ * Execution plans form a tree of execution steps. Each step is described by a {@link ExecutionPlanDescription} object.
+ */
+public interface ExecutionPlanDescription
+{
+ /**
+ * Retrieves the name of this execution step.
+ *
+ * @return descriptive name for this kind of execution step
+ */
+ String getName();
+
+ /**
+ * Retrieves the children of this execution step.
+ *
+ * @return list of previous (child) execution step descriptions
+ */
+ List getChildren();
+
+ /**
+ * Retrieve argument map for the associated execution step
+ *
+ * Valid arguments are all Java primitive values, Strings, Arrays of those, and Maps from Strings to
+ * valid arguments. Results are guaranteed to be trees (i.e. there are no cyclic dependencies among values)
+ *
+ * @return a map containing arguments that describe this execution step in more detail
+ */
+ Map getArguments();
+
+ /**
+ * @return the set of identifiers used in this execution step
+ */
+ public Set getIdentifiers();
+
+ /**
+ * Signifies that the query was profiled, and that statistics from the profiling can
+ * {@link #getProfilerStatistics() be retrieved}.
+ *
+ * The {@code PROFILE} directive in Cypher
+ * ensures the presence of profiler statistics in the plan description.
+ *
+ * @return true, if {@link ProfilerStatistics} are available for this execution step
+ */
+ boolean hasProfilerStatistics();
+
+ /**
+ * Retrieve the statistics collected from profiling this query.
+ *
+ * If the query was not profiled, this method will throw {@link java.util.NoSuchElementException}.
+ *
+ * @return profiler statistics for this execution step iff available
+ * @throws java.util.NoSuchElementException iff profiler statistics are not available
+ */
+ ProfilerStatistics getProfilerStatistics();
+
+ /**
+ * Instances describe statistics from the profiler of a particular step in the execution plan.
+ */
+ interface ProfilerStatistics
+ {
+ /**
+ * @return number of rows processed by the associated execution step
+ */
+ long getRows();
+
+ /**
+ * @return number of database hits (potential disk accesses) caused by executing the associated execution step
+ */
+ long getDbHits();
+ }
+}
diff --git a/spring-data-neo4j/src/main/java/org/neo4j/graphdb/QueryExecutionType.java b/spring-data-neo4j/src/main/java/org/neo4j/graphdb/QueryExecutionType.java
new file mode 100644
index 000000000..d036ab485
--- /dev/null
+++ b/spring-data-neo4j/src/main/java/org/neo4j/graphdb/QueryExecutionType.java
@@ -0,0 +1,228 @@
+/*
+ * Copyright (c) 2002-2015 "Neo Technology,"
+ * Network Engine for Objects in Lund AB [http://neotechnology.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.graphdb;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Signifies how a query is executed, as well as what side effects and results could be expected from the query.
+ *
+ * In Cypher there are three different modes of execution:
+ *
+ * Instances of this class contain the required information to be able to tell these different execution modes apart.
+ * It also contains information about what effects the query could have, and whether it could yield any results, in
+ * form
+ * of the {@link QueryType QueryType enum}.
+ *
+ * Queries executed with the {@code PROFILE} directive can have side effects and produce results in the same way as a
+ * normally executed method. The difference being that the user has expressed an interest in seeing the plan used to
+ * execute the query, and that this plan will (after execution completes) be annotated with
+ * {@linkplain org.neo4j.graphdb.ExecutionPlanDescription#getProfilerStatistics() profiling information} from the execution of the query.
+ *
+ * Queries executed with the {@code EXPLAIN} directive never have any side effects, nor do they ever yield any rows in
+ * the results, the sole purpose of this mode of execution is to
+ * {@linkplain org.neo4j.graphdb.Result#getExecutionPlanDescription() get a description of the plan} that would be executed
+ * if/when the query is executed normally (or under {@code PROFILE}).
+ */
+public final class QueryExecutionType
+{
+ /**
+ * Signifies what type of query an {@link QueryExecutionType} executes.
+ */
+ public enum QueryType
+ {
+ /** A read-only query, that does not change any data, but only produces a result. */
+ READ_ONLY,
+ /** A read/write query, that creates or updates data, and also produces a result. */
+ READ_WRITE,
+ /** A write-only query, that creates or updates data, but does not yield any rows in the result. */
+ WRITE,
+ /**
+ * A schema changing query, that updates the schema but neither changes any data nor yields any rows in the
+ * result.
+ */
+ SCHEMA_WRITE,;
+ private final QueryExecutionType query, profiled, explained;
+
+ QueryType()
+ {
+ this.query = new QueryExecutionType( Execution.QUERY, this );
+ this.profiled = new QueryExecutionType( Execution.PROFILE, this );
+ this.explained = new QueryExecutionType( Execution.EXPLAIN, this );
+ }
+ }
+
+ /**
+ * Get the {@link QueryExecutionType} that signifies normal execution of a query of the supplied type.
+ *
+ * @param type the type of query executed.
+ * @return The instance that signifies normal execution of the supplied {@link QueryType}.
+ */
+ public static QueryExecutionType query( QueryType type )
+ {
+ return requireNonNull( type, "QueryType" ).query;
+ }
+
+ /**
+ * Get the {@link QueryExecutionType} that signifies profiled execution of a query of the supplied type.
+ *
+ * @param type the type of query executed.
+ * @return The instance that signifies profiled execution of the supplied {@link QueryType}.
+ */
+ public static QueryExecutionType profiled( QueryType type )
+ {
+ return requireNonNull( type, "QueryType" ).profiled;
+ }
+
+ /**
+ * Get the {@link QueryExecutionType} that signifies explaining the plan of a query of the supplied type.
+ *
+ * @param type the type of query executed.
+ * @return The instance that signifies explaining the plan of the supplied {@link QueryType}.
+ */
+ public static QueryExecutionType explained( QueryType type )
+ {
+ return requireNonNull( type, "QueryType" ).explained;
+ }
+
+ /**
+ * Get the type of query this execution refers to.
+ *
+ * @return the type of query this execution refers to.
+ */
+ public QueryType queryType()
+ {
+ return type;
+ }
+
+ /**
+ * Signifies whether results from this execution
+ * {@linkplain org.neo4j.graphdb.ExecutionPlanDescription#getProfilerStatistics() contains profiling information}.
+ *
+ * This is {@code true} for queries executed with the
+ * {@code PROFILE} directive.
+ *
+ * @return {@code true} if the results from this execution would contain profiling information.
+ */
+ public boolean isProfiled()
+ {
+ return execution == Execution.PROFILE;
+ }
+
+ /**
+ * Signifies whether the supplied query contained a directive that asked for a
+ * {@linkplain org.neo4j.graphdb.ExecutionPlanDescription description of the execution plan}.
+ *
+ * This is {@code true} for queries executed with either the
+ * {@code EXPLAIN} or {@code PROFILE} directives.
+ *
+ * @return {@code true} if a description of the plan should be presented to the user.
+ */
+ public boolean requestedExecutionPlanDescription()
+ {
+ return execution != Execution.QUERY;
+ }
+
+ /**
+ * Signifies that the query was executed with the
+ * {@code EXPLAIN} directive.
+ *
+ * @return {@code true} if the query was executed using the {@code EXPLAIN} directive.
+ */
+ public boolean isExplained()
+ {
+ return execution == Execution.EXPLAIN;
+ }
+
+ /**
+ * Signifies that the execution of the query could produce a result.
+ *
+ * This is an important distinction from the result being empty.
+ *
+ * @return {@code true} if the execution would yield rows in the result set.
+ */
+ public boolean canContainResults()
+ {
+ return (type == QueryType.READ_ONLY || type == QueryType.READ_WRITE) && execution != Execution.EXPLAIN;
+ }
+
+ /**
+ * Signifies that the execution of the query could perform changes to the data.
+ *
+ * {@link org.neo4j.graphdb.Result}{@link org.neo4j.graphdb.Result#getQueryStatistics() .getQueryStatistics()}{@link org.neo4j.graphdb.QueryStatistics#containsUpdates()
+ * .containsUpdates()} signifies whether the query actually performed any updates.
+ *
+ * @return {@code true} if the execution could perform changes to data.
+ */
+ public boolean canUpdateData()
+ {
+ return (type == QueryType.READ_WRITE || type == QueryType.WRITE) && execution != Execution.EXPLAIN;
+ }
+
+ /**
+ * Signifies that the execution of the query updates the schema.
+ *
+ * @return {@code true} if the execution updates the schema.
+ */
+ public boolean canUpdateSchema()
+ {
+ return type == QueryType.SCHEMA_WRITE && execution != Execution.EXPLAIN;
+ }
+
+ private final Execution execution;
+ private final QueryType type;
+
+ private QueryExecutionType(Execution execution, QueryType type)
+ {
+ this.execution = execution;
+ this.type = type;
+ }
+
+ @Override
+ public String toString()
+ {
+ return execution.toString( type );
+ }
+
+ private enum Execution
+ {
+ QUERY
+ {
+ @Override
+ String toString( QueryType type )
+ {
+ return type.name();
+ }
+ },
+ PROFILE,
+ EXPLAIN,;
+
+ String toString( QueryType type )
+ {
+ return name() + ":" + type.name();
+ }
+ }
+}
diff --git a/spring-data-neo4j/src/main/java/org/neo4j/graphdb/QueryStatistics.java b/spring-data-neo4j/src/main/java/org/neo4j/graphdb/QueryStatistics.java
new file mode 100644
index 000000000..81564a233
--- /dev/null
+++ b/spring-data-neo4j/src/main/java/org/neo4j/graphdb/QueryStatistics.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2002-2015 "Neo Technology,"
+ * Network Engine for Objects in Lund AB [http://neotechnology.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.graphdb;
+
+/**
+ * Represents statistics about the effects of a query.
+ *
+ * If the query did not perform any {@link #containsUpdates() updates}, all the methods of this interface will return
+ * {@code 0}.
+ */
+public interface QueryStatistics
+{
+ /**
+ * Returns the number of nodes created by this query.
+ *
+ * @return the number of nodes created by this query.
+ */
+ int getNodesCreated();
+
+ /**
+ * Returns the number of nodes deleted by this query.
+ *
+ * @return the number of nodes deleted by this query.
+ */
+ int getNodesDeleted();
+
+ /**
+ * Returns the number of relationships created by this query.
+ *
+ * @return the number of relationships created by this query.
+ */
+ int getRelationshipsCreated();
+
+ /**
+ * Returns the number of relationships deleted by this query.
+ *
+ * @return the number of relationships deleted by this query.
+ */
+ int getRelationshipsDeleted();
+
+ /**
+ * Returns the number of properties set by this query. Setting a property to the same value again still counts
+ * towards this.
+ *
+ * @return the number of properties set by this query.
+ */
+ int getPropertiesSet();
+
+ /**
+ * Returns the number of labels added to any node by this query.
+ *
+ * @return the number of labels added to any node by this query.
+ */
+ int getLabelsAdded();
+
+ /**
+ * Returns the number of labels removed from any node by this query.
+ *
+ * @return the number of labels removed from any node by this query.
+ */
+ int getLabelsRemoved();
+
+ /**
+ * Returns the number of indexes added by this query.
+ *
+ * @return the number of indexes added by this query.
+ */
+ int getIndexesAdded();
+
+ /**
+ * Returns the number of indexes removed by this query.
+ *
+ * @return the number of indexes removed by this query.
+ */
+ int getIndexesRemoved();
+
+ /**
+ * Returns the number of constraints added by this query.
+ *
+ * @return the number of constraints added by this query.
+ */
+ int getConstraintsAdded();
+
+ /**
+ * Returns the number of constraints removed by this query.
+ *
+ * @return the number of constraints removed by this query.
+ */
+ int getConstraintsRemoved();
+
+ /**
+ * If the query updated the graph in any way, this method will return true.
+ *
+ * @return if the graph has been updated.
+ */
+ boolean containsUpdates();
+}
diff --git a/spring-data-neo4j/src/main/java/org/neo4j/graphdb/Result.java b/spring-data-neo4j/src/main/java/org/neo4j/graphdb/Result.java
new file mode 100644
index 000000000..c72cddbeb
--- /dev/null
+++ b/spring-data-neo4j/src/main/java/org/neo4j/graphdb/Result.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2002-2015 "Neo Technology,"
+ * Network Engine for Objects in Lund AB [http://neotechnology.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.graphdb;
+
+import java.io.PrintWriter;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Represents the result of {@link org.neo4j.graphdb.GraphDatabaseService#execute(String, java.util.Map) executing} a query.
+ *
+ * The result is comprised of a number of rows, potentially computed lazily, with this result object being an iterator
+ * over those rows. Each row is represented as a {@link java.util.Map}<{@link String}, {@link Object}>, the
+ * keys in this map are the names of the columns in the row, as specified by the {@code return} clause of the query,
+ * and the values of the map is the corresponding computed value of the expression in the {@code return} clause. Each
+ * row will thus have the same set of keys, and these keys can be retrieved using the
+ * {@linkplain #columns() columns-method}.
+ *
+ * To ensure that any resource, including transactions bound to the query, are properly freed, the result must either
+ * be fully exhausted, by means of the {@linkplain java.util.Iterator iterator protocol}, or the result has to be
+ * explicitly closed, by invoking the {@linkplain #close() close-method}.
+ *
+ * Idiomatic use of the Result object would look like this:
+ *
+ * try ( Result result = graphDatabase.execute( query, parameters ) )
+ * {
+ * while ( result.hasNext() )
+ * {
+ * Map<String, Object> row = result.next();
+ * for ( String key : result.columns() )
+ * {
+ * System.out.printf( "%s = %s%n", key, row.get( key ) );
+ * }
+ * }
+ * }
+ *
+ * If the result consists of only a single column, or if only one of the columns is of interest, a projection can be
+ * extracted using {@link #columnAs(String)}. This produces a new iterator over the values of the named column. It
+ * should be noted that this iterator consumes the rows of the result in the same way as invoking {@link #next()} on
+ * this object would, and that the {@link #close() close-method} on either iterator has the same effect. It is thus
+ * safe to either close the projected column iterator, or this iterator, or both if all rows have not been consumed.
+ *
+ * In addition to the {@link #next() iteration methods} on this interface, {@link #close()}, and the
+ * {@link #columnAs(String) column projection method}, there are two methods for getting a string representation of the
+ * result that also consumes the entire result if invoked. {@link #resultAsString()} returns a single string
+ * representation of all (remaining) rows in the result, and {@link #writeAsStringTo(java.io.PrintWriter)} does the same, but
+ * streams the result to the provided {@link java.io.PrintWriter} instead, without allocating large string objects.
+ *
+ * The methods that do not consume any rows from the result, or in other ways alter the state of the result are safe to
+ * invoke at any time, even after the result has been {@linkplain #close() closed} or fully exhausted. These methods
+ * are:
+ *
+ * - {@link #columns()}
+ * - {@link #getQueryStatistics()}
+ * - {@link #getQueryExecutionType()}
+ * - {@link #getExecutionPlanDescription()}
+ *
+ *
+ * Not all queries produce an actual result, and some queries that do might yield an empty result set. In order to
+ * distinguish between these cases the {@link org.neo4j.graphdb.QueryExecutionType} {@linkplain #getQueryExecutionType() of this result}
+ * can be queried.
+ */
+public interface Result extends ResourceIterator