Fading Coder

One Final Commit for the Last Sprint

Configuring JPA with Spring and Container-Managed DataSources

Setting Up a JNDI DataSource To use a cnotainer-managed database connection, define a bean that looks up the resource via JNDI. The following cnofiguration retrieves a MySQL data source bound to jdbc/mysql: package com.example.setup; import javax.naming.NamingException; import javax.sql.DataSource;...

Java Development Tips and Examples

Java 8 Stream Operatinos // Extract a specific property list from a collection List<String> taskIds = taskList.stream().map(TaskItem::getTaskId).collect(Collectors.toList()); // Group collection elements by an attribute (key: attribute value, value: sub-list) Map<String, List<UserProfile...

Essential MySQL Query Patterns and Techniques

Conditional Query Execution Execute queries only when parameter are not empty: SELECT * FROM t_interlinkage WHERE IF('翁二翁' != '', name LIKE '%翁二翁%', 1=1); Enhanced fuzzy search with concatenation: SELECT * FROM t_interlinkage WHERE IF('翁二翁' != '', name LIKE CONCAT('%', '翁二翁', '%'), 1=1); Comma-Separ...

Understanding the Performance Impact of @Transactional(readOnly=true) in Spring

Today, I want to discuss the @Transactional(readOnly = true) annotation provided by Spring. I'm bringing this up because there are many instances of @Transactional(readOnly = true) in my company's project code, and colleagues who have used it say that @Transactional(readOnly = true) improves perform...

Constructing a Full-Outer-Join Style View Across Two Entities with Spring Data JPA

When two tables are related but you either don’t model the association or cannot rely on right joins through the Criteria API, you can still project a full "view" by composing three queries: interscetion (inner join), left-only, and right-only. The union of these results behaves like a ful...