Skip to content

Commit

Permalink
Added RootContainerObject concept. Closes #8.
Browse files Browse the repository at this point in the history
This allows a root container object to be accessed from any object in the model. The overrides the existing functionality of providing a database for a root collection. If there are multiple levels to the hierarchy then changing the root collection object to utilise a RootContainer will allow all children to automatically find the reference to the parent root container object.
  • Loading branch information
hisystems committed Mar 21, 2012
1 parent 8f82b57 commit 038d490
Show file tree
Hide file tree
Showing 22 changed files with 372 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Database/DatabaseObject.vb
Expand Up @@ -173,6 +173,18 @@ Public MustInherit Class DatabaseObject
End Get
End Property

''' <summary>
''' Returns the root container object that this object is a child of.
''' </summary>
''' <remarks>
''' Traverses up the object heirarchy to find the root container class.
''' </remarks>
Protected Friend Function RootContainer(Of TRootContainer As RootContainer)() As TRootContainer

Return pobjParentCollection.RootContainer(Of TRootContainer)()

End Function

''' <summary>
''' Deletes the record from the database associated with this record.
''' After which this object becomes invalid.
Expand Down
44 changes: 44 additions & 0 deletions Database/DatabaseObjects.vb
Expand Up @@ -34,6 +34,12 @@ Public MustInherit Class DatabaseObjects
Private pobjDatabase As Database
Private pobjParent As DatabaseObject

''' <summary>
''' May optionally be set to the container object that this object is a child of.
''' </summary>
''' <remarks></remarks>
Private _rootContainer As RootContainer

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes a new DatabaseObjects with it's associated database.
Expand All @@ -53,6 +59,26 @@ Public MustInherit Class DatabaseObjects

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes with it the associated root container and database.
''' </summary>
'''
''' <param name="rootContainer">
''' The root object that this collection is associated with.
''' </param>
''' --------------------------------------------------------------------------------
Protected Sub New(ByVal rootContainer As RootContainer)

If rootContainer Is Nothing Then
Throw New ArgumentNullException
End If

Me._rootContainer = rootContainer
pobjDatabase = rootContainer.Database

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes a new DatabaseObjects with it's associated parent object.
Expand Down Expand Up @@ -89,6 +115,24 @@ Public MustInherit Class DatabaseObjects
End Get
End Property

''' <summary>
''' Returns the root container object that this object is a child of.
''' </summary>
''' <remarks>
''' Traverses up the object heirarchy to find the root container class.
''' </remarks>
Protected Friend Function RootContainer(Of TRootContainer As RootContainer)() As TRootContainer

If _rootContainer IsNot Nothing Then
Return DirectCast(Me._rootContainer, TRootContainer)
ElseIf pobjParent IsNot Nothing Then
Return pobjParent.RootContainer(Of TRootContainer)()
Else
Return Nothing
End If

End Function

''' --------------------------------------------------------------------------------
''' <summary>
''' Returns the distinct value of the parent i.e. Parent.DistinctValue
Expand Down
15 changes: 15 additions & 0 deletions Database/DatabaseObjectsEnumerable.vb
Expand Up @@ -35,6 +35,21 @@ Public MustInherit Class DatabaseObjectsEnumerable

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes with it the associated root container and database.
''' </summary>
'''
''' <param name="rootContainer">
''' The root object that this collection is associated with.
''' </param>
''' --------------------------------------------------------------------------------
Protected Sub New(ByVal rootContainer As RootContainer)

MyBase.New(rootContainer)

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes a new DatabaseObjects with it's associated parent object.
Expand Down
16 changes: 16 additions & 0 deletions Database/DatabaseObjectsUsingAttributes.vb
Expand Up @@ -51,6 +51,22 @@ Public MustInherit Class DatabaseObjectsUsingAttributes

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes with it the associated root container and database.
''' </summary>
'''
''' <param name="rootContainer">
''' The root object that this collection is associated with.
''' </param>
''' --------------------------------------------------------------------------------
Protected Sub New(ByVal rootContainer As RootContainer)

MyBase.New(rootContainer)
pobjAttributeHelper = New DatabaseObjectsUsingAttributesHelper(Me)

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes a new DatabaseObjects with it's associated parent object.
Expand Down
16 changes: 16 additions & 0 deletions Database/DatabaseObjectsVolatile.vb
Expand Up @@ -60,6 +60,22 @@ Public MustInherit Class DatabaseObjectsVolatile

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes with it the associated root container and database.
''' </summary>
'''
''' <param name="rootContainer">
''' The root object that this collection is associated with.
''' </param>
''' --------------------------------------------------------------------------------
Protected Sub New(ByVal rootContainer As RootContainer)

MyBase.New(rootContainer)
VolatileItemsLoad()

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes a new instance with it's associated database and data that
Expand Down
16 changes: 16 additions & 0 deletions Database/DatabaseObjectsVolatileUsingAttributes.vb
Expand Up @@ -68,6 +68,22 @@ Public MustInherit Class DatabaseObjectsVolatileUsingAttributes

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes with it the associated root container and database.
''' </summary>
'''
''' <param name="rootContainer">
''' The root object that this collection is associated with.
''' </param>
''' --------------------------------------------------------------------------------
Protected Sub New(ByVal rootContainer As RootContainer)

MyBase.New(rootContainer)
pobjAttributeHelper = New DatabaseObjectsUsingAttributesHelper(Me)

End Sub

''' <summary>
''' Must override VolatileItemsLoad so that the attributes can be read before
''' any of the objects are loaded.
Expand Down
37 changes: 37 additions & 0 deletions Database/RootContainer.vb
@@ -0,0 +1,37 @@

' ___________________________________________________
'
' © Hi-Integrity Systems 2012. All rights reserved.
' www.hisystems.com.au - Toby Wicks
' ___________________________________________________
'

Option Strict On
Option Explicit On

Imports System.Data

Public MustInherit Class RootContainer

Private _database As Database

Protected Sub New(ByVal database As Database)

If database Is Nothing Then
Throw New ArgumentNullException
End If

Me._database = database

End Sub

Protected Friend ReadOnly Property Database As Database
Get

Return Me._database

End Get
End Property

End Class

1 change: 1 addition & 0 deletions DatabaseObjects.vbproj
Expand Up @@ -121,6 +121,7 @@
<Compile Include="Contraints\NumberIsMaximumOrLesserConstraint.vb" />
<Compile Include="Contraints\StringMaxLengthConstraint.vb" />
<Compile Include="Database\ConnectionScope.vb" />
<Compile Include="Database\RootContainer.vb" />
<Compile Include="Database\DatabaseObjectsUsingAttributes.vb" />
<Compile Include="Database\DatabaseObjectsUsingAttributesHelper.vb" />
<Compile Include="Database\DatabaseObjectsVolatileUsingAttributes.vb" />
Expand Down
15 changes: 15 additions & 0 deletions Generic/DatabaseObjects.vb
Expand Up @@ -32,6 +32,21 @@ Namespace Generic

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes with it the associated root container and database.
''' </summary>
'''
''' <param name="rootContainer">
''' The root object that this collection is associated with.
''' </param>
''' --------------------------------------------------------------------------------
Protected Sub New(ByVal rootContainer As RootContainer)

MyBase.New(rootContainer)

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes a new DatabaseObjects with it's associated parent object.
Expand Down
15 changes: 15 additions & 0 deletions Generic/DatabaseObjectsEnumerable.vb
Expand Up @@ -37,6 +37,21 @@ Namespace Generic

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes with it the associated root container and database.
''' </summary>
'''
''' <param name="rootContainer">
''' The root object that this collection is associated with.
''' </param>
''' --------------------------------------------------------------------------------
Protected Sub New(ByVal rootContainer As RootContainer)

MyBase.New(rootContainer)

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes a new DatabaseObjects with it's associated parent object.
Expand Down
16 changes: 16 additions & 0 deletions Generic/DatabaseObjectsEnumerableUsingAttributes.vb
Expand Up @@ -51,6 +51,22 @@ Namespace Generic

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes with it the associated root container and database.
''' </summary>
'''
''' <param name="rootContainer">
''' The root object that this collection is associated with.
''' </param>
''' --------------------------------------------------------------------------------
Protected Sub New(ByVal rootContainer As RootContainer)

MyBase.New(rootContainer)
pobjAttributeHelper = New DatabaseObjectsUsingAttributesHelper(Me)

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes a new DatabaseObjects with it's associated parent object.
Expand Down
15 changes: 15 additions & 0 deletions Generic/DatabaseObjectsList.vb
Expand Up @@ -34,6 +34,21 @@ Namespace Generic

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes with it the associated root container and database.
''' </summary>
'''
''' <param name="rootContainer">
''' The root object that this collection is associated with.
''' </param>
''' --------------------------------------------------------------------------------
Protected Sub New(ByVal rootContainer As RootContainer)

MyBase.New(rootContainer)

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes a new DatabaseObjects with it's associated parent object.
Expand Down
15 changes: 15 additions & 0 deletions Generic/DatabaseObjectsListKeyed.vb
Expand Up @@ -35,6 +35,21 @@ Namespace Generic

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes with it the associated root container and database.
''' </summary>
'''
''' <param name="rootContainer">
''' The root object that this collection is associated with.
''' </param>
''' --------------------------------------------------------------------------------
Protected Sub New(ByVal rootContainer As RootContainer)

MyBase.New(rootContainer)

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes a new DatabaseObjects with it's associated parent object.
Expand Down
16 changes: 16 additions & 0 deletions Generic/DatabaseObjectsListKeyedUsingAttributes.vb
Expand Up @@ -50,6 +50,22 @@ Namespace Generic

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes with it the associated root container and database.
''' </summary>
'''
''' <param name="rootContainer">
''' The root object that this collection is associated with.
''' </param>
''' --------------------------------------------------------------------------------
Protected Sub New(ByVal rootContainer As RootContainer)

MyBase.New(rootContainer)
pobjAttributeHelper = New DatabaseObjectsUsingAttributesHelper(Me)

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes a new DatabaseObjects with it's associated parent object.
Expand Down
16 changes: 16 additions & 0 deletions Generic/DatabaseObjectsListUsingAttributes.vb
Expand Up @@ -49,6 +49,22 @@ Namespace Generic

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes with it the associated root container and database.
''' </summary>
'''
''' <param name="rootContainer">
''' The root object that this collection is associated with.
''' </param>
''' --------------------------------------------------------------------------------
Protected Sub New(ByVal rootContainer As RootContainer)

MyBase.New(rootContainer)
pobjAttributeHelper = New DatabaseObjectsUsingAttributesHelper(Me)

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes a new DatabaseObjects with it's associated parent object.
Expand Down
15 changes: 15 additions & 0 deletions Generic/DatabaseObjectsMultipleSubclass.vb
Expand Up @@ -58,6 +58,21 @@ Namespace Generic

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes with it the associated root container and database.
''' </summary>
'''
''' <param name="rootContainer">
''' The root object that this collection is associated with.
''' </param>
''' --------------------------------------------------------------------------------
Protected Sub New(ByVal rootContainer As RootContainer)

MyBase.New(rootContainer)

End Sub

''' --------------------------------------------------------------------------------
''' <summary>
''' Initializes a new DatabaseObjects with it's associated parent object.
Expand Down

0 comments on commit 038d490

Please sign in to comment.