I have an application that contains a number of business objects. These objects are mainly Editable Roots implementing DataPortal_Create, DataPortal_Fetch, DataPortal_Update & DataPortal_Delete. All of this database access is via the DataPortal. I need the objects to access the database in ways other than these CRUD methods ie GetNextQuoteRef - a method that would need to access the DB to generate the next Quote number (based on a custom algorithm). What is the recommended way of implementing this type of DB activity within CSLA framework? The choices I seem to have are
1) write a method in my object such as the following pseudo code
Public Function GetNextQuoteRef () as String
OpenDBConnection
CreateCommandObject
ExecuteCommand
Return OutputParamFromCommand
End Function
Alternatively I could create a class that inherits from the CommandBase say clsGetNextQuoteRef and have this class execute my stored procedure. I could then use this class from my Quote business object. This is the route I have taken, but I would like some perspectives on the alternatives
tia
Terry Holland
The approach you have taken sounds fine to me.
You have encapsulated the behavior of "getting the next quote ref" into a single re-usable BO.
Your pseudo code contains a huge mistake though. It opens a DB connection without ensuring you have passed through the data portal. If you ever turn on Remoting, your code will break right there.
The rest of the pseudo sounds like a good way to use the command object you created and return its output so it looks like a method on your class but is really a database hit.
Joe
I think my original post was a bit unclear. The pseudo code I provided was an option that I decided not to persue. It had occured to me that all DB interation should go through the DataPortal. The route Ive taken was to create a class clsGetNextQuoteRef. This class inherits from the CommandBase CSLA class and DB activity is through the dataportal. My Quote business object has a the following method:
Public Class clsQuote
Inherits Csla.BusinessBase(Of clsQuote)
....
Private Function GetNextQuoteRef() as String
Return clsGetNextQuoteRef.Execute
End Function
End Class
So my business object (Quote) would call its GetNextQuoteRef method which would call the shared Execute method on my clsGetNextQuoteRef class (this class inherits from CommandBase and interacts with the DB via the DataPortal)
I have avoided communicating with DB unless it is via DataPortal and I think Im looking for confirmation that what Im doing is correct - it sounds as though it is
Terry
Copyright (c) Marimer LLC