Class TagHistoryDatasourceSink

    • Field Detail

      • checkEnabled

        protected boolean checkEnabled
    • Method Detail

      • getLocalGatewayName

        protected java.lang.String getLocalGatewayName()
      • updateStatusProperties

        public void updateStatusProperties​(java.util.List<NamedValue> properties)
      • updateStatMetrics

        public void updateStatMetrics​(java.util.Map<java.lang.String,​NamedValue<StatMetric>> statMetrics)
      • isLicensedFor

        public boolean isLicensedFor​(HistoryFlavor dataType)
        Description copied from interface: HistoryStorer
        Assuming the storer accepts the flavor, is it currently licensed for it? If not, the data will not be stored.
        Specified by:
        isLicensedFor in interface HistoryStorer
      • tryToInit

        protected boolean tryToInit()
        Initialization is really complex in this class because we don't really want to initialize until data comes in. So, we have to prevent init, but also claim to accept, until we get the first data.
        Overrides:
        tryToInit in class AbstractSink
      • getOrCreatePartitionManager

        protected PartitionManager getOrCreatePartitionManager​(java.lang.Integer systemId)
                                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • startOptimizedEngine

        protected void startOptimizedEngine​(java.lang.Integer systemId,
                                            PartitionManager pm)
      • createPartitionManager

        protected PartitionManager createPartitionManager​(java.lang.Integer systemId,
                                                          int time,
                                                          TimeUnits units)
                                                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getProviderId

        public TagHistoryDatasourceSink.ProviderId getProviderId​(java.lang.String gatewayName,
                                                                 java.lang.String providerName)
                                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getSystemDetails

        protected SystemProviderDetails getSystemDetails​(java.lang.String gatewayName,
                                                         boolean create)
                                                  throws java.lang.Exception
        Get the provider details of the gateway. Will look it up/insert the gateway if allowed and necessary.
        Throws:
        java.lang.Exception
      • getSystemDetails

        protected SystemProviderDetails getSystemDetails​(int systemId)
        Looks up the system details for the given id.
      • loadOrCreateSystemDetails

        protected SystemProviderDetails loadOrCreateSystemDetails​(java.lang.String systemName)
                                                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • insertProvider

        protected void insertProvider​(java.lang.String systemName,
                                      java.lang.String providerName)
                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • storeDataToDatasource

        protected void storeDataToDatasource​(SRConnection conn,
                                             HistoricalData data)
                                      throws java.lang.Exception
        Stores the given data against the connection which has been pre-setup to execute in a transaction. Any error that occurs will cause the transaction to roll back.
        Specified by:
        storeDataToDatasource in class AbstractDatasourceSink
        Throws:
        java.lang.Exception
      • storeScanClassSet

        protected void storeScanClassSet​(SRConnection conn,
                                         ScanclassHistorySet data)
                                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • updateSystemName

        protected void updateSystemName​(java.lang.String newName)
      • startMaintenanceTasks

        protected void startMaintenanceTasks()
        If a maintenance task is defined, and we've been initialized (determined by the presence of Partition Manager), will register the tag with the execution engine.
      • stopMaintenanceTasks

        protected void stopMaintenanceTasks()
      • updateSCExecRecord

        protected void updateSCExecRecord​(SRConnection conn,
                                          TagHistoryDatasourceSink.ProviderId provId,
                                          java.lang.String scName,
                                          int rate,
                                          java.util.Date execTime)
                                   throws java.lang.Exception
        This class updates the scan class execution table. This function updates an existing row with: matching name, matching rate, and end_time>(exec-2*rate). If nothing matches, a new row is inserted.

        A special case, however, occurs when rate==0. This indicates that the scan class does not run regularly. In this case, nothing will happen.

        Throws:
        java.lang.Exception
      • getIdOfScanclassName

        protected int getIdOfScanclassName​(TagHistoryDatasourceSink.ProviderId pid,
                                           java.lang.String scName)
                                    throws java.lang.Exception
        Gets the id of the given SC name, inserting if necessary.
        Throws:
        java.lang.Exception
      • getKeyForTagIdCache

        protected java.lang.String getKeyForTagIdCache​(int providerId,
                                                       java.lang.String path)
      • loadTagIdCache

        protected void loadTagIdCache​(java.lang.Integer systemId)
                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getCurrentTagIds

        public java.util.Map<java.lang.String,​java.lang.Long> getCurrentTagIds​(TagHistoryDatasourceSink.ProviderId provId,
                                                                                     java.util.Collection<java.lang.String> tagPathKeys)
                                                                              throws java.lang.Exception
        This is a simplified version of getTagIds for retrieving the latest ids of existing tags. It will not add or retire tags. Anything that isn't present and valid is returned as -1.
        Throws:
        java.lang.Exception
      • retireTags

        protected void retireTags​(SRConnection conn,
                                  TagRetirementList paths)
                           throws java.lang.Exception
        Marks the given paths as retired, and removes them from the cache. This is used when tags are deleted from the system. The getTagIds() function also retires tags when necessary.
        Throws:
        java.lang.Exception
      • loadAllTags

        protected java.util.List<TagPath> loadAllTags()
      • storeAnnotations

        protected java.util.List<QualifiedValue> storeAnnotations​(SRConnection conn,
                                                                  java.util.List<Annotation> annotations)
                                                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • insertAnnotations

        protected java.util.List<QualifiedValue> insertAnnotations​(SRConnection conn,
                                                                   java.util.List<Annotation> annotations)
                                                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • executeAnnotationQuery

        protected java.util.List<QualifiedValue> executeAnnotationQuery​(SRConnection conn,
                                                                        java.lang.String query,
                                                                        java.util.List<Annotation> annotations,
                                                                        java.util.function.Function<Annotation,​java.lang.String> idRetriever,
                                                                        com.inductiveautomation.gateway.tags.history.storage.TagHistoryDatasourceSink.QueryType qt)
                                                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • checkTables

        protected void checkTables()
                            throws java.lang.Exception
        Throws:
        java.lang.Exception