Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
N-tier examples
Message
De
18/11/2004 16:17:29
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Titre:
N-tier examples
Divers
Thread ID:
00962825
Message ID:
00962825
Vues:
43
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. :)
Jim Newsom
IT Director, ICG Inc.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform