use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class DataPurge method purgePoint.
private void purgePoint(DataPointVO dataPoint, boolean countPointValues) {
if (dataPoint.getLoggingType() == DataPointVO.LoggingTypes.NONE) {
// If there is no logging, then there should be no data, unless logging was just changed to none. In either
// case, it's ok to delete everything.
log.info("Purging all data for data point with id " + dataPoint.getId() + " because it is set to logging type NONE.");
if (Common.runtimeManager.getState() == RuntimeManager.RUNNING) {
if (countPointValues)
deletedSamples += Common.runtimeManager.purgeDataPointValues(dataPoint.getId());
else {
if (Common.runtimeManager.purgeDataPointValuesWithoutCount(dataPoint.getId()))
anyDeletedSamples = true;
}
}
} else {
// Determine the purging properties to use.
int purgeType;
int purgePeriod;
if (dataPoint.isPurgeOverride()) {
purgeType = dataPoint.getPurgeType();
purgePeriod = dataPoint.getPurgePeriod();
} else {
// Check the data source level.
DataSourceVO<?> ds = DataSourceDao.instance.getDataSource(dataPoint.getDataSourceId());
if (ds.isPurgeOverride()) {
purgeType = ds.getPurgeType();
purgePeriod = ds.getPurgePeriod();
} else {
// Use the system settings.
purgeType = SystemSettingsDao.getIntValue(SystemSettingsDao.POINT_DATA_PURGE_PERIOD_TYPE);
purgePeriod = SystemSettingsDao.getIntValue(SystemSettingsDao.POINT_DATA_PURGE_PERIODS);
}
}
List<PurgeFilter> purgeFilters = new ArrayList<PurgeFilter>();
for (PurgeFilterDefinition pfd : ModuleRegistry.getDefinitions(PurgeFilterDefinition.class)) purgeFilters.add(pfd.getPurgeFilter());
// No matter when this purge actually runs, we want it to act like it's midnight.
DateTime cutoff = new DateTime(runtime);
cutoff = DateUtils.truncateDateTime(cutoff, Common.TimePeriods.DAYS);
cutoff = DateUtils.minus(cutoff, purgeType, purgePeriod);
if (Common.runtimeManager.getState() == RuntimeManager.RUNNING) {
long millis = cutoff.getMillis();
for (PurgeFilter pf : purgeFilters) millis = pf.adjustPurgeTime(dataPoint, millis);
if (countPointValues)
deletedSamples += Common.runtimeManager.purgeDataPointValues(dataPoint.getId(), cutoff.getMillis());
else {
if (Common.runtimeManager.purgeDataPointValuesWithoutCount(dataPoint.getId(), cutoff.getMillis()))
anyDeletedSamples = true;
}
}
// If this is an image data type, get the point value ids.
if (dataPoint.getPointLocator().getDataTypeId() == DataTypes.IMAGE)
fileIds.addAll(pointValueDao.getFiledataIds(dataPoint.getId()));
}
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class JsonEmportScriptUtility method dataPointQuery.
public String dataPointQuery(String query, int prettyIndent) {
Map<String, Object> data = new LinkedHashMap<>();
if (admin) {
ASTNode root = parser.parse(query);
List<DataPointVO> dataPoints = new ArrayList<>();
ConditionSortLimitWithTagKeys conditions = DataPointDao.instance.rqlToCondition(root);
DataPointDao.instance.customizedQuery(conditions, new MappedRowCallback<DataPointVO>() {
@Override
public void row(DataPointVO item, int index) {
dataPoints.add(item);
}
});
data.put(ConfigurationExportData.DATA_POINTS, dataPoints);
}
return EmportDwr.export(data, prettyIndent);
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class VarNames method contextToString.
public static String contextToString(List<IntStringPair> context) {
DataPointDao dataPointDao = DataPointDao.instance;
StringBuilder sb = new StringBuilder();
boolean first = true;
for (IntStringPair ivp : context) {
DataPointVO dp = dataPointDao.getDataPoint(ivp.getKey(), false);
if (first)
first = false;
else
sb.append(", ");
if (dp == null)
sb.append("?=");
else
sb.append(dp.getExtendedName()).append("=");
sb.append(ivp.getValue());
}
return sb.toString();
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class DataPointDao method bulkClearPermissions.
/**
* @param node
* @param updateSetPermissions - true will update set, false will update read
* @return
*/
public long bulkClearPermissions(ASTNode root, boolean updateSetPermissions) {
long count;
if (root == null) {
// All points
count = ejt.execute(new DataPointPermissionChangePreparedStatementCreator("SELECT dp.id,dp.readPermission,dp.setPermission FROM dataPoints AS dp FOR UPDATE; ", new ArrayList<Object>()), new DataPointPermissionChangeCallback(updateSetPermissions, null));
} else {
switch(Common.databaseProxy.getType()) {
case H2:
case DERBY:
case MSSQL:
case MYSQL:
case POSTGRES:
default:
final SQLStatement select = new SQLStatement("SELECT dp.id,dp.readPermission,dp.setPermission FROM ", COUNT_BASE, this.joins, this.tableName, this.TABLE_PREFIX, true, false, super.getIndexes(), this.databaseType);
root.accept(new RQLToSQLSelect<DataPointVO>(this), select);
select.build();
count = ejt.execute(new DataPointPermissionChangePreparedStatementCreator(select.getSelectSql() + " FOR UPDATE; ", select.getSelectArgs()), new DataPointPermissionChangeCallback(updateSetPermissions, null));
break;
}
}
return count;
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-core-public by infiniteautomation.
the class DataPointDao method bulkUpdatePermissions.
/**
* @param node
* @param permissions
* @param updateSetPermissions - true will update set, false will update read
* @return
*/
public long bulkUpdatePermissions(ASTNode root, String uncleanPermissions, boolean updateSetPermissions) {
// Anything to do?
if (StringUtils.isEmpty(uncleanPermissions))
return 0;
// Trim off any ending commas
if (uncleanPermissions.endsWith(",")) {
uncleanPermissions = uncleanPermissions.substring(0, uncleanPermissions.length() - 1);
}
final String newPermissions = uncleanPermissions;
long count;
if (root == null) {
// All points
count = ejt.execute(new DataPointPermissionChangePreparedStatementCreator("SELECT dp.id,dp.readPermission,dp.setPermission FROM dataPoints AS dp FOR UPDATE; ", new ArrayList<Object>()), new DataPointPermissionChangeCallback(updateSetPermissions, newPermissions));
} else {
switch(Common.databaseProxy.getType()) {
case H2:
case DERBY:
case MSSQL:
case MYSQL:
case POSTGRES:
default:
final SQLStatement select = new SQLStatement("SELECT dp.id,dp.readPermission,dp.setPermission FROM ", COUNT_BASE, this.joins, this.tableName, this.TABLE_PREFIX, true, false, super.getIndexes(), this.databaseType);
root.accept(new RQLToSQLSelect<DataPointVO>(this), select);
select.build();
count = ejt.execute(new DataPointPermissionChangePreparedStatementCreator(select.getSelectSql() + " FOR UPDATE; ", select.getSelectArgs()), new DataPointPermissionChangeCallback(updateSetPermissions, newPermissions));
break;
}
}
return count;
}
Aggregations