Search in sources :

Example 11 with SetPointSource

use of com.serotonin.m2m2.rt.dataImage.SetPointSource in project ma-core-public by infiniteautomation.

the class PointValueDaoSQL method savePointValueImpl.

private long savePointValueImpl(int pointId, int dataType, double dvalue, long time, String svalue, SetPointSource source) {
    long id = doInsertLong(POINT_VALUE_INSERT, new Object[] { pointId, dataType, dvalue, time });
    if (svalue == null && dataType == DataTypes.IMAGE)
        svalue = Long.toString(id);
    // Check if we need to create an annotation.
    TranslatableMessage sourceMessage = null;
    if (source != null)
        sourceMessage = source.getSetPointSourceMessage();
    if (svalue != null || sourceMessage != null) {
        String shortString = null;
        String longString = null;
        if (svalue != null) {
            if (svalue.length() > 128)
                longString = svalue;
            else
                shortString = svalue;
        }
        // 
        ejt.update(// 
        POINT_VALUE_ANNOTATION_INSERT, // 
        new Object[] { id, shortString, longString, writeTranslatableMessage(sourceMessage) }, new int[] { Types.INTEGER, Types.VARCHAR, Types.CLOB, Types.CLOB });
    }
    return id;
}
Also used : TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 12 with SetPointSource

use of com.serotonin.m2m2.rt.dataImage.SetPointSource in project ma-core-public by infiniteautomation.

the class PointValueDaoSQL method savePointValueImpl.

long savePointValueImpl(final int pointId, final PointValueTime pointValue, final SetPointSource source, boolean async) {
    DataValue value = pointValue.getValue();
    final int dataType = DataTypes.getDataType(value);
    double dvalue = 0;
    String svalue = null;
    if (dataType == DataTypes.IMAGE) {
        ImageValue imageValue = (ImageValue) value;
        dvalue = imageValue.getType();
        if (imageValue.isSaved())
            svalue = Long.toString(imageValue.getId());
    } else if (value.hasDoubleRepresentation())
        dvalue = value.getDoubleValue();
    else
        svalue = value.getStringValue();
    // Check if we need to create an annotation.
    long id;
    try {
        if (svalue != null || source != null || dataType == DataTypes.IMAGE)
            async = false;
        id = savePointValue(pointId, dataType, dvalue, pointValue.getTime(), svalue, source, async);
    } catch (ConcurrencyFailureException e) {
        // Still failed to insert after all of the retries. Store the data
        synchronized (UNSAVED_POINT_VALUES) {
            UNSAVED_POINT_VALUES.add(new UnsavedPointValue(pointId, pointValue, source));
        }
        return -1;
    }
    // Check if we need to save an image
    if (dataType == DataTypes.IMAGE) {
        ImageValue imageValue = (ImageValue) value;
        if (!imageValue.isSaved()) {
            imageValue.setId(id);
            File file = new File(Common.getFiledataPath(), imageValue.getFilename());
            // Write the file.
            FileOutputStream out = null;
            try {
                out = new FileOutputStream(file);
                StreamUtils.transfer(new ByteArrayInputStream(imageValue.getData()), out);
            } catch (IOException e) {
                // Rethrow as an RTE
                throw new ImageSaveException(e);
            } finally {
                try {
                    if (out != null)
                        out.close();
                } catch (IOException e) {
                // no op
                }
            }
            // Allow the data to be GC'ed
            imageValue.setData(null);
        }
    }
    clearUnsavedPointValues();
    clearUnsavedPointUpdates();
    return id;
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) ConcurrencyFailureException(org.springframework.dao.ConcurrencyFailureException) FileOutputStream(java.io.FileOutputStream) ImageSaveException(com.serotonin.m2m2.ImageSaveException) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue) File(java.io.File)

Example 13 with SetPointSource

use of com.serotonin.m2m2.rt.dataImage.SetPointSource in project ma-core-public by infiniteautomation.

the class PointValueDaoMetrics method updatePointValueSync.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.db.dao.PointValueDao#updatePointValueSync(int, com.serotonin.m2m2.rt.dataImage.PointValueIdTime, com.serotonin.m2m2.rt.dataImage.SetPointSource)
	 */
@Override
public PointValueTime updatePointValueSync(int dataPointId, PointValueTime pvt, SetPointSource source) {
    LogStopWatch LogStopWatch = new LogStopWatch();
    PointValueTime value = dao.updatePointValueSync(dataPointId, pvt, source);
    LogStopWatch.stop("updatePointValuesSync(dataPointId, ts, source) (" + dataPointId + ", pvt, source)", this.metricsThreshold);
    return value;
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) LogStopWatch(com.serotonin.log.LogStopWatch)

Aggregations

PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)5 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)4 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)4 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)4 ConcurrencyFailureException (org.springframework.dao.ConcurrencyFailureException)4 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)3 IOException (java.io.IOException)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 ImageSaveException (com.serotonin.m2m2.ImageSaveException)2 AnnotatedIdPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedIdPointValueTime)2 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 SerialPortException (com.infiniteautomation.mango.io.serial.SerialPortException)1 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)1 ValidationFailedRestException (com.infiniteautomation.mango.rest.v2.exception.ValidationFailedRestException)1 LogStopWatch (com.serotonin.log.LogStopWatch)1 RTException (com.serotonin.m2m2.rt.RTException)1