removed obsolete roo addon support for fake JPA implementation

This commit is contained in:
Michael Hunger
2011-04-02 00:06:01 +02:00
parent 5328431cab
commit cc1100ca47
23 changed files with 0 additions and 2126 deletions

View File

@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>spring-data-neo4j-roo</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.ajdt.ui.ajnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>

View File

@@ -1,6 +0,0 @@
#Fri Oct 29 18:37:18 EDT 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6

View File

@@ -1,9 +0,0 @@
#Fri Oct 29 18:37:14 EDT 2010
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
resolveWorkspaceProjects=true
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1

View File

@@ -1,203 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-graph-parent</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<relativePath>../spring-data-graph-parent/pom.xml</relativePath>
</parent>
<artifactId>spring-data-neo4j-roo</artifactId>
<packaging>jar</packaging>
<name>Spring Data Neo4J Roo Support</name>
<properties>
<aspectj.version>1.6.11.RELEASE</aspectj.version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- Spring Data -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons-core</artifactId>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<!-- Neo4J -->
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-kernel</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<!-- JPA -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<!-- For Tests -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.5.5-Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>neo4j-public-repository</id>
<name>Neo4J Public Repository</name>
<url>http://m2.neo4j.org</url>
</repository>
<repository>
<id>jboss-repository</id>
<name>JBoss Public Repository</name>
<url>http://repository.jboss.org/nexus/content/groups/public-jboss</url>
</repository>
<repository>
<id>spring-maven-snapshot</id>
<snapshots>
<enabled>true</enabled>
</snapshots>
<name>Springframework Maven SNAPSHOT Repository</name>
<url>http://maven.springframework.org/snapshot</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.2</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<outxml>true</outxml>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,309 +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.graph.neo4j.jpa;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.neo4j.repository.GraphRepository;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.repository.NodeGraphRepository;
import org.springframework.data.graph.neo4j.support.Tuple2;
import javax.persistence.*;
import javax.persistence.spi.PersistenceUnitInfo;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.springframework.data.graph.neo4j.jpa.Neo4jQueryParameter.param;
import static org.springframework.data.graph.neo4j.support.Tuple2._;
import static org.springframework.util.ObjectUtils.nullSafeEquals;
/**
* @author Michael Hunger
* @since 29.08.2010
*/
public class Neo4JQuery<T> implements TypedQuery<T> {
protected final Class<T> resultClass;
protected final String qlString;
private final DirectGraphRepositoryFactory graphRepositoryFactory;
private final PersistenceUnitInfo info;
private final Pattern fromPattern = Pattern.compile("^.*\\bfrom\\s+([A-Z][A-Za-z0-9]+)\\b.*");
private int startPosition = 0;
private int maxResult = -1;
private QueryExecutor<?> queryExecutor;
private Map<Parameter<?>, Tuple2<?, TemporalType>> parameters = new HashMap<Parameter<?>, Tuple2<?, TemporalType>>();
public Neo4JQuery(final String qlString, final DirectGraphRepositoryFactory graphRepositoryFactory, final PersistenceUnitInfo info, Class<T> resultClass) {
this.qlString = qlString;
this.graphRepositoryFactory = graphRepositoryFactory;
this.info = info;
this.resultClass = resultClass;
queryExecutor = createExecutor(qlString);
}
private QueryExecutor<T> createExecutor(final String qlString) {
final GraphRepository<?,?> graphRepository = getFinderFromQuery(qlString);
if (qlString.contains(" count(")) {
return new QueryExecutor<T>() {
@Override
protected T findObject() {
return (T)Long.valueOf(graphRepository.count());
}
};
}
return new QueryExecutor<T>() {
@Override
protected Iterable<T> findList() {
return (Iterable<T>) graphRepository.findAll();
}
};
}
private NodeGraphRepository<? extends NodeBacked> getFinderFromQuery(String qlString) {
final Matcher matcher = fromPattern.matcher(qlString);
if (!matcher.matches()) throw new IllegalAccessError("Unable to parse query " + qlString);
final String shortName = matcher.group(1);
final Class<? extends NodeBacked> entityClass = getEntityClass(shortName);
return graphRepositoryFactory.createNodeEntityRepository(entityClass);
}
abstract static class QueryExecutor<T> {
protected Iterable<T> findList() {
return Collections.singleton(findObject());
}
protected T findObject() {
return null;
}
}
private Class<? extends NodeBacked> getEntityClass(final String shortName) {
try {
final String className = getFQN(shortName);
return (Class<? extends NodeBacked>) Class.forName(className);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Error resolving class " + shortName, e);
}
}
private String getFQN(final String shortName) throws ClassNotFoundException {
for (final String className : info.getManagedClassNames()) {
if (className.endsWith(shortName)) return className;
}
throw new ClassNotFoundException("No mapped class found for " + shortName);
}
@Override
public List<T> getResultList() {
final List<T> result = new ArrayList<T>();
int count = 0;
for (final T nodeBacked : (Iterable<T>) queryExecutor.findList()) {
if (maxResult >= 0 && count == startPosition + maxResult) break;
if (count >= startPosition) {
result.add(nodeBacked);
}
count++;
}
return result;
}
@Override
public T getSingleResult() {
final Iterator<?> found = queryExecutor.findList().iterator();
return found.hasNext() ? (T) found.next() : null; // todo errors when none or too many ?
}
@Override
public int executeUpdate() {
return 0;
}
@Override
public TypedQuery<T> setMaxResults(final int maxResult) {
this.maxResult = maxResult;
return this;
}
@Override
public int getMaxResults() {
return maxResult;
}
@Override
public TypedQuery<T> setFirstResult(final int startPosition) {
this.startPosition = startPosition;
return this;
}
@Override
public int getFirstResult() {
return startPosition;
}
@Override
public TypedQuery<T> setHint(final String hintName, final Object value) {
return this;
}
@Override
public Map<String, Object> getHints() {
return Collections.emptyMap();
}
@Override
public <P> TypedQuery<T> setParameter(final Parameter<P> parameter, final P value) {
this.parameters.put(parameter, value(value));
return this;
}
private static <P> Tuple2<P, TemporalType> value(final P value) {
return _(value, (TemporalType) null);
}
@Override
public TypedQuery<T> setParameter(final Parameter<Calendar> parameter, final Calendar calendar, final TemporalType temporalType) {
this.parameters.put(parameter, _(calendar, temporalType));
return this;
}
@Override
public TypedQuery<T> setParameter(final Parameter<Date> parameter, final Date date, final TemporalType temporalType) {
this.parameters.put(parameter, _(date, temporalType));
return this;
}
@Override
public TypedQuery<T> setParameter(final String name, final Object value) {
this.parameters.put(param(name), value(value));
return this;
}
@Override
public TypedQuery<T> setParameter(final String name, final Date value, final TemporalType temporalType) {
this.parameters.put(param(name), _(value, temporalType));
return this;
}
@Override
public TypedQuery<T> setParameter(final String name, final Calendar value, final TemporalType temporalType) {
this.parameters.put(param(name), _(value, temporalType));
return this;
}
@Override
public TypedQuery<T> setParameter(final int position, final Object value) {
this.parameters.put(param(position), value(value));
return this;
}
@Override
public TypedQuery<T> setParameter(final int position, final Date value, final TemporalType temporalType) {
this.parameters.put(param(position), value(value));
return this;
}
@Override
public Set<Parameter<?>> getParameters() {
return parameters.keySet();
}
@Override
public Parameter<?> getParameter(final String name) {
for (final Parameter<?> parameter : parameters.keySet()) {
if (nullSafeEquals(parameter.getName(), name)) return parameter;
}
return null;
}
@Override
public <T> Parameter<T> getParameter(final String name, final Class<T> type) {
for (final Parameter<?> parameter : parameters.keySet()) {
if (nullSafeEquals(parameter.getName(), name) && nullSafeEquals(type, parameter.getParameterType()))
return (Parameter<T>) parameter;
}
return null;
}
@Override
public Parameter<?> getParameter(final int index) {
for (final Parameter<?> parameter : parameters.keySet()) {
if (nullSafeEquals(parameter.getPosition(), index)) return parameter;
}
return null;
}
@Override
public <T> Parameter<T> getParameter(final int index, final Class<T> type) {
for (final Parameter<?> parameter : parameters.keySet()) {
if (nullSafeEquals(parameter.getPosition(), index) && nullSafeEquals(type, parameter.getParameterType()))
return (Parameter<T>) parameter;
}
return null;
}
@Override
public boolean isBound(final Parameter<?> parameter) {
return parameters.containsKey(parameter);
}
@Override
public <T> T getParameterValue(final Parameter<T> parameter) {
return (T) parameters.get(parameter)._1;
}
@Override
public Object getParameterValue(final String name) {
return getParameterValue(getParameter(name));
}
@Override
public Object getParameterValue(final int index) {
return getParameterValue(getParameter(index));
}
@Override
public TypedQuery<T> setParameter(final int position, final Calendar value, final TemporalType temporalType) {
parameters.put(param(position), _(value, temporalType));
return this;
}
@Override
public TypedQuery<T> setFlushMode(final FlushModeType flushMode) {
return this;
}
@Override
public FlushModeType getFlushMode() {
return null;
}
@Override
public TypedQuery<T> setLockMode(final LockModeType lockModeType) {
return null;
}
@Override
public LockModeType getLockMode() {
return null;
}
@Override
public <T> T unwrap(final Class<T> tClass) {
return null;
}
}

View File

@@ -1,339 +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.graph.neo4j.jpa;
import org.neo4j.graphdb.*;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.data.graph.core.NodeBacked;
import org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.persistence.*;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.metamodel.Metamodel;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.transaction.*;
import java.util.Map;
/**
* @author Michael Hunger
* @since 20.08.2010
* TODO Relationships
*/
//@Service
@Transactional
@Configurable
public class Neo4jEntityManager implements EntityManager {
private GraphDatabaseContext graphDatabaseContext;
private PersistenceUnitInfo info;
private Map params;
private volatile boolean closed;
private final DirectGraphRepositoryFactory graphRepositoryFactory;
@Resource
private EntityManagerFactory entityManagerFactory;
public Neo4jEntityManager(final GraphDatabaseContext graphDatabaseContext,final PersistenceUnitInfo info, final Map params) {
this.graphDatabaseContext = graphDatabaseContext;
this.info = info;
this.params = params;
graphRepositoryFactory = new DirectGraphRepositoryFactory(graphDatabaseContext);
}
public Neo4jEntityManager() {
graphRepositoryFactory = new DirectGraphRepositoryFactory(graphDatabaseContext);
}
private Node nodeFor(final Object entity) {
checkClosed();
if (!(entity instanceof NodeBacked)) throw new IllegalArgumentException("Not a nodebacked entity " + entity);
final Node node = ((NodeBacked) entity).getPersistentState();
if (node == null) throw new IllegalArgumentException("Node of entity " + entity + " is null");
return node;
}
@Override
public void persist(final Object entity) {
checkClosed();
//todo nodebacked justwriteback, no check
}
@Override
public <T> T merge(final T entity) {
checkClosed();
// todo nodebacked merge
return entity;
}
@Override
public void remove(final Object entity) {
final Node node = nodeFor(entity);
for (final Relationship r : node.getRelationships()) {
r.delete();
}
node.delete();
}
@SuppressWarnings({"unchecked"})
@Override
public <T> T find(final Class<T> entityClass, final Object primaryKey) {
checkClosed();
if (!NodeBacked.class.isAssignableFrom(entityClass))
throw new IllegalArgumentException("Not a nodebacked entity type " + entityClass);
if (!(primaryKey instanceof Number))
throw new IllegalArgumentException("Primary Key for entity type " + entityClass + " is not a number " + primaryKey);
final Node node = graphDatabaseContext.getNodeById(((Number) primaryKey).longValue());
return (T) graphDatabaseContext.createEntityFromState(node, (Class<? extends NodeBacked>) entityClass);
}
@Override
public <T> T find(final Class<T> entityClass, final Object primaryKey, final Map<String, Object> params) {
return find(entityClass, primaryKey);
}
@Override
public <T> T find(final Class<T> entityClass, final Object primaryKey, final LockModeType lockModeType) {
return find(entityClass, primaryKey);
}
@Override
public <T> T find(final Class<T> entityClass, final Object primaryKey, final LockModeType lockModeType, final Map<String, Object> params) {
return find(entityClass, primaryKey);
}
@Override
public <T> T getReference(final Class<T> entityClass, final Object primaryKey) {
return find(entityClass, primaryKey);
}
@Override
public void flush() {
checkClosed();
}
@Override
public void setFlushMode(final FlushModeType flushMode) {
checkClosed();
}
@Override
public FlushModeType getFlushMode() {
checkClosed();
return FlushModeType.AUTO;
}
@Override
public void lock(final Object entity, final LockModeType lockModeType) {
nodeFor(entity);
}
@Override
public void lock(final Object entity, final LockModeType lockModeType, final Map<String, Object> params) {
lock(entity,lockModeType);
}
@Override
public void refresh(final Object entity) {
// todo nodebacked.refresh, throw away dirty
nodeFor(entity);
}
@Override
public void refresh(final Object entity, final Map<String, Object> params) {
refresh(entity);
}
@Override
public void refresh(final Object entity, final LockModeType lockModeType) {
refresh(entity);
}
@Override
public void refresh(final Object entity, final LockModeType lockModeType, final Map<String, Object> params) {
refresh(entity);
}
/**
* Clear the persistence context, causing all managed entities to become detached.
*/
@Override
public void clear() {
checkClosed();
}
@Override
public void detach(final Object entity) {
}
@Override
public boolean contains(final Object entity) {
checkClosed();
try {
return nodeFor(entity) != null;
} catch (IllegalArgumentException e) {
return false;
}
}
@Override
public LockModeType getLockMode(final Object entity) {
return LockModeType.NONE; // todo use neo4j locks?
}
@Override
public void setProperty(final String name, final Object value) {
params.put(name,value);
}
@Override
public Map<String, Object> getProperties() {
return params;
}
/*
TODO Gremlin
*/
@Override
public Query createQuery(final String qlString) {
return createQuery(qlString,null);
}
@Override
public <T> TypedQuery<T> createQuery(final CriteriaQuery<T> query) {
return null;
}
@SuppressWarnings({"unchecked"})
@Override
public <T> TypedQuery<T> createQuery(final String qlString, final Class<T> entityClass) {
checkClosed();
return (TypedQuery<T>)createNeo4jQuery(qlString,entityClass);
}
public <T> TypedQuery<T> createNeo4jQuery(final String qlString, final Class<T> entityClass) {
return new Neo4JQuery<T>(qlString, graphRepositoryFactory,info,entityClass);
}
/*
TODO Gremlin
*/
@Override
public Query createNamedQuery(final String name) {
checkClosed();
throw new UnsupportedOperationException();
}
@Override
public <T> TypedQuery<T> createNamedQuery(final String s, final Class<T> entityClass) {
return null;
}
/*
TODO Gremlin
*/
@Override
public Query createNativeQuery(final String sqlString) {
checkClosed();
throw new UnsupportedOperationException();
}
/*
TODO Gremlin
*/
@Override
public Query createNativeQuery(final String sqlString, final Class resulentityClass) {
checkClosed();
throw new UnsupportedOperationException();
}
/*
TODO Gremlin
*/
@Override
public Query createNativeQuery(final String sqlString, final String resultSetMapping) {
checkClosed();
throw new UnsupportedOperationException();
}
/*
TODO Johan
*/
@Override
public void joinTransaction() {
checkClosed();
throw new UnsupportedOperationException();
}
@Override
public <T> T unwrap(final Class<T> entityClass) {
return null;
}
@Override
public Object getDelegate() {
checkClosed();
return graphDatabaseContext;
}
@Override
public void close() {
checkClosed();
this.closed = true;
}
@Override
public boolean isOpen() {
return !closed;
}
private void checkClosed() {
if (closed) throw new IllegalStateException("EntityManager is closed");
}
@Override
public EntityTransaction getTransaction() {
final TransactionManager transactionManager = graphDatabaseContext.getTxManager();
return new Neo4jEntityTransaction(transactionManager);
}
@Override
public EntityManagerFactory getEntityManagerFactory() {
return entityManagerFactory;
}
@Override
public CriteriaBuilder getCriteriaBuilder() {
return null;
}
@Override
public Metamodel getMetamodel() {
return null;
}
}

View File

@@ -1,90 +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.graph.neo4j.jpa;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import javax.persistence.Cache;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnitUtil;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.metamodel.Metamodel;
import javax.persistence.spi.PersistenceUnitInfo;
import java.util.Collections;
import java.util.Map;
/**
* @author Michael Hunger
* @since 23.08.2010
*/
public class Neo4jEntityManagerFactory implements EntityManagerFactory {
private PersistenceUnitInfo info;
private Map params;
private final GraphDatabaseContext graphDatabaseContext;
public Neo4jEntityManagerFactory(GraphDatabaseContext graphDatabaseContext, PersistenceUnitInfo info, Map params) {
this.graphDatabaseContext = graphDatabaseContext;
this.info = info;
this.params = params;
}
@Override
public EntityManager createEntityManager() {
return new Neo4jEntityManager(graphDatabaseContext,info,params);
}
/* TODO handle different directories for target datastore */
@Override
public EntityManager createEntityManager(Map map) {
return new Neo4jEntityManager(graphDatabaseContext,info,params);
}
@Override
public CriteriaBuilder getCriteriaBuilder() {
return null;
}
@Override
public Metamodel getMetamodel() {
return null;
}
@Override
public void close() {
}
@Override
public Map<String, Object> getProperties() {
return Collections.emptyMap();
}
@Override
public Cache getCache() {
return null;
}
@Override
public PersistenceUnitUtil getPersistenceUnitUtil() {
return null;
}
@Override
public boolean isOpen() {
return true;
}
}

View File

@@ -1,94 +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.graph.neo4j.jpa;
import javax.persistence.EntityTransaction;
import javax.transaction.*;
/**
* @author Michael Hunger
* @since 20.08.2010
*/
class Neo4jEntityTransaction implements EntityTransaction {
private final TransactionManager transactionManager;
public Neo4jEntityTransaction(final TransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
@Override
public void begin() {
try {
transactionManager.begin();
} catch (SystemException e) {
throw new IllegalStateException(e);
} catch (NotSupportedException e) {
throw new IllegalStateException(e);
}
}
@Override
public void commit() {
try {
transactionManager.commit();
} catch (SystemException e) {
throw new IllegalStateException(e);
} catch (HeuristicRollbackException e) {
throw new IllegalStateException(e);
} catch (HeuristicMixedException e) {
throw new IllegalStateException(e);
} catch (RollbackException e) {
throw new IllegalStateException(e);
}
}
@Override
public void rollback() {
try {
transactionManager.rollback();
} catch (SystemException e) {
throw new IllegalStateException(e);
}
}
@Override
public void setRollbackOnly() {
try {
transactionManager.setRollbackOnly();
} catch (SystemException e) {
throw new IllegalStateException(e);
}
}
@Override
public boolean getRollbackOnly() {
try {
return transactionManager.getStatus() == Status.STATUS_MARKED_ROLLBACK;
} catch (SystemException e) {
throw new IllegalStateException(e);
}
}
@Override
public boolean isActive() {
try {
return transactionManager.getStatus() == Status.STATUS_ACTIVE;
} catch (SystemException e) {
throw new IllegalStateException(e);
}
}
}

View File

@@ -1,86 +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.graph.neo4j.jpa;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.datasource.ConnectionHandle;
import org.springframework.orm.jpa.EntityManagerFactoryPlusOperations;
import org.springframework.orm.jpa.EntityManagerPlusOperations;
import org.springframework.orm.jpa.JpaDialect;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceException;
import java.sql.SQLException;
/**
* @author Michael Hunger
* @since 23.08.2010
*/
public class Neo4jJpaDialect implements JpaDialect {
@Override
public boolean supportsEntityManagerFactoryPlusOperations() {
return false;
}
@Override
public boolean supportsEntityManagerPlusOperations() {
return false;
}
@Override
public EntityManagerFactoryPlusOperations getEntityManagerFactoryPlusOperations(final EntityManagerFactory entityManagerFactory) {
return null;
}
@Override
public EntityManagerPlusOperations getEntityManagerPlusOperations(final EntityManager entityManager) {
return null;
}
// todo
@Override
public Object beginTransaction(final EntityManager entityManager, final TransactionDefinition transactionDefinition) throws PersistenceException, SQLException, TransactionException {
return null;
}
@Override
public Object prepareTransaction(final EntityManager entityManager, final boolean b, final String s) throws PersistenceException {
return null;
}
@Override
public void cleanupTransaction(final Object o) {
}
@Override
public ConnectionHandle getJdbcConnection(final EntityManager entityManager, final boolean b) throws PersistenceException, SQLException {
return null;
}
@Override
public void releaseJdbcConnection(final ConnectionHandle connectionHandle, final EntityManager entityManager) throws PersistenceException, SQLException {
}
// todo
@Override
public DataAccessException translateExceptionIfPossible(final RuntimeException e) {
return null;
}
}

View File

@@ -1,78 +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.graph.neo4j.jpa;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import javax.annotation.Resource;
import javax.persistence.EntityManagerFactory;
import javax.persistence.spi.LoadState;
import javax.persistence.spi.PersistenceProvider;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.ProviderUtil;
import java.util.Map;
/**
* @author Michael Hunger
* @since 23.08.2010
*/
// todo handle additinal info + database path
@Configurable
public class Neo4jPersistenceProvider implements PersistenceProvider {
@Resource
private GraphDatabaseContext graphDatabaseContext;
@Override
public EntityManagerFactory createEntityManagerFactory(String emName, Map params) {
System.out.println("emName = " + emName);
System.out.println("params = " + params);
return new Neo4jEntityManagerFactory(graphDatabaseContext, null,params);
}
@Override
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map params) {
System.out.println("info.getPersistenceProviderClassName() = " + info.getPersistenceProviderClassName());
System.out.println("info.getManagedClassNames() = " + info.getManagedClassNames());
System.out.println("info.getMappingFileNames() = " + info.getMappingFileNames());
System.out.println("info.getTransactionType() = " + info.getTransactionType());
System.out.println("info.getProperties() = " + info.getProperties());
System.out.println("info.getPersistenceUnitName() = " + info.getPersistenceUnitName());
System.out.println("params = " + params);
return new Neo4jEntityManagerFactory(graphDatabaseContext,info,params);
}
@Override
public ProviderUtil getProviderUtil() {
return new ProviderUtil(){
@Override
public LoadState isLoadedWithoutReference(Object o, String s) {
return LoadState.UNKNOWN;
}
@Override
public LoadState isLoadedWithReference(Object o, String s) {
return LoadState.UNKNOWN;
}
@Override
public LoadState isLoaded(Object o) {
return LoadState.UNKNOWN;
}
};
}
}

View File

@@ -1,53 +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.graph.neo4j.jpa;
import javax.persistence.Parameter;
/**
* @author Michael Hunger
* @since 11.09.2010
*/
public class Neo4jQueryParameter<T> implements Parameter<T> {
private final Class<T> type;
private final String name;
private final Integer position;
public Neo4jQueryParameter(Class<T> type, String name, Integer position) {
this.type = type;
this.name = name;
this.position = position;
}
@Override
public String getName() {
return name;
}
@Override
public Integer getPosition() {
return position;
}
@Override
public Class<T> getParameterType() {
return type;
}
public static Parameter<?> param(String name) { return new Neo4jQueryParameter<Object>(null,name,null);}
public static Parameter<?> param(Integer position) { return new Neo4jQueryParameter<Object>(null,null,position);}
public static <T> Parameter<T> param(Class<T> type, String name, Integer position) { return new Neo4jQueryParameter<T>(type,name,position);}
}

View File

@@ -1,30 +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.graph.neo4j;
import org.neo4j.graphdb.Node;
import org.springframework.data.graph.annotation.NodeEntity;
@NodeEntity
public abstract class Car {
public Car() {
}
public Car(Node n) {
setPersistentState(n);
}
}

View File

@@ -1,97 +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.graph.neo4j;
import org.springframework.data.graph.annotation.EndNode;
import org.springframework.data.graph.annotation.RelationshipEntity;
import org.springframework.data.graph.annotation.StartNode;
import org.springframework.data.graph.neo4j.Person;
import static org.springframework.data.graph.neo4j.Person.persistedPerson;
import static org.springframework.data.graph.neo4j.Person.persistedPerson;
import java.util.Date;
@RelationshipEntity(useShortNames = false)
public class Friendship {
public Friendship() {
}
public Friendship(Person p1, Person p2) {
this.p1 = p1;
this.p2 = p2;
}
public Friendship(Person p1, Person p2, int years) {
this.p1 = p1;
this.p2 = p2;
this.years = years;
}
@StartNode
private Person p1;
@EndNode
private Person p2;
private int years;
private Date firstMeetingDate;
private transient String latestLocation;
public void setPerson1(Person p) {
p1 = p;
}
public Person getPerson1() {
return p1;
}
public void setPerson2(Person p) {
p2 = p;
}
public Person getPerson2() {
return p2;
}
public void setYears(int years) {
this.years = years;
}
public int getYears() {
return years;
}
public void setFirstMeetingDate(Date firstMeetingDate) {
this.firstMeetingDate = firstMeetingDate;
}
public Date getFirstMeetingDate() {
return firstMeetingDate;
}
public void setLatestLocation(String latestLocation) {
this.latestLocation = latestLocation;
}
public String getLatestLocation() {
return latestLocation;
}
}

View File

@@ -1,211 +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.graph.neo4j;
import org.springframework.data.annotation.Indexed;
import org.springframework.data.graph.annotation.GraphId;
import org.springframework.data.graph.annotation.NodeEntity;
import org.springframework.data.graph.annotation.RelatedTo;
import org.springframework.data.graph.annotation.RelatedToVia;
import org.springframework.data.graph.core.Direction;
import java.util.Date;
@NodeEntity(useShortNames = false)
public class Person
{
public static final String NAME_INDEX = "name_index";
@GraphId
private Long graphId;
@Indexed(indexName = NAME_INDEX)
private String name;
@Indexed
private String nickname;
private int age;
private Short height;
private transient String thought;
private Personality personality;
private Date birthdate;
private Person spouse;
private Car car;
@RelatedTo(type = "mother", direction = Direction.OUTGOING)
private Person mother;
@RelatedTo(type = "boss", direction = Direction.INCOMING)
private Person boss;
@RelatedToVia(type = "knows", elementClass = Friendship.class)
private Iterable<Friendship> friendships;
public Person()
{
}
public Person( String name, int age )
{
this.name = name;
this.age = age;
}
public String getName()
{
return name;
}
public void setName( String name )
{
this.name = name;
}
public int getAge()
{
return age;
}
public void setAge( int age )
{
this.age = age;
}
public Short getHeight()
{
return height;
}
public void setHeight( Short height )
{
this.height = height;
}
public Person getSpouse()
{
return spouse;
}
public void setSpouse( Person spouse )
{
this.spouse = spouse;
}
public Person getMother()
{
return mother;
}
public void setMother( Person mother )
{
this.mother = mother;
}
public Person getBoss()
{
return boss;
}
public void setBoss( Person boss )
{
this.boss = boss;
}
@Override
public String toString()
{
return name;
}
public Iterable<Friendship> getFriendships()
{
return friendships;
}
public void setFriendships( Iterable<Friendship> f )
{
friendships = f;
}
public Friendship knows( Person p )
{
return (Friendship) relateTo( p, Friendship.class, "knows" );
}
public void setPersonality( Personality personality )
{
this.personality = personality;
}
public Personality getPersonality()
{
return personality;
}
public void setThought( String thought )
{
this.thought = thought;
}
public String getThought()
{
return thought;
}
public Date getBirthdate()
{
return birthdate;
}
public void setBirthdate( Date birthdate )
{
this.birthdate = birthdate;
}
public long getId()
{
return graphId;
}
public void setCar( Car car )
{
this.car = car;
}
public Car getCar()
{
return car;
}
public void setNickname( String nickname )
{
this.nickname = nickname;
}
public static Person persistedPerson(String name, int age) {
return new Person(name,age).persist();
}
}

View File

@@ -1,21 +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.graph.neo4j;
public enum Personality {
EXTROVERT, INTROVERT
}

View File

@@ -1,227 +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.graph.neo4j.jpa;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.junit.*;
import org.junit.runner.RunWith;
import org.neo4j.graphdb.Node;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.graph.neo4j.Person;
import static org.springframework.data.graph.neo4j.Person.persistedPerson;
import static org.springframework.data.graph.neo4j.Person.persistedPerson;
import org.springframework.data.graph.neo4j.support.GraphDatabaseContext;
import org.springframework.data.graph.neo4j.support.node.Neo4jHelper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
/**
* @author Michael Hunger
* @since 20.08.2010
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@Transactional
public class Neo4jEntityManagerTest {
@Resource
GraphDatabaseContext graphDatabaseContext;
@PersistenceContext(unitName="neo4j-persistence")
EntityManager entityManager;
Person person;
private Node node;
@BeforeTransaction
public void cleanDb() {
Neo4jHelper.cleanDb(graphDatabaseContext);
}
@Before
public void setUp() {
person = persistedPerson("Michael", 35);
node = person.getPersistentState();
}
@Test
public void testPersist() throws Exception {
entityManager.persist(person);
}
@Test
public void testMerge() throws Exception {
Person merged=entityManager.merge(person);
assertEquals(person,merged);
}
@Ignore
@Test
public void testRemove() throws Exception {
long nodeId=node.getId();
entityManager.remove(person);
final Node foundNode = graphDatabaseContext.getNodeById(nodeId);
assertNull(foundNode);
}
@Test
public void testFind() throws Exception {
final Person found = entityManager.find(Person.class, node.getId());
assertEquals(person,found);
}
@Test
public void testFindSingle() throws Exception {
final Query query = entityManager.createQuery("select o from Person o");
final Person found = (Person) query.getSingleResult();
assertEquals(person,found);
}
@Test
public void testFindAll() throws Exception {
final Query query = entityManager.createQuery("select o from Person o");
Collection<Person> people=query.getResultList();
Assert.assertEquals(asList(person),people);
}
@Test
public void testFindAll2() throws Exception {
final Person person2 = persistedPerson("Rod", 39);
final Query query = entityManager.createQuery("select o from Person o");
Collection<Person> people=query.getResultList();
Assert.assertEquals(new HashSet<Person>(asList(person,person2)),new HashSet<Person>(people));
}
@Test
public void testFindAllStart() throws Exception {
final Query query = entityManager.createQuery("select o from Person o").setFirstResult(1);
Collection<Person> people=query.getResultList();
Assert.assertEquals(Collections.<Person>emptySet(),new HashSet<Person>(people));
}
@Test
public void testFindAllEnd() throws Exception {
final Query query = entityManager.createQuery("select o from Person o").setMaxResults(0);
Collection<Person> people=query.getResultList();
Assert.assertEquals(Collections.<Person>emptySet(),new HashSet<Person>(people));
}
@Test
public void testFindAllStartEnd() throws Exception {
persistedPerson("Rod", 39);
final Query query = entityManager.createQuery("select o from Person o").setMaxResults(1).setFirstResult(1);
Collection<Person> people=query.getResultList();
Assert.assertEquals(1,people.size());
}
@Test
public void testGetReference() throws Exception {
final Person found = entityManager.getReference(Person.class, node.getId());
assertEquals(person,found);
}
@Test
public void testFlush() throws Exception {
}
@Test
public void testSetFlushMode() throws Exception {
}
@Test
public void testGetFlushMode() throws Exception {
}
@Test
public void testLock() throws Exception {
}
@Test
public void testRefresh() throws Exception {
entityManager.refresh(person);
assertEquals(node, person.getPersistentState());
}
@Test
public void testClear() throws Exception {
}
@Test(expected=InvalidDataAccessApiUsageException.class)
public void removeThrowsErrorForNonNodeBacked() throws Exception {
entityManager.remove(new Object());
}
@Test
public void testContains() throws Exception {
final Person p2 = persistedPerson("Rod", 39);
assertTrue(entityManager.contains(person));
assertTrue(entityManager.contains(p2));
assertFalse(entityManager.contains(new Object()));
}
/*
@Test
public void testCreateQuery() throws Exception {
}
@Test
public void testCreateNamedQuery() throws Exception {
}
@Test
public void testCreateNativeQuery() throws Exception {
}
@Test
public void testJoinTransaction() throws Exception {
}
*/
@Test
public void testGetDelegate() throws Exception {
assertTrue(entityManager.getDelegate() instanceof GraphDatabaseContext);
}
@Ignore("Springs shared EM does not honor the contract of close")
@Test(expected=InvalidDataAccessApiUsageException.class)
public void testClose() throws Exception {
entityManager.close();
assertFalse(entityManager.isOpen());
entityManager.refresh(person);
}
@Test
public void testIsOpen() throws Exception {
assertTrue(entityManager.isOpen());
}
@Ignore("Springs shared EM does not allow getTransaction")
@Test
public void testGetTransaction() throws Exception {
final EntityTransaction transaction = entityManager.getTransaction();
assertFalse(transaction.getRollbackOnly());
person.setName("Michael");
entityManager.persist(person);
transaction.setRollbackOnly();
}
}

View File

@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="neo4j-persistence" transaction-type="RESOURCE_LOCAL">
<provider>org.springframework.data.graph.neo4j.jpa.Neo4jPersistenceProvider</provider>
<class>org.springframework.data.graph.neo4j.Person</class>
<class>org.springframework.data.graph.neo4j.Group</class>
<class>org.springframework.data.graph.neo4j.Friendship</class>
<properties>
<property name="neo4j.path" value="test/data"/> <!-- TODO handle this -->
</properties>
</persistence-unit>
</persistence>

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>org.springframework.data.graph.neo4j.partial.User</class>
<class>org.springframework.data.graph.neo4j.partial.Restaurant</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>

View File

@@ -1,6 +0,0 @@
#Updated at Tue Mar 23 14:26:10 PDT 2010
#Tue Mar 23 14:26:10 PDT 2010
database.password=
database.url=jdbc\:hsqldb\:mem\:test
database.username=sa
database.driverClassName=org.hsqldb.jdbcDriver

View File

@@ -1 +0,0 @@
neo4j.databaseDirectory=target/data/test

View File

@@ -1,23 +0,0 @@
log4j.rootLogger=WARN, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Print the date in ISO 8601 format
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=target/application.log
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
log4j.category.org.springframework=WARN
#log4j.category.org.springframework.data=TRACE
#log4j.category.org.springframework.data.support=TRACE
#log4j.category.org.springframework.persistence=TRACE
#log4j.category.org.springframework.data.graph.neo4j.support=DEBUG

View File

@@ -1,182 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!--
This will automatically locate any and all property files you have
within your classpath, provided they fall under the META-INF/spring
directory. The located property files are parsed and their values can
then be used within application context files in the form of
${propertyKey}.
-->
<context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>
<!--
Turn on AspectJ @Configurable support. As a result, any time you
instantiate an object, Spring will attempt to perform dependency
injection on that object. This occurs for instantiation via the "new"
keyword, as well as via reflection. This is possible because AspectJ
is used to "weave" Roo-based applications at compile time. In effect
this feature allows dependency injection of any object at all in your
system, which is a very useful feature (without @Configurable you'd
only be able to dependency inject objects acquired from Spring or
subsequently presented to a specific Spring dependency injection
method). Roo applications use this useful feature in a number of
areas, such as @PersistenceContext injection into entities.
-->
<context:spring-configured/>
<!--
This declaration will cause Spring to locate every @Component,
@Repository and @Service in your application. In practical terms this
allows you to write a POJO and then simply annotate the new POJO as an
@Service and Spring will automatically detect, instantiate and
dependency inject your service at startup time. Importantly, you can
then also have your new service injected into any other class that
requires it simply by declaring a field for your service inside the
relying class and Spring will inject it. Note that two exclude filters
are declared. The first ensures that Spring doesn't spend time
introspecting Roo-specific ITD aspects. The second ensures Roo doesn't
instantiate your @Controller classes, as these should be instantiated
by a web tier application context. Refer to web.xml for more details
about the web tier application context setup services.
Furthermore, this turns on @Autowired, @PostConstruct etc support. These
annotations allow you to use common Spring and Java Enterprise Edition
annotations in your classes without needing to do any special configuration.
The most commonly used annotation is @Autowired, which instructs Spring to
dependency inject an object into your class.
-->
<context:component-scan base-package="org.springframework.data.graph.neo4j">
<context:exclude-filter expression=".*_Roo_.*" type="regex"/>
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
<!--
Start datastore config
-->
<bean id="neo4jNodeBacking" class="org.springframework.data.graph.neo4j.support.node.Neo4jNodeBacking" factory-method="aspectOf">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="nodeEntityStateFactory" ref="nodeEntityStateFactory"/>
</bean>
<bean class="org.springframework.data.graph.neo4j.support.relationship.Neo4jRelationshipBacking" factory-method="aspectOf">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="relationshipEntityStateFactory" ref="relationshipEntityStateFactory"/>
</bean>
<!--
<bean class="org.springframework.persistence.graph.Neo4jSimpleNodePropertyStorageForeignStoreKeyManager"/>
-->
<bean id="graphDatabaseService" class="org.neo4j.kernel.ImpermanentGraphDatabase"
destroy-method="shutdown" scope="singleton">
<constructor-arg index="0" value="target/data/emtest" />
</bean>
<bean id="graphDatabaseContext" class="org.springframework.data.graph.neo4j.support.GraphDatabaseContext">
<property name="graphDatabaseService" ref="graphDatabaseService"/>
<property name="conversionService">
<bean class="org.springframework.data.graph.neo4j.fieldaccess.Neo4jConversionServiceFactoryBean"/>
</property>
<property name="nodeTypeRepresentationStrategy" ref="nodeTypeRepresentationStrategy" />
<property name="relationshipTypeRepresentationStrategy" ref="relationshipTypeRepresentationStrategy" />
</bean>
<bean id="relationshipEntityInstantiator"
class="org.springframework.data.graph.neo4j.support.relationship.RelationshipEntityInstantiator"/>
<bean id="typeRepresentationStrategyFactory" class="org.springframework.data.graph.neo4j.support.TypeRepresentationStrategyFactory">
<constructor-arg ref="graphDatabaseService"/>
<constructor-arg ref="graphEntityInstantiator"/>
<constructor-arg ref="relationshipEntityInstantiator"/>
</bean>
<bean id="nodeTypeRepresentationStrategy" factory-bean="typeRepresentationStrategyFactory" factory-method="getNodeTypeRepresentationStrategy" />
<bean id="relationshipTypeRepresentationStrategy" factory-bean="typeRepresentationStrategyFactory" factory-method="getRelationshipTypeRepresentationStrategy"/>
<bean id="graphEntityInstantiator"
class="org.springframework.data.graph.neo4j.support.node.NodeEntityInstantiator"/>
<bean id="nodeEntityStateFactory" class="org.springframework.data.graph.neo4j.fieldaccess.NodeEntityStateFactory">
<property name="nodeDelegatingFieldAccessorFactory">
<bean class="org.springframework.data.graph.neo4j.fieldaccess.NodeDelegatingFieldAccessorFactory">
<constructor-arg ref="graphDatabaseContext"/>
<constructor-arg ref="graphRepositoryFactory"/>
</bean>
</property>
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="graphRepositoryFactory" ref="graphRepositoryFactory"/>
</bean>
<bean id="relationshipEntityStateFactory" class="org.springframework.data.graph.neo4j.fieldaccess.RelationshipEntityStateFactory">
<property name="graphDatabaseContext" ref="graphDatabaseContext"/>
<property name="graphRepositoryFactory" ref="graphRepositoryFactory"/>
</bean>
<bean id="graphRepositoryFactory" class="org.springframework.data.graph.neo4j.repository.DirectGraphRepositoryFactory">
<constructor-arg ref="graphDatabaseContext" />
</bean>
<!--bean id="transactionManager" class="org.springframework.persistence.transaction.NaiveDoubleTransactionManager" >
<constructor-arg>
<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name="dataSource" ref="dataSource"/>
</bean>
</constructor-arg>
<constructor-arg>
<bean
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="neo4jTransactionManagerService" />
<property name="userTransaction" ref="neo4jUserTransactionService" />
</bean>
</constructor-arg>
</bean-->
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="neo4jTransactionManagerService" />
<property name="userTransaction" ref="neo4jUserTransactionService" />
</bean>
<bean id="neo4jTransactionManagerService" class="org.neo4j.kernel.impl.transaction.SpringTransactionManager" >
<constructor-arg index="0" ref="graphDatabaseService" />
</bean>
<bean id="neo4jUserTransactionService" class="org.neo4j.kernel.impl.transaction.UserTransactionImpl">
<constructor-arg index="0" ref="graphDatabaseService" />
</bean>
<!--bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">
<property name="driverClassName" value="${database.driverClassName}"/>
<property name="url" value="${database.url}"/>
<property name="username" value="${database.username}"/>
<property name="password" value="${database.password}"/>
</bean-->
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="jpaDialect">
<bean class="org.springframework.data.graph.neo4j.jpa.Neo4jJpaDialect"/>
</property>
<property name="persistenceProvider">
<bean class="org.springframework.data.graph.neo4j.jpa.Neo4jPersistenceProvider"/>
</property>
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence-neo4j.xml"/>
</bean>
<!--bean id="neoEntityManager" class="org.springframework.persistence.graph.neo4j.Neo4jEntityManager" scope="prototype"/-->
</beans>