update the file ID on a document with a native query

This commit is contained in:
Benjamin Gamard 2019-02-07 14:50:47 +01:00
parent 516a5f03e3
commit e39c83a5a6
2 changed files with 19 additions and 17 deletions

View File

@ -196,21 +196,6 @@ public class DocumentDao {
* @return Updated document * @return Updated document
*/ */
public Document update(Document document, String userId) { public Document update(Document document, String userId) {
Document documentDb = updateSilently(document);
// Create audit log
AuditLogUtil.create(documentDb, AuditLogType.UPDATE, userId);
return documentDb;
}
/**
* Update a document without audit log.
*
* @param document Document to update
* @return Updated document
*/
public Document updateSilently(Document document) {
EntityManager em = ThreadLocalContext.get().getEntityManager(); EntityManager em = ThreadLocalContext.get().getEntityManager();
// Get the document // Get the document
@ -233,10 +218,27 @@ public class DocumentDao {
documentDb.setLanguage(document.getLanguage()); documentDb.setLanguage(document.getLanguage());
documentDb.setFileId(document.getFileId()); documentDb.setFileId(document.getFileId());
documentDb.setUpdateDate(new Date()); documentDb.setUpdateDate(new Date());
// Create audit log
AuditLogUtil.create(documentDb, AuditLogType.UPDATE, userId);
return documentDb; return documentDb;
} }
/**
* Update the file ID on a document.
*
* @param document Document
*/
public void updateFileId(Document document) {
EntityManager em = ThreadLocalContext.get().getEntityManager();
Query query = em.createNativeQuery("update T_DOCUMENT d set d.DOC_IDFILE_C = :fileId where d.DOC_ID_C = :id");
query.setParameter("fileId", document.getFileId());
query.setParameter("id", document.getId());
query.executeUpdate();
}
/** /**
* Returns the number of documents. * Returns the number of documents.
* *

View File

@ -58,7 +58,7 @@ public class DocumentUpdatedAsyncListener {
} }
// Update database and index // Update database and index
documentDao.updateSilently(document); documentDao.updateFileId(document);
AppContext.getInstance().getIndexingHandler().updateDocument(document); AppContext.getInstance().getIndexingHandler().updateDocument(document);
// Update contributors list // Update contributors list