VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "c_DBManagerImpl"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
'Generated by IDL2VB v092. Copyright (c) 1999 Martin.Both
'Source File Name: ../demos/db_query/database.idl

Option Explicit

Implements cOrbSkeleton
Implements c_DBManager

'interface ::DB::Manager
Const sTypeId As String = "IDL:DB/Manager:1.0"
Private oObjRef As cOrbObjRef
Private oDelegate As c_DBManager

Friend Property Get ObjRef() As cOrbObjRef
    Set ObjRef = oObjRef
End Property

Friend Property Get This() As c_DBManager
    Dim oObj As cOrbObject
    Set oObj = New c_DBManager
    If oObj.setObjRef(oObjRef, False) Then
        Set This = Nothing
    Else
        Set This = oObj
    End If
End Property

Private Property Get cOrbSkeleton_TypeId(ByVal Item As Integer) As String
    Select Case Item
    Case 0: cOrbSkeleton_TypeId = sTypeId
    Case 1: cOrbSkeleton_TypeId = "IDL:omg.org/CORBA/Object:1.0"
    End Select
End Property

Private Property Get cOrbSkeleton_ObjRef() As cOrbObjRef
    Set cOrbSkeleton_ObjRef = oObjRef
End Property

Private Property Set cOrbSkeleton_ObjRef(ByVal newObjRef As cOrbObjRef)
    Set oObjRef = newObjRef
End Property

'Helper
Private Function cOrbSkeleton_execute(ByVal sOperation As String, _
    ByVal oIn As cOrbStream, ByVal oOut As cOrbStream) As Long
    On Error GoTo ErrHandler
    Dim oImpl_ As c_DBManager
    Set oImpl_ = IIf(oDelegate Is Nothing, Me, oDelegate)
    Select Case sOperation
    Case "getSession"
        Dim a1_url As String
        a1_url = oIn.readString()
        Dim a1_user As String
        a1_user = oIn.readString()
        Dim a1_password As String
        a1_password = oIn.readString()
        Dim a1_warns As c_DBMessageSeq
        Dim getSession As c_DBSession
        Set getSession = oImpl_.getSession(a1_url, a1_user, a1_password, _
            a1_warns)
        Call oOut.writeObject(getSession)
        Call a1_warns.writeMe(oOut, 0)
    Case "shutdownServer"
        Dim a2_user As String
        a2_user = oIn.readString()
        Dim a2_password As String
        a2_password = oIn.readString()
        Call oImpl_.shutdownServer(a2_user, a2_password)
    Case Else
        Call VBOrb.raiseBADOPERATION(1, VBOrb.CompletedNO, sOperation)
    End Select
    cOrbSkeleton_execute = 0 'NO_EXCEPTION
    Exit Function
UserExWriter:
    Call VBOrb.getException().writeMe(oOut)
    cOrbSkeleton_execute = 1 'USER_EXCEPTION
    Exit Function
ErrHandler:
    If VBOrb.ErrIsUserEx() Then Resume UserExWriter
    Call VBOrb.ErrReraise(Err, "Manager.execute(" & sOperation & ")")
End Function

'Implements c_DBManager

'getSession() raises(c_DBErrMsgsEx)
Private Function c_DBManager_getSession(ByVal url As String, _
    ByVal user As String, ByVal password As String, _
    ByRef warns As c_DBMessageSeq) As c_DBSession
    On Error GoTo ErrHandler
    Dim oEx As VBOrb.cOrbException
    Dim oDBEx As c_DBErrMsgsEx
    Dim oErrMsg As c_DBMessage
    If StrConv(user, vbLowerCase) <> "petra" Then
        Set oErrMsg = New c_DBMessage
        oErrMsg.sqlcode = -977
        oErrMsg.sqlstate = "EE977"
        oErrMsg.sqlmessage = "Unknown user " & user & ". (Only Petra is known.)"
        Set oDBEx = New c_DBErrMsgsEx
        Set oDBEx.errs = New c_DBMessageSeq
        oDBEx.errs.Length = 1
        Set oDBEx.errs.Item(0) = oErrMsg
        Set oEx = oDBEx
        GoTo ExHandler
    End If
    If StrConv(password, vbLowerCase) <> "geheim" Then
        Set oErrMsg = New c_DBMessage
        oErrMsg.sqlcode = -978
        oErrMsg.sqlstate = "EE978"
        oErrMsg.sqlmessage = "User " & user & " not authorized. (Wrong password.)"
        Set oDBEx = New c_DBErrMsgsEx
        Set oDBEx.errs = New c_DBMessageSeq
        oDBEx.errs.Length = 1
        Set oDBEx.errs.Item(0) = oErrMsg
        Set oEx = oDBEx
        GoTo ExHandler
    End If
    'Do a connection
    Dim oDBSessImpl As c_DBSessionImpl
    Set oDBSessImpl = New c_DBSessionImpl
    Call oObjRef.Orb.Connect(oDBSessImpl)
    'Returning warnings if any
    Set warns = New c_DBMessageSeq
    warns.Length = 2
    Set warns.Item(0) = New c_DBMessage
    warns.Item(0).sqlcode = 222
    warns.Item(0).sqlstate = "IW222"
    warns.Item(0).sqlmessage = "Connected to Visual Basic demo database"
    Set warns.Item(1) = New c_DBMessage
    warns.Item(1).sqlcode = 223
    warns.Item(1).sqlstate = "IW223"
    warns.Item(1).sqlmessage = "Connected to DB-URL " & url
    'Returning a reference of the connection object
    Set c_DBManager_getSession = oDBSessImpl.This
    Exit Function
ExHandler:
    Call oEx.addInfos("getSession")
    Call VBOrb.raiseUserEx(oEx)
    Exit Function
ErrHandler:
    Call VBOrb.ErrReraise(Err, "getSession")
End Function

'shutdownServer() raises(c_DBErrMsgsEx)
Private Sub c_DBManager_shutdownServer(ByVal user As String, _
    ByVal password As String)
    On Error GoTo ErrHandler
    Dim oEx As VBOrb.cOrbException
    Dim oDBEx As c_DBErrMsgsEx
    Dim oErrMsg As c_DBMessage
    If StrConv(user, vbLowerCase) <> "petra" Then
        Set oErrMsg = New c_DBMessage
        oErrMsg.sqlcode = -977
        oErrMsg.sqlstate = "EE977"
        oErrMsg.sqlmessage = "Unknown user " & user & ". (Only Petra is known.)"
        Set oDBEx = New c_DBErrMsgsEx
        Set oDBEx.errs = New c_DBMessageSeq
        oDBEx.errs.Length = 1
        Set oDBEx.errs.Item(0) = oErrMsg
        Set oEx = oDBEx
        GoTo ExHandler
    End If
    If StrConv(password, vbLowerCase) <> "geheim" Then
        Set oErrMsg = New c_DBMessage
        oErrMsg.sqlcode = -978
        oErrMsg.sqlstate = "EE978"
        oErrMsg.sqlmessage = "User " & user & " not authorized. (Wrong password.)"
        Set oDBEx = New c_DBErrMsgsEx
        Set oDBEx.errs = New c_DBMessageSeq
        oDBEx.errs.Length = 1
        Set oDBEx.errs.Item(0) = oErrMsg
        Set oEx = oDBEx
        GoTo ExHandler
    End If
    Call oObjRef.Orb.shutdown(False)
    Exit Sub
ExHandler:
    Call oEx.addInfos("shutdownServer")
    Call VBOrb.raiseUserEx(oEx)
    Exit Sub
ErrHandler:
    Call VBOrb.ErrReraise(Err, "shutdownServer")
End Sub
