论坛首页> 三共建设

iEco平台EAV对象接口

iEco平台EAV对象接口

一、          EAV技术原理

EAV的设计中,每行保存单一的数据(fact)。Fact有三列:实体,属性,值。新平台实现了两种EAV模式,一种是存粹的将一个简单的,结构化或半结构化的对象用行存储的模式持久化存储(CEAV)一种是在已知的结构化数据,需要根据不同应用场景,动态的扩展存储需求(GEAV)。


二、          CEAV接口:

(一)             接口:

1.       设置实体对象名称

Void setNameKey(const string & name)

2.       设置实体对象类型ID

Void setIDKey( long long  type)

3.       获取实体对象名称

String getNameKey()

4.       获取实体对象类型ID

Longlong getIDKey()

5.       设置对象所属项目

Void setSchemaName( const string & schema)

6.       获取实体对象名称列表

vector<string> listNamesOfSiblings(QCBase*)

7.       获取实体对象名称列表

vector<string> listNamesOfSiblings(QCQueryDataByColumns*)

8.       获取当前对象的兄弟对象列表

vector<NDataObject*> listSiblings(QCQueryDataByColumns*)

9.       设置属性值

Void setValue(const string& key, int value)

Void setValue(const string& key, long long value)

Void setValue(const string& key, string value)

Void setValue(const string& key, float value)

Void setValue(const string& key, double value)

10.  根据属性key获取值信息

Void getValue(const string& key, int value)

Void getValue(const string& key, long long value)

Void getValue(const string& key, string value)

Void getValue(const string& key, float value)

Void getValue(const string& key, double value)

11.  删除当前对象

NStatus & del()

12.  获取当前对象信息

NStatus & get()

(二)             示例:

   /*插入一个名称为test3,类型为2ceav对象,此对象包含两个属性x,y*/

void insert(ICEav * eav,const string & prj)

{

    eav->setNameKey("test3");

    eav->setSchemaName(prj);

    eav->setIDKey(2);

    eav->setValue("x",600);

    eav->setValue("y",700);

    eav->save();

}

/*获得一个名称为test3,类型为2de ceav对象*/

void geteavmesg(ICEav * eav,const string & prj)

{

    eav->setNameKey("test3");

    eav->setSchemaName(prj);

    eav->setIDKey(2);

    eav->get();

    string mo = "";

    mo = eav->getValue("x",mo);

    int type = eav->getValue("y",type);

    cout<<" the eav mesg modify = "<< mo<<" type = "<< type<<endl;

}

/*删除一个名称为test1,类型为2ceav对象*/

void del(ICEav * eav,const string & prj)

{

    eav->setNameKey("test1");

    av->setSchemaName(prj);

    eav->setIDKey(2);

    eav->del();

}

/*通过QCQueryDataByColumns 得到一个类型为2的所有对象名称列表*/

void getnamelist(ICEav * eav,const string & prj)

{

    eav->setSchemaName(prj);

    QCQueryDataByColumns tmp;

    tmp.setColumn("type");

    tmp.pushValue(2);

    vector<string> nlist = eav->listNamesOfSiblings(&tmp);

    for(int i = 0; i <nlist.size(); i ++)

        cout<<" the name = "<< nlist[i]<<endl;

 

}

/*得到类型为2的所有ceav 对象列表*/

void getv(ICEav * eav,const string & prj)

{

    eav->setSchemaName(prj);

    eav->setIDKey(2);

    QCQueryDataByColumns tmp;

   vector<NDataObject*>  v = eav->listSiblings(&tmp);

 

   for(int i = 0; i <v.size(); i ++)

   {

        ICEav * a =  (ICEav *) v[i];

        int x =  a->getValue("x",x);

        int y =  a->getValue("y",y);

        cout<<" x = "<< x<<" y = "<< y<<endl;

   }

   cout<<" size = "<< v.size()<<endl;

 

}

int main()

{

 

    string dsname = "ndp01";

    string prjname = "ndp0831";

    string user    = "admin1";

    string pwd     = "admin1";

    string db      = "ndp01";

    string prj     = "ndp0831";

    NDPSystem* theNDP = NDPSystem::instance();

    IDataProvider* pprd = theNDP->createProvider(user,pwd,db);

    if (NULL == pprd)

    {

        cout << "Error: " << theNDP->Message() << endl;

        return -1;

    }

    IProject* pprj = pprd->getChild<IProject>(prj);

 

    ICEav * eav = pprj->createChild<ICEav>("");

    //insert(eav,prj);

    //geteavmesg(eav,prj);

    //del(eav,prj);

    //getnamelist(eav,prj);

    getv(eav,prj);

    delete eav;

}

三、          GEAV

(一)             接口:

1.       设置实体对象名称

Void setNameKey(const string & name)

2.       设置实体对象类型ID

Void setIDKey( long long  type)

3.       获取实体对象名称

String getNameKey()

4.       获取实体对象类型ID

Longlong getIDKey()

5.       设置对象所属项目

voidsetSchemaName( const string & schema)

6.       获取实体对象名称列表

vector<string>listNamesOfSiblings(QCBase*)

7.       获取实体对象名称列表

vector<string>listNamesOfSiblings(QCQueryDataByColumns*)

8.       设置属性值

voidsetValue(const string& key, int value)

void setValue(const string& key, long longvalue)

void setValue(const string& key, string value)

void setValue(const string& key, float value)

void setValue(const string& key, double value)

9.       根据属性key获取值信息

Void getValue(const string& key, int value)

Void getValue(const string& key, long long value)

Void getValue(const string& key, string value)

Void getValue(const string& key, float value)

Void getValue(const string& key, double value)

10.  删除当前对象

NStatus&del()

11.  获取当前对象信息

NStatus&get()

(二)             示例:

/*插入表gg_gridpk_id =1014020行的 扩展属性 modify type

void insert(IGEav * eav,const string & prj)

{

    eav->setNameKey("gg_grid");

    eav->setSchemaName(prj);

    eav->setIDKey(1014020);

    eav->setValue("modify","wxh2");

    eav->setValue("type",102);

    eav->save();

}

/*获取一个geav对象,其中关联的统一模型表为gg_grid,行为1014020扩展属性为modify type*/

void geteavmesg(IGEav * eav,const string & prj)

{

    eav->setNameKey("gg_grid");

    eav->setSchemaName(prj);

    eav->setIDKey(1014020);

    eav->get();

    string mo = "";

    mo = eav->getValue("modify",mo);

    int type = eav->getValue("type",type);

    cout<<" the eav mesg modify = "<< mo<<" type = "<< type<<endl;

}

int main()

{

 

    string dsname = "ndp01";

    string prjname = "ndp0831";

    string user    = "admin1";

    string pwd     = "admin1";

    string db      = "ndp01";

    string prj     = "ndp0831";

    NDPSystem* theNDP = NDPSystem::instance();

    IDataProvider* pprd = theNDP->createProvider(user,pwd,db);

    if (NULL == pprd)

    {

        cout << "Error: " << theNDP->Message() << endl;

        return -1;

    }

    IProject* pprj = pprd->getChild<IProject>(prj);

 

    IGEav * eav = pprj->createChild<IGEav>("");

    //insert(eav,prj);

    geteavmesg(eav,prj);

    delete eav;

}

全部回复

暂无更多回复内容