00001 /* 00002 * Copyright (c) 2010 Ferruccio Vitale <unixo@devzero.it> 00003 * All rights reserved. 00004 * 00005 * $Id: ManagedObject.h 75 2010-09-13 09:25:53Z 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 00028 class ManagedObject : public Observable 00029 { 00030 private: 00031 ulonglong _lastInsertID; 00032 void initEntity(string anEntityName); 00033 00034 protected: 00036 set<string> _keys; 00038 set<string> _updatedKeys; 00040 map<string, string> _fields; 00042 string _entityName; 00044 bool _fault; 00045 00046 public: 00047 ManagedObject(string anEntityName); 00048 ManagedObject(string anEntityName, Row & aRow); 00049 virtual ~ManagedObject(); 00050 00051 void setBoolForKey(string aKey, bool aValue); 00052 void setFloatForKey(string aKey, float aValue); 00053 void setIntForKey(string aKey, int aValue); 00054 void setValueForKey(string aKey, string aValue) throw (InvalidArgument); 00055 00056 float floatForKey(string aKey) throw (InvalidArgument); 00057 int intForKey(string aKey) throw (InvalidArgument); 00058 bool boolForKey(string aKey) throw (InvalidArgument); 00059 string valueForKey(string aKey) throw (InvalidArgument); 00060 00061 ulonglong getLastInsertID() const; 00062 bool store(); 00063 bool update(); 00064 00065 virtual string primaryKey() = 0; 00066 }; 00067 00068 #endif /* __MANAGEDOBJECT_H__ */