In Java servers, persistence layer is also known as the repository layer. This layer is responsible for data persistence and is used by the business layer to access the cache and database.
In terms of functionality, it is fine to write the persistence layer code in the service class. This is why many users are happy to accept this coding method. But we may meet some problems in this way.
Main Problems
The following is a recommended solution which takes the direct query of the database persistence middleware Hibernate as an example.
/** User DAO CLass */
@Repository
public class UserDAO {
/** Session factory */
@Autowired
private SessionFactory sessionFactory;
/** Get user function based on job number */
public UserDO getUserByEmpId(String empId) {
// Assemble HQLstatement
String hql = "from t_user where emp_id = '" + empId + "'";
// Perform database query
Query query = sessionFactory.getCurrentSession().createQuery(hql);
List<UserDO> userList = query.list();
if (CollectionUtils.isEmpty(userList)) {
return null;
}
// Return user information
return userList.get(0);
}
}
/** User Service Class */
@Service
public class UserService {
/** User DAO */
@Autowired
private UserDAO userDAO;
/** Get user function based on job number */
public UserVO getUserByEmpId(String empId) {
// Query user based on job number
UserDO userDO = userDAO.getUserByEmpId(empId);
if (Objects.isNull(userDO)) {
return null;
}
// Convert and return user
UserVO userVO = new UserVO();
BeanUtils.copyProperties(userDO, userVO);
return userVO;
}
}
For other chaos and solutions for Java servers, you can go to Let's Talk about Some of the Chaos You'll Find on Java Servers in Startups.
SaaS service providers must always consider the large number of users when designing an appropriate business architecture. The large user base and massive user data require both efficiency and stability in the infrastructure construction. However, traditional infrastructure construction programs are costly, laborious, and involve complex implementation.
When the user completes the initialization and starts business operations, the business layer will call the operation interface of DB Wrapper. After DB Wrapper receives the request, it will match the router based on the User_id passed in from the business layer to determine the final RDS instance and database on which to operate. After making the judgment, the next task will be establishing connections and executing the requests systematically. Specific code implementation requires their combination with their respective persistence layer framework and a developer who has made some research on the persistence layer framework should be able to complete the process.
This article summarizes the presentation at the Yunqi Community Director's Course and shares some practical tips and development trends of the Cloud Native technology.
Alibaba Cloud Container Service provides a solution that supports the end-to-end analysis of Jaeger based on SLS. No maintenance is required in the data persistence layer.
This topic describes the integration of the Alibaba Cloud LongVideo AppServer. You can use this AppServer for many events such as data exchange between the LongVideo application and ApsaraVideo for VOD, business logic processing, and data management. For example, you can randomly generate users, obtain video lists, obtain credential information, upload videos, and process various callback events. The technologies involved include the Spring Boot microservice framework, ApsaraDB RDS for MySQL, and MyBatis persistence framework.
The AppServer project supports the client in calling relevant methods and organizes data logic for the client. The directory structure of the project can be divided to the control layer, dao layer, service layer, and persistence layer.
The following Alibaba Cloud services are required: Elastic Compute Service (ECS) with Java environment configured, ApsaraDB for RDS, and ApsaraVideo for VOD.
High-speed Service Framework (HSF) is a distributed RPC service framework widely used within the Alibaba Group.
HSF connects different business systems, decoupling the implementation of the systems from each other.HSF unifies service publishing/call methods from the perspective of distributed applications, helping you conveniently and quickly develop distributed applications. It provides public function modules, which avoid complex technical details in distributed systems, such as remote communication, serialization implementation, performance loss, and synchronous/asynchronous call method implementation.
The persistent configuration center is used to store various governance rules of HSF services. At startup, the HSF client subscribes necessary service governance rules, such as routing rules, grouping rules, and weight rules, from the persistent configuration center to intervene in the address selection logic of the calling procedure based on the rules.The role of persistence configuration center is played by Diamond.
Check out Alibaba's Big Double 11 Bash and See How Alibaba's Revolutionizing E-Commerce
2,599 posts | 762 followers
FollowAlibaba Cloud Native - November 4, 2019
Alibaba Clouder - August 24, 2017
Alibaba Developer - December 17, 2018
Alibaba Clouder - November 23, 2020
Alibaba Cloud Security - March 20, 2019
Alibaba Cloud Serverless - November 10, 2022
2,599 posts | 762 followers
FollowLearn More
Elastic and secure virtual cloud servers to cater all your cloud hosting needs.
Learn MoreMore Posts by Alibaba Clouder