📄 joinexample.h
字号:
// join example data class ... note the class declaration is now free of any of these DB// abstractions// Initial: 9/5/2000 - MG// Edited: 12/20/2000 - MG - added namespace support - cleaned up class declaration#ifndef _JOIN_EXAMPLE_H#define _JOIN_EXAMPLE_H#include "dtl.h"using namespace dtl;// assume the corresponding native data for this class is in the DB_EXAMPLE table in// the database except class JoinExample{ private: // tablename.columnname: int exampleInt; // DB_EXAMPLE.INT_VALUE string exampleStr; // DB_EXAMPLE.STRING_VALUE double exampleDouble; // DB_EXAMPLE.DOUBLE_VALUE unsigned long sampleLong; // DB_SAMPLE.SAMPLE_LONG double extraDouble; // DB_SAMPLE.EXTRA_FLOAT public: JoinExample() : exampleInt(0), exampleStr(""), exampleDouble(0.0), sampleLong(0), extraDouble(0.0) { } JoinExample(int exInt, string exStr, double exDouble, unsigned long samLong, double extra) : exampleInt(exInt), exampleStr(exStr), exampleDouble(exDouble), sampleLong(samLong), extraDouble(extra) { } friend class BCAJoinExampleObj; friend class BCAJoinFuncObj; friend class DefaultBCA<JoinExample>; friend class BCAJoinParamObj; friend class DefaultInsValidate<JoinExample>; friend class IntValuePosSelValidate; friend ostream& operator<<(ostream &o, const JoinExample &je) { o << "JoinExample(" << je.exampleInt << ", \"" << je.exampleStr << "\", "; o << je.exampleDouble << ", " << je.sampleLong << ", " << je.extraDouble; o << ")"; return o; }};// BCA for JoinExample ... needed to store bindings between// view records and members in JoinExample objects// as a reference is passed in for each rowbuf member, the member's address// will be stored in the BoundColumn object for the corresponding DB column// void BCAJoinExample(BoundIOs &boundIOs, JoinExample &rowbuf);BEGIN_DTL_NAMESPACE#if 1// BCA for JoinExample ... needed to store bindings between// view records and members in JoinExample objects// as a reference is passed in for each rowbuf member, the member's address// will be stored in the BoundColumn object for the corresponding DB column// void BCAJoinExample(BoundIOs &boundIOs, JoinExample &rowbuf);template<> class DefaultBCA<JoinExample>{public: void operator()(BoundIOs &boundIOs, JoinExample &rowbuf) { boundIOs["INT_VALUE"] == rowbuf.exampleInt; boundIOs["STRING_VALUE"] == rowbuf.exampleStr; boundIOs["DOUBLE_VALUE"] == rowbuf.exampleDouble; boundIOs["SAMPLE_LONG"] == rowbuf.sampleLong; boundIOs["EXTRA_FLOAT"] == rowbuf.extraDouble; }};#endif// insertions should never be valid for JoinExample because it is a join on two tables// so we specialize DefaultInsValidate to always return false for JoinExamplestemplate<> class DefaultInsValidate<JoinExample>{public: bool operator()(JoinExample &rowbuf) { return false; // insertions never allowed }};END_DTL_NAMESPACEclass BCAJoinFuncObj{public: void operator()(BoundIOs &boundIOs, JoinExample &rowbuf) { boundIOs["INT_VALUE"] == rowbuf.exampleInt; boundIOs["STRING_VALUE"] == rowbuf.exampleStr; boundIOs["DOUBLE_VALUE"] == rowbuf.exampleDouble; boundIOs["SAMPLE_LONG"] == rowbuf.sampleLong; boundIOs["EXTRA_FLOAT"] == rowbuf.extraDouble; }};// here, we are happy with the default parameter object's behavior// but let's define a custom parameter object// a data class can be associated with any number of parameter object classesclass JoinParamObj{public: int intValue; string strValue; int sampleInt; string sampleStr;};class BPAJoinParamObj{public: void operator()(BoundIOs &boundIOs, JoinParamObj ¶mObj) { boundIOs[0] == paramObj.intValue; boundIOs[1] == paramObj.strValue; boundIOs[2] == paramObj.sampleInt; boundIOs[3] == paramObj.sampleStr; }};// BCA for JoinExample ... needed to store bindings between// view records and members in JoinExample objects// as a reference is passed in for each rowbuf member, the member's address// will be stored in the BoundColumn object for the corresponding DB columnclass BCAJoinExampleObj{public: void operator()(BoundIOs &boundIOs, JoinExample &rowbuf) { boundIOs["INT_VALUE"] == rowbuf.exampleInt; boundIOs["STRING_VALUE"] == rowbuf.exampleStr; boundIOs["DOUBLE_VALUE"] == rowbuf.exampleDouble; boundIOs["SAMPLE_LONG"] == rowbuf.sampleLong; boundIOs["EXTRA_FLOAT"] == rowbuf.extraDouble; }};// we want to use the generic default behavior usually for SelValidate for JoinExamples// but with the view we want, assume we only care that the intValue is positiveclass IntValuePosSelValidate{public: bool operator()(BoundIOs &boundIOs, JoinExample &rowbuf) { return (!boundIOs["INT_VALUE"].IsNull() && rowbuf.exampleInt > 0); }};// insertions should never be valid for JoinParamObj because it is a join on two tables// so we specialize DefaultInsValidate to always return false for JoinExamples// bool DefaultInsValidate(JoinExample &rowbuf);#if 0// insertions should never be valid for JoinParamObj because it is a join on two tables// so we specialize DefaultInsValidate to always return false for JoinExamples// bool JoinExampleInsValidate(JoinExample &rowbuf);#endif// we want to use the generic default behavior usually for SelValidate for JoinExamples// but with the view we want, assume we only care that the intValue is positive// bool IntValuePosInsValidate(BoundIOs &boundIOs, JoinExample &rowbuf);// one BPA for JoinParamObj
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -