127 lines
4.7 KiB
VB.net
127 lines
4.7 KiB
VB.net
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.EDMI.API
|
|
Imports DigitalData.Modules.EDMI.API.Constants
|
|
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
|
|
Imports DigitalData.Modules.Logging
|
|
Imports DigitalData.Modules.Language.Utils
|
|
|
|
Public Class DatabaseWithFallback
|
|
Private ReadOnly _Logger As Logger
|
|
Private ReadOnly _Client As Client
|
|
Private ReadOnly _DatabaseEDM As MSSQLServer
|
|
Private ReadOnly _DatabaseIDB As MSSQLServer
|
|
|
|
Public Enum TableType
|
|
TBIDB_ATTRIBUTE
|
|
End Enum
|
|
|
|
Public Class Table
|
|
Public TableName As String
|
|
Public SQLCommand As String
|
|
Public DatabaseType As Constants.DatabaseType
|
|
End Class
|
|
|
|
Public Property Tables As New List(Of Table) From {
|
|
New Table With {.DatabaseType = DatabaseType.IDB, .TableName = "TBIDB_ATTRIBUTE", .SQLCommand = "SELECT * FROM TBIDB_ATTRIBUTE"}
|
|
}
|
|
|
|
|
|
Public Sub New(LogConfig As LogConfig, Client As Client, DatabaseECM As MSSQLServer, DatabaseIDB As MSSQLServer)
|
|
_Logger = LogConfig.GetLogger()
|
|
_Client = Client
|
|
_DatabaseEDM = DatabaseECM
|
|
_DatabaseIDB = DatabaseIDB
|
|
End Sub
|
|
|
|
''' <summary>
|
|
''' Attempt at making loading big tables less annoying
|
|
''' </summary>
|
|
''' <returns></returns>
|
|
Public Function GetDatatable(pTable As TableType, Optional FilterExpression As String = "", Optional SortByColumn As String = "", Optional ForceFallback As Boolean = False)
|
|
Dim oTable = Tables.Where(Function(t) t.DatabaseType = pTable).SingleOrDefault()
|
|
|
|
If oTable Is Nothing Then
|
|
Return Nothing
|
|
Else
|
|
Return GetDatatable(oTable.TableName, oTable.SQLCommand, oTable.DatabaseType, FilterExpression, SortByColumn, ForceFallback)
|
|
End If
|
|
End Function
|
|
|
|
Public Function GetDatatable(DataTable As String, FallbackSQL As String, FallbackType As Constants.DatabaseType, Optional FilterExpression As String = "", Optional SortByColumn As String = "", Optional ForceFallback As Boolean = False) As DataTable
|
|
Try
|
|
Dim oResult As DataTable = Nothing
|
|
|
|
If ForceFallback = False Then
|
|
Dim oTableResult As TableResult
|
|
|
|
Try
|
|
oTableResult = _Client.GetDatatableByName(DataTable, FilterExpression, SortByColumn)
|
|
Catch ex As Exception
|
|
_Logger.Error(ex)
|
|
oTableResult = Nothing
|
|
End Try
|
|
|
|
If oTableResult Is Nothing OrElse oTableResult.OK = False Then
|
|
_Logger.Warn("Datatable [{0}] could not be fetched from AppServer Cache. Falling back to direct Database Access.")
|
|
Return GetDatatableFromDatabase(FallbackSQL, FallbackType)
|
|
End If
|
|
|
|
Return oTableResult.Table
|
|
Else
|
|
Return GetDatatableFromDatabase(FallbackSQL, FallbackType)
|
|
End If
|
|
Catch ex As Exception
|
|
_Logger.Error(ex)
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
|
|
Private Function GetDatatableFromDatabase(SQLCommand As String, DatabaseType As DatabaseType)
|
|
Try
|
|
Select Case DatabaseType
|
|
Case DatabaseType.ECM
|
|
Return _DatabaseEDM.GetDatatable(SQLCommand)
|
|
|
|
Case DatabaseType.IDB
|
|
Return _DatabaseIDB.GetDatatable(SQLCommand)
|
|
|
|
Case Else
|
|
Return Nothing
|
|
|
|
End Select
|
|
Catch ex As Exception
|
|
_Logger.Error(ex)
|
|
Return Nothing
|
|
|
|
End Try
|
|
End Function
|
|
|
|
Public Function GetUserData(UserName As String, ModuleCode As String, Client As Integer) As UserData
|
|
'Dim oSQL = $"SELECT * FROM FNDD_CHECK_USER_MODULE('{UserName}','{ModuleCode}',{Client})"
|
|
'Dim oTable As DataTable = GetDatatable("TBDD_USER_MODULE", $"USERNAME = '{UserName.ToLower}' AND MODULE_SHORT = '{ModuleCode}'", "", oSQL, DatabaseType.ECM)
|
|
|
|
'If oTable Is Nothing Then
|
|
' Return Nothing
|
|
'End If
|
|
|
|
'If oTable.Rows.Count = 0 Then
|
|
' Return Nothing
|
|
'End If
|
|
|
|
'Dim oRow As DataRow = oTable.Rows.Item(0)
|
|
'Dim oUserData As New UserData With {
|
|
' .Id = NotNull(oRow, "USER_ID", -1),
|
|
' .Surname = NotNull(oRow, "USER_SURNAME", String.Empty),
|
|
' .Prename = NotNull(oRow, "USER_PRENAME", String.Empty),
|
|
' .Shortname = NotNull(oRow, "USER_SHORTNAME", String.Empty),
|
|
' .Email = NotNull(oRow, "USER_EMAIL", String.Empty),
|
|
' .Language = NotNull(oRow, "USER_LANGUAGE", "de-DE"),
|
|
' .DateFormat = NotNull(oRow, "USER_DATE_FORMAT", "dd.MM.yyyy")
|
|
'}
|
|
|
|
Throw New NotImplementedException()
|
|
End Function
|
|
|
|
End Class
|
|
|