diff --git a/pom.xml b/pom.xml
index d83db4c97..ddeb43d54 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,6 +12,7 @@
spring-data-commons-parent
spring-data-commons-core
spring-data-commons-aspects
+ spring-data-commons-extensions
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java
index f05f5e720..7907550a4 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java
@@ -89,7 +89,7 @@ public class QueryMethod {
}
- public EntityMetadata> getEntityMetadata() {
+ public EntityMetadata> getEntityInformation() {
return new EntityMetadata() {
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/AbstractEntityInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/AbstractEntityInformation.java
index fd715e23e..2a6ed38dc 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/AbstractEntityInformation.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/AbstractEntityInformation.java
@@ -15,6 +15,8 @@
*/
package org.springframework.data.repository.support;
+import java.io.Serializable;
+
import org.springframework.util.Assert;
@@ -24,8 +26,8 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
*/
-public abstract class AbstractEntityInformation implements
- EntityInformation {
+public abstract class AbstractEntityInformation implements
+ EntityInformation {
private final Class domainClass;
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/EntityInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/EntityInformation.java
index 33797d33f..8ccf3b538 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/EntityInformation.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/EntityInformation.java
@@ -15,13 +15,15 @@
*/
package org.springframework.data.repository.support;
+import java.io.Serializable;
+
/**
* Extension of {@link EntityMetadata} to add functionality to query information
* of entity instances.
*
* @author Oliver Gierke
*/
-public interface EntityInformation extends EntityMetadata {
+public interface EntityInformation extends EntityMetadata {
/**
* Returns whether the given entity is considered to be new.
@@ -38,5 +40,12 @@ public interface EntityInformation extends EntityMetadata {
* @param entity must never be {@literal null}
* @return
*/
- Object getId(T entity);
+ ID getId(T entity);
+
+ /**
+ * Returns the type of the id of the entity.
+ *
+ * @return
+ */
+ Class getIdType();
}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/PersistableEntityInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/PersistableEntityInformation.java
index ffb873a39..d99c74314 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/PersistableEntityInformation.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/PersistableEntityInformation.java
@@ -15,6 +15,9 @@
*/
package org.springframework.data.repository.support;
+import java.io.Serializable;
+
+import org.springframework.core.GenericTypeResolver;
import org.springframework.data.domain.Persistable;
@@ -25,18 +28,21 @@ import org.springframework.data.domain.Persistable;
*
* @author Oliver Gierke
*/
-@SuppressWarnings("rawtypes")
-public class PersistableEntityInformation extends
- AbstractEntityInformation {
+public class PersistableEntityInformation, ID extends Serializable> extends
+ AbstractEntityInformation {
+
+ private Class idClass;
/**
* Creates a new {@link PersistableEntityInformation}.
*
* @param domainClass
*/
+ @SuppressWarnings("unchecked")
public PersistableEntityInformation(Class domainClass) {
super(domainClass);
+ this.idClass = (Class) GenericTypeResolver.resolveTypeArgument(domainClass, Persistable.class);
}
@@ -61,8 +67,15 @@ public class PersistableEntityInformation extends
* org.springframework.data.repository.support.IdAware#getId(java.lang.Object
* )
*/
- public Object getId(T entity) {
+ public ID getId(T entity) {
return entity.getId();
}
+
+ /* (non-Javadoc)
+ * @see org.springframework.data.repository.support.EntityInformation#getIdType()
+ */
+ public Class getIdType() {
+ return this.idClass;
+ }
}
\ No newline at end of file
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactoryBeanSupport.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactoryBeanSupport.java
index 00ab4b49b..a576501b9 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactoryBeanSupport.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactoryBeanSupport.java
@@ -15,6 +15,8 @@
*/
package org.springframework.data.repository.support;
+import java.io.Serializable;
+
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Required;
@@ -31,8 +33,8 @@ import org.springframework.util.Assert;
* @author Oliver Gierke
* @param the type of the repository
*/
-public abstract class RepositoryFactoryBeanSupport>
- implements FactoryBean, InitializingBean {
+public abstract class RepositoryFactoryBeanSupport, S, ID extends Serializable>
+ implements InitializingBean, RepositoryFactoryInformation, FactoryBean {
private RepositoryFactorySupport factory;
@@ -75,6 +77,25 @@ public abstract class RepositoryFactoryBeanSupport>
this.customImplementation = customImplementation;
}
+
+ /* (non-Javadoc)
+ * @see org.springframework.data.repository.support.EntityMetadataProvider#getEntityMetadata()
+ */
+ public EntityInformation getEntityInformation() {
+
+ RepositoryMetadata repositoryMetadata = factory.getRepositoryMetadata(repositoryInterface);
+ return (EntityInformation) factory.getEntityInformation(repositoryMetadata.getDomainClass());
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.springframework.data.repository.support.RepositoryFactoryInformation#getRepositoryInterface()
+ */
+ @Override
+ public Class extends T> getRepositoryInterface() {
+
+ return repositoryInterface;
+ }
/*
* (non-Javadoc)
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactoryInformation.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactoryInformation.java
new file mode 100644
index 000000000..1a2a0831c
--- /dev/null
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactoryInformation.java
@@ -0,0 +1,45 @@
+/*
+ * 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.repository.support;
+
+import java.io.Serializable;
+
+import org.springframework.data.repository.Repository;
+
+
+/**
+ * Interface for components that can provide {@link EntityInformation} this
+ * interface
+ *
+ * @author Oliver Gierke
+ */
+public interface RepositoryFactoryInformation {
+
+ /**
+ * Returns {@link EntityInformation} the repository factory is using.
+ *
+ * @return
+ */
+ EntityInformation getEntityInformation();
+
+
+ /**
+ * Returns the interface of the {@link Repository} the factory will create.
+ *
+ * @return
+ */
+ Class extends Repository> getRepositoryInterface();
+}
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactorySupport.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactorySupport.java
index ecb978219..c6b8477be 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactorySupport.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/RepositoryFactorySupport.java
@@ -17,6 +17,7 @@ package org.springframework.data.repository.support;
import static org.springframework.util.ReflectionUtils.*;
+import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -124,8 +125,7 @@ public abstract class RepositoryFactorySupport {
Object customImplementation) {
RepositoryMetadata metadata =
- new DefaultRepositoryMetadata(repositoryInterface,
- getRepositoryBaseClass(repositoryInterface));
+ getRepositoryMetadata(repositoryInterface);
validate(metadata, customImplementation);
@@ -145,6 +145,29 @@ public abstract class RepositoryFactorySupport {
return (T) result.getProxy();
}
+
+
+ /**
+ * Returns the {@link RepositoryMetadata} for the given repository interface.
+ *
+ * @param repositoryInterface
+ * @return
+ */
+ protected RepositoryMetadata getRepositoryMetadata(Class> repositoryInterface) {
+
+ return new DefaultRepositoryMetadata(repositoryInterface, getRepositoryBaseClass(repositoryInterface));
+ }
+
+
+ /**
+ * Returns the {@link EntityInformation} for the given domain class.
+ *
+ * @param the entity type
+ * @param the id type
+ * @param domainClass
+ * @return
+ */
+ public abstract EntityInformation getEntityInformation(Class domainClass);
/**
diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/TransactionalRepositoryFactoryBeanSupport.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/TransactionalRepositoryFactoryBeanSupport.java
index 4a189163f..ec236563b 100644
--- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/TransactionalRepositoryFactoryBeanSupport.java
+++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/support/TransactionalRepositoryFactoryBeanSupport.java
@@ -15,6 +15,8 @@
*/
package org.springframework.data.repository.support;
+import java.io.Serializable;
+
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.ListableBeanFactory;
@@ -32,8 +34,8 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
*/
-public abstract class TransactionalRepositoryFactoryBeanSupport>
- extends RepositoryFactoryBeanSupport implements BeanFactoryAware {
+public abstract class TransactionalRepositoryFactoryBeanSupport, S, ID extends Serializable>
+ extends RepositoryFactoryBeanSupport implements BeanFactoryAware {
private String transactionManagerName = TxUtils.DEFAULT_TRANSACTION_MANAGER;
private RepositoryProxyPostProcessor txPostProcessor;
diff --git a/spring-data-commons-core/src/test/java/org/springframework/data/repository/support/AbstractEntityInformationUnitTests.java b/spring-data-commons-core/src/test/java/org/springframework/data/repository/support/AbstractEntityInformationUnitTests.java
index 9b114f0b2..aaac8c846 100644
--- a/spring-data-commons-core/src/test/java/org/springframework/data/repository/support/AbstractEntityInformationUnitTests.java
+++ b/spring-data-commons-core/src/test/java/org/springframework/data/repository/support/AbstractEntityInformationUnitTests.java
@@ -18,6 +18,8 @@ package org.springframework.data.repository.support;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
+import java.io.Serializable;
+
import org.junit.Test;
@@ -38,14 +40,14 @@ public class AbstractEntityInformationUnitTests {
@Test
public void considersEntityNewIfGetIdReturnsNull() throws Exception {
- EntityInformation