moved shared cross-store code to cross-store project
This commit is contained in:
14
pom.xml
14
pom.xml
@@ -11,11 +11,19 @@
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring.version>3.0.3.RELEASE</spring.version>
|
||||
<aspectj.version>1.6.9</aspectj.version>
|
||||
<aspectj.version>1.6.10.BUILD-SNAPSHOT</aspectj.version>
|
||||
<slf4j.version>1.6.0</slf4j.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<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>
|
||||
<repository>
|
||||
<id>neo4j-public-repository</id>
|
||||
<url>http://m2.neo4j.org </url>
|
||||
@@ -138,8 +146,8 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>data-commons</artifactId>
|
||||
<groupId>org.springframework.datastore</groupId>
|
||||
<artifactId>datastore-cross-store</artifactId>
|
||||
<version>1.0.0.CI-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
package org.springframework.persistence.support;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Try for a constructor taking state: failing that, try a no-arg
|
||||
* constructor and then setUnderlyingNode().
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public abstract class AbstractConstructorEntityInstantiator<BACKING_INTERFACE, STATE> implements EntityInstantiator<BACKING_INTERFACE, STATE> {
|
||||
|
||||
private final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
final public <T extends BACKING_INTERFACE> T createEntityFromState(STATE n, Class<T> c) {
|
||||
try {
|
||||
return fromStateInternal(n, c);
|
||||
} catch (InstantiationException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
final private <T extends BACKING_INTERFACE> T fromStateInternal(STATE n, Class<T> c) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||
// TODO this is fragile
|
||||
Class<? extends STATE> stateInterface = (Class<? extends STATE>) n.getClass().getInterfaces()[0];
|
||||
Constructor<T> nodeConstructor = ClassUtils.getConstructorIfAvailable(c, stateInterface);
|
||||
if (nodeConstructor != null) {
|
||||
// TODO is this the correct way to instantiate or does Spring have a preferred way?
|
||||
log.info("Using " + c + " constructor taking " + stateInterface);
|
||||
return nodeConstructor.newInstance(n);
|
||||
}
|
||||
|
||||
Constructor<T> noArgConstructor = ClassUtils.getConstructorIfAvailable(c);
|
||||
if (noArgConstructor != null) {
|
||||
log.info("Using " + c + " no-arg constructor");
|
||||
T t = noArgConstructor.newInstance();
|
||||
setState(t, n);
|
||||
return t;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(getClass().getSimpleName() + ": entity " + c + " must have either a constructor taking [" + stateInterface +
|
||||
"] or a no-arg constructor and state set method");
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses must implement to set state
|
||||
* @param entity
|
||||
* @param s
|
||||
*/
|
||||
protected abstract void setState(BACKING_INTERFACE entity, STATE s);
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package org.springframework.persistence.support;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Configurable;
|
||||
import org.springframework.persistence.RelatedEntity;
|
||||
|
||||
/**
|
||||
* Abstract superaspect to advise field read and write
|
||||
* and introduce a mixin interface.
|
||||
*
|
||||
* @param <N> type of introduced interface
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
privileged abstract public aspect AbstractMixinFields<N> {
|
||||
|
||||
protected final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// ITDs to add behavior and state to classes
|
||||
//-------------------------------------------------------------------------
|
||||
// Enable Spring DI for all mixed-in objects
|
||||
declare @type: N+: @Configurable;
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Advice for field get/set to delegate to backing Node.
|
||||
//-------------------------------------------------------------------------
|
||||
protected pointcut entityFieldGet(N entity) :
|
||||
get(* N+.*) &&
|
||||
this(entity) &&
|
||||
!(get(@RelatedEntity * *)
|
||||
|| get(* N.*)
|
||||
|| getsNotToAdvise());
|
||||
|
||||
/**
|
||||
* Never matches. Subclasses can override to exempt certain field reads from advice
|
||||
*/
|
||||
protected pointcut getsNotToAdvise();
|
||||
|
||||
protected pointcut entityFieldSet(N entity, Object newVal) :
|
||||
set(* N+.*) &&
|
||||
this(entity) &&
|
||||
args(newVal) &&
|
||||
!(set(@RelatedEntity * *) ||
|
||||
set(* N.*) ||
|
||||
setsNotToAdvise());
|
||||
|
||||
/**
|
||||
* Never matches. Subclasses can override to exempt certain field writes from advice
|
||||
*/
|
||||
protected pointcut setsNotToAdvise();
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package org.springframework.persistence.support;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
/**
|
||||
* Abstract superaspect for aspects that advice
|
||||
* field access with a mixin for all types annotated with
|
||||
* a given annotation.
|
||||
*
|
||||
* @param <ET> annotation on entity
|
||||
* @param <N> type of introduced interface
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
privileged abstract public aspect AbstractTypeAnnotatingMixinFields<ET extends Annotation, N>
|
||||
extends AbstractMixinFields<N> {
|
||||
|
||||
// ITD to introduce N state to Annotated objects
|
||||
declare parents : (@ET *) implements N;
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package org.springframework.persistence.support;
|
||||
|
||||
|
||||
/**
|
||||
* Interface to be implemented by classes that can instantiate and
|
||||
* configure entities.
|
||||
* The framework must do this when creating objects resulting from finders,
|
||||
* even when there may be no no-arg constructor supplied by the user.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public interface EntityInstantiator<BACKING_INTERFACE,STATE> {
|
||||
|
||||
/*
|
||||
* The best solution if available is to add a constructor that takes Node
|
||||
* to each GraphEntity. This means generating an aspect beside every
|
||||
* class as Roo presently does.
|
||||
*
|
||||
* An alternative that does not require Roo
|
||||
* is a user-authored constructor taking Node and calling setUnderlyingNode()
|
||||
* but this is less elegant and pollutes the domain object.
|
||||
*
|
||||
* If the user supplies a no-arg constructor, instantiation can occur by invoking it
|
||||
* prior to calling setUnderlyingNode().
|
||||
*
|
||||
* If the user does NOT supply a no-arg constructor, we must rely on Sun-specific
|
||||
* code to instantiate entities without invoking a constructor.
|
||||
*/
|
||||
|
||||
<T extends BACKING_INTERFACE> T createEntityFromState(STATE s, Class<T> c);
|
||||
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package org.springframework.persistence.transaction;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.DefaultTransactionStatus;
|
||||
|
||||
public class NaiveDoubleTransactionManager implements PlatformTransactionManager {
|
||||
Map<TransactionStatus,TransactionStatus> status=new IdentityHashMap<TransactionStatus, TransactionStatus>();
|
||||
private final PlatformTransactionManager a;
|
||||
|
||||
private final PlatformTransactionManager b;
|
||||
|
||||
public NaiveDoubleTransactionManager(PlatformTransactionManager a, PlatformTransactionManager b) {
|
||||
System.err.println("WARNING: Naive JTA/Neo4j Spring transaction manager--must implement properly");
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit(TransactionStatus ts) throws TransactionException {
|
||||
try {
|
||||
final TransactionStatus tsb = copyTransactionStatus(status.get(ts));
|
||||
try {
|
||||
a.commit(ts);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
System.err.println("Continuing to commit tx despite this:" + t);
|
||||
}
|
||||
try {
|
||||
b.commit(tsb);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
System.err.println("Can't commit tx" + t);
|
||||
throw new TransactionException(t.getMessage(), t) {};
|
||||
}
|
||||
} finally {
|
||||
status.remove(ts);
|
||||
}
|
||||
}
|
||||
|
||||
private TransactionStatus copyTransactionStatus(TransactionStatus ts) {
|
||||
Object t = (ts instanceof DefaultTransactionStatus) ? ((DefaultTransactionStatus) ts).getTransaction() : null;
|
||||
return new DefaultTransactionStatus(t,ts.isNewTransaction(), false, false, false, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransactionStatus getTransaction(TransactionDefinition td)
|
||||
throws TransactionException {
|
||||
TransactionStatus atx = a.getTransaction(td);
|
||||
TransactionStatus btx = b.getTransaction(td);
|
||||
status.put(atx, btx);
|
||||
return atx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback(TransactionStatus ts) throws TransactionException {
|
||||
final TransactionStatus tsb = copyTransactionStatus(status.remove(ts));
|
||||
try {
|
||||
a.rollback(ts);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
System.err.println("Continuing to rollback tx despite this:" + t);
|
||||
}
|
||||
try {
|
||||
b.rollback(tsb);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
System.err.println("Can't rollback tx" + t);
|
||||
throw new TransactionException(t.getMessage(), t) {};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ Import-Template:
|
||||
org.springframework.util.*;version="[3.0.0, 4.0.0)",
|
||||
org.springframework.data.core.*;version="[1.0.0, 2.0.0)",
|
||||
org.springframework.datastore.core.*;version="[1.0.0, 2.0.0)",
|
||||
org.springframework.datastore.persistence.*;version="[1.0.0, 2.0.0)",
|
||||
org.neo4j.*;version="[1.1.0, 2.0.0)",
|
||||
org.aspectj.*;version="[1.6.5, 2.0.0)",
|
||||
org.apache.commons.logging.*;version="[1.1.1, 2.0.0)"
|
||||
|
||||
Reference in New Issue
Block a user