00001 /* 00002 * Copyright (c) 2010 Ferruccio Vitale <unixo@devzero.it> 00003 * All rights reserved. 00004 * 00005 * $Id: ManagedObject.h 72 2010-08-03 16:43:52Z unixo $ 00006 */ 00007 00008 #ifndef __MANAGEDOBJECT_H__ 00009 #define __MANAGEDOBJECT_H__ 00010 00011 #include "Observable.h" 00012 #include "Exceptions.h" 00013 #include "Database.h" 00014 00015 using namespace std; 00016 using namespace mysqlpp; 00017 00018 00027 class ManagedObject : public Observable 00028 { 00029 private: 00030 ulonglong lastInsertID; 00031 void initEntity(string anEntityName); 00032 00033 protected: 00035 set<string> _keys; 00037 set<string> _updatedKeys; 00039 map<string, string> _fields; 00041 string _entityName; 00043 bool _fault; 00044 00045 public: 00046 ManagedObject(string anEntityName); 00047 ManagedObject(string anEntityName, Row & aRow); 00048 ~ManagedObject(); 00049 00050 void setBoolForKey(string aKey, bool aValue); 00051 void setFloatForKey(string aKey, float aValue); 00052 void setIntForKey(string aKey, int aValue); 00053 void setValueForKey(string aKey, string aValue) throw (InvalidArgument); 00054 00055 float floatForKey(string aKey) throw (InvalidArgument); 00056 int intForKey(string aKey) throw (InvalidArgument); 00057 bool boolForKey(string aKey) throw (InvalidArgument); 00058 string valueForKey(string aKey) throw (InvalidArgument); 00059 00060 ulonglong getLastInsertID() const; 00061 bool store(); 00062 bool update(); 00063 00064 virtual string primaryKey() = 0; 00065 }; 00066 00067 #endif /* __MANAGEDOBJECT_H__ */