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;
}
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;
}
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;
}
Aggregations