Files
spring-data-examples/jpa/java8
Spring Operator 6d51ebf294 #473 - URL Cleanup.
This commit updates URLs to prefer the https protocol. Redirects are not followed to avoid accidentally expanding intentionally shortened URLs (i.e. if using a URL shortener).

# HTTP URLs that Could Not Be Fixed
These URLs were unable to be fixed. Please review them to see if they can be manually resolved.

* http://mybatis.org/dtd/mybatis-3-config.dtd (301) with 1 occurrences could not be migrated:
   ([https](https://mybatis.org/dtd/mybatis-3-config.dtd) result SSLHandshakeException).
* http://mybatis.org/dtd/mybatis-3-mapper.dtd (301) with 2 occurrences could not be migrated:
   ([https](https://mybatis.org/dtd/mybatis-3-mapper.dtd) result SSLHandshakeException).

# Fixed URLs

## Fixed Success
These URLs were switched to an https URL with a 2xx status. While the status was successful, your review is still recommended.

* http://maven.apache.org/xsd/maven-4.0.0.xsd with 70 occurrences migrated to:
  https://maven.apache.org/xsd/maven-4.0.0.xsd ([https](https://maven.apache.org/xsd/maven-4.0.0.xsd) result 200).
* http://maven.apache.org/maven-v4_0_0.xsd with 6 occurrences migrated to:
  https://maven.apache.org/maven-v4_0_0.xsd ([https](https://maven.apache.org/maven-v4_0_0.xsd) result 301).
* http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd with 1 occurrences migrated to:
  https://java.sun.com/xml/ns/persistence/persistence_2_0.xsd ([https](https://java.sun.com/xml/ns/persistence/persistence_2_0.xsd) result 302).

# Ignored
These URLs were intentionally ignored.

* http://java.sun.com/xml/ns/persistence with 2 occurrences
* http://maven.apache.org/POM/4.0.0 with 152 occurrences
* http://www.w3.org/2001/XMLSchema-instance with 77 occurrences

Original pull request: #472
2019-03-20 10:10:59 -05:00
..
2019-03-20 10:10:59 -05:00
2015-10-15 09:15:41 +02:00

Spring Data - Java 8 examples

This project contains samples of Java 8 specific features of Spring Data (JPA).

Support for JDK 8's Optional for repository methods

interface CustomerRepository extends Repository<Customer, Long> {

  // CRUD method using Optional
  Optional<Customer> findOne(Long id);

  // Query method using Optional
  Optional<Customer> findByLastname(String lastname);
}
  • CustomerRepository.findOne(Long) effectively "overrides" the default CrudRepository.findOne(…) to return Optional.empty() instead of null in case no unique element satisfying the query can be found.
  • CustomerRepository.findByLastname(…) does the same for a normal query method.

Support for JDK 8's date/time types in the auditing sub-system

  • Customer extends AbstractEntity which contains fields of JDK 8's new date/time API and those can be populated the same way legacy types like Date and Calendar can.

Support for JDK 8' Stream in repository methods

JPA repositories can now use Stream as return type for query methods to trigger streamed execution of the query. This will cause Spring Data JPA to use persistence provider specific API to traverse the query result one-by-one.

interface CustomerRepository extends Repository<Customer, Long> {

  @Query("select c from Customer c")
  Stream<Customer> streamAllCustomers();
}

try (Stream<Customer> customers = repository.streamAllCustomers()) {
  // use the stream here
}

Note how the returned Stream has to be used in a try-with-resources clause as the underlying resources have to be closed once we finished iterating over the result.

Support for JDK 8' CompletableFuture in @Async repository methods

JPA repositories can now use CompletableFuture as return type for query methods for async execution of the query with support for fluent processing.

Note that: Support for CompletableFuture in combination with @Async is available in Spring Framework 4.2.x.

interface CustomerRepository extends Repository<Customer, Long> {

  @Async
  CompletableFuture<List<Customer>> readAllBy();
}

CompletableFuture<List<Customer>> future = repository.readAllBy().thenApply(this::doSomethingWithCustomers);

while (!future.isDone()) {
	log.info("Waiting for the CompletableFuture to finish...");
	TimeUnit.MILLISECONDS.sleep(500);
}

List<Customer> processedCustomers = future.get();