Click here to Skip to main content
15,881,248 members
Articles / Programming Languages / Visual Basic

Object-Oriented database design with the DatabaseObjects library

Rate me:
Please Sign up or sign in to vote.
4.00/5 (6 votes)
31 Jan 20076 min read 109.3K   3.9K   64  
Demonstrates creating object-oriented database systems with the DatabaseObjects library.
' ___________________________________________________
'
'  � Hi-Integrity Systems 2007. All rights reserved.
'  www.hisystems.com.au - Toby Wicks
' ___________________________________________________
'

Option Strict On
Option Explicit On

Namespace SQL

    Public Class SQLSelectTableJoins
        Implements IEnumerable

        Private pobjJoins As ArrayList = New ArrayList

        Public Sub New()

            MyBase.New()

        End Sub

        Public Function Add() As SQLSelectTableJoin

            Dim objJoin As SQLSelectTableJoin = New SQLSelectTableJoin(Me)

            pobjJoins.Add(objJoin)

            Return objJoin

        End Function

        Public Function Add( _
            ByVal objLeftTable As SQLSelectTable, _
            ByVal eJoin As SQLSelectTableJoin.Type, _
            ByVal objRightTable As SQLSelectTable) As SQLSelectTableJoin

            Dim objJoin As SQLSelectTableJoin = New SQLSelectTableJoin(Me)

            objJoin.LeftTable = objLeftTable
            objJoin.TheType = eJoin
            objJoin.RightTable = objRightTable

            pobjJoins.Add(objJoin)

            Return objJoin

        End Function

        Default Public ReadOnly Property Item(ByVal intIndex As Integer) As SQLSelectTableJoin
            Get

                Return DirectCast(pobjJoins.Item(intIndex), SQLSelectTableJoin)

            End Get
        End Property

        Public ReadOnly Property Count() As Integer
            Get

                Return pobjJoins.Count()

            End Get
        End Property

        Public Function Exists(ByVal objTable As SQLSelectTable) As Boolean

            For intIndex As Integer = 0 To pobjJoins.Count() - 1
                With Me.Item(intIndex)
                    If .LeftTable Is objTable Or .RightTable Is objTable Then
                        Return True
                    End If
                End With
            Next

        End Function

        Public Sub Delete(ByVal objJoin As SQLSelectTableJoin)

            If Not pobjJoins.Contains(objJoin) Then
                Throw New ObjectDoesNotExistException
            End If

            pobjJoins.Remove(objJoin)
            objJoin = Nothing

        End Sub

        Friend ReadOnly Property SQL(ByVal eConnectionType As Database.ConnectionType) As String
            Get

                If Me.Count > 0 Then
                    'recurse through the joins from right to left
                    Return Me.Item(Me.Count - 1).SQL(eConnectionType)
                End If

            End Get
        End Property

        Private Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator

            Return pobjJoins.GetEnumerator

        End Function

    End Class

End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions