Commit Graph

116 Commits

Author SHA1 Message Date
Oliver Gierke
943be87908 DATAJPA-288 - Separate test execution for different persistence providers.
Re-enabled more integration tests integration tests.
2013-01-25 18:51:20 +01:00
Oliver Gierke
a74fadd234 DATAJPA-287 - Count query execution now considers distinct flag of query.
If the implementation of a Specification sets the distinct flag, we now create a count query that is honoring the distinct flag as well.
2013-01-25 18:50:45 +01:00
Oliver Gierke
28a565faec DATAJPA-286 - Added test infrastructure for plain JPA tests.
Added integration tests in org.springframework.data.jpa.infrastructure that will not be included in the normal test execution as they are purely means to quickly identify potential differences in persistence provider implementations.
2013-01-17 16:08:00 +01:00
Oliver Gierke
bc6e2a7bc9 DATAJPA-277 - Specification execution with sorting now uses left joins where necessary.
When applying sorting options to a Specification based query we have to make sure to apply left joins where necessary as we otherwise exclude results with null associations. Applying the sort options does an enhanced inspection of the target path and declares a left join instead of a get if the path logically points to an entity. The Metamodel API is not without caveats here, see http://bit.ly/10geC02.
2013-01-17 15:34:10 +01:00
Oliver Gierke
02239859bb DATAJPA-284 - Added @OneToOne as annotation to be considered an association. 2013-01-16 17:48:56 +01:00
Oliver Gierke
258af43397 DATAJPA-274 - Introduce JPA Metamodel based MappingContext implementation.
Implemented rudimentary MappingContext to expose a JpaPersistentEntity through RepositoryFactoryInformation.
2012-11-28 18:15:49 +01:00
Oliver Gierke
69bcc3d887 DATAJPA-272 - Polished logging setup to reduce noise in test cases. 2012-11-27 16:14:53 +01:00
Oliver Gierke
fc818b7087 DATAJPA-116 - Improved implementation to support annotation-based auditing.
Re-engineered our auditing setup to leverage the APIs introduced from DATACMNS-137.
2012-11-27 15:26:22 +01:00
Oliver Gierke
688f62516b DATAJPA-268 - LockModePopulatingMethodInterceptor cleans up resources correctly.
LockModePopulatingMethodInterceptor now safely unbinds the LockModeMetadata after the target method invocation completes.
2012-11-06 14:30:16 +01:00
Oliver Gierke
918099e395 DATAJPA-253 - Fixed application of Specifications.not(…).
Specifications.not(…) now also gets applied correctly when used without where(…) wrapper. Polished Specifications class, JavaDoc and added not null assertions.
2012-08-30 11:36:09 +02:00
Oliver Gierke
a9cfe73511 DATAJPA-252 - Applying sort to manually defined queries considers joins.
If a manually defined query uses outer joins, prefixing the sort criteria handed to the execution of the method causes an additional join being added as the JPA considers path expressions to be inner joins always (see Sect. 4.4.4, JPA 2.0 spec).

We now parse the outer join aliases potentially used in a manually defined JPQL query and do not prefix the query with the root entity's alias.
2012-08-29 17:16:33 +02:00
Oliver Gierke
e59b8b3194 DATAJPA-243 - QueryDslJpaRepository applies sort given through Pageable correctly.
During the refactoring of the Querydsl interaction a regression of not applying a Sort wrapped in a Pageable was introduced in QueryDsl utility class.
2012-08-13 10:28:12 +02:00
Oliver Gierke
372ac45922 DATAJPA-232 - Fixed parameter binding in SimpleJpaRepository.findAll(Iterable<ID> ids).
We bound the given Iterable<ID> using List as parameter type which gets rejected if you hand in something that's not a List actually (e.g. HashSet). Changed parameter binding to hand in Iterable now.
2012-07-19 09:58:39 +02:00
Oliver Gierke
42718c57fe Check OpenJpa query validation. 2012-07-18 11:35:04 +02:00
Oliver Gierke
9734010d8e DATAJPA-226 - Working around ambiguities in the JPA spec.
We now expect a much broader range of exceptions possibly popping up from EntityManager.createQuery(…). It turns out the spec is not very strict about what must be returned from the call in case the provided query String is invalid. E.g. Hibernate seems to throw an IllegalStateException in case the query seems generally acceptable but has a typo in some keyword.

We now catch RuntimeException invoking the call and simply rethrow the original exception if it is an IllegalArgumentException indeed but wrap any other into an IAE.

See http://java.net/projects/jpa-spec/lists/jsr338-experts/archive/2012-07/message/17
2012-07-17 11:41:26 +02:00
Oliver Gierke
2087ce29d2 DATAJPA-69 - Added JavaConfig support for repositories.
The repositories can now be bootstrapped using @EnableJpaRepositories annotation as follows:

@Configuration
@EnableJpaRepositories
class ApplicationConfig {
  
  // … declare EntityManagerFactory
  // … declare PlatformTransactionManager
}
2012-07-16 20:25:49 +02:00
Oliver Gierke
de16544194 DATAJPA-226 - Test case failing to reproduce the issue. 2012-07-16 17:19:06 +02:00
Oliver Gierke
4c1a1450b9 DATAJPA-176 - Introduce Querydsl abstraction.
Introduced Querydsl helper class to allow using more functionality from QuerydslJpaRepository as well as QuerydslRepositorySupport. Moved applyPagination(…) and applySorting(…) methods into that helper class. Removed QuerydslUtils and moved functionality into Querydsl helper.

This change breaks exposed API in Querydsl repo and repo support classes.
2012-06-04 16:33:58 +02:00
Oliver Gierke
fd930e3fde DATACMNS-171 - Let JpaQueryMethod new method of QueryMethod.
Drop custom method to determine whether a query method returns an entity and rather use the newly introduced method in Spring Data Commons' QueryMethod.
2012-05-16 14:36:06 +02:00
Oliver Gierke
72da417171 Improve project setup.
Reactivated test cases that were not executed because they were named *Test, not *Tests. Upgraded to Maven Surefire Plugin 2.12 and activated parallel test execution per method. Upgraded Maven Compiler Plugin to 2.4.
2012-05-15 17:58:25 +02:00
Oliver Gierke
f466744acd DATAJPA-207 - Fixed query creation for projections on native queries.
When executing a projecting query through a native query we must not use em.createNativeQuery(String, Class<?>) as this expects an entity type as type parameter. We now use the newly introduced isQueryMethodForEntity() on JpaQueryMethod to determine whether the query is actually projecting and rather use the plain em.createNativeQuery(String).

Fixed dependency configuration for Hamcrest and JUnit (upgrade to JUnit 4.10, depending on junit-dep).
2012-05-15 17:57:08 +02:00
Oliver Gierke
f8fd5c4b7a DATACMNS-166 - Adapted changes in Spring Data Commons. 2012-05-02 19:55:10 +02:00
Oliver Gierke
5eaa686b9b DATAJPA-201 - Fixed NullPointerException for null Pageables.
The optimization for DATAJPA-124 introduced a NullPointerException being thrown if the Pageable instance handed to a paging query was null. Added a guard to handle this situation correctly. Unfortunately had to disable the test case for EclipseLink as the bug with HSQL still exists.
2012-04-27 18:44:48 +02:00
Oliver Gierke
9c20aff99d DATAJPA-201 - Test case showing handing in null for Pageable arguments works. 2012-04-26 19:22:40 +02:00
Oliver Gierke
11d624f266 DATAJPA-177 - Throw exception if entity to delete does not exist.
We now do an exists check inside SimpleJpaRepository.delete(ID id) before actually triggering the deletion to avoid an exception when trying to delete a null value. We throw an EmptyResultDataAccessException to indicate the nonexistent entity now.
2012-04-15 20:24:41 +02:00
Oliver Gierke
393d3e2000 DATAJPA-189, DATAJPA-190 - Improvements to MergingPersistenceUnitManager.
MergingPersistenceUnitManager now also merges mapping file locations. We also make sure now that the persistence unit root URL does not get added twice accidentally as some persistence providers refuse to work then.
2012-04-12 09:39:21 +02:00
Oliver Gierke
f441087cf4 DATAJPA-180 - Added support for StartingWith, EndingWith, Containing to query creator.
The query derivation mechanism now supports StartingWith, EndingWith and Containing as keywords using the Criteria API's like predicate and massaging the given parameters accordingly. Refactored parameter binding  for CriteriaQuery instances to encapsulate the knowledge of how to massage a parameter based on the type.
2012-04-12 09:39:04 +02:00
Oliver Gierke
26f0eec010 DATAJPA-185 - Sanity check named parameter names in JpaQueryMethod.
To avoid the query execution to fail due to typos in the named parameter mapping, JpaQueryMethod now checks the named parameters potentially annotated using @Param to be present in the annotated query.
2012-04-11 20:48:34 +02:00
Oliver Gierke
0ff84c94e8 DATAJPA-188 - Added support for After and Before query creation. 2012-04-10 18:24:20 +02:00
Oliver Gierke
5b2cef4938 DATAJPA-169 - Fixed regression in SimpleJpaQuery.
When using a projection to a collection property in a manually defined query we must not set the domain class type when creating the query:

interface UserRepository implements Repository<User, Long> {

  @Query("select u.colleagues from User u where u = ?1")
  List<User> findColleguesFor(User user);
}

We now must not call em.createQuery(queryString, User.class) as we were before as this causes some persistence providers (tested with Hibernate) to reject the query type. Thus we now simply create an untyped query as we don't need the typing here. Unfortunately we cannot activate the test case currently as OpenJPA does not support using projections on a collection property and breaks the bootstrap process of the integration test.
2012-03-12 19:18:12 +01:00
Oliver Gierke
4e6a93390f DATAJPA-151, DATAJPA-167 - Upgrade to Spring 3.1.1.
Needed to get rid of SPR-8954. Updated build to run against Spring 3.1.1.
2012-02-27 14:39:12 +01:00
Oliver Gierke
3f1043a0fd DATAJPA-164 - Prepare 1.1.0.RC1. 2012-02-08 19:02:36 +01:00
Oliver Gierke
f676e92e6a DATACMNS-128 - Implement CrudRepository.findAll(Iterable<ID> ids).
Implemented said method in SimpleJpaRepository and added test case. Comment that one out for failing persistence providers.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477
https://issues.apache.org/jira/browse/OPENJPA-2018
2012-02-02 18:13:47 +01:00
Oliver Gierke
19cca03953 DATAJPA-137 - Fixed deleteAll() handling.
SimpleJpaRepository now deletes entities 1 by 1 for a call to deleteAll() to ensure the cascades get triggered. Introduced deleteAllInBatch() that contains the old behaviour.
2012-02-02 15:38:37 +01:00
Oliver Gierke
5c95016717 DATAJPA-121 - Corrected query handling if null parameters are provided.
If a query is executed and null values are provided we now recreate a query with an IS NULL predicate correctly.
2012-02-02 14:49:01 +01:00
Oliver Gierke
9ae8caa1b8 DATAJPA-9 - Added DateTimeProvider SPI for auditing.
Extracted the DateTime instance calculation to be used for auditing into a DateTimeProvider callback interface to open it up for customization. AuditingEntityListener can get an instance of it configured. Exposed the property via the auditing namespace. By default a CurrentDateTimeProvider its used that contains the behavior we had so far.
2012-02-01 18:41:48 +01:00
Oliver Gierke
3962f1ab31 DATAJPA-50 - Introduced support for usage of @IdClass.
Introduced to support @IdClass to define entity ids. The JpeMetamodelEntityInformation builds instances of the annotated @IdClass in case any of the attributes of the entity declared in the @IdClass has a non-null value.
2012-01-31 17:18:09 +01:00
Oliver Gierke
b303498842 DATAJPA-69 - Sample of how to configure repositories with JavaConfig. 2012-01-31 13:29:32 +01:00
Oliver Gierke
1a14e92e69 DATAJPA-142 - Allow using a NamedQuery for count queries in pagination.
We will now prefer a declared NamedQuery for count queries instead of deriving it from the actual NamedQuery under the following conditions:

- by default a query named ${namedQueryName}.count exists
- the name of the NamedQuery to be used is defined in @Query(countQueryName = "…")

Note that a potential reconfiguration of the NamedQuery name will be taken into account for the according count query name to assure symmetry. Examples

Page<User> findByLastname(String lastname, Pageable pageable)
NamedQuery name: User.findByLastname
Count NamedQuery name: User.findByLastname.count

@Query(name = "Foo.bar")
Page<User> findByLastname(String lastname, Pageable pageable)
NamedQuery name: Foo.bar
Count NamedQuery name: Foo.bar.count

@Query(countName = "Foo.bar.count")
Page<User> findByLastname(String lastname, Pageable pageable)
NamedQuery name: User.findByLastname
Count NamedQuery name: Foo.bar.count

@Query(name = "Foo.bar", countName = "something")
Page<User> findByLastname(String lastname, Pageable pageable)
NamedQuery name: Foo.bar
Count NamedQuery name: something
2012-01-11 15:12:33 +01:00
Oliver Gierke
9224a4b14f DATAJPA-138 - Make MergingPesistenceUnitManager work again.
Override isPersistenceUnitOverrideAllowed() newly introduced in Spring 3.1.1 to indicate we can deal with persistence units of the same name. For Spring 3.0.x versions the implementation was not broken.
2012-01-11 14:16:02 +01:00
Dirk Mahler
c4ae2ba7bb DATAJPA-136 - Initial draft of CDI integration.
Implemented CDI integration based on the Spring Data Commons code introduced in DATACMNS-110.
2011-12-19 16:44:56 +01:00
Oliver Gierke
ea8fff00fc DATAJPA-141 - JpaMetamodelEntityInformation now works with MappedSuperclasses as well.
We now call Metamodel.managedClass(…) instead of Metamodel.entityType(…) to be able to detect ids in @MappedSuperclass types as well. Unfortunately this currently still fails with Hibernate as theit Metamodel implementation only considers entities. See [0] for further details.

[0] https://hibernate.onjira.com/browse/HHH-6896
2011-12-15 11:30:13 +01:00
Oliver Gierke
fe36a77f38 DATAJPA-135 - Improved extensibility of QueryDslRepositorySupport.
Moved @PersistenceContext annotation to the setter method to make it overridable and thus re-configurable. Introduced protected getEntityManager() method to allow subclasses having access to the EntityManager.
2011-12-09 13:02:20 +01:00
Oliver Gierke
c915077074 DATAJPA-73 - Added support for locking.
Repository query methods can now be equipped with a @Lock annotation that carries the LockModeType to be used when executing the query. Beyond that, CRUD methods can be redeclared to carry lock metadata as well.

interface UserRepository extends Repository<User, Long> {
  // CRUD method redeclaration
  @Lock(LockModeType.READ)
  List<User> findAll();

  // Query method
  @Lock(LockModeType.READ)
  List<User> findByLastname(String lastname);
}
2011-12-06 11:12:57 +01:00
Tomasz Nurkiewicz
d49d4d5f0a DATAJPA-124 - Optimized pagination execution.
For pagination we already need to trigger a count query to find out the total number of pages available. Now if there are less elements available than the offset of the current page points to we don't need to trigger the actual content reading query at all. E.g. if there's only 20 elements in the database and we request page 3 by a page size of 10 we already know that there won't be any elements found.

Implemented that optimization for general CRUD pagination as well as pagination in query methods.
2011-12-05 18:24:29 +01:00
Oliver Gierke
42b60cf8d4 DATAJPA-132 - Implemented handling of True and False keywords on query creation.
Query derivation mechanism now supports True and False as keywords in finder methods:

class User {
  boolean active;
}

interface UserRepository<User, Long> {
  List<User> findByActiveTrue() ;
}
2011-12-05 14:38:39 +01:00
Oliver Gierke
d3bced0f86 DATAJPA-123 - Added classpath-scanning PersistenceUnitPostProcessor.
Added ClasspathScanningPersistenceUnitPostProcessor that will scan the configured base package for classes annotated with @Entity or @MappedSuperclass and add them to the PersistenceUnit handled.

Beyond that it will scan for JPA XML mapping files if an optional mapping file name pattern is configured on the PUPP instance.
2011-12-03 11:55:57 +01:00
Oliver Gierke
aef195eaed DATAJPA-129 - Allow definition of NamedQuery name to be used in @Query.
@Query now has a name attribute that allows defining the NamedQuery name to be used to override the convention based ${domainClass}.${finderMethodName}.
2011-12-03 01:30:53 +01:00
Oliver Gierke
c134e10727 DATAJPA-117 - Added nativeQuery flag to @Query.
@Query can now be used to execute native queries by setting the nativeQuery flag of the annotation to true. Polished JavaDoc of the @Query annotation. Upgraded EclipseLink dependency to 2.3.1 as we stumble over a NullPointerException otherwise which is fixed in the current one.
2011-12-03 00:34:23 +01:00
Oliver Gierke
add1336ed1 DATACMNS-91 - Enforce parameter handling defined by CrudRepository.
Reject null values for id and entity values. Polished JavaDoc in terms of parameter specification.
2011-12-02 17:47:07 +01:00