Calling with custom SQL statements - SmartPlant Foundation - IM Update 44 - Customization & Programming - Hexagon

SmartPlant Foundation Customization

Language
English
Product
SmartPlant Foundation
Search by Category
Customization & Programming
SmartPlant Foundation / SDx Version
10

Inflation class implementation

Many inflator operations are now easier to implement, as they can be replaced by the CustomisableObjInflator or CustomisableRelInflator class definitions. These classes have customizable columns so they can select from the OBJ or REL tables and the IF and PR tables, as well as filter with a set of property definition UIDs.

If only one table is required, the inflator automatically uses one-shot OBID criteria for a potential performance gain.

The following is an example of the replacement of a light object inflation class.

Public Class LightObjInflator

    Inherits CustomisableObjInflator

    Implements IObjInflator

    Public Sub New()

        MyBase.New(

            Nothing,

            Nothing,

            New List(Of String)({

                "OBJOBID", "OBID", "PROPERTYDEFUID",

                "STRVALUE", "UOM", "EXTENDEDIND"}),

            New List(Of Integer)({1, 2}),

            Nothing)

    End Sub

End Class

Results counting class implementation

Previously, a data set returned with one row that contained a count of the results. By the time this row was reached in the code, an SQL statement had been executed to insert rows into the temporary database table.

The new implementation returns a Long value, rather than a data set, and uses the one-shot OBID criteria from the new results provider. Depending on which implementation of the IResultsProvider interface definition is supplied, it is possible that temp tables or IN lists are never used. Therefore, the whole count could be completed in one scalar query.

The following example in the new implementation shows that a post processor now counts the results of a query:

Public Class ObjCounter

    Implements IPostProcessor(Of IObjResultsProvider, Long)

    Public Function PostProcess(

            ByVal pobjObjResultsProvider As IObjResultsProvider) As Long _

            Implements IPostProcessor(Of IObjResultsProvider, Long).PostProcess

        '

        ' Validate parameters.

        '

        If pobjObjResultsProvider Is Nothing Then

            Throw New ArgumentNullException("pobjObjResultsProvider")

        End If

        '

        ' Build a "SELECT COUNT(*) FROM ..." SQL statement.

        '

        Dim lobjCountSql As New SPFSQL

        lobjCountSql.Append("SELECT COUNT (*) FROM ")

        lobjCountSql.Append(pobjObjResultsProvider.TablePrefix)

        lobjCountSql.Append(pobjObjResultsProvider.TableSuffix)

        lobjCountSql.Append(" oc WHERE oc.OBID IN (")

        lojbCountSql.MergeSQL(

            pobjObjResultsProvider.GetOneShotObidCriteria(),

            pobjObjResultsProvider.DBProvider)

        lobjCountSql.Append(")")

        Return CLng(pobjObjResultsProvider.DBProvider.

ExecuteScalarQuery(lobjCountSql))

    End Function

End Class

Usage and execution of new inflation classes

Usage is still handled in the same stack trace that processes edge expansion, queries, and so on, except for some slightly altered method signatures. These executions have the same stack trace up until the work is handed over to the IObjInflator implementations, which execute SQL statements, as shown in the following examples:

Create the inflation class passing in the query:

Dim lobjIFPRInflationClass As New SPF.Common.DataAccessLayer.DataRetrieval.ObjIFPRInflationClass(mobjCriteria)

Invoke the query:

Dim lobjResults As IObjectDictionary = Me.QueryObjects(FullObjInflator.Instance, -1, lobjContainer)