use of de.metas.ui.web.window.model.DocumentQuery in project metasfresh-webui-api by metasfresh.
the class SqlDocumentsRepository method refresh.
private void refresh(@NonNull final Document document, @NonNull final DocumentId documentId) {
logger.debug("Refreshing: {}, using ID={}", document, documentId);
if (documentId.isNew()) {
throw new AdempiereException("Invalid documentId to refresh: " + documentId);
}
final DocumentEntityDescriptor entityDescriptor = document.getEntityDescriptor();
final DocumentQuery query = DocumentQuery.ofRecordId(entityDescriptor, documentId).setChangesCollector(document.getChangesCollector()).build();
final SqlDocumentQueryBuilder sqlBuilder = SqlDocumentQueryBuilder.of(query);
final List<Object> sqlParams = new ArrayList<>();
final String sql = sqlBuilder.getSql(sqlParams);
final String adLanguage = sqlBuilder.getAD_Language();
logger.debug("Retrieving records: SQL={} -- {}", sql, sqlParams);
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, ITrx.TRXNAME_ThreadInherited);
DB.setParameters(pstmt, sqlParams);
rs = pstmt.executeQuery();
if (rs.next()) {
final ResultSetDocumentValuesSupplier fieldValueSupplier = new ResultSetDocumentValuesSupplier(entityDescriptor, adLanguage, rs);
document.refreshFromSupplier(fieldValueSupplier);
} else {
// Document is no longer in our repository
final DocumentPath documentPathEffective = document.getDocumentPath().withDocumentId(documentId);
throw new DocumentNotFoundException(documentPathEffective);
}
if (rs.next()) {
throw new AdempiereException("More than one record found while trying to reload document: " + document);
}
} catch (final SQLException e) {
throw new DBException(e, sql, sqlParams);
} finally {
DB.close(rs, pstmt);
}
}
Aggregations