Rapid Data Access Tier Implementation
by John Cheng, Abdul Akbari, & Hong Rong



Listing One

(a) For single table

DEPT
(
  OID       NOT NULL NUMBER(38),
  DEPTNO    NOT NULL NUMBER(2),
  DNAME              VARCHAR2(14),
  LOC                VARCHAR2(13)
)

(b) Corresponding class generated in C#

public class Dept : DataAccessBase, IDept, IDataAccessBase
{
 ...
  long _Oid;
  long _Deptno;
  string _Dname;
  string _Loc;

  bool _OidNull = true;
  bool _DeptnoNull = true;
  bool _DnameNull = true;
  bool _LocNull = true;

  public long Oid
  {
    get {return _Oid;}
    set {_OidNull = false; _Oid = value;}
  }
 ...
}

(c) For table joins

SELECT
     DEPT.DNAME AS DEPARTMENT,
     EMP.EMPNO AS EMPNO,
     EMP.ENAME AS EMPNAME,
     EMP.SAL AS SALARY
FROM DEPT, EMP
WHERE DEPT.OID=EMP.DEPTOID
ORDER BY DEPARTMENT

(d) Corresponding class generated in C#

public class DeptEmp : DataAccessBase, IDeptEmp
{
 ...
  string _Department;
  long _Empno;
  string _Empname;
  long _Salary;

  public string Department
  {
    get {return _Department;}
  }
 ...
}


Listing Two

(a) Raw SQL statement

select emp.* from emp, dept where emp.deptoid=dept.oid
                                       and dept.dname='ACCOUNTING';

(b) SQL built with generated information

...
emp.Retrieve(Emp.DEPTOID == Dept.OID & Dept.DNAME == "ACCOUNTING");
 ...
Listing Three
(a) Code Template
columnNameStr =
//!!FOREACH MEMBER!!//
  "$COLUMN_NAME$," +
//!!END FOREACH MEMBER!!//
//!!REPLACE Options=64; Count=1; Regex=/," \+/"/ !!//
  ;

(b) Generated C# code
columnNameStr =
  "OID," +
  "EMPNO," +
  "ENAME," +
  "JOB," +
  "MGR," +
  "HIREDATE," +
  "SAL," +
  "COMM," +
  "DEPTOID"
  ;

(c) Code template

//!!FOREACH MEMBER!!//
bool Is$MEMBER_NAME$Null {get;set;}
//!!END FOREACH MEMBER!!//

(d) Generated C# code.

bool IsOidNull {get;set;}
bool IsEmpnoNull {get;set;}
bool IsEnameNull {get;set;}
bool IsJobNull {get;set;}
bool IsMgrNull {get;set;}
bool IsHiredateNull {get;set;}
bool IsSalNull {get;set;}
bool IsCommNull {get;set;}
bool IsDeptoidNull {get;set;}


(e) Code template

//!!FOREACH MEMBER!!//
//!!IF MEMBER_TYPE=long!!//
  _$MEMBER_NAME$Null = fSql.IsNextColumnNull();
  _$MEMBER_NAME$ = fSql.GetNextColumnInteger();
//!!END IF!!//
//!!IF MEMBER_TYPE=double!!//
  _$MEMBER_NAME$Null = fSql.IsNextColumnNull();
  _$MEMBER_NAME$ = fSql.GetNextColumnDouble();
//!!END IF!!//
//!!IF MEMBER_TYPE=string!!//
  _$MEMBER_NAME$Null = fSql.IsNextColumnNull();
  _$MEMBER_NAME$ = fSql.GetNextColumnString();
//!!END IF!!//
//!!IF MEMBER_TYPE=DateTime!!//
  _$MEMBER_NAME$Null = fSql.IsNextColumnNull();
  _$MEMBER_NAME$ = fSql.GetNextColumnDateTime();
//!!END IF!!//
//!!IF MEMBER_TYPE=byte[]!!//
  _$MEMBER_NAME$Null = fSql.IsNextColumnNull();
  _$MEMBER_NAME$ = fSql.GetNextColumnBytes(1024*200);
//!!END IF!!//
//!!END FOREACH MEMBER!!//

(f) Generated C# code
_OidNull = fSql.IsNextColumnNull();
_Oid = fSql.GetNextColumnInteger();

_EmpnoNull = fSql.IsNextColumnNull();
_Empno = fSql.GetNextColumnInteger();

_EnameNull = fSql.IsNextColumnNull();
_Ename = fSql.GetNextColumnString();

_JobNull = fSql.IsNextColumnNull();
_Job = fSql.GetNextColumnString();

_MgrNull = fSql.IsNextColumnNull();
_Mgr = fSql.GetNextColumnInteger();

_HiredateNull = fSql.IsNextColumnNull();
_Hiredate = fSql.GetNextColumnDateTime();

_SalNull = fSql.IsNextColumnNull();
_Sal = fSql.GetNextColumnInteger();

_CommNull = fSql.IsNextColumnNull();
_Comm = fSql.GetNextColumnInteger();

_DeptoidNull = fSql.IsNextColumnNull();
_Deptoid = fSql.GetNextColumnInteger();


Listing Four

//!!FOREACH MAPPED TABLE!!//
    $CLASS_NAME$
    $TABLE_NAME$
    $GUID1$
    $GUID2$
    $MEMBER_COUNT$
    $FOREIGN_KEY_COUNT$
//!!END FOREACH MAPPED TABLE!!//
//!!FOREACH MAPPED JOINT!!//
    $CLASS_NAME$
    $GUID1$
    $GUID2$
    $MEMBER_COUNT$
    $SELECT_STRING$
    $UPDATE_STRING$
    $DELETE_STRING$
    $INSERT_STRING$
//!!END FOREACH MAPPED JOINT!!//

//!!FOREACH MEMBER!!//
//!!FOREACH PRIMARY_KEY!!//
//!!FOREACH FOREIGN_KEY!!//
    //!!IF MEMBER_NAME=?!!// //!! ... !!//
    //!!IF COLUMN_NAME=?!!// //!! ... !!//
    //!!IF MEMBER_TYPE=?!!// //!! ... !!//
    //!!IF COLUMN_TYPE=?!!// //!! ... !!//
    //!!IF KEY_TYPE=?!!// //!! ... !!//
    //!!IF MEMBER_ACCESS=?!!// //!! ... !!//

    //!!END IF!!//

    $MEMBER_NAME$
    $COLUMN_NAME$
    $KEY_TYPE$
    $MEMBER_TYPE$
    $COLUMN_TYPE$
    $MEMBER_ACCESS$
    $COLUMN_ORDINAL$
    $COLUMN_MAXLENGTH$
    $COLUMN_TYPE$
//!!END FOREACH MEMBER!!//
//!!END FOREACH PRIMARY_KEY!!//
//!!END FOREACH FOREIGN_KEY!!//

//!!FOREACH PARENT!!//
    $CLASS_NAME$
    $TABLE_NAME$
    $PARENT_TABLE$
    $PARENT_CLASS$
    $COLUMN_TO_PARENT$
    $COLUMN_OF_PARENT$
    $MEMBER_TO_PARENT$
    $MEMBER_OF_PARENT$
//!!END FOREACH PARENT!!//

//!!FOREACH CHILD!!//
    $CLASS_NAME$
    $TABLE_NAME$
    $CHILD_TABLE$
    $CHILD_CLASS$
    $COLUMN_TO_CHILD$
    $COLUMN_OF_CHILD$
    $MEMBER_TO_CHILD$
    $MEMBER_OF_CHILD$
//!!END FOREACH CHILD!!//

//!!REPLACE Options=?; Count=?; Regex=/???/???/ !!//



