SQLSerialize.h

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  * 
00007  * Intel Open Source License 
00008  * 
00009  * Copyright (c) 2004 Intel Corporation. All rights reserved. 
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  * 
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  * 
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  * 
00022  *   Neither the name of the Intel Corporation nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *  
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00030  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 #ifndef _OASYS_SQL_SERIALIZE_H_
00039 #define _OASYS_SQL_SERIALIZE_H_
00040 
00048 #include "Serialize.h"
00049 #include "../util/StringBuffer.h"
00050 
00051 namespace oasys {
00052 
00053 class SQLImplementation;
00054 
00059 class SQLQuery : public SerializeAction {
00060 public:
00064     SQLQuery(action_t type, const char* table_name, SQLImplementation* impl,
00065              const char* initial_query = 0);
00066     
00070     const char* query() { return query_.c_str(); }
00071     
00075     StringBuffer* querybuf() { return &query_; }
00076     
00077 protected:
00078     const char* table_name_;
00079     SQLImplementation* sql_impl_ ;
00080     StringBuffer query_;
00081 };
00082 
00087 class SQLInsert : public SQLQuery {
00088 public:
00092     SQLInsert(const char* table_name, SQLImplementation *impl);
00093   
00094     virtual void begin_action();
00095     virtual void end_action();
00096     
00101     int action(const SerializableObject* const_object)
00102     {
00103         return(SerializeAction::action((SerializableObject*)const_object));
00104     }
00105         
00106     // Virtual functions inherited from SerializeAction
00107     void process(const char* name, u_int32_t* i);
00108     void process(const char* name, u_int16_t* i);
00109     void process(const char* name, u_int8_t* i);
00110     void process(const char* name, int32_t* i);
00111     void process(const char* name, int16_t* i);
00112     void process(const char* name, int8_t* i);
00113     void process(const char* name, bool* b);
00114     void process(const char* name, u_char* bp, size_t len);
00115     void process(const char* name, u_char** bp, size_t* lenp, int flags);
00116     void process(const char* name, std::string* s);
00117 };
00118 
00123 class SQLUpdate : public SQLQuery {
00124 public:
00128     SQLUpdate(const char* table_name, SQLImplementation *impl);
00129   
00130     virtual void begin_action();
00131     virtual void end_action();
00132     
00137     int action(const SerializableObject* const_object)
00138     {
00139         return(SerializeAction::action((SerializableObject*)const_object));
00140     }
00141         
00142     // Virtual functions inherited from SerializeAction
00143     void process(const char* name, u_int32_t* i);
00144     void process(const char* name, u_int16_t* i);
00145     void process(const char* name, u_int8_t* i);
00146     void process(const char* name, int32_t* i);
00147     void process(const char* name, int16_t* i);
00148     void process(const char* name, int8_t* i);
00149     void process(const char* name, bool* b);
00150     void process(const char* name, u_char* bp, size_t len);
00151     void process(const char* name, u_char** bp, size_t* lenp, int flags);
00152     void process(const char* name, std::string* s);
00153 };
00154 
00159 class SQLTableFormat : public SQLQuery {
00160 public:
00164     SQLTableFormat(const char* table_name, SQLImplementation *impl);
00165     
00166     virtual void begin_action();
00167     virtual void end_action();
00168     
00173     int action(const SerializableObject* const_object)
00174     {
00175         return(SerializeAction::action((SerializableObject*)const_object));
00176     }
00177         
00178     // Virtual functions inherited from SerializeAction
00179     void process(const char* name,  SerializableObject* object);
00180     void process(const char* name, u_int32_t* i);
00181     void process(const char* name, u_int16_t* i);
00182     void process(const char* name, u_int8_t* i);
00183     void process(const char* name, bool* b);
00184     void process(const char* name, u_char* bp, size_t len);
00185     void process(const char* name, u_char** bp, size_t* lenp, int flags);
00186     void process(const char* name, std::string* s);
00187 
00188  protected:
00189     void append(const char* name, const char* type);
00190     StringBuffer column_prefix_;
00191 };
00192 
00197 class SQLExtract : public SerializeAction {
00198 public:
00199     SQLExtract(SQLImplementation *impl);
00200     
00201     // get the next field from the db
00202     const char* next_field() ;
00203 
00204     // Virtual functions inherited from SerializeAction
00205     void process(const char* name, u_int32_t* i);
00206     void process(const char* name, u_int16_t* i);
00207     void process(const char* name, u_int8_t* i);
00208     void process(const char* name, bool* b);
00209     void process(const char* name, u_char* bp, size_t len);
00210     void process(const char* name, u_char** bp, size_t* lenp, int flags);
00211     void process(const char* name, std::string* s); 
00212 
00213  protected:
00214     int field_;         
00215     
00216  private:
00217     SQLImplementation *sql_impl_;
00218 };
00219 
00220 } // namespace oasys
00221 
00222 #endif /* _OASYS_SQL_SERIALIZE_H_ */

Generated on Fri Dec 22 14:48:00 2006 for DTN Reference Implementation by  doxygen 1.5.1