Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
N-tier examples
Message
From
18/11/2004 17:00:14
 
 
To
18/11/2004 16:17:29
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Miscellaneous
Thread ID:
00962825
Message ID:
00962841
Views:
9
I would make a single DLL for all the data and have separate methods for getting to the data. You could have one class per table if you wanted.

I would also use SQL SELECTs. IMO, it makes the passing of data easier and you want to pass the actual data around, not record numbers, etc. Use CURSORTOXML and XMLTOCURSOR to make data passing easy.

I use methods for standard lookup stuff: GetCustomerByNumber(CustNo), GetCustomerByPhone(PhoneNo), GetCustomerByName(LastName, FirstName), etc. For generic queries, I use GetCustomerByCustom(where clause) or a similarly named method. Pass in just the parts of the WHERE clause of the SQL SELECT.


>Ok, my quest to make a small COM+ example has begin to grow out of control slightly. I'm looking for guidelines on the data layer. I'm thinking to make a component for each table, that would handle access to that table: Creating, finding, deleting, or updating records in the table.
>
>Now for the real problem, which is how to code a general enough Find() method.
>
>Here's a specific method. It returns the primary key for a record in the statemnt table, if the expression results in a hit.
>
>	Procedure FindRec
>	Parameters iStm_id, cTaxYear
>	Local lnReturn, loMtx, loContext
>* Create a reference to the MTS object
>	loMtx = Createobject("MTXAS.APPSERVER.1")
>
>	loContext = loMtx.GetObjectContext()
>
>	lnReturn = 0
>
>	Select Statemnt
>	Locate For (stm_id == iStm_id) And (taxyear == cTaxYear)
>	If Found()
>		lnReturn = Statemnt.Id
>	Endif
>
>	loContext.SetComplete()
>
>	Return lnReturn
>
>	Endproc
>
>
>
>However, I would prefer to be more general than this.
>
>	Procedure FindRec
>	Parameters cExpression, cTag
>	Local lnReturn, loMtx, loContext
>* Create a reference to the MTS object
>	loMtx = Createobject("MTXAS.APPSERVER.1")
>
>	loContext = loMtx.GetObjectContext()
>
>	lnReturn = 0
>
>	Select &&my genereric TABLE here
>	
>	Locate For ( cExpression )
>	If Found()
>		lnReturn = &&<whatever should be returned, here>
>	Endif
>
>	loContext.SetComplete()
>
>	Return lnReturn
>
>	Endproc
>
>
>My problem is to best use whatever index tags were available, so say the parameter cTag was optional
>I'd like to make use of it, if possible.
>
>For that matter, how DO you do optional parameters, anyway?
>
>Then, theres the update method: This looks ok for if you just want to update a few fields in a record, but what if you want to update many fields? Multiple calls would be slow, on the other hand, I don;t know that I want an update method that takes a single parameter for every possible field in the table, either. I wonder what kinds of things you can pass to a COM+ component anyway?
>
>I wonder if I should pass a "cursor" of the stuff I want to update. Like generate XML and send that over, and then code the update procedure to figure out what all needs updating.
>
>
>	Procedure UpdateRec
>	Parameters iMyId, cFldName, gValue
>
>	Local loMtx, loContext, lSuccess
>
>* Create a reference to the MTS object
>	loMtx = Createobject(“MTXAS.APPSERVER.1”)
>
>* Create a reference to the Context object
>	loContext = loMtx.GetObjectContext()
>	Select Statemnt
>	If Seek(iMyId)
>		Replace ( Alltrim(Upper(cFldName)) ) With gValue
>		=Tableupdate(0,.T.,"statemnt")
>	Endif
>
>* Commit the transaction if there is one
>* and tell MTS that we’re done using the component
>	loContext.SetComplete()
>	Endproc
>
>
>
>Are there any references on making a robust data layer? I'm not planning to change back ends etc, but I'd like to make a reasonably robust set of data access objects. Again, this is a small test project. I'm not looking to learn a framework, or anything. I want to understand how to do this task in fox. :)
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform