Skip to content

Instantly share code, notes, and snippets.

View hoangnt-2197's full-sized avatar

Nguyễn Trọng Hoàng hoangnt-2197

  • Công ty TNHH Sun Asterisk Việt Nam
View GitHub Profile
[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>:
Post post = forumService.newPost(
"High-Performance Java Persistence",
"JDBC", "JPA", "Hibernate"
);
List<Post> posts = forumService.findAllPostsByTitle(
"High-Performance Java Persistence"
);
log_min_duration_statement = 0
log_line_prefix = '[%d] '
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
@Configuration
@ComponentScan(
basePackages = "com.example.routing.hpjp.util.spring.routing"
)
@PropertySource(
"/META-INF/jdbc-postgresql-replication.properties"
)
public class TransactionRoutingConfiguration
extends AbstractJPAConfiguration {
public enum DataSourceType {
READ_WRITE,
READ_ONLY
}
public class TransactionRoutingDataSource
extends AbstractRoutingDataSource {
@Nullable
@Override
protected Object determineCurrentLookupKey() {
return TransactionSynchronizationManager
.isCurrentTransactionReadOnly() ?
DataSourceType.READ_ONLY :
DataSourceType.READ_WRITE;
@Service
@Transactional(readOnly = true)
public class ForumServiceImpl
implements ForumService {
@PersistenceContext
private EntityManager entityManager;
@Override
@Transactional
@Service
public class ForumServiceImpl
implements ForumService {
@PersistenceContext
private EntityManager entityManager;
@Override
@Transactional
public Post newPost(String title, String... tags) {
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)