From dbea0e81eda5216de9957bdc34c3705208909d20 Mon Sep 17 00:00:00 2001 From: Michael Hunger Date: Tue, 28 May 2013 03:06:52 +0200 Subject: [PATCH] DATAGRAPH-355 Upgrade to Neo4j 1.9.GA --- pom.xml | 8 +- spring-data-neo4j-aspects/pom.xml | 6 +- .../aspects/support/GraphRepositoryTests.java | 2 +- spring-data-neo4j-cross-store/pom.xml | 2 +- ...aGraphNamespaceHandlerCrossStoreTests.java | 2 +- .../backwardscompatibility/pom.xml | 2 +- .../cineasts-aspects/pom.xml | 2 +- spring-data-neo4j-examples/cineasts/pom.xml | 2 +- spring-data-neo4j-rest/pom.xml | 6 +- .../neo4j/rest/support/LocalTestServer.java | 199 ------------------ .../data/neo4j/rest/support/RestTestBase.java | 22 +- .../neo4j/rest/support/RestTestHelper.java | 20 +- .../neo4j/rest/support/ServerPluginTests.java | 2 +- .../support/SpringPluginInitializerTests.java | 26 ++- .../neo4j/transaction/SpringProvider.java | 5 +- .../neo4j/transaction/SpringServiceImpl.java | 40 +++- spring-data-neo4j/pom.xml | 5 +- .../data/neo4j/support/node/Neo4jHelper.java | 13 +- .../DataGraphNamespaceHandlerTests.java | 4 +- .../repository/GraphRepositoryTests.java | 4 +- .../src/test/resources/logback.xml | 18 ++ 21 files changed, 152 insertions(+), 238 deletions(-) delete mode 100644 spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/LocalTestServer.java create mode 100644 spring-data-neo4j/src/test/resources/logback.xml diff --git a/pom.xml b/pom.xml index 5a3e77c1a..4d1205cab 100644 --- a/pom.xml +++ b/pom.xml @@ -34,14 +34,14 @@ spring-data-neo4j 1.6.0.BUILD-SNAPSHOT - 1.8.1 + 1.9 - 0.10.1 - 0.5 + 0.11-neo4j-1.9 + 0.6-neo4j-1.9 1.2 1.5 1.5 - 1.9.M04 + 1.9 diff --git a/spring-data-neo4j-aspects/pom.xml b/spring-data-neo4j-aspects/pom.xml index 8c4fd2ff3..67cc0c1b1 100644 --- a/spring-data-neo4j-aspects/pom.xml +++ b/spring-data-neo4j-aspects/pom.xml @@ -126,7 +126,7 @@ cglib cglib - 2.2 + 2.2.2 @@ -162,6 +162,10 @@ blueprints-neo4j-graph ${blueprints.version} + + org.neo4j + neo4j-management + org.neo4j neo4j diff --git a/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/support/GraphRepositoryTests.java b/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/support/GraphRepositoryTests.java index 194b6e1ec..dd186db9b 100644 --- a/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/support/GraphRepositoryTests.java +++ b/spring-data-neo4j-aspects/src/test/java/org/springframework/data/neo4j/aspects/support/GraphRepositoryTests.java @@ -102,7 +102,7 @@ public class GraphRepositoryTests extends EntityTestBase { Page teamMemberPage1 = personRepository.findAllTeamMembersPaged(testTeam.sdg,null); assertEquals(new HashSet(asList(testTeam.david, testTeam.emil, testTeam.michael)), addToCollection(teamMemberPage1, new HashSet())); assertThat(teamMemberPage1.isFirstPage(), is(true)); - assertThat(teamMemberPage1.isLastPage(), is(false)); + assertThat(teamMemberPage1.isLastPage(), is(true)); } @Test diff --git a/spring-data-neo4j-cross-store/pom.xml b/spring-data-neo4j-cross-store/pom.xml index 45fad0c01..43fafd4d4 100644 --- a/spring-data-neo4j-cross-store/pom.xml +++ b/spring-data-neo4j-cross-store/pom.xml @@ -82,7 +82,7 @@ cglib cglib - 2.2 + 2.2.2 diff --git a/spring-data-neo4j-cross-store/src/test/java/org/springframework/data/neo4j/config/DataGraphNamespaceHandlerCrossStoreTests.java b/spring-data-neo4j-cross-store/src/test/java/org/springframework/data/neo4j/config/DataGraphNamespaceHandlerCrossStoreTests.java index 8bbbbb3aa..d347645a0 100644 --- a/spring-data-neo4j-cross-store/src/test/java/org/springframework/data/neo4j/config/DataGraphNamespaceHandlerCrossStoreTests.java +++ b/spring-data-neo4j-cross-store/src/test/java/org/springframework/data/neo4j/config/DataGraphNamespaceHandlerCrossStoreTests.java @@ -46,7 +46,7 @@ public class DataGraphNamespaceHandlerCrossStoreTests { Assert.assertNotNull("template", template); EmbeddedGraphDatabase graphDatabaseService = (EmbeddedGraphDatabase) template.getGraphDatabaseService(); File directory = new File("target", "config-test"); - Assert.assertTrue("store-dir", graphDatabaseService.getStoreDir().equals(directory.getAbsolutePath())); + Assert.assertTrue("store-dir", graphDatabaseService.getStoreDir().equals(directory.getPath())); Assert.assertNotNull("graphDatabaseService", graphDatabaseService); Assert.assertNotNull("transactionManager", transactionManager); } diff --git a/spring-data-neo4j-examples/backwardscompatibility/pom.xml b/spring-data-neo4j-examples/backwardscompatibility/pom.xml index 8654361bb..cddbf2024 100644 --- a/spring-data-neo4j-examples/backwardscompatibility/pom.xml +++ b/spring-data-neo4j-examples/backwardscompatibility/pom.xml @@ -86,7 +86,7 @@ 1.8.M07 - 1.8.M06 + 1.8.M07 diff --git a/spring-data-neo4j-examples/cineasts-aspects/pom.xml b/spring-data-neo4j-examples/cineasts-aspects/pom.xml index 7e3400ed6..87a907286 100644 --- a/spring-data-neo4j-examples/cineasts-aspects/pom.xml +++ b/spring-data-neo4j-examples/cineasts-aspects/pom.xml @@ -229,7 +229,7 @@ cglib cglib-nodep - 2.2 + 2.2.2 diff --git a/spring-data-neo4j-examples/cineasts/pom.xml b/spring-data-neo4j-examples/cineasts/pom.xml index d5808845e..118f1e779 100644 --- a/spring-data-neo4j-examples/cineasts/pom.xml +++ b/spring-data-neo4j-examples/cineasts/pom.xml @@ -229,7 +229,7 @@ cglib cglib-nodep - 2.2 + 2.2.2 diff --git a/spring-data-neo4j-rest/pom.xml b/spring-data-neo4j-rest/pom.xml index ee66520c5..79c43bcb6 100644 --- a/spring-data-neo4j-rest/pom.xml +++ b/spring-data-neo4j-rest/pom.xml @@ -19,7 +19,7 @@ 1.0.0.GA 1.4 - 1.8.1 + 1.9 @@ -197,6 +197,10 @@ ${blueprints.version} true + + org.neo4j + neo4j-management + org.neo4j neo4j diff --git a/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/LocalTestServer.java b/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/LocalTestServer.java deleted file mode 100644 index b661ed1d2..000000000 --- a/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/LocalTestServer.java +++ /dev/null @@ -1,199 +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.rest.support; - -import org.mortbay.component.LifeCycle; -import org.mortbay.jetty.Server; -import org.neo4j.graphdb.GraphDatabaseService; -import org.neo4j.server.CommunityNeoServer; -import org.neo4j.server.configuration.PropertyFileConfigurator; -import org.neo4j.server.database.Database; -import org.neo4j.server.database.WrappingDatabase; -import org.neo4j.server.modules.RESTApiModule; -import org.neo4j.server.modules.ServerModule; -import org.neo4j.server.modules.ThirdPartyJAXRSModule; -import org.neo4j.server.startup.healthcheck.StartupHealthCheck; -import org.neo4j.server.web.Jetty6WebServer; -import org.neo4j.server.web.WebServer; -import org.neo4j.test.ImpermanentGraphDatabase; - -import java.io.File; -import java.net.URI; -import java.net.URL; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static java.util.Arrays.asList; - -public class LocalTestServer { - private CommunityNeoServer neoServer; - private final int port; - private final String hostname; - protected String propertiesFile = "test-db.properties"; - private final ImpermanentGraphDatabase graphDatabase; - - public LocalTestServer() { - this("localhost",7473); - } - - public LocalTestServer(String hostname, int port) { - this.port = port; - this.hostname = hostname; - graphDatabase = new ImpermanentGraphDatabase(); - } - - public void start() { - if (neoServer!=null) throw new IllegalStateException("Server already running"); - URL url = getClass().getResource("/" + propertiesFile); - if (url==null) throw new IllegalArgumentException("Could not resolve properties file "+propertiesFile); - final Jetty6WebServer jettyWebServer = new Jetty6WebServer() { - @Override - protected void startJetty() { - final Server jettyServer = getJetty(); - jettyServer.setStopAtShutdown(true); - final JettyStartupListener startupListener = new JettyStartupListener(); - jettyServer.getServer().addLifeCycleListener(startupListener); - // System.err.println("jetty is started before notification " + jettyServer.isStarted()); - - super.startJetty(); - - startupListener.await(); - jettyServer.removeLifeCycleListener(startupListener); - // System.err.println("jetty is started after notification " + jettyServer.isStarted()); - } - - @Override - public void stop() { - final Server jettyServer = getJetty(); - final JettyStartupListener listener = new JettyStartupListener(); - jettyServer.getServer().addLifeCycleListener(listener); - - super.stop(); - - listener.await(); - jettyServer.removeLifeCycleListener(listener); - } - }; - neoServer = new CommunityNeoServer(new PropertyFileConfigurator(new File(url.getPath()))) { - @Override - protected int getWebServerPort() { - return port; - } - - @Override - protected StartupHealthCheck createHealthCheck() { - return new StartupHealthCheck(); - } - - @Override - protected Database createDatabase() { - return new WrappingDatabase(graphDatabase); - } - - - @Override - protected WebServer createWebServer() { - return jettyWebServer; - } - - @Override - protected Iterable createServerModules() { - return asList(new RESTApiModule(webServer,database,configurator.configuration()),new ThirdPartyJAXRSModule(webServer,configurator)); - } - }; - neoServer.start(); - } - - public void stop() { - try { - neoServer.stop(); - } catch(Exception e) { - System.err.println("Error stopping server: "+e.getMessage()); - } - neoServer=null; - } - - public int getPort() { - return port; - } - - public String getHostname() { - return hostname; - } - - public LocalTestServer withPropertiesFile(String propertiesFile) { - this.propertiesFile = propertiesFile; - return this; - } - public Database getDatabase() { - return neoServer.getDatabase(); - } - - public URI baseUri() { - return neoServer.baseUri(); - } - - public void cleanDb() { - Neo4jDatabaseCleaner cleaner = new Neo4jDatabaseCleaner(getGraphDatabase()); - cleaner.cleanDb(); - } - - public GraphDatabaseService getGraphDatabase() { - return getDatabase().graph; - } - - private static class JettyStartupListener implements LifeCycle.Listener { - CountDownLatch latch=new CountDownLatch(1); - public void await() { - try { - latch.await(10, TimeUnit.SECONDS); - } catch(InterruptedException ie) { - System.err.println("ERROR startup took too long - await()"); - throw new RuntimeException("Jetty did not start correctly",ie); - } - } - - @Override - public void lifeCycleStarting(LifeCycle event) { - System.err.println("STARTING"); - } - - @Override - public void lifeCycleStarted(LifeCycle event) { - System.err.println("STARTED"); - latch.countDown(); - } - - @Override - public void lifeCycleFailure(LifeCycle event, Throwable cause) { - System.out.println("FAILURE "+cause.getMessage()); - latch.countDown(); - throw new RuntimeException(cause); - } - - @Override - public void lifeCycleStopping(LifeCycle event) { - System.err.println("STOPPING"); - } - - @Override - public void lifeCycleStopped(LifeCycle event) { - System.err.println("STOPPED"); - latch.countDown(); - } - } -} diff --git a/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/RestTestBase.java b/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/RestTestBase.java index e3fd1a6e3..ecd2076b7 100644 --- a/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/RestTestBase.java +++ b/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/RestTestBase.java @@ -30,22 +30,33 @@ import org.neo4j.graphdb.Relationship; import org.neo4j.rest.graphdb.ExecutingRestRequest; import org.neo4j.rest.graphdb.RequestResult; import org.neo4j.rest.graphdb.RestRequest; +import org.neo4j.server.NeoServer; +import org.neo4j.server.WrappingNeoServerBootstrapper; +import org.neo4j.server.configuration.Configurator; +import org.neo4j.server.configuration.PropertyFileConfigurator; +import org.neo4j.server.configuration.ServerConfigurator; +import org.neo4j.test.ImpermanentGraphDatabase; import org.springframework.data.neo4j.rest.SpringRestGraphDatabase; import static org.junit.Assert.assertEquals; public class RestTestBase { + protected static ImpermanentGraphDatabase db; protected SpringRestGraphDatabase restGraphDatabase; private static final String HOSTNAME = "127.0.0.1"; public static final int PORT = 7470; - protected static LocalTestServer neoServer = new LocalTestServer(HOSTNAME,PORT).withPropertiesFile("test-db.properties"); + protected static NeoServer neoServer = null; public static final String SERVER_ROOT_URI = "http://" + HOSTNAME + ":" + PORT + "/db/data/"; @BeforeClass public static void startDb() throws Exception { - BasicConfigurator.configure(); - neoServer.start(); + db = new ImpermanentGraphDatabase(); + final ServerConfigurator configurator = new ServerConfigurator(db); + configurator.configuration().setProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY,PORT); + final WrappingNeoServerBootstrapper bootstrapper = new WrappingNeoServerBootstrapper(db, configurator); + bootstrapper.start(); + neoServer = bootstrapper.getServer(); tryConnect(); } @@ -72,7 +83,8 @@ public class RestTestBase { } public static void cleanDb() { - neoServer.cleanDb(); + new Neo4jDatabaseCleaner(db).cleanDb(); + //db.cleanContent(true); } @AfterClass @@ -81,7 +93,7 @@ public class RestTestBase { } public GraphDatabaseService getGraphDatabase() { - return neoServer.getGraphDatabase(); + return db; } diff --git a/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/RestTestHelper.java b/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/RestTestHelper.java index b6830e060..b7a9374b4 100644 --- a/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/RestTestHelper.java +++ b/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/RestTestHelper.java @@ -20,22 +20,30 @@ package org.springframework.data.neo4j.rest.support; import java.net.URISyntaxException; import org.apache.log4j.BasicConfigurator; +import org.neo4j.server.NeoServer; +import org.neo4j.server.WrappingNeoServerBootstrapper; +import org.neo4j.server.configuration.Configurator; +import org.neo4j.server.configuration.ServerConfigurator; +import org.neo4j.test.ImpermanentGraphDatabase; import org.springframework.data.neo4j.core.GraphDatabase; import org.springframework.data.neo4j.rest.SpringRestGraphDatabase; public class RestTestHelper { - protected SpringRestGraphDatabase graphDb; private static final String HOSTNAME = "localhost"; private static final int PORT = 7470; - private static LocalTestServer neoServer; + private static NeoServer neoServer; private static final String SERVER_ROOT_URI = "http://" + HOSTNAME + ":" + PORT + "/db/data/"; + private static ImpermanentGraphDatabase db; public void startServer() throws Exception { - BasicConfigurator.configure(); - neoServer = new LocalTestServer(HOSTNAME,PORT).withPropertiesFile("test-db.properties"); - neoServer.start(); + db = new ImpermanentGraphDatabase(); + final ServerConfigurator configurator = new ServerConfigurator(db); + configurator.configuration().setProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY,PORT); + final WrappingNeoServerBootstrapper bootstrapper = new WrappingNeoServerBootstrapper(db, configurator); + bootstrapper.start(); + neoServer = bootstrapper.getServer(); } public GraphDatabase createGraphDatabase() throws URISyntaxException { @@ -43,7 +51,7 @@ public class RestTestHelper } public void cleanDb() { - neoServer.cleanDb(); + db.cleanContent(true); } public static void shutdownServer() { diff --git a/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/ServerPluginTests.java b/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/ServerPluginTests.java index 51bbd2fb0..9abd022aa 100644 --- a/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/ServerPluginTests.java +++ b/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/ServerPluginTests.java @@ -41,7 +41,7 @@ public class ServerPluginTests extends RestTestBase { @BeforeClass public static void init() { - new ProvidedClassPathXmlApplicationContext(neoServer.getGraphDatabase(), "Plugin-context.xml"); + new ProvidedClassPathXmlApplicationContext(db, "Plugin-context.xml"); } @Test diff --git a/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/SpringPluginInitializerTests.java b/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/SpringPluginInitializerTests.java index 11a52b11f..2c628b380 100644 --- a/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/SpringPluginInitializerTests.java +++ b/spring-data-neo4j-rest/src/test/java/org/springframework/data/neo4j/rest/support/SpringPluginInitializerTests.java @@ -18,12 +18,19 @@ package org.springframework.data.neo4j.rest.support; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; +import org.apache.commons.configuration.Configuration; import org.apache.log4j.BasicConfigurator; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.neo4j.rest.graphdb.RequestResult; +import org.neo4j.server.NeoServer; +import org.neo4j.server.WrappingNeoServerBootstrapper; +import org.neo4j.server.configuration.Configurator; +import org.neo4j.server.configuration.ServerConfigurator; +import org.neo4j.server.configuration.ThirdPartyJaxRsPackage; +import org.neo4j.test.ImpermanentGraphDatabase; import org.springframework.data.neo4j.server.SpringPluginInitializer; import javax.ws.rs.POST; @@ -31,10 +38,12 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import java.util.Collections; +import java.util.Set; @Path( "/" ) public class SpringPluginInitializerTests extends SpringPluginInitializer implements TestInterface { - private LocalTestServer neoServer; + private NeoServer neoServer; public SpringPluginInitializerTests() { super( new String[]{"ServerTests-context.xml"}, expose("testObject", TestInterface.class) ); @@ -59,10 +68,19 @@ public class SpringPluginInitializerTests extends SpringPluginInitializer implem @Before public void setUp() throws Exception { - BasicConfigurator.configure(); - neoServer = new LocalTestServer( HOSTNAME, PORT ).withPropertiesFile( "server-test-db.properties" ); - neoServer.start(); + ImpermanentGraphDatabase db = new ImpermanentGraphDatabase(); + final ServerConfigurator configurator = new ServerConfigurator(db) { + @Override + public Set getThirdpartyJaxRsClasses() { + return Collections.singleton(new ThirdPartyJaxRsPackage("org.springframework.data.neo4j.rest.support","/test")); + } + }; + final Configuration configuration = configurator.configuration(); + configuration.setProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY, PORT); + final WrappingNeoServerBootstrapper bootstrapper = new WrappingNeoServerBootstrapper(db, configurator); touched=0; + bootstrapper.start(); + neoServer = bootstrapper.getServer(); } @After 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 index bc6e796c9..4169fd367 100644 --- 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 @@ -21,6 +21,7 @@ import org.neo4j.kernel.impl.core.KernelPanicEventGenerator; import org.neo4j.kernel.impl.nioneo.store.FileSystemAbstraction; import org.neo4j.kernel.impl.transaction.AbstractTransactionManager; import org.neo4j.kernel.impl.transaction.TransactionManagerProvider; +import org.neo4j.kernel.impl.transaction.TransactionStateFactory; import org.neo4j.kernel.impl.transaction.TxHook; import org.neo4j.kernel.impl.transaction.XaDataSourceManager; import org.neo4j.kernel.impl.util.StringLogger; @@ -36,7 +37,7 @@ public class SpringProvider extends TransactionManagerProvider } @Override - public AbstractTransactionManager loadTransactionManager(String txLogDir, XaDataSourceManager xaDataSourceManager, KernelPanicEventGenerator kpe, TxHook rollbackHook, StringLogger msgLog, FileSystemAbstraction fileSystem) { - return new SpringServiceImpl(); + public AbstractTransactionManager loadTransactionManager(String s, XaDataSourceManager xaDataSourceManager, KernelPanicEventGenerator kernelPanicEventGenerator, TxHook txHook, StringLogger stringLogger, FileSystemAbstraction fileSystemAbstraction, TransactionStateFactory transactionStateFactory) { + return new SpringServiceImpl(transactionStateFactory); } } 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 index b2995d21a..73b388a6f 100644 --- 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 @@ -16,13 +16,17 @@ package org.springframework.data.neo4j.transaction; +import org.neo4j.kernel.impl.core.TransactionState; import org.neo4j.kernel.impl.transaction.AbstractTransactionManager; +import org.neo4j.kernel.impl.transaction.TransactionStateFactory; 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 java.util.Map; +import java.util.WeakHashMap; /** * @author Chris Gioran @@ -34,8 +38,12 @@ class SpringServiceImpl extends AbstractTransactionManager private TransactionManager delegate; - SpringServiceImpl() + private final Map states = new WeakHashMap(); + private final TransactionStateFactory stateFactory; + + SpringServiceImpl(TransactionStateFactory stateFactory) { + this.stateFactory = stateFactory; } @Override @@ -47,6 +55,28 @@ class SpringServiceImpl extends AbstractTransactionManager } } + @Override + public void doRecovery() throws Throwable { + } + + @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 { @@ -54,19 +84,23 @@ class SpringServiceImpl extends AbstractTransactionManager @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)); } public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException { + Transaction tx = getTransaction(); delegate.commit(); + states.remove(tx); } public int getStatus() throws SystemException @@ -88,7 +122,9 @@ class SpringServiceImpl extends AbstractTransactionManager public void rollback() throws IllegalStateException, SecurityException, SystemException { + Transaction tx = getTransaction(); delegate.rollback(); + states.remove(tx); } public void setRollbackOnly() throws IllegalStateException, SystemException diff --git a/spring-data-neo4j/pom.xml b/spring-data-neo4j/pom.xml index 530483fe8..b5b8da68f 100644 --- a/spring-data-neo4j/pom.xml +++ b/spring-data-neo4j/pom.xml @@ -17,7 +17,6 @@ 1.0.0.GA - 2.9.0 @@ -196,6 +195,10 @@ blueprints-neo4j-graph ${blueprints.version} + + org.neo4j + neo4j-management + org.neo4j neo4j diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/node/Neo4jHelper.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/node/Neo4jHelper.java index 4c6d67ac9..f572b5156 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/node/Neo4jHelper.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/node/Neo4jHelper.java @@ -77,12 +77,21 @@ public abstract class Neo4jHelper { final GlobalGraphOperations globalGraphOperations = GlobalGraphOperations.at(graphDatabaseService); for (Node node : globalGraphOperations.getAllNodes()) { for (Relationship rel : node.getRelationships(Direction.OUTGOING)) { - rel.delete(); + try { + rel.delete(); + } catch(IllegalStateException ise) { + if (!ise.getMessage().contains("since it has already been deleted")) throw ise; + } + } } for (Node node : globalGraphOperations.getAllNodes()) { if (includeReferenceNode || !graphDatabaseService.getReferenceNode().equals(node)) { - node.delete(); + try { + node.delete(); + } catch(IllegalStateException ise) { + if (!ise.getMessage().contains("since it has already been deleted")) throw ise; + } } } } diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/config/DataGraphNamespaceHandlerTests.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/config/DataGraphNamespaceHandlerTests.java index d7541af2c..1f57b3dce 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/config/DataGraphNamespaceHandlerTests.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/config/DataGraphNamespaceHandlerTests.java @@ -100,7 +100,7 @@ public class DataGraphNamespaceHandlerTests { public void injectionForCodeConfiguredExistingGraphDatabaseService() { assertInjected("-code"); } - @Test + @Test @Ignore("BeanCreationException DATAGRAPH-354") public void injectionForBasePackageOfEntities() { Config config = assertInjected("-entities"); Collection> entities = config.mappingContext.getPersistentEntities(); @@ -123,7 +123,7 @@ public class DataGraphNamespaceHandlerTests { Assert.assertNotNull("template", template); AbstractGraphDatabase graphDatabaseService = (AbstractGraphDatabase) template.getGraphDatabaseService(); File directory = new File("target", "config-test"); - Assert.assertEquals("store-dir", directory.getAbsolutePath(),graphDatabaseService.getStoreDir()); + Assert.assertEquals("store-dir", directory.getPath(),graphDatabaseService.getStoreDir()); Assert.assertNotNull("graphDatabaseService",config.graphDatabaseService); Assert.assertNotNull("transactionManager",config.transactionManager); config.graphDatabaseService.shutdown(); diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/GraphRepositoryTests.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/GraphRepositoryTests.java index 00538daa5..e639bf9da 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/GraphRepositoryTests.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/GraphRepositoryTests.java @@ -247,7 +247,7 @@ public class GraphRepositoryTests { Page teamMemberPage1 = personRepository.findAllTeamMembersPaged(testTeam.sdg, null); assertEquals(new HashSet(asList(testTeam.david, testTeam.emil, testTeam.michael)), addToCollection(teamMemberPage1, new HashSet())); assertThat(teamMemberPage1.isFirstPage(), is(true)); - assertThat(teamMemberPage1.isLastPage(), is(false)); + assertThat(teamMemberPage1.isLastPage(), is(true)); } @Test @Transactional @@ -392,7 +392,7 @@ public class GraphRepositoryTests { assertEquals(root.getId(),p2.getRoot().getId()); } - @Test + @Test @Transactional public void testUseInterfaceAsPersistentEntity() { final List beings = beingRepository.findAll().as(List.class); assertEquals(3,beings.size()); diff --git a/spring-data-neo4j/src/test/resources/logback.xml b/spring-data-neo4j/src/test/resources/logback.xml new file mode 100644 index 000000000..573cf9db6 --- /dev/null +++ b/spring-data-neo4j/src/test/resources/logback.xml @@ -0,0 +1,18 @@ + + + + + + %d %5p %40.40c:%4L - %m%n + + + + + + + + + + \ No newline at end of file