use of com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition in project ma-core-public by infiniteautomation.
the class DataPointDao method insertDataPoint.
void insertDataPoint(final DataPointVO dp) {
for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.beforeInsert(dp);
// Create a default text renderer
if (dp.getTextRenderer() == null)
dp.defaultTextRenderer();
dp.setId(ejt.doInsert(//
"insert into dataPoints (xid, dataSourceId, name, deviceName, enabled, pointFolderId, loggingType, " + //
"intervalLoggingPeriodType, intervalLoggingPeriod, intervalLoggingType, tolerance, " + //
"purgeOverride, purgeType, purgePeriod, defaultCacheSize, discardExtremeValues, " + //
"engineeringUnits, readPermission, setPermission, templateId, rollup, dataTypeId, data) " + //
"values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", new Object[] { dp.getXid(), dp.getDataSourceId(), dp.getName(), dp.getDeviceName(), boolToChar(dp.isEnabled()), dp.getPointFolderId(), dp.getLoggingType(), dp.getIntervalLoggingPeriodType(), dp.getIntervalLoggingPeriod(), dp.getIntervalLoggingType(), dp.getTolerance(), boolToChar(dp.isPurgeOverride()), dp.getPurgeType(), dp.getPurgePeriod(), dp.getDefaultCacheSize(), boolToChar(dp.isDiscardExtremeValues()), dp.getEngineeringUnits(), dp.getReadPermission(), dp.getSetPermission(), dp.getTemplateId(), dp.getRollup(), dp.getPointLocator().getDataTypeId(), //
SerializationHelper.writeObject(dp) }, new int[] { Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.CHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.DOUBLE, Types.CHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.CHAR, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.BINARY }));
// Save the relational information.
saveRelationalData(dp, true);
AuditEventType.raiseAddedEvent(AuditEventType.TYPE_DATA_POINT, dp);
for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.afterInsert(dp);
this.countMonitor.increment();
}
use of com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition in project ma-core-public by infiniteautomation.
the class DataPointDao method deleteDataPoint.
public void deleteDataPoint(final int dataPointId) {
DataPointVO dp = getDataPoint(dataPointId);
if (dp != null) {
for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.beforeDelete(dataPointId);
getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
deleteDataPointImpl(Integer.toString(dataPointId));
}
});
for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.afterDelete(dataPointId);
AuditEventType.raiseDeletedEvent(AuditEventType.TYPE_DATA_POINT, dp);
countMonitor.decrement();
}
}
use of com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition in project ma-core-public by infiniteautomation.
the class DataPointDao method deleteBatch.
/**
* Delete a batch of data points in bulk (for performance)
*/
protected void deleteBatch(List<DataPointVO> batch, List<Integer> ids, Set<Integer> permissionIds, Set<Integer> seriesIds) {
// delete event handler mappings
create.deleteFrom(eventHandlersMapping).where(eventHandlersMapping.eventTypeName.eq(EventTypeNames.DATA_POINT), eventHandlersMapping.eventTypeRef1.in(ids)).execute();
// delete user comments
create.deleteFrom(userComments).where(userComments.commentType.eq(2), userComments.typeKey.in(ids)).execute();
// delete event detectors
create.deleteFrom(eventDetectors).where(eventDetectors.dataPointId.in(ids)).execute();
for (DataPointVO vo : batch) {
DataSourceDefinition<? extends DataSourceVO> def = ModuleRegistry.getDataSourceDefinition(vo.getPointLocator().getDataSourceType());
if (def != null) {
def.deleteRelationalData(vo);
}
// Run Pre Delete Change definitions
for (DataPointChangeDefinition changeDefinition : changeDefinitions) {
changeDefinition.preDelete(vo);
}
}
// delete the points in bulk
int deleted = create.deleteFrom(table).where(table.id.in(ids)).execute();
if (this.countMonitor != null) {
this.countMonitor.addValue(-deleted);
}
for (Integer id : permissionIds) {
permissionService.deletePermissionId(id);
}
// Try to delete the timeSeries.id row
for (Integer seriesId : seriesIds) {
try {
this.create.deleteFrom(TimeSeries.TIME_SERIES).where(TimeSeries.TIME_SERIES.id.eq(seriesId)).execute();
} catch (Exception e) {
// Probably in use by another point (2 points on the same series)
}
}
// Run Post Delete Change definitions
for (DataPointVO vo : batch) {
for (DataPointChangeDefinition changeDefinition : changeDefinitions) {
changeDefinition.postDelete(vo);
}
}
// Audit Events/Dao events
for (DataPointVO vo : batch) {
publishEvent(createDaoEvent(DaoEventType.DELETE, vo, null));
publishAuditEvent(new DeleteAuditEvent<DataPointVO>(this.auditEventType, Common.getUser(), vo));
}
}
use of com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition in project ma-core-public by infiniteautomation.
the class DataPointService method update.
@Override
protected DataPointVO update(DataPointVO existing, DataPointVO vo) throws PermissionException, ValidationException {
PermissionHolder user = Common.getUser();
ensureEditPermission(user, existing);
vo.setId(existing.getId());
for (DataPointChangeDefinition def : changeDefinitions) {
def.preUpdate(vo);
}
ensureValid(existing, vo);
getRuntimeManager().stopDataPoint(vo.getId());
dao.update(existing, vo);
for (DataPointChangeDefinition def : changeDefinitions) {
def.postUpdate(vo);
}
if (vo.isEnabled()) {
List<AbstractPointEventDetectorVO> detectors = eventDetectorDao.getWithSource(vo.getId(), vo);
getRuntimeManager().startDataPoint(new DataPointWithEventDetectors(vo, detectors));
}
return vo;
}
use of com.serotonin.m2m2.module.definitions.dataPoint.DataPointChangeDefinition in project ma-core-public by infiniteautomation.
the class DataPointService method delete.
@Override
protected DataPointVO delete(DataPointVO vo) throws PermissionException, NotFoundException {
PermissionHolder user = Common.getUser();
ensureDeletePermission(user, vo);
for (DataPointChangeDefinition def : changeDefinitions) {
def.preDelete(vo);
}
getRuntimeManager().stopDataPoint(vo.getId());
dao.delete(vo);
for (DataPointChangeDefinition def : changeDefinitions) {
def.postDelete(vo);
}
pointValueCache.deleteCache(vo);
getEventManager().cancelEventsForDataPoint(vo.getId());
return vo;
}
Aggregations