Commit Graph

233 Commits

Author SHA1 Message Date
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
Oliver Gierke
45bcdb60ac DATAJPA-127 - Setup hybrid Spring 3.0.6 / 3.1 build.
Removed deprecated usage of XmlBeanFactory in tests.
2011-12-02 17:46:40 +01:00
Oliver Gierke
70b42b8ba3 Removed unused import. 2011-11-23 12:35:26 +01:00
Oliver Gierke
99e04dbcae DATACMNS-98 - Adapt refactorings. 2011-11-23 12:27:26 +01:00
Oliver Gierke
d6c4c2ef12 Polished UserRepositoryTests. 2011-10-12 11:36:48 +02:00
Oliver Gierke
db8aebe4d7 DATAJPA-111 - Removed unnecessary em.clear() from mass delete methods. 2011-10-12 11:36:33 +02:00
Oliver Gierke
c8a0f0d3b6 DATAJPA-110 - Fixed alias detection for entity names containing numbers. 2011-10-11 18:23:21 +02:00
Oliver Gierke
54f8cb8700 DATAJPA-108 - Added support for GreaterThanEqual and LessThanEqual. 2011-10-11 18:15:25 +02:00
Oliver Gierke
515a85f005 DATAJPA-113 - Improved DI for QueryDslRepositorySupport.
Removed @Required annotation from the setter for EntityManager property. The annotation triggered a dependency check that was not aware of the EntityManager being injected by a PersistenceAnnotationBeanPostProcessor. As we already have a validation callback using @PostConstruct we can simply rely on the not-null check for the EntityManager being implemented there.
2011-10-11 12:57:05 +02:00
Oliver Gierke
a5cb8ee6c0 DATAJPA-54 - Added forCounting() flag to @QueryHints.
The flag defaults to true and allows disabling of QueryHints being applied to the count query additionally triggered for pagination.
2011-09-06 13:47:38 +02:00
Oliver Gierke
6fec65b504 DATAJPA-97 - Added test to verify hints get applied to all queries correctly.
The actual fix for this ticket has been introduced during the refactoring for DATAJPA-86 (04349d25dc) thus it's already fixed in 1.1.0.M1. Added a test case to verify the behavior.
2011-09-06 13:19:59 +02:00
Oliver Gierke
9bf6703c63 DATADOC-99 - ParameterExpressionProvider now uses parameter type instead of handed in type if assignable.
JpaQueryCreator hands Comparable into ParameterExpressionProvider to create ParameterExpression instances for Comparables. The ParameterExpressionProvider in turn now inspects the actual Parameter type and hand this one into the builder in case it's assignable (read: more concrete) to the given type requested.
2011-09-06 11:49:07 +02:00
Oliver Gierke
ca52ec29be DATAJPA-81 - SimpleJpaRepository.exists(…) now projects to the id to prevent the entire object being read and mapped. 2011-09-05 08:31:32 +02:00
Oliver Gierke
04349d25dc DATAJPA-86 - Pagination over queries using group-by works correctly.
Added handling of count methods for queries using group by. In case the count query returns multiple results we use the number of results instead of failing. If the result contains one result we use this one.

Moved hint handling to AbstractJpaQuery.
2011-09-04 16:56:50 +02:00
Oliver Gierke
7516816adb DATADOC-93 - Don't catch IllegalArgumentExceptions raised by missing domain class in JPA Metamodel.
We now don't catch an IllegalArgumentException being thrown in case a domain class is not found in the metamodel. If it occurs there's nothing we can do about it as we can't come up with an EntityInformation instance then and the persistence provider couldn't handle it anyway.
2011-09-04 14:25:27 +02:00
Oliver Gierke
b291a5f5f9 DATAJPA-98 - Formatted sources with Spring Data Eclipse formatting settings. 2011-09-02 18:11:10 +02:00
Phillip Webb
27ad91fbbc DATAJPA-92 - JpaQueryCreator now inspects enum to decide how to handle ignore case scenarios. 2011-08-29 18:06:30 +02:00
Phillip Webb
aa6a7c1983 DATAJPA-94 - Repository queries consider Sort instance in a Pageable again. 2011-08-29 11:31:47 +02:00
Phil Webb
5b9e959b3e DATAJPA-92 - Added support for IgnoreCase keyword.
The query creation subsystem now supports using IgnoreCase when referencing String parameters, e.g.:

  findByUsernameIgnoreCase(String username);

Both 'IgnoreCase' and 'IgnoringCase' are supported. If you'd like to entirely ignore cases for all String property references add 'AllIgnoreCase' or 'AllIgnoringCase' to the query method.
2011-08-25 12:52:14 +02:00
Oliver Gierke
0144be5b16 DATADOC-90 - Refactored PartTreeJpaQuery to create new JpaQueryCreator on every query recreation.
JpaQueryCreator is stateful as we create a list of ParameterExpressions and iterate over them. So we have to re-instantiate the JpaQueryCreator to not create an exception on the second attempt.
2011-08-21 14:33:55 +02:00
Oliver Gierke
160b738a4d DATACMNS-62 - Adapt changes in Spring Data Commons. 2011-08-21 14:33:00 +02:00
Oliver Gierke
00ece2c25e Polished codebase and added architecture management.
Added Sonargraph architecture description. Removed cyclic package dependency. Introduced JpaEntityInformationSupport to contain common getEntityName() method and serving as factory for JpaEntityInformation instances.
2011-07-21 12:20:18 +02:00
Oliver Gierke
d0b7901ce8 DATAJPA-78 - Upgrade to Querydsl 2.2.0.
Upgraded to Querydsl 2.2.0. Added configuration to generate query classes for AbstractPersistable and AbstractAuditable. Package those query classes into the source JAR and compile it into the binary as well. Upgraded Mysema APT plugin to 1.0.2.
2011-07-19 17:25:47 +02:00
Oliver Gierke
537ac8c23c DATAJPA-77 - Count queries for manually defined queries don't get pagination applied anymore. 2011-07-19 09:22:02 +02:00
Oliver Gierke
5d3602d53f DATACMNS-49 - Added integration for Spring Data named queries.
We now support extracting query definitions into a properties file which can be configured on the JpaRepositoryFactoryBean. The namespace will look for classpath*:META-INF/jpa-named-queries.properties by default.
2011-06-23 19:47:59 +02:00
Oliver Gierke
405fccb04f DATAJPA-64 - Refactored query execution to use ParameterExpression.
The JpaQueryCreator now creates a CriteriaQuery using ParameterExpressions that have to be bound later on. Refactored the RepositoryQuery implementation hierarchy and JpaQueryExecution as binding has to be done by the query classes now. This required the introduction of a special CriteraQueryParameterBinder as well. It uses the ParameterExpressions of the CriteriaQuery to bind the actual query values later on.

We have to convert arrays passed into query method into collections as none of the major persistence providers support binding arrays to IN parameters currently.
2011-06-21 20:49:54 +02:00
Oliver Gierke
53c3cf9230 DATAJPA-38 - Introduced MergingPersistenceUnitManager. 2011-06-13 20:28:50 -07:00
Oliver Gierke
ea0ff71499 Adapted package refactorings in Spring Data Commons.
Resolved package dependencies as well.
2011-06-13 20:28:23 -07:00
Oliver Gierke
b8ad5e8b81 DATAJPA-68 - Refactored AuditingEntityListener.
Separated touch(…) methods for updating and creation as some persistence providers might hand in entities with IDs already assigned into a @PrePersist method and thus the isNew() check will fail.
2011-06-13 16:24:10 -07:00
Oliver Gierke
356ce6330c Moved QueryDslPredicateExecutor into Spring Data Commons. 2011-05-23 12:23:52 +02:00
Oliver Gierke
75281a99d4 DATACMNS-29 - Adapted changes in Spring Data Commons. 2011-05-12 14:01:56 +02:00
Oliver Gierke
ad40b37f40 DATACMNS-35 - Added implementation and test for newly introduced Repository.delete(ID id) method. 2011-05-11 18:39:27 +02:00
Oliver Gierke
30bb367e96 DATAJPA-59, DATAJPA-60 - Improved handling of PersistenceProviders not capable of extracting queries for paging query methods.
Removed check for that capability (QueryExtractor.canExtractQuery()) from JpaQueryMethod and defer it into NamedQuery as we can handle derived queries and queries annotated with @Query regardless of that capability.

Made exception message a bit more verbose to give hints what to do if the exception occurs.
2011-05-11 13:33:35 +02:00
Oliver Gierke
536f8ccd91 DATAJPA-58 - JpaPersistableEntityInformation now uses Persistable.isNew(…).
Added unit tests to verify behavior and updated changelog accordingly.
2011-05-10 12:20:29 +02:00