SQLSerialize.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef _OASYS_SQL_SERIALIZE_H_
00018 #define _OASYS_SQL_SERIALIZE_H_
00019 
00027 #include "Serialize.h"
00028 #include "../util/StringBuffer.h"
00029 
00030 namespace oasys {
00031 
00032 class SQLImplementation;
00033 
00038 class SQLQuery : public SerializeAction {
00039 public:
00043     SQLQuery(action_t type, const char* table_name, SQLImplementation* impl,
00044              const char* initial_query = 0);
00045     
00049     const char* query() { return query_.c_str(); }
00050     
00054     StringBuffer* querybuf() { return &query_; }
00055     
00056 protected:
00057     const char* table_name_;
00058     SQLImplementation* sql_impl_ ;
00059     StringBuffer query_;
00060 };
00061 
00066 class SQLInsert : public SQLQuery {
00067 public:
00071     SQLInsert(const char* table_name, SQLImplementation *impl);
00072   
00073     virtual void begin_action();
00074     virtual void end_action();
00075     
00080     int action(const SerializableObject* const_object)
00081     {
00082         return(SerializeAction::action((SerializableObject*)const_object));
00083     }
00084         
00085     // Virtual functions inherited from SerializeAction
00086     void process(const char* name, u_int32_t* i);
00087     void process(const char* name, u_int16_t* i);
00088     void process(const char* name, u_int8_t* i);
00089     void process(const char* name, int32_t* i);
00090     void process(const char* name, int16_t* i);
00091     void process(const char* name, int8_t* i);
00092     void process(const char* name, bool* b);
00093     void process(const char* name, u_char* bp, size_t len);
00094     void process(const char* name, u_char** bp, size_t* lenp, int flags);
00095     void process(const char* name, std::string* s);
00096 };
00097 
00102 class SQLUpdate : public SQLQuery {
00103 public:
00107     SQLUpdate(const char* table_name, SQLImplementation *impl);
00108   
00109     virtual void begin_action();
00110     virtual void end_action();
00111     
00116     int action(const SerializableObject* const_object)
00117     {
00118         return(SerializeAction::action((SerializableObject*)const_object));
00119     }
00120         
00121     // Virtual functions inherited from SerializeAction
00122     void process(const char* name, u_int32_t* i);
00123     void process(const char* name, u_int16_t* i);
00124     void process(const char* name, u_int8_t* i);
00125     void process(const char* name, int32_t* i);
00126     void process(const char* name, int16_t* i);
00127     void process(const char* name, int8_t* i);
00128     void process(const char* name, bool* b);
00129     void process(const char* name, u_char* bp, size_t len);
00130     void process(const char* name, u_char** bp, size_t* lenp, int flags);
00131     void process(const char* name, std::string* s);
00132 };
00133 
00138 class SQLTableFormat : public SQLQuery {
00139 public:
00143     SQLTableFormat(const char* table_name, SQLImplementation *impl);
00144     
00145     virtual void begin_action();
00146     virtual void end_action();
00147     
00152     int action(const SerializableObject* const_object)
00153     {
00154         return(SerializeAction::action((SerializableObject*)const_object));
00155     }
00156         
00157     // Virtual functions inherited from SerializeAction
00158     void process(const char* name,  SerializableObject* object);
00159     void process(const char* name, u_int32_t* i);
00160     void process(const char* name, u_int16_t* i);
00161     void process(const char* name, u_int8_t* i);
00162     void process(const char* name, bool* b);
00163     void process(const char* name, u_char* bp, size_t len);
00164     void process(const char* name, u_char** bp, size_t* lenp, int flags);
00165     void process(const char* name, std::string* s);
00166 
00167  protected:
00168     void append(const char* name, const char* type);
00169     StringBuffer column_prefix_;
00170 };
00171 
00176 class SQLExtract : public SerializeAction {
00177 public:
00178     SQLExtract(SQLImplementation *impl);
00179     
00180     // get the next field from the db
00181     const char* next_field() ;
00182 
00183     // Virtual functions inherited from SerializeAction
00184     void process(const char* name, u_int32_t* i);
00185     void process(const char* name, u_int16_t* i);
00186     void process(const char* name, u_int8_t* i);
00187     void process(const char* name, bool* b);
00188     void process(const char* name, u_char* bp, size_t len);
00189     void process(const char* name, u_char** bp, size_t* lenp, int flags);
00190     void process(const char* name, std::string* s); 
00191 
00192  protected:
00193     int field_;         
00194     
00195  private:
00196     SQLImplementation *sql_impl_;
00197 };
00198 
00199 } // namespace oasys
00200 
00201 #endif /* _OASYS_SQL_SERIALIZE_H_ */

Generated on Sat Sep 8 08:36:18 2007 for DTN Reference Implementation by  doxygen 1.5.3