Examples of NoSQLDao


Examples of com.serotonin.m2m2.db.dao.nosql.NoSQLDao

                boolToChar(false) });
      }else{
        //We need to get the report instances to delete first
        List<ReportInstance> instances =  query(REPORT_INSTANCE_SELECT + "where runStartTime<? and preventPurge=?", new Object[] { time,
                    boolToChar(false) },new ReportInstanceRowMapper());
          final NoSQLDao dao = Common.databaseProxy.getNoSQLProxy().createNoSQLDao(ReportPointValueTimeSerializer.get(), "reports");
       
        for(ReportInstance instance :instances){
          List<ExportPointInfo> points = this.getReportInstancePoints(instance.getId());
          //Drop the series for these
          for(ExportPointInfo point : points){
            dao.deleteStore(instance.getId() + "_" + point.getReportPointId());
          }
        }
       
        return ejt.update("delete from reportInstances where runStartTime<? and preventPurge=?", new Object[] { time,
                    boolToChar(false) });
View Full Code Here

Examples of com.serotonin.m2m2.db.dao.nosql.NoSQLDao

        final ExportDataValue edv = new ExportDataValue();
        for (final ExportPointInfo point : pointInfos) {
            handler.startPoint(point);

            edv.setReportPointId(point.getReportPointId());
            final NoSQLDao dao = Common.databaseProxy.getNoSQLProxy().createNoSQLDao(ReportPointValueTimeSerializer.get(), "reports");
            final String pointStore = instanceId + "_" + point.getReportPointId();
            dao.getData(pointStore, 0, Long.MAX_VALUE, -1, false, new NoSQLQueryCallback(){

        @Override
        public void entry(String storeName, long timestamp, ITime entry) {
          PointValueTime pvt = (PointValueTime) entry;
          edv.setValue(pvt.getValue());
View Full Code Here

Examples of com.serotonin.m2m2.db.dao.nosql.NoSQLDao

     * @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();
      }
       });
       
        // Insert the reportInstanceUserComments records for the selected events
        if (instance.isIncludeUserComments()) {
            String commentSQL = "insert into reportInstanceUserComments " //
                    + "  (reportInstanceId, username, commentType, typeKey, ts, commentText)" //
                    + "  select " + instance.getId() + ", u.username, " + UserComment.TYPE_EVENT + ", uc.typeKey, " //
                    + "    uc.ts, uc.commentText " //
                    + "  from userComments uc " //
                    + "    left join users u on uc.userId=u.id " //
                    + "    join reportInstanceEvents re on re.eventId=uc.typeKey " //
                    + "  where uc.commentType=" + UserComment.TYPE_EVENT //
                    + "    and re.reportInstanceId=? ";
            ejt.update(commentSQL, new Object[] { instance.getId() });
        }

        // If the report had undefined start or end times, update them with values from the data.
        if (instance.isFromInception() || instance.isToNow()) {
          if(instance.isFromInception()){
            final List<ITime> firstValueTimeList = new ArrayList<ITime>();
        dao.getData("reports", 0L, Long.MAX_VALUE, 1, false, new NoSQLQueryCallback(){
          @Override
          public void entry(String storeName, long timestamp,
              ITime entry) {
            firstValueTimeList.add(entry);
          }
             });
 
        if(firstValueTimeList.size() > 0){
          instance.setReportStartTime(firstValueTimeList.get(0).getTime());
        }
          }   
          if(instance.isToNow()){
            final List<ITime> lastValueTimeList = new ArrayList<ITime>();
        dao.getData("reports", 0L, Long.MAX_VALUE, 1, true, new NoSQLQueryCallback(){
          @Override
          public void entry(String storeName, long timestamp,
              ITime entry) {
            lastValueTimeList.add(entry);
          }
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.