Examples of PointValueDao


Examples of com.serotonin.m2m2.db.dao.PointValueDao

    }

    private int importCsv(FileItem item) throws IOException, TranslatableException {
        CSVReader csvReader = new CSVReader(new InputStreamReader(item.getInputStream()));
        DataPointDao dataPointDao = new DataPointDao();
        PointValueDao pointValueDao = Common.databaseProxy.newPointValueDao();
        DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss");

        // Basic validation
        String[] nextLine = csvReader.readNext();
        if (nextLine == null)
            throw new TranslatableException(new TranslatableMessage("dataImport.import.noData"));
        if (nextLine.length < 2)
            throw new TranslatableException(new TranslatableMessage("dataImport.import.noPoints"));

        // Find the points by XID
        DataPointVO[] vos = new DataPointVO[nextLine.length - 1];

        for (int i = 1; i < nextLine.length; i++) {
            if (StringUtils.isBlank(nextLine[i]))
                throw new TranslatableException(new TranslatableMessage("dataImport.import.badXid", i));

            DataPointVO vo = dataPointDao.getDataPoint(nextLine[i]);
            if (vo == null)
                throw new TranslatableException(new TranslatableMessage("dataImport.import.xidNotFound", nextLine[i]));

            vos[i - 1] = vo;
        }

        // Find the RTs for the points if they are enabled
        DataPointRT[] rts = new DataPointRT[vos.length];
        for (int i = 0; i < vos.length; i++)
            rts[i] = Common.runtimeManager.getDataPoint(vos[i].getId());

        // Import the data
        int count = 0;
        while ((nextLine = csvReader.readNext()) != null) {
            // The first value is always a date.
            long time = dtf.parseDateTime(nextLine[0]).getMillis();

            // The rest of the values are point samples.
            for (int i = 1; i < nextLine.length; i++) {
                DataValue value = DataValue.stringToValue(nextLine[i], vos[i - 1].getPointLocator().getDataTypeId());
                PointValueTime pvt = new PointValueTime(value, time);

                if (rts[i - 1] != null)
                    rts[i - 1].savePointValueDirectToCache(pvt, null, true, true);
                else
                    // Save directly to the database
                    pointValueDao.savePointValueAsync(vos[i - 1].getId(), pvt, null);
            }

            count++;
        }
View Full Code Here

Examples of com.serotonin.m2m2.db.dao.PointValueDao

     * @param instance
     * @param points
     * @return
     */
    public int runReportSQL(final ReportInstance instance, List<PointInfo> points) {
        PointValueDao pointValueDao = Common.databaseProxy.newPointValueDao();
        int count = 0;

        // The timestamp selection code is used multiple times for different tables
        String timestampSql;
        Object[] timestampParams;
        if (instance.isFromInception() && instance.isToNow()) {
            timestampSql = "";
            timestampParams = new Object[0];
        }
        else if (instance.isFromInception()) {
            timestampSql = "and ${field}<?";
            timestampParams = new Object[] { instance.getReportEndTime() };
        }
        else if (instance.isToNow()) {
            timestampSql = "and ${field}>=?";
            timestampParams = new Object[] { instance.getReportStartTime() };
        }
        else {
            timestampSql = "and ${field}>=? and ${field}<?";
            timestampParams = new Object[] { instance.getReportStartTime(), instance.getReportEndTime() };
        }

        // For each point.
        for (PointInfo pointInfo : points) {
            DataPointVO point = pointInfo.getPoint();
            int dataType = point.getPointLocator().getDataTypeId();

            DataValue startValue = null;
            if (!instance.isFromInception()) {
                // Get the value just before the start of the report
                PointValueTime pvt = pointValueDao.getPointValueBefore(point.getId(), instance.getReportStartTime());
                if (pvt != null)
                    startValue = pvt.getValue();

                // Make sure the data types match
                if (DataTypes.getDataType(startValue) != dataType)
View Full Code Here

Examples of com.serotonin.m2m2.db.dao.PointValueDao

     * @param instance
     * @param points
     * @return
     */
    public int runReportNoSQL(final ReportInstance instance, List<PointInfo> points) {
        PointValueDao pointValueDao = Common.databaseProxy.newPointValueDao();
        final MappedCallbackCounter count = new MappedCallbackCounter();
        final NoSQLDao dao = Common.databaseProxy.getNoSQLProxy().createNoSQLDao(ReportPointValueTimeSerializer.get(), "reports");

        // The timestamp selection code is used multiple times for different tables
        String timestampSql;
        Object[] timestampParams;
        if (instance.isFromInception() && instance.isToNow()) {
            timestampSql = "";
            timestampParams = new Object[0];
        }
        else if (instance.isFromInception()) {
            timestampSql = "and ${field}<?";
            timestampParams = new Object[] { instance.getReportEndTime() };
        }
        else if (instance.isToNow()) {
            timestampSql = "and ${field}>=?";
            timestampParams = new Object[] { instance.getReportStartTime() };
        }
        else {
            timestampSql = "and ${field}>=? and ${field}<?";
            timestampParams = new Object[] { instance.getReportStartTime(), instance.getReportEndTime() };
        }

        // For each point.
        List<Integer> pointIds = new ArrayList<Integer>();
        //Map the pointId to the Report PointId
        final Map<Integer,Integer> pointIdMap = new HashMap<Integer,Integer>();

        //Loop over all points, pre-process them and prepare to transfer the data to
        // the reports table/data store
        for (PointInfo pointInfo : points) {
            DataPointVO point = pointInfo.getPoint();
            pointIds.add(point.getId());
            int dataType = point.getPointLocator().getDataTypeId();
           
           
            DataValue startValue = null;
            if (!instance.isFromInception()) {
                // Get the value just before the start of the report
                PointValueTime pvt = pointValueDao.getPointValueBefore(point.getId(), instance.getReportStartTime());
                if (pvt != null)
                    startValue = pvt.getValue();

                // Make sure the data types match
                if (DataTypes.getDataType(startValue) != dataType)
                    startValue = null;
            }

            // Insert the reportInstancePoints record
            String name = Functions.truncate(point.getName(), 100);
           
            int reportPointId = doInsert(
                    REPORT_INSTANCE_POINTS_INSERT,
                    new Object[] { instance.getId(), point.getDeviceName(), name, pointInfo.getPoint().getXid(), dataType,
                            DataTypes.valueToString(startValue),
                            SerializationHelper.writeObject(point.getTextRenderer()), pointInfo.getColour(),
                            pointInfo.getWeight(), boolToChar(pointInfo.isConsolidatedChart()), pointInfo.getPlotType() },
                    new int[] { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.BLOB,
                            Types.VARCHAR, Types.FLOAT, Types.CHAR, Types.INTEGER });

            //Keep the info in the map
            pointIdMap.put(pointInfo.getPoint().getId(), reportPointId);

            // Insert the reportInstanceDataAnnotations records
            ejt.update(
                    "insert into reportInstanceDataAnnotations " //
                            + "  (pointValueId, reportInstancePointId, textPointValueShort, textPointValueLong, sourceMessage) " //
                            + "  select rd.pointValueId, rd.reportInstancePointId, pva.textPointValueShort, " //
                            + "    pva.textPointValueLong, pva.sourceMessage " //
                            + "  from reportInstanceData rd " //
                            + "    join reportInstancePoints rp on rd.reportInstancePointId = rp.id " //
                            + "    join pointValueAnnotations pva on rd.pointValueId = pva.pointValueId " //
                            + "  where rp.id = ?", new Object[] { reportPointId });

            // Insert the reportInstanceEvents records for the point.
            if (instance.getIncludeEvents() != ReportVO.EVENTS_NONE) {
                String eventSQL = "insert into reportInstanceEvents " //
                        + "  (eventId, reportInstanceId, typeName, subtypeName, typeRef1, typeRef2, activeTs, " //
                        + "   rtnApplicable, rtnTs, rtnCause, alarmLevel, message, ackTs, ackUsername, " //
                        + "   alternateAckSource)" //
                        + "  select e.id, " + instance.getId() + ", e.typeName, e.subtypeName, e.typeRef1, " //
                        + "    e.typeRef2, e.activeTs, e.rtnApplicable, e.rtnTs, e.rtnCause, e.alarmLevel, " //
                        + "    e.message, e.ackTs, u.username, e.alternateAckSource " //
                        + "  from events e join userEvents ue on ue.eventId=e.id " //
                        + "    left join users u on e.ackUserId=u.id " //
                        + "  where ue.userId=? " //
                        + "    and e.typeName=? " //
                        + "    and e.typeRef1=? ";

                if (instance.getIncludeEvents() == ReportVO.EVENTS_ALARMS)
                    eventSQL += "and e.alarmLevel > 0 ";

                eventSQL += StringUtils.replaceMacro(timestampSql, "field", "e.activeTs");
                ejt.update(
                        eventSQL,
                        appendParameters(timestampParams, instance.getUserId(), EventType.EventTypeNames.DATA_POINT,
                                point.getId()));
            }

            // Insert the reportInstanceUserComments records for the point.
            if (instance.isIncludeUserComments()) {
                String commentSQL = "insert into reportInstanceUserComments " //
                        + "  (reportInstanceId, username, commentType, typeKey, ts, commentText)" //
                        + "  select " + instance.getId() + ", u.username, " + UserComment.TYPE_POINT + ", " //
                        + reportPointId + ", uc.ts, uc.commentText " //
                        + "  from userComments uc " //
                        + "    left join users u on uc.userId=u.id " //
                        + "  where uc.commentType=" + UserComment.TYPE_POINT //
                        + "    and uc.typeKey=? ";

                // Only include comments made in the duration of the report.
                commentSQL += StringUtils.replaceMacro(timestampSql, "field", "uc.ts");
                ejt.update(commentSQL, appendParameters(timestampParams, point.getId()));
            }
        } //end for all points

        //Insert the data into the NoSQL DB
        //The series name is reportInstanceId_reportPointId
       final String reportId = Integer.toString(instance.getId()) + "_";
       pointValueDao.getPointValuesBetween(pointIds, instance.getReportStartTime(), instance.getReportEndTime(), new MappedRowCallback<IdPointValueTime>(){
      @Override
      public void row(final IdPointValueTime ipvt, int rowId) {
        dao.storeData( reportId + Integer.toString(pointIdMap.get(ipvt.getDataPointId())),ipvt);
        count.increment();
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.