CLASSES_TO_DEPEND = Arrays.asList(JPA_PACKAGE
+ + "LocalContainerEntityManagerFactoryBean", JPA_PACKAGE + "LocalEntityManagerFactoryBean");
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#
+ * postProcessBeanFactory
+ * (org.springframework.beans.factory.config.ConfigurableListableBeanFactory
+ * )
+ */
+ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#
- * postProcessBeanFactory
- * (org.springframework.beans.factory.config.ConfigurableListableBeanFactory
- * )
- */
- public void postProcessBeanFactory(
- ConfigurableListableBeanFactory beanFactory) {
+ if (!isSpringConfigured(beanFactory)) {
+ return;
+ }
- if (!isSpringConfigured(beanFactory)) {
- return;
- }
+ for (String beanName : beanFactory.getBeanDefinitionNames()) {
- for (String beanName : beanFactory.getBeanDefinitionNames()) {
+ BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
- BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
+ if (CLASSES_TO_DEPEND.contains(definition.getBeanClassName())) {
+ definition.setDependsOn(StringUtils.addStringToArray(definition.getDependsOn(),
+ BEAN_CONFIGURER_ASPECT_BEAN_NAME));
+ }
+ }
- if (CLASSES_TO_DEPEND.contains(definition.getBeanClassName())) {
- definition.setDependsOn(StringUtils.addStringToArray(
- definition.getDependsOn(),
- BEAN_CONFIGURER_ASPECT_BEAN_NAME));
- }
- }
+ for (String beanName : BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, AuditorAware.class, true,
+ false)) {
+ BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
+ definition.setLazyInit(true);
+ }
+ }
- for (String beanName : BeanFactoryUtils
- .beanNamesForTypeIncludingAncestors(beanFactory,
- AuditorAware.class, true, false)) {
- BeanDefinition definition = beanFactory.getBeanDefinition(beanName);
- definition.setLazyInit(true);
- }
- }
+ /**
+ * Returns whether we have a bean factory for which {@code <context:spring-configured>} was activated.
+ *
+ * @param factory
+ * @return
+ */
+ private boolean isSpringConfigured(BeanFactory factory) {
-
- /**
- * Returns whether we have a bean factory for which
- * {@code <context:spring-configured>} was activated.
- *
- * @param factory
- * @return
- */
- private boolean isSpringConfigured(BeanFactory factory) {
-
- try {
- factory.getBean(BEAN_CONFIGURER_ASPECT_BEAN_NAME);
- return true;
- } catch (NoSuchBeanDefinitionException e) {
- return false;
- }
- }
+ try {
+ factory.getBean(BEAN_CONFIGURER_ASPECT_BEAN_NAME);
+ return true;
+ } catch (NoSuchBeanDefinitionException e) {
+ return false;
+ }
+ }
}
diff --git a/src/main/java/org/springframework/data/jpa/domain/support/AuditingEntityListener.java b/src/main/java/org/springframework/data/jpa/domain/support/AuditingEntityListener.java
index 6f4047d8b..4e63026e5 100644
--- a/src/main/java/org/springframework/data/jpa/domain/support/AuditingEntityListener.java
+++ b/src/main/java/org/springframework/data/jpa/domain/support/AuditingEntityListener.java
@@ -27,11 +27,9 @@ import org.springframework.data.domain.Auditable;
import org.springframework.data.domain.AuditorAware;
import org.springframework.util.Assert;
-
/**
- * JPA entity listener to capture auditing information on persiting and updating
- * entities. To get this one flying be sure you configure it as entity listener
- * in your {@code orm.xml} as follows:
+ * JPA entity listener to capture auditing information on persiting and updating entities. To get this one flying be
+ * sure you configure it as entity listener in your {@code orm.xml} as follows:
*
*
* <persistence-unit-metadata>
@@ -54,167 +52,150 @@ import org.springframework.util.Assert;
@Configurable
public class AuditingEntityListener implements InitializingBean {
- private static final Logger LOG = LoggerFactory
- .getLogger(AuditingEntityListener.class);
+ private static final Logger LOG = LoggerFactory.getLogger(AuditingEntityListener.class);
- private AuditorAware auditorAware;
+ private AuditorAware auditorAware;
- private boolean dateTimeForNow = true;
- private boolean modifyOnCreation = true;
+ private boolean dateTimeForNow = true;
+ private boolean modifyOnCreation = true;
+ /**
+ * Setter to inject a {@code AuditorAware} component to retrieve the current auditor.
+ *
+ * @param auditorAware the auditorAware to set
+ */
+ public void setAuditorAware(final AuditorAware auditorAware) {
- /**
- * Setter to inject a {@code AuditorAware} component to retrieve the current
- * auditor.
- *
- * @param auditorAware the auditorAware to set
- */
- public void setAuditorAware(final AuditorAware auditorAware) {
+ Assert.notNull(auditorAware);
+ this.auditorAware = auditorAware;
+ }
- Assert.notNull(auditorAware);
- this.auditorAware = auditorAware;
- }
+ /**
+ * Setter do determine if {@link Auditable#setCreatedDate(DateTime)} and
+ * {@link Auditable#setLastModifiedDate(DateTime)} shall be filled with the current Java time. Defaults to
+ * {@code true}. One might set this to {@code false} to use database features to set entity time.
+ *
+ * @param dateTimeForNow the dateTimeForNow to set
+ */
+ public void setDateTimeForNow(boolean dateTimeForNow) {
+ this.dateTimeForNow = dateTimeForNow;
+ }
- /**
- * Setter do determine if {@link Auditable#setCreatedDate(DateTime)} and
- * {@link Auditable#setLastModifiedDate(DateTime)} shall be filled with the
- * current Java time. Defaults to {@code true}. One might set this to
- * {@code false} to use database features to set entity time.
- *
- * @param dateTimeForNow the dateTimeForNow to set
- */
- public void setDateTimeForNow(boolean dateTimeForNow) {
+ /**
+ * Set this to false if you want to treat entity creation as modification and thus set the current date as
+ * modification date, too. Defaults to {@code true}.
+ *
+ * @param modifyOnCreation if modification information shall be set on creation, too
+ */
+ public void setModifyOnCreation(final boolean modifyOnCreation) {
- this.dateTimeForNow = dateTimeForNow;
- }
+ this.modifyOnCreation = modifyOnCreation;
+ }
+ /**
+ * Sets modification and creation date and auditor on the target object in case it implements {@link Auditable} on
+ * persist events.
+ *
+ * @param target
+ */
+ @PrePersist
+ public void touchForCreate(Object target) {
- /**
- * Set this to false if you want to treat entity creation as modification
- * and thus set the current date as modification date, too. Defaults to
- * {@code true}.
- *
- * @param modifyOnCreation if modification information shall be set on
- * creation, too
- */
- public void setModifyOnCreation(final boolean modifyOnCreation) {
+ touch(target, true);
+ }
- this.modifyOnCreation = modifyOnCreation;
- }
+ /**
+ * Sets modification and creation date and auditor on the target object in case it implements {@link Auditable} on
+ * update events.
+ *
+ * @param target
+ */
+ @PreUpdate
+ public void touchForUpdate(Object target) {
+ touch(target, false);
+ }
- /**
- * Sets modification and creation date and auditor on the target object in
- * case it implements {@link Auditable} on persist events.
- *
- * @param target
- */
- @PrePersist
- public void touchForCreate(Object target) {
+ private void touch(Object target, boolean isNew) {
- touch(target, true);
- }
+ if (!(target instanceof Auditable)) {
+ return;
+ }
+ @SuppressWarnings("unchecked")
+ Auditable auditable = (Auditable) target;
- /**
- * Sets modification and creation date and auditor on the target object in
- * case it implements {@link Auditable} on update events.
- *
- * @param target
- */
- @PreUpdate
- public void touchForUpdate(Object target) {
+ T auditor = touchAuditor(auditable, isNew);
+ DateTime now = dateTimeForNow ? touchDate(auditable, isNew) : null;
- touch(target, false);
- }
+ Object defaultedNow = now == null ? "not set" : now;
+ Object defaultedAuditor = auditor == null ? "unknown" : auditor;
+ LOG.debug("Touched {} - Last modification at {} by {}", new Object[] { auditable, defaultedNow, defaultedAuditor });
+ }
- private void touch(Object target, boolean isNew) {
+ /**
+ * Sets modifying and creating auditioner. Creating auditioner is only set on new auditables.
+ *
+ * @param auditable
+ * @return
+ */
+ private T touchAuditor(final Auditable auditable, boolean isNew) {
- if (!(target instanceof Auditable)) {
- return;
- }
+ if (null == auditorAware) {
+ return null;
+ }
- @SuppressWarnings("unchecked")
- Auditable auditable = (Auditable) target;
+ T auditor = auditorAware.getCurrentAuditor();
- T auditor = touchAuditor(auditable, isNew);
- DateTime now = dateTimeForNow ? touchDate(auditable, isNew) : null;
+ if (isNew) {
- Object defaultedNow = now == null ? "not set" : now;
- Object defaultedAuditor = auditor == null ? "unknown" : auditor;
+ auditable.setCreatedBy(auditor);
- LOG.debug("Touched {} - Last modification at {} by {}", new Object[] {
- auditable, defaultedNow, defaultedAuditor });
- }
+ if (!modifyOnCreation) {
+ return auditor;
+ }
+ }
+ auditable.setLastModifiedBy(auditor);
- /**
- * Sets modifying and creating auditioner. Creating auditioner is only set
- * on new auditables.
- *
- * @param auditable
- * @return
- */
- private T touchAuditor(final Auditable auditable, boolean isNew) {
+ return auditor;
+ }
- if (null == auditorAware) {
- return null;
- }
+ /**
+ * Touches the auditable regarding modification and creation date. Creation date is only set on new auditables.
+ *
+ * @param auditable
+ * @return
+ */
+ private DateTime touchDate(final Auditable auditable, boolean isNew) {
- T auditor = auditorAware.getCurrentAuditor();
+ DateTime now = new DateTime();
- if (isNew) {
+ if (isNew) {
+ auditable.setCreatedDate(now);
- auditable.setCreatedBy(auditor);
+ if (!modifyOnCreation) {
+ return now;
+ }
+ }
- if (!modifyOnCreation) {
- return auditor;
- }
- }
+ auditable.setLastModifiedDate(now);
- auditable.setLastModifiedBy(auditor);
+ return now;
+ }
- return auditor;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
+ */
+ public void afterPropertiesSet() {
-
- /**
- * Touches the auditable regarding modification and creation date. Creation
- * date is only set on new auditables.
- *
- * @param auditable
- * @return
- */
- private DateTime touchDate(final Auditable auditable, boolean isNew) {
-
- DateTime now = new DateTime();
-
- if (isNew) {
- auditable.setCreatedDate(now);
-
- if (!modifyOnCreation) {
- return now;
- }
- }
-
- auditable.setLastModifiedDate(now);
-
- return now;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
- */
- public void afterPropertiesSet() {
-
- if (auditorAware == null) {
- LOG.debug("No AuditorAware set! Auditing will not be applied!");
- }
- }
+ if (auditorAware == null) {
+ LOG.debug("No AuditorAware set! Auditing will not be applied!");
+ }
+ }
}
diff --git a/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java
index e0c769d87..48445d2c6 100644
--- a/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java
+++ b/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java
@@ -23,64 +23,55 @@ import javax.persistence.EntityManager;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.PagingAndSortingRepository;
-
/**
- * JPA specific extension of
- * {@link org.springframework.data.repository.Repository}.
+ * JPA specific extension of {@link org.springframework.data.repository.Repository}.
*
* @author Oliver Gierke
*/
-public interface JpaRepository extends
- PagingAndSortingRepository {
+public interface JpaRepository extends PagingAndSortingRepository {
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.data.repository.Repository#findAll()
- */
- List findAll();
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.springframework.data.repository.Repository#findAll()
+ */
+ List findAll();
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.springframework.data.repository.PagingAndSortingRepository#findAll
+ * (org.springframework.data.domain.Sort)
+ */
+ List findAll(Sort sort);
- /*
- * (non-Javadoc)
- *
- * @see
- * org.springframework.data.repository.PagingAndSortingRepository#findAll
- * (org.springframework.data.domain.Sort)
- */
- List findAll(Sort sort);
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.springframework.data.repository.Repository#save(java.lang.Iterable)
+ */
+ List save(Iterable extends T> entities);
+ /**
+ * Flushes all pending changes to the database.
+ */
+ void flush();
- /*
- * (non-Javadoc)
- *
- * @see
- * org.springframework.data.repository.Repository#save(java.lang.Iterable)
- */
- List save(Iterable extends T> entities);
+ /**
+ * Saves an entity and flushes changes instantly.
+ *
+ * @param entity
+ * @return the saved entity
+ */
+ T saveAndFlush(T entity);
-
- /**
- * Flushes all pending changes to the database.
- */
- void flush();
-
-
- /**
- * Saves an entity and flushes changes instantly.
- *
- * @param entity
- * @return the saved entity
- */
- T saveAndFlush(T entity);
-
-
- /**
- * Deletes the given entities in a batch which means it will create a single
- * {@link Query}. Assume that we will clear the {@link EntityManager} after
- * the call.
- *
- * @param entities
- */
- void deleteInBatch(Iterable entities);
+ /**
+ * Deletes the given entities in a batch which means it will create a single {@link Query}. Assume that we will clear
+ * the {@link EntityManager} after the call.
+ *
+ * @param entities
+ */
+ void deleteInBatch(Iterable entities);
}
diff --git a/src/main/java/org/springframework/data/jpa/repository/JpaSpecificationExecutor.java b/src/main/java/org/springframework/data/jpa/repository/JpaSpecificationExecutor.java
index 633c84f4e..fb37dec7f 100644
--- a/src/main/java/org/springframework/data/jpa/repository/JpaSpecificationExecutor.java
+++ b/src/main/java/org/springframework/data/jpa/repository/JpaSpecificationExecutor.java
@@ -22,61 +22,52 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
-
/**
- * Interface to allow execution of {@link Specification}s based on the JPA
- * criteria API.
+ * Interface to allow execution of {@link Specification}s based on the JPA criteria API.
*
* @author Oliver Gierke
*/
public interface JpaSpecificationExecutor {
- /**
- * Returns a single entity matching the given {@link Specification}.
- *
- * @param spec
- * @return
- */
- T findOne(Specification spec);
+ /**
+ * Returns a single entity matching the given {@link Specification}.
+ *
+ * @param spec
+ * @return
+ */
+ T findOne(Specification spec);
+ /**
+ * Returns all entities matching the given {@link Specification}.
+ *
+ * @param spec
+ * @return
+ */
+ List findAll(Specification spec);
- /**
- * Returns all entities matching the given {@link Specification}.
- *
- * @param spec
- * @return
- */
- List findAll(Specification spec);
+ /**
+ * Returns a {@link Page} of entities matching the given {@link Specification}.
+ *
+ * @param spec
+ * @param pageable
+ * @return
+ */
+ Page findAll(Specification spec, Pageable pageable);
+ /**
+ * Returns all entities matching the given {@link Specification} and {@link Sort}.
+ *
+ * @param spec
+ * @param sort
+ * @return
+ */
+ List findAll(Specification spec, Sort sort);
- /**
- * Returns a {@link Page} of entities matching the given
- * {@link Specification}.
- *
- * @param spec
- * @param pageable
- * @return
- */
- Page findAll(Specification spec, Pageable pageable);
-
-
- /**
- * Returns all entities matching the given {@link Specification} and
- * {@link Sort}.
- *
- * @param spec
- * @param sort
- * @return
- */
- List findAll(Specification spec, Sort sort);
-
-
- /**
- * Returns the number of instances that the given {@link Specification} will
- * return.
- *
- * @param spec the {@link Specification} to count instances for
- * @return the number of instances
- */
- long count(Specification spec);
+ /**
+ * Returns the number of instances that the given {@link Specification} will return.
+ *
+ * @param spec the {@link Specification} to count instances for
+ * @return the number of instances
+ */
+ long count(Specification spec);
}
diff --git a/src/main/java/org/springframework/data/jpa/repository/Modifying.java b/src/main/java/org/springframework/data/jpa/repository/Modifying.java
index e29531d0d..b2c38b291 100644
--- a/src/main/java/org/springframework/data/jpa/repository/Modifying.java
+++ b/src/main/java/org/springframework/data/jpa/repository/Modifying.java
@@ -21,7 +21,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-
/**
* Indicates a method should be regarded as modifying query.
*
@@ -32,11 +31,10 @@ import java.lang.annotation.Target;
@Documented
public @interface Modifying {
- /**
- * Defines whether we should clear the underlying persistence context after
- * excuting the modifying query.
- *
- * @return
- */
- boolean clearAutomatically() default false;
+ /**
+ * Defines whether we should clear the underlying persistence context after excuting the modifying query.
+ *
+ * @return
+ */
+ boolean clearAutomatically() default false;
}
diff --git a/src/main/java/org/springframework/data/jpa/repository/Query.java b/src/main/java/org/springframework/data/jpa/repository/Query.java
index 4a226ba01..c2fad74dc 100644
--- a/src/main/java/org/springframework/data/jpa/repository/Query.java
+++ b/src/main/java/org/springframework/data/jpa/repository/Query.java
@@ -21,7 +21,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-
/**
* Annotation to declare finder queries directly on repository methods.
*
@@ -32,8 +31,7 @@ import java.lang.annotation.Target;
@Documented
public @interface Query {
- String value() default "";
+ String value() default "";
-
- String countQuery() default "";
+ String countQuery() default "";
}
diff --git a/src/main/java/org/springframework/data/jpa/repository/QueryHints.java b/src/main/java/org/springframework/data/jpa/repository/QueryHints.java
index da814a99d..d375cab4c 100644
--- a/src/main/java/org/springframework/data/jpa/repository/QueryHints.java
+++ b/src/main/java/org/springframework/data/jpa/repository/QueryHints.java
@@ -22,13 +22,11 @@ import java.lang.annotation.Target;
import javax.persistence.QueryHint;
-
/**
- * Wrapper annotation to allow {@link QueryHint} annotations to be bound to
- * methods. It will be evaluated when using {@link Query} on a query method or
- * if you derive the query from the method name. If you rely on named queries
- * either use the XML or annotation based way to declare {@link QueryHint}s in
- * combination with the actual named query declaration.
+ * Wrapper annotation to allow {@link QueryHint} annotations to be bound to methods. It will be evaluated when using
+ * {@link Query} on a query method or if you derive the query from the method name. If you rely on named queries either
+ * use the XML or annotation based way to declare {@link QueryHint}s in combination with the actual named query
+ * declaration.
*
* @author Oliver Gierke
*/
@@ -36,5 +34,5 @@ import javax.persistence.QueryHint;
@Retention(RetentionPolicy.RUNTIME)
public @interface QueryHints {
- QueryHint[] value() default {};
+ QueryHint[] value() default {};
}
diff --git a/src/main/java/org/springframework/data/jpa/repository/config/AuditingBeanDefinitionParser.java b/src/main/java/org/springframework/data/jpa/repository/config/AuditingBeanDefinitionParser.java
index 304d3fa14..915d33914 100644
--- a/src/main/java/org/springframework/data/jpa/repository/config/AuditingBeanDefinitionParser.java
+++ b/src/main/java/org/springframework/data/jpa/repository/config/AuditingBeanDefinitionParser.java
@@ -29,117 +29,94 @@ import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
-
/**
- * {@link BeanDefinitionParser} for the {@code auditing} element. Sets up an
- * AudE
+ * {@link BeanDefinitionParser} for the {@code auditing} element. Sets up an AudE
*
* @author Oliver Gierke
*/
public class AuditingBeanDefinitionParser implements BeanDefinitionParser {
- static final String AUDITING_ENTITY_LISTENER_CLASS_NAME =
- "org.springframework.data.jpa.domain.support.AuditingEntityListener";
- private static final String AUDITING_BFPP_CLASS_NAME =
- "org.springframework.data.jpa.domain.support.AuditingBeanFactoryPostProcessor";
+ static final String AUDITING_ENTITY_LISTENER_CLASS_NAME = "org.springframework.data.jpa.domain.support.AuditingEntityListener";
+ private static final String AUDITING_BFPP_CLASS_NAME = "org.springframework.data.jpa.domain.support.AuditingBeanFactoryPostProcessor";
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.
+ * w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
+ */
+ public BeanDefinition parse(Element element, ParserContext parser) {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.
- * w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
- */
- public BeanDefinition parse(Element element, ParserContext parser) {
+ new SpringConfiguredBeanDefinitionParser().parse(element, parser);
- new SpringConfiguredBeanDefinitionParser().parse(element, parser);
+ BeanDefinitionBuilder builder = rootBeanDefinition(AUDITING_ENTITY_LISTENER_CLASS_NAME);
+ builder.setScope("prototype");
- BeanDefinitionBuilder builder =
- rootBeanDefinition(AUDITING_ENTITY_LISTENER_CLASS_NAME);
- builder.setScope("prototype");
+ String auditorAwareRef = element.getAttribute("auditor-aware-ref");
- String auditorAwareRef = element.getAttribute("auditor-aware-ref");
+ if (StringUtils.hasText(auditorAwareRef)) {
+ builder.addPropertyValue("auditorAware", createLazyInitTargetSourceBeanDefinition(auditorAwareRef));
+ }
- if (StringUtils.hasText(auditorAwareRef)) {
- builder.addPropertyValue("auditorAware",
- createLazyInitTargetSourceBeanDefinition(auditorAwareRef));
- }
+ builder.addPropertyValue("dateTimeForNow", element.getAttribute("set-dates"));
- builder.addPropertyValue("dateTimeForNow",
- element.getAttribute("set-dates"));
+ registerInfrastructureBeanWithId(builder.getRawBeanDefinition(), AUDITING_ENTITY_LISTENER_CLASS_NAME, parser,
+ element);
- registerInfrastructureBeanWithId(builder.getRawBeanDefinition(),
- AUDITING_ENTITY_LISTENER_CLASS_NAME, parser, element);
+ RootBeanDefinition def = new RootBeanDefinition();
+ def.setBeanClassName(AUDITING_BFPP_CLASS_NAME);
+ registerInfrastructureBeanWithId(def, AUDITING_BFPP_CLASS_NAME, parser, element);
- RootBeanDefinition def = new RootBeanDefinition();
- def.setBeanClassName(AUDITING_BFPP_CLASS_NAME);
- registerInfrastructureBeanWithId(def, AUDITING_BFPP_CLASS_NAME, parser,
- element);
+ return null;
+ }
- return null;
- }
+ private BeanDefinition createLazyInitTargetSourceBeanDefinition(String auditorAwareRef) {
+ BeanDefinitionBuilder targetSourceBuilder = rootBeanDefinition(LazyInitTargetSource.class);
+ targetSourceBuilder.addPropertyValue("targetBeanName", auditorAwareRef);
- private BeanDefinition createLazyInitTargetSourceBeanDefinition(
- String auditorAwareRef) {
+ BeanDefinitionBuilder builder = rootBeanDefinition(ProxyFactoryBean.class);
+ builder.addPropertyValue("targetSource", targetSourceBuilder.getBeanDefinition());
- BeanDefinitionBuilder targetSourceBuilder =
- rootBeanDefinition(LazyInitTargetSource.class);
- targetSourceBuilder.addPropertyValue("targetBeanName", auditorAwareRef);
+ return builder.getBeanDefinition();
+ }
- BeanDefinitionBuilder builder =
- rootBeanDefinition(ProxyFactoryBean.class);
- builder.addPropertyValue("targetSource",
- targetSourceBuilder.getBeanDefinition());
+ private void registerInfrastructureBeanWithId(AbstractBeanDefinition def, String id, ParserContext context,
+ Element element) {
- return builder.getBeanDefinition();
- }
+ def.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
+ def.setSource(context.extractSource(element));
+ context.registerBeanComponent(new BeanComponentDefinition(def, id));
+ }
+ /**
+ * Copied code of SpringConfiguredBeanDefinitionParser until this class gets public.
+ *
+ * @see http://jira.springframework.org/browse/SPR-7340
+ * @author Juergen Hoeller
+ */
+ private static class SpringConfiguredBeanDefinitionParser implements BeanDefinitionParser {
- private void registerInfrastructureBeanWithId(AbstractBeanDefinition def,
- String id, ParserContext context, Element element) {
+ /**
+ * The bean name of the internally managed bean configurer aspect.
+ */
+ private static final String BEAN_CONFIGURER_ASPECT_BEAN_NAME = "org.springframework.context.config.internalBeanConfigurerAspect";
- def.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
- def.setSource(context.extractSource(element));
- context.registerBeanComponent(new BeanComponentDefinition(def, id));
- }
+ private static final String BEAN_CONFIGURER_ASPECT_CLASS_NAME = "org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect";
- /**
- * Copied code of SpringConfiguredBeanDefinitionParser until this class gets
- * public.
- *
- * @see http://jira.springframework.org/browse/SPR-7340
- * @author Juergen Hoeller
- */
- private static class SpringConfiguredBeanDefinitionParser implements
- BeanDefinitionParser {
+ public BeanDefinition parse(Element element, ParserContext parserContext) {
- /**
- * The bean name of the internally managed bean configurer aspect.
- */
- private static final String BEAN_CONFIGURER_ASPECT_BEAN_NAME =
- "org.springframework.context.config.internalBeanConfigurerAspect";
+ if (!parserContext.getRegistry().containsBeanDefinition(BEAN_CONFIGURER_ASPECT_BEAN_NAME)) {
+ RootBeanDefinition def = new RootBeanDefinition();
+ def.setBeanClassName(BEAN_CONFIGURER_ASPECT_CLASS_NAME);
+ def.setFactoryMethodName("aspectOf");
- private static final String BEAN_CONFIGURER_ASPECT_CLASS_NAME =
- "org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect";
-
-
- public BeanDefinition parse(Element element, ParserContext parserContext) {
-
- if (!parserContext.getRegistry().containsBeanDefinition(
- BEAN_CONFIGURER_ASPECT_BEAN_NAME)) {
- RootBeanDefinition def = new RootBeanDefinition();
- def.setBeanClassName(BEAN_CONFIGURER_ASPECT_CLASS_NAME);
- def.setFactoryMethodName("aspectOf");
-
- def.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
- def.setSource(parserContext.extractSource(element));
- parserContext
- .registerBeanComponent(new BeanComponentDefinition(def,
- BEAN_CONFIGURER_ASPECT_BEAN_NAME));
- }
- return null;
- }
- }
+ def.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
+ def.setSource(parserContext.extractSource(element));
+ parserContext.registerBeanComponent(new BeanComponentDefinition(def, BEAN_CONFIGURER_ASPECT_BEAN_NAME));
+ }
+ return null;
+ }
+ }
}
diff --git a/src/main/java/org/springframework/data/jpa/repository/config/JpaRepositoryConfigDefinitionParser.java b/src/main/java/org/springframework/data/jpa/repository/config/JpaRepositoryConfigDefinitionParser.java
index 79e5ba69c..d7215e717 100644
--- a/src/main/java/org/springframework/data/jpa/repository/config/JpaRepositoryConfigDefinitionParser.java
+++ b/src/main/java/org/springframework/data/jpa/repository/config/JpaRepositoryConfigDefinitionParser.java
@@ -26,132 +26,106 @@ import org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcesso
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
-
/**
- * Parser to create bean definitions for repositories namespace. Registers bean
- * definitions for repositories as well as
- * {@code PersistenceAnnotationBeanPostProcessor} and
- * {@code PersistenceExceptionTranslationPostProcessor} to transparently inject
- * entity manager factory instance and apply exception translation.
+ * Parser to create bean definitions for repositories namespace. Registers bean definitions for repositories as well as
+ * {@code PersistenceAnnotationBeanPostProcessor} and {@code PersistenceExceptionTranslationPostProcessor} to
+ * transparently inject entity manager factory instance and apply exception translation.
*
- * The definition parser allows two ways of configuration. Either it looks up
- * the manually defined repository instances or scans the defined domain package
- * for candidates for repositories.
+ * The definition parser allows two ways of configuration. Either it looks up the manually defined repository instances
+ * or scans the defined domain package for candidates for repositories.
*
* @author Oliver Gierke
* @author Eberhard Wolff
* @author Gil Markham
*/
-class JpaRepositoryConfigDefinitionParser
- extends
- AbstractRepositoryConfigDefinitionParser {
+class JpaRepositoryConfigDefinitionParser extends
+ AbstractRepositoryConfigDefinitionParser {
- private static final Class> PAB_POST_PROCESSOR =
- PersistenceAnnotationBeanPostProcessor.class;
- private static final Class> PET_POST_PROCESSOR =
- PersistenceExceptionTranslationPostProcessor.class;
+ private static final Class> PAB_POST_PROCESSOR = PersistenceAnnotationBeanPostProcessor.class;
+ private static final Class> PET_POST_PROCESSOR = PersistenceExceptionTranslationPostProcessor.class;
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.springframework.data.repository.config.
+ * AbstractRepositoryConfigDefinitionParser
+ * #getGlobalRepositoryConfigInformation(org.w3c.dom.Element)
+ */
+ @Override
+ protected SimpleJpaRepositoryConfiguration getGlobalRepositoryConfigInformation(Element element) {
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.data.repository.config.
- * AbstractRepositoryConfigDefinitionParser
- * #getGlobalRepositoryConfigInformation(org.w3c.dom.Element)
- */
- @Override
- protected SimpleJpaRepositoryConfiguration getGlobalRepositoryConfigInformation(
- Element element) {
+ return new SimpleJpaRepositoryConfiguration(element);
+ }
- return new SimpleJpaRepositoryConfiguration(element);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.springframework.data.repository.config.
+ * AbstractRepositoryConfigDefinitionParser
+ * #postProcessBeanDefinition(org.springframework
+ * .data.repository.config.SingleRepositoryConfigInformation,
+ * org.springframework.beans.factory.support.BeanDefinitionBuilder,
+ * org.springframework.beans.factory.support.BeanDefinitionRegistry,
+ * java.lang.Object)
+ */
+ @Override
+ protected void postProcessBeanDefinition(JpaRepositoryConfiguration ctx, BeanDefinitionBuilder builder,
+ BeanDefinitionRegistry registry, Object beanSource) {
+ String entityManagerRef = ctx.getEntityManagerFactoryRef();
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.data.repository.config.
- * AbstractRepositoryConfigDefinitionParser
- * #postProcessBeanDefinition(org.springframework
- * .data.repository.config.SingleRepositoryConfigInformation,
- * org.springframework.beans.factory.support.BeanDefinitionBuilder,
- * org.springframework.beans.factory.support.BeanDefinitionRegistry,
- * java.lang.Object)
- */
- @Override
- protected void postProcessBeanDefinition(JpaRepositoryConfiguration ctx,
- BeanDefinitionBuilder builder, BeanDefinitionRegistry registry,
- Object beanSource) {
+ if (StringUtils.hasText(entityManagerRef)) {
+ builder.addPropertyValue("entityManager", getEntityManagerBeanDefinitionFor(entityManagerRef, beanSource));
+ }
+ }
- String entityManagerRef = ctx.getEntityManagerFactoryRef();
+ /**
+ * Creates an anonymous factory to extract the actual {@link javax.persistence.EntityManager} from the
+ * {@link javax.persistence.EntityManagerFactory} bean name reference.
+ *
+ * @param entityManagerFactoryBeanName
+ * @param source
+ * @return
+ */
+ private BeanDefinition getEntityManagerBeanDefinitionFor(String entityManagerFactoryBeanName, Object source) {
- if (StringUtils.hasText(entityManagerRef)) {
- builder.addPropertyValue(
- "entityManager",
- getEntityManagerBeanDefinitionFor(entityManagerRef,
- beanSource));
- }
- }
+ BeanDefinitionBuilder builder = BeanDefinitionBuilder
+ .rootBeanDefinition("org.springframework.orm.jpa.SharedEntityManagerCreator");
+ builder.setFactoryMethod("createSharedEntityManager");
+ builder.addConstructorArgReference(entityManagerFactoryBeanName);
+ AbstractBeanDefinition bean = builder.getRawBeanDefinition();
+ bean.setSource(source);
- /**
- * Creates an anonymous factory to extract the actual
- * {@link javax.persistence.EntityManager} from the
- * {@link javax.persistence.EntityManagerFactory} bean name reference.
- *
- * @param entityManagerFactoryBeanName
- * @param source
- * @return
- */
- private BeanDefinition getEntityManagerBeanDefinitionFor(
- String entityManagerFactoryBeanName, Object source) {
+ return bean;
+ }
- BeanDefinitionBuilder builder =
- BeanDefinitionBuilder
- .rootBeanDefinition("org.springframework.orm.jpa.SharedEntityManagerCreator");
- builder.setFactoryMethod("createSharedEntityManager");
- builder.addConstructorArgReference(entityManagerFactoryBeanName);
+ /**
+ * Registers an additional {@link org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor} to
+ * trigger automatic injextion of {@link javax.persistence.EntityManager} .
+ *
+ * @param registry
+ * @param source
+ */
+ @Override
+ protected void registerBeansForRoot(BeanDefinitionRegistry registry, Object source) {
- AbstractBeanDefinition bean = builder.getRawBeanDefinition();
- bean.setSource(source);
+ super.registerBeansForRoot(registry, source);
- return bean;
- }
+ if (!hasBean(PET_POST_PROCESSOR, registry)) {
+ AbstractBeanDefinition definition = BeanDefinitionBuilder.rootBeanDefinition(PET_POST_PROCESSOR)
+ .getBeanDefinition();
- /**
- * Registers an additional
- * {@link org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor}
- * to trigger automatic injextion of {@link javax.persistence.EntityManager}
- * .
- *
- * @param registry
- * @param source
- */
- @Override
- protected void registerBeansForRoot(BeanDefinitionRegistry registry,
- Object source) {
+ registerWithSourceAndGeneratedBeanName(registry, definition, source);
+ }
- super.registerBeansForRoot(registry, source);
+ if (!hasBean(PAB_POST_PROCESSOR, registry)) {
- if (!hasBean(PET_POST_PROCESSOR, registry)) {
+ AbstractBeanDefinition definition = BeanDefinitionBuilder.rootBeanDefinition(PAB_POST_PROCESSOR)
+ .getBeanDefinition();
- AbstractBeanDefinition definition =
- BeanDefinitionBuilder
- .rootBeanDefinition(PET_POST_PROCESSOR)
- .getBeanDefinition();
-
- registerWithSourceAndGeneratedBeanName(registry, definition, source);
- }
-
- if (!hasBean(PAB_POST_PROCESSOR, registry)) {
-
- AbstractBeanDefinition definition =
- BeanDefinitionBuilder
- .rootBeanDefinition(PAB_POST_PROCESSOR)
- .getBeanDefinition();
-
- registerWithSourceAndGeneratedBeanName(registry, definition, source);
- }
- }
+ registerWithSourceAndGeneratedBeanName(registry, definition, source);
+ }
+ }
}
diff --git a/src/main/java/org/springframework/data/jpa/repository/config/JpaRepositoryNameSpaceHandler.java b/src/main/java/org/springframework/data/jpa/repository/config/JpaRepositoryNameSpaceHandler.java
index d1abedf7b..710c618cd 100644
--- a/src/main/java/org/springframework/data/jpa/repository/config/JpaRepositoryNameSpaceHandler.java
+++ b/src/main/java/org/springframework/data/jpa/repository/config/JpaRepositoryNameSpaceHandler.java
@@ -17,7 +17,6 @@ package org.springframework.data.jpa.repository.config;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
-
/**
* Simple namespace handler for {@literal repositories} namespace.
*
@@ -25,16 +24,14 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
*/
public class JpaRepositoryNameSpaceHandler extends NamespaceHandlerSupport {
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.beans.factory.xml.NamespaceHandler#init()
- */
- public void init() {
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.springframework.beans.factory.xml.NamespaceHandler#init()
+ */
+ public void init() {
- registerBeanDefinitionParser("repositories",
- new JpaRepositoryConfigDefinitionParser());
- registerBeanDefinitionParser("auditing",
- new AuditingBeanDefinitionParser());
- }
+ registerBeanDefinitionParser("repositories", new JpaRepositoryConfigDefinitionParser());
+ registerBeanDefinitionParser("auditing", new AuditingBeanDefinitionParser());
+ }
}
diff --git a/src/main/java/org/springframework/data/jpa/repository/config/SimpleJpaRepositoryConfiguration.java b/src/main/java/org/springframework/data/jpa/repository/config/SimpleJpaRepositoryConfiguration.java
index 09931ca7d..2cca4f3df 100644
--- a/src/main/java/org/springframework/data/jpa/repository/config/SimpleJpaRepositoryConfiguration.java
+++ b/src/main/java/org/springframework/data/jpa/repository/config/SimpleJpaRepositoryConfiguration.java
@@ -21,134 +21,116 @@ import org.springframework.data.repository.config.RepositoryConfig;
import org.springframework.data.repository.config.SingleRepositoryConfigInformation;
import org.w3c.dom.Element;
-
/**
* @author Oliver Gierke
*/
-public class SimpleJpaRepositoryConfiguration
- extends
- RepositoryConfig {
+public class SimpleJpaRepositoryConfiguration extends
+ RepositoryConfig {
- private static final String FACTORY_CLASS =
- "org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean";
- private static final String ENTITY_MANAGER_FACTORY_REF =
- "entity-manager-factory-ref";
+ private static final String FACTORY_CLASS = "org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean";
+ private static final String ENTITY_MANAGER_FACTORY_REF = "entity-manager-factory-ref";
+ /**
+ * @param repositoriesElement
+ */
+ public SimpleJpaRepositoryConfiguration(Element repositoriesElement) {
- /**
- * @param repositoriesElement
- */
- public SimpleJpaRepositoryConfiguration(Element repositoriesElement) {
+ super(repositoriesElement, FACTORY_CLASS);
+ }
- super(repositoriesElement, FACTORY_CLASS);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.springframework.data.repository.config.GlobalRepositoryConfigInformation
+ * #getAutoconfigRepositoryInformation(java.lang.String)
+ */
+ public JpaRepositoryConfiguration getAutoconfigRepositoryInformation(String interfaceName) {
+ return new AutomaticJpaRepositoryConfigInformation(interfaceName, this);
+ }
- /*
- * (non-Javadoc)
- *
- * @see
- * org.springframework.data.repository.config.GlobalRepositoryConfigInformation
- * #getAutoconfigRepositoryInformation(java.lang.String)
- */
- public JpaRepositoryConfiguration getAutoconfigRepositoryInformation(
- String interfaceName) {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.springframework.data.jpa.repository.config.RepositoryConfigContext
+ * #getManualRepositoryInformation(org.w3c.dom.Element,
+ * org.springframework.data
+ * .jpa.repository.config.CommonRepositoryInformation)
+ */
+ @Override
+ public JpaRepositoryConfiguration createSingleRepositoryConfigInformationFor(Element element) {
- return new AutomaticJpaRepositoryConfigInformation(interfaceName, this);
- }
+ return new ManualJpaRepositoryConfigInformation(element, this);
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.springframework.data.repository.config.CommonRepositoryConfigInformation
+ * #getNamedQueriesLocation()
+ */
+ public String getNamedQueriesLocation() {
- /*
- * (non-Javadoc)
- *
- * @see
- * org.springframework.data.jpa.repository.config.RepositoryConfigContext
- * #getManualRepositoryInformation(org.w3c.dom.Element,
- * org.springframework.data
- * .jpa.repository.config.CommonRepositoryInformation)
- */
- @Override
- public JpaRepositoryConfiguration createSingleRepositoryConfigInformationFor(
- Element element) {
+ return "classpath*:META-INF/jpa-named-queries.properties";
+ }
- return new ManualJpaRepositoryConfigInformation(element, this);
- }
+ /**
+ * Returns the name of the entity manager factory bean.
+ *
+ * @return
+ */
+ public String getEntityManagerFactoryRef() {
+ return getSource().getAttribute(ENTITY_MANAGER_FACTORY_REF);
+ }
- /*
- * (non-Javadoc)
- *
- * @see
- * org.springframework.data.repository.config.CommonRepositoryConfigInformation
- * #getNamedQueriesLocation()
- */
- public String getNamedQueriesLocation() {
+ private static class AutomaticJpaRepositoryConfigInformation extends
+ AutomaticRepositoryConfigInformation implements JpaRepositoryConfiguration {
- return "classpath*:META-INF/jpa-named-queries.properties";
- }
+ public AutomaticJpaRepositoryConfigInformation(String interfaceName, SimpleJpaRepositoryConfiguration parent) {
+ super(interfaceName, parent);
+ }
- /**
- * Returns the name of the entity manager factory bean.
- *
- * @return
- */
- public String getEntityManagerFactoryRef() {
+ /**
+ * Returns the {@link javax.persistence.EntityManagerFactory} reference to be used for all the repository instances
+ * configured.
+ *
+ * @return
+ */
+ public String getEntityManagerFactoryRef() {
- return getSource().getAttribute(ENTITY_MANAGER_FACTORY_REF);
- }
+ return getParent().getEntityManagerFactoryRef();
+ }
+ }
- private static class AutomaticJpaRepositoryConfigInformation
- extends
- AutomaticRepositoryConfigInformation
- implements JpaRepositoryConfiguration {
+ private static class ManualJpaRepositoryConfigInformation extends
+ ManualRepositoryConfigInformation implements JpaRepositoryConfiguration {
- public AutomaticJpaRepositoryConfigInformation(String interfaceName,
- SimpleJpaRepositoryConfiguration parent) {
+ public ManualJpaRepositoryConfigInformation(Element element, SimpleJpaRepositoryConfiguration parent) {
- super(interfaceName, parent);
- }
+ super(element, parent);
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.springframework.data.jpa.repository.config.
+ * SimpleJpaRepositoryConfiguration
+ * .JpaRepositoryConfiguration#getEntityManagerFactoryRef()
+ */
+ public String getEntityManagerFactoryRef() {
- /**
- * Returns the {@link javax.persistence.EntityManagerFactory} reference
- * to be used for all the repository instances configured.
- *
- * @return
- */
- public String getEntityManagerFactoryRef() {
+ return getAttribute(ENTITY_MANAGER_FACTORY_REF);
+ }
+ }
- return getParent().getEntityManagerFactoryRef();
- }
- }
+ static interface JpaRepositoryConfiguration extends
+ SingleRepositoryConfigInformation {
- private static class ManualJpaRepositoryConfigInformation extends
- ManualRepositoryConfigInformation
- implements JpaRepositoryConfiguration {
-
- public ManualJpaRepositoryConfigInformation(Element element,
- SimpleJpaRepositoryConfiguration parent) {
-
- super(element, parent);
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.springframework.data.jpa.repository.config.
- * SimpleJpaRepositoryConfiguration
- * .JpaRepositoryConfiguration#getEntityManagerFactoryRef()
- */
- public String getEntityManagerFactoryRef() {
-
- return getAttribute(ENTITY_MANAGER_FACTORY_REF);
- }
- }
-
- static interface JpaRepositoryConfiguration extends
- SingleRepositoryConfigInformation {
-
- String getEntityManagerFactoryRef();
- }
+ String getEntityManagerFactoryRef();
+ }
}
diff --git a/src/main/java/org/springframework/data/jpa/repository/query/AbstractJpaQuery.java b/src/main/java/org/springframework/data/jpa/repository/query/AbstractJpaQuery.java
index c4ac0a219..7bdaf5094 100644
--- a/src/main/java/org/springframework/data/jpa/repository/query/AbstractJpaQuery.java
+++ b/src/main/java/org/springframework/data/jpa/repository/query/AbstractJpaQuery.java
@@ -26,7 +26,6 @@ import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.util.Assert;
-
/**
* Abstract base class to implement {@link RepositoryQuery}s.
*
@@ -34,98 +33,87 @@ import org.springframework.util.Assert;
*/
public abstract class AbstractJpaQuery implements RepositoryQuery {
- private final JpaQueryMethod method;
- private final EntityManager em;
+ private final JpaQueryMethod method;
+ private final EntityManager em;
+ /**
+ * Creates a new {@link AbstractJpaQuery} from the given {@link JpaQueryMethod}.
+ *
+ * @param method
+ * @param em
+ */
+ public AbstractJpaQuery(JpaQueryMethod method, EntityManager em) {
- /**
- * Creates a new {@link AbstractJpaQuery} from the given
- * {@link JpaQueryMethod}.
- *
- * @param method
- * @param em
- */
- public AbstractJpaQuery(JpaQueryMethod method, EntityManager em) {
+ Assert.notNull(method);
+ Assert.notNull(em);
- Assert.notNull(method);
- Assert.notNull(em);
+ this.method = method;
+ this.em = em;
+ }
- this.method = method;
- this.em = em;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.springframework.data.repository.query.RepositoryQuery#getQueryMethod
+ * ()
+ */
+ public QueryMethod getQueryMethod() {
+ return method;
+ }
- /*
- * (non-Javadoc)
- *
- * @see
- * org.springframework.data.repository.query.RepositoryQuery#getQueryMethod
- * ()
- */
- public QueryMethod getQueryMethod() {
+ /**
+ * @return the em
+ */
+ protected EntityManager getEntityManager() {
- return method;
- }
+ return em;
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.springframework.data.repository.query.RepositoryQuery#execute(java
+ * .lang.Object[])
+ */
+ public Object execute(Object[] parameters) {
- /**
- * @return the em
- */
- protected EntityManager getEntityManager() {
+ return doExecute(getExecution(), parameters);
+ }
- return em;
- }
+ /**
+ * @param execution
+ * @param values
+ * @return
+ */
+ private Object doExecute(JpaQueryExecution execution, Object[] values) {
+ return execution.execute(this, values);
+ }
- /*
- * (non-Javadoc)
- *
- * @see
- * org.springframework.data.repository.query.RepositoryQuery#execute(java
- * .lang.Object[])
- */
- public Object execute(Object[] parameters) {
+ protected JpaQueryExecution getExecution() {
- return doExecute(getExecution(), parameters);
- }
+ switch (method.getType()) {
+ case COLLECTION:
+ return new CollectionExecution();
+ case PAGING:
+ return new PagedExecution(method.getParameters());
+ case MODIFYING:
+ return method.getClearAutomatically() ? new ModifyingExecution(method, em) : new ModifyingExecution(method, null);
+ default:
+ return new SingleEntityExecution();
+ }
+ }
- /**
- * @param execution
- * @param values
- * @return
- */
- private Object doExecute(JpaQueryExecution execution, Object[] values) {
+ protected ParameterBinder createBinder(Object[] values) {
- return execution.execute(this, values);
- }
+ return new ParameterBinder(getQueryMethod().getParameters(), values);
+ }
+ protected abstract Query createQuery(Object[] values);
- protected JpaQueryExecution getExecution() {
-
- switch (method.getType()) {
-
- case COLLECTION:
- return new CollectionExecution();
- case PAGING:
- return new PagedExecution(method.getParameters());
- case MODIFYING:
- return method.getClearAutomatically() ? new ModifyingExecution(
- method, em) : new ModifyingExecution(method, null);
- default:
- return new SingleEntityExecution();
- }
- }
-
-
- protected ParameterBinder createBinder(Object[] values) {
-
- return new ParameterBinder(getQueryMethod().getParameters(), values);
- }
-
-
- protected abstract Query createQuery(Object[] values);
-
-
- protected abstract Query createCountQuery(Object[] values);
+ protected abstract Query createCountQuery(Object[] values);
}
\ No newline at end of file
diff --git a/src/main/java/org/springframework/data/jpa/repository/query/AbstractStringBasedJpaQuery.java b/src/main/java/org/springframework/data/jpa/repository/query/AbstractStringBasedJpaQuery.java
index 208d22993..106ff6e5f 100644
--- a/src/main/java/org/springframework/data/jpa/repository/query/AbstractStringBasedJpaQuery.java
+++ b/src/main/java/org/springframework/data/jpa/repository/query/AbstractStringBasedJpaQuery.java
@@ -17,7 +17,6 @@ package org.springframework.data.jpa.repository.query;
import javax.persistence.EntityManager;
-
/**
* Base class for {@link String} based JPA queries.
*
@@ -25,15 +24,15 @@ import javax.persistence.EntityManager;
*/
public abstract class AbstractStringBasedJpaQuery extends AbstractJpaQuery {
- /**
- * Creates a new {@link AbstractStringBasedJpaQuery}.
- *
- * @param method
- * @param em
- */
- public AbstractStringBasedJpaQuery(JpaQueryMethod method, EntityManager em) {
+ /**
+ * Creates a new {@link AbstractStringBasedJpaQuery}.
+ *
+ * @param method
+ * @param em
+ */
+ public AbstractStringBasedJpaQuery(JpaQueryMethod method, EntityManager em) {
- super(method, em);
- }
+ super(method, em);
+ }
}
diff --git a/src/main/java/org/springframework/data/jpa/repository/query/CriteriaQueryParameterBinder.java b/src/main/java/org/springframework/data/jpa/repository/query/CriteriaQueryParameterBinder.java
index 4a7300993..576cdcaeb 100644
--- a/src/main/java/org/springframework/data/jpa/repository/query/CriteriaQueryParameterBinder.java
+++ b/src/main/java/org/springframework/data/jpa/repository/query/CriteriaQueryParameterBinder.java
@@ -29,80 +29,68 @@ import org.springframework.data.repository.query.Parameters;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
-
/**
- * Special {@link ParameterBinder} that uses {@link ParameterExpression}s to
- * bind query parameters.
+ * Special {@link ParameterBinder} that uses {@link ParameterExpression}s to bind query parameters.
*
* @author Oliver Gierke
*/
class CriteriaQueryParameterBinder extends ParameterBinder {
- private final Iterator> expressions;
+ private final Iterator> expressions;
+ /**
+ * Creates a new {@link CriteriaQueryParameterBinder} for the given {@link Parameters}, values and some
+ * {@link ParameterExpression}.
+ *
+ * @param parameters
+ */
+ CriteriaQueryParameterBinder(Parameters parameters, Object[] values, Iterable> expressions) {
- /**
- * Creates a new {@link CriteriaQueryParameterBinder} for the given
- * {@link Parameters}, values and some {@link ParameterExpression}.
- *
- * @param parameters
- */
- CriteriaQueryParameterBinder(Parameters parameters, Object[] values,
- Iterable> expressions) {
+ super(parameters, values);
+ Assert.notNull(expressions);
+ this.expressions = expressions.iterator();
+ }
- super(parameters, values);
- Assert.notNull(expressions);
- this.expressions = expressions.iterator();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.springframework.data.jpa.repository.query.ParameterBinder#bind(javax
+ * .persistence.Query, org.springframework.data.repository.query.Parameter,
+ * java.lang.Object, int)
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void bind(Query query, Parameter parameter, Object value, int position) {
+ ParameterExpression