use of org.thingsboard.server.dao.model.sql.EventEntity in project thingsboard by thingsboard.
the class JpaBaseEventDao method findEvents.
@Override
public List<Event> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink) {
Specification<EventEntity> timeSearchSpec = JpaAbstractSearchTimeDao.getTimeSearchPageSpec(pageLink, "id");
Specification<EventEntity> fieldsSpec = getEntityFieldsSpec(tenantId, entityId, eventType);
Sort.Direction sortDirection = pageLink.isAscOrder() ? Sort.Direction.ASC : Sort.Direction.DESC;
Pageable pageable = new PageRequest(0, pageLink.getLimit(), sortDirection, ID_PROPERTY);
return DaoUtil.convertDataList(eventRepository.findAll(where(timeSearchSpec).and(fieldsSpec), pageable).getContent());
}
use of org.thingsboard.server.dao.model.sql.EventEntity in project thingsboard by thingsboard.
the class JpaBaseEventDao method init.
@PostConstruct
private void init() {
TbSqlBlockingQueueParams params = TbSqlBlockingQueueParams.builder().logName("Events").batchSize(batchSize).maxDelay(maxDelay).statsPrintIntervalMs(statsPrintIntervalMs).statsNamePrefix("events").batchSortEnabled(batchSortEnabled).build();
Function<EventEntity, Integer> hashcodeFunction = entity -> entity.getEntityId().hashCode();
queue = new TbSqlBlockingQueueWrapper<>(params, hashcodeFunction, batchThreads, statsFactory);
queue.init(logExecutor, v -> eventInsertRepository.save(v), Comparator.comparing((EventEntity eventEntity) -> eventEntity.getTs()));
}
use of org.thingsboard.server.dao.model.sql.EventEntity in project thingsboard by thingsboard.
the class EventInsertRepository method save.
protected void save(List<EventEntity> entities) {
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
jdbcTemplate.batchUpdate(INSERT, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
EventEntity event = entities.get(i);
ps.setObject(1, event.getId());
ps.setLong(2, event.getCreatedTime());
ps.setString(3, replaceNullChars(event.getBody().toString()));
ps.setObject(4, event.getEntityId());
ps.setString(5, event.getEntityType().name());
ps.setString(6, event.getEventType());
ps.setString(7, event.getEventUid());
ps.setObject(8, event.getTenantId());
ps.setLong(9, event.getTs());
}
@Override
public int getBatchSize() {
return entities.size();
}
});
}
});
}
use of org.thingsboard.server.dao.model.sql.EventEntity in project thingsboard by thingsboard.
the class JpaBaseEventDao method saveAsync.
@Override
public ListenableFuture<Void> saveAsync(Event event) {
log.debug("Save event [{}] ", event);
if (event.getId() == null) {
UUID timeBased = Uuids.timeBased();
event.setId(new EventId(timeBased));
event.setCreatedTime(Uuids.unixTimestamp(timeBased));
} else if (event.getCreatedTime() == 0L) {
UUID eventId = event.getId().getId();
if (eventId.version() == 1) {
event.setCreatedTime(Uuids.unixTimestamp(eventId));
} else {
event.setCreatedTime(System.currentTimeMillis());
}
}
if (StringUtils.isEmpty(event.getUid())) {
event.setUid(event.getId().toString());
}
return save(new EventEntity(event));
}
Aggregations