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
[high_performance_java_persistence] LOG: execute <unnamed>: | |
BEGIN | |
[high_performance_java_persistence] DETAIL: | |
parameters: $1 = 'JDBC', $2 = 'JPA', $3 = 'Hibernate' | |
[high_performance_java_persistence] LOG: execute <unnamed>: | |
select tag0_.id as id1_4_, tag0_.name as name2_4_ | |
from tag tag0_ where tag0_.name in ($1 , $2 , $3) | |
[high_performance_java_persistence] LOG: execute <unnamed>: |
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
Post post = forumService.newPost( | |
"High-Performance Java Persistence", | |
"JDBC", "JPA", "Hibernate" | |
); | |
List<Post> posts = forumService.findAllPostsByTitle( | |
"High-Performance Java Persistence" | |
); |
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
log_min_duration_statement = 0 | |
log_line_prefix = '[%d] ' |
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
hibernate.dialect=org.hibernate.dialect.PostgreSQL10Dialect | |
jdbc.url.primary=jdbc:postgresql://localhost:5432/high_performance_java_persistence | |
jdbc.url.replica=jdbc:postgresql://localhost:5432/high_performance_java_persistence_replica | |
jdbc.username=postgres | |
jdbc.password=admin |
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
@Configuration | |
@ComponentScan( | |
basePackages = "com.example.routing.hpjp.util.spring.routing" | |
) | |
@PropertySource( | |
"/META-INF/jdbc-postgresql-replication.properties" | |
) | |
public class TransactionRoutingConfiguration | |
extends AbstractJPAConfiguration { | |
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
public enum DataSourceType { | |
READ_WRITE, | |
READ_ONLY | |
} |
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
public class TransactionRoutingDataSource | |
extends AbstractRoutingDataSource { | |
@Nullable | |
@Override | |
protected Object determineCurrentLookupKey() { | |
return TransactionSynchronizationManager | |
.isCurrentTransactionReadOnly() ? | |
DataSourceType.READ_ONLY : | |
DataSourceType.READ_WRITE; |
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
@Service | |
@Transactional(readOnly = true) | |
public class ForumServiceImpl | |
implements ForumService { | |
@PersistenceContext | |
private EntityManager entityManager; | |
@Override | |
@Transactional |
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
@Service | |
public class ForumServiceImpl | |
implements ForumService { | |
@PersistenceContext | |
private EntityManager entityManager; | |
@Override | |
@Transactional | |
public Post newPost(String title, String... tags) { |
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
insert into post (title, id) | |
values ('First post', 1) | |
insert into post_comment (review, id) | |
values ('My first review', 2) | |
insert into post_comment (review, id) | |
values ('My second review', 3) | |
insert into post_comment (review, id) |
NewerOlder