Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#392 - Added example for deferred repository initialization.
- Loading branch information
Showing
6,005 changed files
with
100,327 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.springframework.data.examples</groupId> | ||
<artifactId>spring-data-jpa-examples</artifactId> | ||
<version>2.0.0.BUILD-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>spring-data-jpa-deferred</artifactId> | ||
<name>Spring Data JPA - Deferred bootstrap modes</name> | ||
|
||
<properties> | ||
<spring-data-releasetrain.version>Lovelace-BUILD-SNAPSHOT</spring-data-releasetrain.version> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2018 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 example; | ||
|
||
import example.model.Customer; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
import org.springframework.data.repository.config.BootstrapMode; | ||
import org.springframework.orm.jpa.JpaVendorAdapter; | ||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class); | ||
} | ||
|
||
/** | ||
* Configures a {@link LocalContainerEntityManagerFactoryBean} to use background initialization for the {@code lazy} | ||
* and {@code deferred} profiles. | ||
* | ||
* @author Oliver Gierke | ||
*/ | ||
@Configuration | ||
@Profile({ "lazy", "deferred" }) | ||
static class LazyJpaConfiguration { | ||
|
||
@Bean | ||
public LocalContainerEntityManagerFactoryBean entityManagerFactory(JpaVendorAdapter jpaVendorAdapter, | ||
DataSource dataSource, Environment environment) { | ||
|
||
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); | ||
threadPoolTaskExecutor.setDaemon(true); | ||
threadPoolTaskExecutor.afterPropertiesSet(); | ||
|
||
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); | ||
emf.setBootstrapExecutor(threadPoolTaskExecutor); | ||
emf.setDataSource(dataSource); | ||
emf.setJpaVendorAdapter(jpaVendorAdapter); | ||
emf.setPackagesToScan(Customer.class.getPackage().getName()); | ||
|
||
return emf; | ||
} | ||
} | ||
|
||
/** | ||
* Bootstraps Spring Data JPA in lazy mode if the {@code lazy} profile is activated. | ||
* | ||
* @author Oliver Gierke | ||
*/ | ||
@Profile("lazy") | ||
@Configuration | ||
@EnableJpaRepositories(bootstrapMode = BootstrapMode.LAZY) | ||
static class LazyRepositoryConfiguration {} | ||
|
||
/** | ||
* Bootstraps Spring Data JPA in deferred mode if the {@code deferred} profile is activated. | ||
* | ||
* @author Oliver Gierke | ||
*/ | ||
@Profile("deferred") | ||
@Configuration | ||
@EnableJpaRepositories(bootstrapMode = BootstrapMode.DEFERRED) | ||
static class DeferredRepositoryConfiguration {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package example.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Customer { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; | ||
private String firstName; | ||
private String lastName; | ||
|
||
protected Customer() {} | ||
|
||
public Customer(String firstName, String lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("Customer[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package example.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Customer1 { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; | ||
private String firstName; | ||
private String lastName; | ||
|
||
protected Customer1() {} | ||
|
||
public Customer1(String firstName, String lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("Customer1[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package example.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Customer10 { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; | ||
private String firstName; | ||
private String lastName; | ||
|
||
protected Customer10() {} | ||
|
||
public Customer10(String firstName, String lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("Customer10[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package example.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Customer100 { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; | ||
private String firstName; | ||
private String lastName; | ||
|
||
protected Customer100() {} | ||
|
||
public Customer100(String firstName, String lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("Customer100[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
jpa/deferred/src/main/java/example/model/Customer1000.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package example.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Customer1000 { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; | ||
private String firstName; | ||
private String lastName; | ||
|
||
protected Customer1000() {} | ||
|
||
public Customer1000(String firstName, String lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("Customer1000[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
jpa/deferred/src/main/java/example/model/Customer1001.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package example.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Customer1001 { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; | ||
private String firstName; | ||
private String lastName; | ||
|
||
protected Customer1001() {} | ||
|
||
public Customer1001(String firstName, String lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("Customer1001[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
jpa/deferred/src/main/java/example/model/Customer1002.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package example.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Customer1002 { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; | ||
private String firstName; | ||
private String lastName; | ||
|
||
protected Customer1002() {} | ||
|
||
public Customer1002(String firstName, String lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("Customer1002[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
jpa/deferred/src/main/java/example/model/Customer1003.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package example.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Customer1003 { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; | ||
private String firstName; | ||
private String lastName; | ||
|
||
protected Customer1003() {} | ||
|
||
public Customer1003(String firstName, String lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("Customer1003[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
jpa/deferred/src/main/java/example/model/Customer1004.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package example.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Customer1004 { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; | ||
private String firstName; | ||
private String lastName; | ||
|
||
protected Customer1004() {} | ||
|
||
public Customer1004(String firstName, String lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("Customer1004[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
jpa/deferred/src/main/java/example/model/Customer1005.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package example.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Customer1005 { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; | ||
private String firstName; | ||
private String lastName; | ||
|
||
protected Customer1005() {} | ||
|
||
public Customer1005(String firstName, String lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("Customer1005[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); | ||
} | ||
|
||
} |
Oops, something went wrong.