Search in sources :

Example 1 with DataPointChangeDefinition

use of com.serotonin.m2m2.module.DataPointChangeDefinition in project ma-core-public by infiniteautomation.

the class DataPointDao method deleteDataPoints.

public void deleteDataPoints(final int dataSourceId) {
    List<DataPointVO> old = getDataPoints(dataSourceId, null, true);
    for (DataPointVO dp : old) {
        for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.beforeDelete(dp.getId());
    }
    getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {

        @SuppressWarnings("synthetic-access")
        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            List<Integer> pointIds = queryForList("select id from dataPoints where dataSourceId=?", new Object[] { dataSourceId }, Integer.class);
            if (pointIds.size() > 0)
                deleteDataPointImpl(createDelimitedList(new HashSet<>(pointIds), ",", null));
        }
    });
    for (DataPointVO dp : old) {
        for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.afterDelete(dp.getId());
        AuditEventType.raiseDeletedEvent(AuditEventType.TYPE_DATA_POINT, dp);
        this.countMonitor.decrement();
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataPointChangeDefinition(com.serotonin.m2m2.module.DataPointChangeDefinition) TransactionStatus(org.springframework.transaction.TransactionStatus) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) HashSet(java.util.HashSet)

Example 2 with DataPointChangeDefinition

use of com.serotonin.m2m2.module.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();
}
Also used : DataPointChangeDefinition(com.serotonin.m2m2.module.DataPointChangeDefinition)

Example 3 with DataPointChangeDefinition

use of com.serotonin.m2m2.module.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();
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointChangeDefinition(com.serotonin.m2m2.module.DataPointChangeDefinition) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 4 with DataPointChangeDefinition

use of com.serotonin.m2m2.module.DataPointChangeDefinition in project ma-core-public by infiniteautomation.

the class DataPointDao method updateDataPoint.

void updateDataPoint(final DataPointVO dp) {
    for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.beforeUpdate(dp);
    DataPointVO old = getDataPoint(dp.getId());
    // If have a new data type we will wipe our history
    if (old.getPointLocator().getDataTypeId() != dp.getPointLocator().getDataTypeId())
        Common.databaseProxy.newPointValueDao().deletePointValues(dp.getId());
    // Save the VO information.
    updateDataPointShallow(dp);
    AuditEventType.raiseChangedEvent(AuditEventType.TYPE_DATA_POINT, old, dp);
    // Save the relational information.
    saveRelationalData(dp, false);
    for (DataPointChangeDefinition def : ModuleRegistry.getDefinitions(DataPointChangeDefinition.class)) def.afterUpdate(dp);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointChangeDefinition(com.serotonin.m2m2.module.DataPointChangeDefinition)

Aggregations

DataPointChangeDefinition (com.serotonin.m2m2.module.DataPointChangeDefinition)4 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 TransactionStatus (org.springframework.transaction.TransactionStatus)2 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1