package app.services.db; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; @Service public class DBService { EntityManager entityManager_rw; EntityManager entityManager_ro; @Autowired public DBService( @Qualifier(value = "RwEntityManager") EntityManager entityManager_rw, @Qualifier(value = "RoEntityManager") EntityManager entityManager_ro ) { this.entityManager_rw = entityManager_rw; this.entityManager_ro = entityManager_ro; } public Long getDBServerTime() { Long rw_time = getMainServerTime(); Long ro_time = getReplicaServerTime(); return rw_time; } public Long getMainServerTime() { return (Long) entityManager_rw.createNativeQuery("SELECT UNIX_TIMESTAMP()") .getSingleResult(); } public Long getReplicaServerTime() { return (Long) entityManager_ro.createNativeQuery("SELECT UNIX_TIMESTAMP()") .getSingleResult(); } }