Link to JPA established and writing :)

This commit is contained in:
MathewFrancis 2025-04-04 14:13:39 +05:30
parent 9f036e3d0e
commit 721f00bdf8
6 changed files with 32 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package com.example.cezenPBX.DAO;
import com.example.cezenPBX.entity.PsEndPoints; import com.example.cezenPBX.entity.PsEndPoints;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -16,8 +17,10 @@ public class BasicAsteriskOpsDAO implements CezenPbxOpsDAO {
// takes the required data from the service class and persists the entity to the database // takes the required data from the service class and persists the entity to the database
// returns true if operation was carried out without an exception // returns true if operation was carried out without an exception
@Override @Override
@Transactional
public boolean addNewEndPoint(PsEndPoints psEndPoints) { public boolean addNewEndPoint(PsEndPoints psEndPoints) {
// if there is an exception in the transaction
try{ try{
this.entityManager.persist(psEndPoints); this.entityManager.persist(psEndPoints);
}catch (Exception e){ }catch (Exception e){

View File

@ -22,6 +22,22 @@ public class CezenPbxController {
System.out.println(psEndPointsRecordDTO); System.out.println(psEndPointsRecordDTO);
return false; // now pass the DTO data to the service
return this.basicPbxServiceInterface.createANewEndpointService(
psEndPointsRecordDTO.id(),
psEndPointsRecordDTO.transport(),
psEndPointsRecordDTO.aors(),
psEndPointsRecordDTO.auth(),
psEndPointsRecordDTO.context(),
psEndPointsRecordDTO.disallow(),
psEndPointsRecordDTO.allow(),
psEndPointsRecordDTO.directMedia(),
psEndPointsRecordDTO.connectedLineMethod(),
psEndPointsRecordDTO.callerid(),
psEndPointsRecordDTO.dtmfMode(),
psEndPointsRecordDTO.mohsuggest(),
psEndPointsRecordDTO.mailboxes()
);
} }
} }

View File

@ -1,9 +1,11 @@
package com.example.cezenPBX.entity; package com.example.cezenPBX.entity;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.Table; import jakarta.persistence.Table;
@Entity
@Table(name = "ps_endpoints") @Table(name = "ps_endpoints")
public class PsEndPoints { public class PsEndPoints {

View File

@ -35,6 +35,12 @@ public class BasicPbxService implements BasicPbxServiceInterface {
mailboxes mailboxes
); );
// if there is an exception in the entity or transaction
try{
return cezenPbxOpsDAO.addNewEndPoint(psEndPoints); return cezenPbxOpsDAO.addNewEndPoint(psEndPoints);
}catch (Exception e) {
System.out.println(e);
return false;
}
} }
} }

View File

@ -2,9 +2,9 @@ spring.application.name=cezenPBX
server.port=8081 server.port=8081
#server.port=8088 #server.port=8088
#spring.datasource.url = jdbc:mariadb://localhost:3308/asterisk_db spring.datasource.url = jdbc:mariadb://localhost:3308/asterisk_db
#spring.datasource.username = asterisk_user spring.datasource.username = asterisk_user
#spring.datasource.password = 12345 spring.datasource.password = 12345
logging.level.org.hibernate.SQL=DEBUG logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE