Class wwBusinessObject

wwBusinessObject provides a base business object CRUD services. This class is a single level business object class that implements both the business and data tier in a single object to provide ease of use and maximum performance.

CRUD - Automated Base Data Access

The base object provides core CRUD (Create, Read, Update, Delete) data access functionality through its base class methods. Native query based data access is also supported through native FoxPro or SQL syntax, using the class methods which can route to the appropriate server backend.

FoxPro and SQL Backend Access

Fox or SQL Server are natively supported. SQL Server is supported with SQL Passthrough commands.The object also supports remote data access over the Web against a SQL Server backend (with some limitations a Fox backend can be used as well).

Internal Data Record Representation in .oData

Data representation of the class is handled through an oData member which contains the class 'data'. Each object is individually loaded except for queries which can return data in variety of formats such as cursors, XML or ADO. The .oData member deals with class instance data (record level operations) and is completely disconnected from the database while in the class. Load() and Save() are the two transfer methods that handle moving data to and from the database.

Web Focused but works for Desktop as well

This object framework is uniquely geared towards offline operation which is ideal for Web operations and passing data around the Web. In Web applications the object's .oData member is useful for holding Model data for databinding to HTML templates and reading data back in bulk using Request.FormVarsToObject().

The odisconnected data model also makes it uniquely qualified for object aggregation by combining multiple objects into an object hierarchy.For example, an oInvoice object contains oCustomer and oLineItems which are accessible through the single oInvoice object reference. Because of the self-contained nature of objects, it's easy to persist data to and from XML and pass them around the Web as well as making it very easy to use the business objects in HTML templates where data is bound to the object properties (<%= oInvoice.oCustomer.oData.LastName %>). Web Connection's object centric approach also allows you to pull in data back into the object from forms using Request.FormVarsToObject resulting in very little code written to transfer data to and from HTML pages.

Easy to get started with

Because the framework consists only of a minimal set of methods on this object it's easy to get started with it. Because of the single level implementation the framework is also very efficient. In addition a Wizard is provided to help you create business objects by mapping to tables.

Required Dependencies

  • wwUtils.prg
  • wwApi.prg

Optional Dependencis

  • wwSQL.prg (only if you use nDataMode = 2)
  • wwHttpSql.prg (only if you use nDataMode = 4)
  • wwXmlState.prg (only if you use Get/SetProperty methods)
Custom
  wwBusinessObject

Class Members

MemberDescription

AddValidationError

Adds a validation error to the oValidationErrors collection. Pass an error string and optional object name.

The object name can optionally be used to provide direct error link in Web Pages of the page framework.

o.AddValidationError(lcMessage,lcObjectName)

Backup

Takes the full content of the table and backs it up into the specified directory.

o.Backup(lcPath,llCreatePath)

Close

Closes the currently open master table or releases the SQL connection.

o.close()

ConvertData

Converts data from a cursor or the current object into the requested result mode.

Note this functionality is also accessible via the Query() methods, lnResultMode parameter which uses the same result mode settings.

o.ConvertData(lnResultMode, lcDocRoot, lcTable, lcRow)

CreateChildObject

o.createchildobject(lcClass)

CreateNewId

o.createnewid()

CreateTable

Create the primary table for this object. This method should always be subclassed and implemented by the developer.

Tip: You can use the CRT_DBF utility in the Tools directory to generate database and index structures for you.

o.createtable(lcFileName)

Delete

Deletes the specified record from the underlying table. If no PK is passed the current PK of the loaded object is used.

o.delete(lnPk)

Execute

Executes a fully qualified raw SQL statement through the class. Can be used for any backend data command using either VFP syntax or SQLExec() style SQL commands.

o.Execute(lcSQL)

Find

o.find(lcFilter, llNoDataMember)

GetBlankRecord

Retrieves an empty record and creates an empty oData member. Note no defaults are set.

o.getblankrecord()

GetProperty

Retrieves a property out of the XML field. Properties can be written with SetProperty.

o.getproperty(lcProperty)

ImportData

Imports data using the same

o.importdata(lnMode,lcData,lcAlias)

Load

o.Load(lnpk)

LoadBase

o.LoadBase(lcFilter,lcFieldList)

New

o.new(llNoNewPk)

Open

Opens the data source or remote connection. For ODBC commands the oSQL member holds the SQL connection.

o.open(lcFile, lcAlias, llForceReconnect)

Query

o.Query(lcSelect, lcCursor, lnResultmode)

Reindex

Used to PACK and Reindex the data files.

Typically you'll want to subclass this method and add your own code to cause tables to reindex. You can pass an extra parameter of .T. to have reindex return you a string of the index commands for the currently active indexes in the table in the vResult property.

o.Reindex(llSaveIndexString)

Save

Saves the current data member in the .oData property to the underlying table.

o.save()

SetError

Sets the error flag and error message properties.

o.SetError(lcErrorMsg, lnError)

SetProperty

Sets a property value in the XML field. Note: for performance reasons no checks are performed if the XML field exists.

o.SetProperty(lcProperty, lvValue)

SetSqlObject

o.setsqlobject(loSQL)

StatusMessage

Displays status information. Use this method to have the business object communicate with whatever output mechanism required. Default is a WAIT WINDOW...

o.StatusMessage(lcMessage)

UpdateStructure

Update the structure of the file based on the CreateTable method's structure.

o.updatestructure()

Validate

o.validate()

calias

The Alias of the master file.

cconnectstring

SQL ConnectString if DataMode=2

cdatapath

Location of the data

cerrormsg

Any error messages that occurred.

cfilename

Filename of the master file of this business object.

cidtable

Table used to generate new PK Ids.

cpkfield

The field used as the primary key in the table. This field must be an integer or numeric field.

cresultxml

Methods returning XML will return the XML in this property.

cServerUrl

A URL on the server that's running the wwHTTPSQLServer component to process client requests.

cskipfieldsforupdates

Property that holds fields that are skipped for Insert and Update statements built on the fly. Use this if you pull extra fields that aren't part of the base cursor used in Save operations.

csql

SQL String for a query

csqlcursor

Requests that return a Fox cursor will use this name for the cursor name.

lCompareUpdates

Will send updates by only updating fields that have changed.

lerror

Error flag for the previous operation. Note this property must be managed by the developer for custom methods.

lThrowOnError

If .T. causes errors to be thrown rather than captured and return in the error info of the various invoke/get/set methods.

Defaults to .F.

lValidateOnSave

Determines whether Save() automatically calls Validate().

ndatamode

Data access mode for the business object. 0 - Fox Data native, 2 - ODBC (SQL Server)

nresultmode

Determines how data requests are returned for Query or ConvertData() calls. Results are always returned in the vResult property.

nupdatemode

Determines whether the data member is in edit or new mode.

  1. Updating record
  2. New record

oData

Data member that receives all of the field names as property values.

loBus = CREATEOBJECT("cCustomer")
if (!loBus.Load("_4FG12Y7UD"))
   RETURN .F.
ENDIF   

loBus.oData.Company = lcCompany
loBus.oData.Updated = DATETIME()

loBus.Save()

oHTTPSQL

An instance member for an wwHTTPSQL class that handles data access over the Web when nDataMode is set to 4.

oSql

An instance of a wwSQL object that handles data connection if nDatamode = 2. All SQL commands run through this object for remote data.

oValidationErrors

vResult

Variable result property. Used at this point only for ADO recordsets returned as a result from queries.

Requirements

Assembly: wwBusinessObject.prg

© West Wind Technologies, 1996-2019 • Updated: 02/15/19
Comment or report problem with topic