EDMIAPI: Add more database methods
This commit is contained in:
parent
b87030a0ff
commit
b023a501ef
@ -576,6 +576,20 @@ Public Class Client
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetDatatableFromECM(pSQL As String, Optional pConnectionId As Integer = 0) As GetDatatableResponse
|
||||
Try
|
||||
Dim oResponse = Channel.ReturnDatatable(New GetDatatableRequest() With {
|
||||
.SqlCommand = pSQL,
|
||||
.NamedDatabase = DatabaseName.ECM,
|
||||
.ConnectionId = pConnectionId
|
||||
})
|
||||
Return oResponse
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function GetDatatableFromIDBAsync(pSQL As String, Optional pConnectionId As Integer = 0) As Task(Of GetDatatableResponse)
|
||||
Try
|
||||
Dim oResponse = Await Channel.ReturnDatatableAsync(New GetDatatableRequest() With {
|
||||
@ -590,6 +604,20 @@ Public Class Client
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function GetDatatableFromECMAsync(pSQL As String, Optional pConnectionId As Integer = 0) As Task(Of GetDatatableResponse)
|
||||
Try
|
||||
Dim oResponse = Await Channel.ReturnDatatableAsync(New GetDatatableRequest() With {
|
||||
.SqlCommand = pSQL,
|
||||
.NamedDatabase = DatabaseName.ECM,
|
||||
.ConnectionId = pConnectionId
|
||||
})
|
||||
Return oResponse
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValueFromIDB(pSQL As String, Optional pConnectionId As Integer = 0) As GetScalarValueResponse
|
||||
Try
|
||||
Dim oResponse = Channel.ReturnScalarValue(New GetScalarValueRequest() With {
|
||||
@ -604,6 +632,20 @@ Public Class Client
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValueFromECM(pSQL As String, Optional pConnectionId As Integer = 0) As GetScalarValueResponse
|
||||
Try
|
||||
Dim oResponse = Channel.ReturnScalarValue(New GetScalarValueRequest() With {
|
||||
.SqlCommand = pSQL,
|
||||
.NamedDatabase = DatabaseName.ECM,
|
||||
.ConnectionId = pConnectionId
|
||||
})
|
||||
Return oResponse
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function GetScalarValueFromIDBAsync(pSQL As String, Optional pConnectionId As Integer = 0) As Task(Of GetScalarValueResponse)
|
||||
Try
|
||||
Dim oResponse = Await Channel.ReturnScalarValueAsync(New GetScalarValueRequest() With {
|
||||
@ -618,6 +660,20 @@ Public Class Client
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function GetScalarValueFromECMAsync(pSQL As String, Optional pConnectionId As Integer = 0) As Task(Of GetScalarValueResponse)
|
||||
Try
|
||||
Dim oResponse = Await Channel.ReturnScalarValueAsync(New GetScalarValueRequest() With {
|
||||
.SqlCommand = pSQL,
|
||||
.NamedDatabase = DatabaseName.ECM,
|
||||
.ConnectionId = pConnectionId
|
||||
})
|
||||
Return oResponse
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetDatatableByName(DatatableName As String, Optional FilterExpression As String = "", Optional SortByColumn As String = "") As TableResult
|
||||
Try
|
||||
Dim oResponse = Channel.ReturnDatatableFromCache(DatatableName, FilterExpression, SortByColumn)
|
||||
|
||||
@ -53,6 +53,26 @@ Public Class DatabaseWithFallback
|
||||
_DatabaseIDB = DatabaseIDB
|
||||
End Sub
|
||||
|
||||
Public Function GetDatatableECM(pSQL As String, Optional pConnectionId As Integer = 0) As DataTable
|
||||
Return GetDatatable(New GetDatatableOptions(pSQL, Constants.DatabaseType.ECM) With {
|
||||
.ConnectionId = pConnectionId
|
||||
})
|
||||
End Function
|
||||
|
||||
Public Function GetDatatableIDB(pSQL As String, Optional pConnectionId As Integer = 0) As DataTable
|
||||
Return GetDatatable(New GetDatatableOptions(pSQL, Constants.DatabaseType.IDB) With {
|
||||
.ConnectionId = pConnectionId
|
||||
})
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValueECM(pSQL As String, Optional pConnectionId As Integer = 0) As Object
|
||||
Return GetScalarValue(pSQL, Constants.DatabaseType.ECM, pForceFallback:=False, pConnectionId)
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValueIDB(pSQL As String, Optional pConnectionId As Integer = 0) As Object
|
||||
Return GetScalarValue(pSQL, Constants.DatabaseType.IDB, pForceFallback:=False, pConnectionId)
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Returns a Datatable by trying to fetch a cached version from the service, then querying the database through the service and querying the database directly as fallback.
|
||||
''' </summary>
|
||||
@ -96,14 +116,14 @@ Public Class DatabaseWithFallback
|
||||
Return GetDatatableFromDatabase(pFallbackSQL, pFallbackType, pConnectionId)
|
||||
End If
|
||||
|
||||
' If the table is not cached, we go to database immediately
|
||||
' If the table is not cached, we try going through the service
|
||||
If Not IsTableCached(pDataTableName) Then
|
||||
Return GetDatatableFromDatabase(pFallbackSQL, pFallbackType, pConnectionId)
|
||||
Return GetDatatableFromService(pFallbackSQL, pFallbackType, pConnectionId)
|
||||
End If
|
||||
|
||||
' If there is a proper ConnectionId, we go to database immediately
|
||||
' If there is a proper ConnectionId, we try going through the service
|
||||
If pConnectionId > 0 Then
|
||||
Return GetDatatableFromDatabase(pFallbackSQL, pFallbackType, pConnectionId)
|
||||
Return GetDatatableFromService(pFallbackSQL, pFallbackType, pConnectionId)
|
||||
End If
|
||||
|
||||
Try
|
||||
@ -127,6 +147,37 @@ Public Class DatabaseWithFallback
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Returns a Scalar Value by querying the database through the service and querying the database directly as fallback.
|
||||
''' </summary>
|
||||
''' <param name="pSQL">SQL Command to execute as fallback</param>
|
||||
''' <param name="pDatabaseType">Named Database to use for the fallback SQL Command</param>
|
||||
''' <param name="pForceFallback">Force the fallback, skipping the service completely</param>
|
||||
''' <param name="pConnectionId">Connection Id to use, references TBDD_CONNECTION</param>
|
||||
Public Function GetScalarValue(pSQL As String, pDatabaseType As Constants.DatabaseType, Optional pForceFallback As Boolean = False, Optional pConnectionId As Integer = 0) As DataTable
|
||||
Try
|
||||
Dim oResult As DataTable = Nothing
|
||||
Dim oTableResult As TableResult = Nothing
|
||||
|
||||
' If there is no client, we assume there is no service (configured)
|
||||
If _Client Is Nothing Then
|
||||
Return GetScalarValueFromDatabase(pSQL, pDatabaseType, pConnectionId)
|
||||
End If
|
||||
|
||||
' If ForceFallback flag is set, we go to database immediately
|
||||
If pForceFallback Then
|
||||
Return GetScalarValueFromDatabase(pSQL, pDatabaseType, pConnectionId)
|
||||
End If
|
||||
|
||||
Return GetScalarValueFromService(pSQL, pDatabaseType, pConnectionId)
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function IsTableCached(pName As String) As Boolean
|
||||
If _Client Is Nothing Then
|
||||
Return False
|
||||
@ -135,14 +186,76 @@ Public Class DatabaseWithFallback
|
||||
Return _Client.CachedTables.Contains(pName.ToUpper)
|
||||
End Function
|
||||
|
||||
Private Function GetDatatableFromDatabase(SQLCommand As String, DatabaseType As Constants.DatabaseType, pConnectionId As Integer)
|
||||
Private Function GetDatatableFromService(pSQLCommand As String, DatabaseType As Constants.DatabaseType, pConnectionId As Integer)
|
||||
Try
|
||||
Select Case DatabaseType
|
||||
Case Constants.DatabaseType.ECM
|
||||
Return _DatabaseEDM.GetDatatable(SQLCommand)
|
||||
Return _Client.GetDatatableFromECM(pSQLCommand, pConnectionId)
|
||||
|
||||
Case Constants.DatabaseType.IDB
|
||||
Return _DatabaseIDB.GetDatatable(SQLCommand)
|
||||
Return _Client.GetDatatableFromIDB(pSQLCommand, pConnectionId)
|
||||
|
||||
Case Else
|
||||
Return Nothing
|
||||
|
||||
End Select
|
||||
Catch ex As Exception
|
||||
_Logger.Warn("GetDatatableFromService failed. Falling back to direct database access.")
|
||||
_Logger.Error(ex)
|
||||
Return GetDatatableFromDatabase(pSQLCommand, DatabaseType, pConnectionId)
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetScalarValueFromService(pSQLCommand As String, DatabaseType As Constants.DatabaseType, pConnectionId As Integer)
|
||||
Try
|
||||
Select Case DatabaseType
|
||||
Case Constants.DatabaseType.ECM
|
||||
Return _Client.GetScalarValueFromECM(pSQLCommand, pConnectionId)
|
||||
|
||||
Case Constants.DatabaseType.IDB
|
||||
Return _Client.GetScalarValueFromIDB(pSQLCommand, pConnectionId)
|
||||
|
||||
Case Else
|
||||
Return Nothing
|
||||
|
||||
End Select
|
||||
Catch ex As Exception
|
||||
_Logger.Warn("GetScalarValueFromService failed. Falling back to direct database access.")
|
||||
_Logger.Error(ex)
|
||||
Return GetDatatableFromDatabase(pSQLCommand, DatabaseType, pConnectionId)
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetDatatableFromDatabase(pSQLCommand As String, DatabaseType As Constants.DatabaseType, pConnectionId As Integer)
|
||||
Try
|
||||
Select Case DatabaseType
|
||||
Case Constants.DatabaseType.ECM
|
||||
Return _DatabaseEDM.GetDatatable(pSQLCommand)
|
||||
|
||||
Case Constants.DatabaseType.IDB
|
||||
Return _DatabaseIDB.GetDatatable(pSQLCommand)
|
||||
|
||||
Case Else
|
||||
Return Nothing
|
||||
|
||||
End Select
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetScalarValueFromDatabase(pSQLCommand As String, DatabaseType As Constants.DatabaseType, pConnectionId As Integer)
|
||||
Try
|
||||
Select Case DatabaseType
|
||||
Case Constants.DatabaseType.ECM
|
||||
Return _DatabaseEDM.GetScalarValue(pSQLCommand)
|
||||
|
||||
Case Constants.DatabaseType.IDB
|
||||
Return _DatabaseIDB.GetScalarValue(pSQLCommand)
|
||||
|
||||
Case Else
|
||||
Return Nothing
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user