I have an application downloading a document. After loading the document, the document path is created again and the document is saved in the file path. At the same time, the document path and associated values are stored in the database table. In my application, after loading, there is a button for deleting an unwanted document. Sometimes the deletion operation does not work properly. There is also memory loss. I want to avoid the situation using a transaction statement. I don’t know, I know how to use a sleep transaction for my work. Is it possible? Please help me get the job done successfully (I use spring with the integration of sleep mode and postgresql)
thanks
In the controller
int supDocId=1102;
String docPath=D:/;
String filePath=docPath+supDocId+".pdf";
File file=new File(filePath);
boolean isDelete = servicesService.deleteDocument(supDocId);
if(isDelete)
{
if(file.exists())
{
file.delete();
}
alertMsg = "The file is deleted sucessfully";
}
else{
alertMsg = "Deletion Failed.!!! File is under processing..";
}
In class of service
public boolean deleteDocument(int supDocId){
return servicesDAO.deleteDocument(supDocId);
}
In the servicesDAO class
public boolean deleteDocument(int supDocId){
int deleteStatus=0;
try {
String deleteQuery = "DELETE FROM tablename WHERE attch_doc_id='"+supDocId+"'";
Query deleteQ = session.createSQLQuery(deleteQuery);
deleteStatus = deleteQ.executeUpdate();
if(deleteStatus>0){
return deleteStatus;
}
} catch (Exception e) {
e.printStackTrace();
}
return deleteStatus;
}
I want to work with two operations (deleting a document and a database) in a DAO class using a transaction statement.
user5387294
source
share