Configuration File Setup Define both data source connections in application.properties: # Primary Data Source spring.datasource.primary.jdbc-url=jdbc:mysql://192.168.1.100:3306/userdb?useUnicode=true&characterEncoding=UTF-8&useSSL=false spring.datasource.primary.username=admin spring.datasou...
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 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...
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...
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...
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...