Go to the documentation of this file.00001 #ifndef INCLUDE_ORA_RELATIONALOPERATION_H
00002 #define INCLUDE_ORA_RELATIONALOPERATION_H
00003
00004
00005 #include "CoralBase/AttributeList.h"
00006 #include "CoralBase/AttributeListSpecification.h"
00007
00008 #include <memory>
00009
00010 namespace coral {
00011 class ISchema;
00012 class IBulkOperation;
00013 class IQuery;
00014 class ICursor;
00015 }
00016
00017 namespace ora {
00018
00019 class IRelationalOperation {
00020 public:
00021
00022 virtual ~IRelationalOperation(){
00023 }
00024
00025 virtual bool isRequired() = 0;
00026
00027 virtual bool execute() = 0 ;
00028
00029 virtual void reset() = 0;
00030
00031 };
00032
00033 typedef enum { Eq, Gt, Lt, Ge, Le } ConditionType;
00034
00035 class IRelationalData {
00036 public:
00037 virtual ~IRelationalData(){
00038 }
00039
00040 virtual int addId( const std::string& columnName ) = 0;
00041
00042 virtual int addData( const std::string& columnName, const std::type_info& columnType ) = 0;
00043
00044 virtual int addBlobData(const std::string& columnName) = 0;
00045
00046
00047
00048 virtual int addWhereId( const std::string& columnName ) = 0;
00049
00050 virtual coral::AttributeList& data() = 0;
00051
00052 virtual coral::AttributeList& whereData() = 0;
00053
00054 virtual std::string& whereClause() = 0;
00055
00056 };
00057
00058 class InputRelationalData : public IRelationalData {
00059
00060 public:
00061
00062 InputRelationalData();
00063
00064 virtual ~InputRelationalData();
00065
00066 public:
00067
00068 int addId(const std::string& columnName);
00069
00070 int addData(const std::string& columnName, const std::type_info& columnType );
00071
00072 int addBlobData(const std::string& columnName);
00073
00074 int addWhereId( const std::string& columnName );
00075
00076 coral::AttributeList& data();
00077
00078 coral::AttributeList& whereData();
00079
00080 std::string& whereClause();
00081
00082 public:
00083
00084 int addWhereId( const std::string& columnName, ConditionType cond );
00085
00086 std::string& updateClause();
00087
00088 private:
00089
00090 coral::AttributeList m_data;
00091 std::string m_setClause;
00092 std::string m_whereClause;
00093 };
00094
00095 class InsertOperation: public InputRelationalData, public IRelationalOperation {
00096 public:
00097 InsertOperation( const std::string& tableName, coral::ISchema& schema );
00098 ~InsertOperation();
00099
00100 public:
00101 bool isRequired();
00102 bool execute();
00103 void reset();
00104
00105 private:
00106 std::string m_tableName;
00107 coral::ISchema& m_schema;
00108 };
00109
00110 class BulkInsertOperation : public InputRelationalData, public IRelationalOperation {
00111 public:
00112 BulkInsertOperation( const std::string& tableName, coral::ISchema& schema );
00113 ~BulkInsertOperation();
00114 coral::IBulkOperation& setUp( int rowCacheSize );
00115
00116 public:
00117 bool isRequired();
00118 bool execute();
00119 void reset();
00120 private:
00121 std::string m_tableName;
00122 coral::ISchema& m_schema;
00123 std::vector<coral::IBulkOperation*> m_bulkOperations;
00124 };
00125
00126 class UpdateOperation : public InputRelationalData, public IRelationalOperation {
00127
00128 public:
00129 explicit UpdateOperation( const std::string& tableName, coral::ISchema& schema );
00130 ~UpdateOperation();
00131
00132 public:
00133 bool isRequired();
00134 bool execute();
00135 void reset();
00136 private:
00137 std::string m_tableName;
00138 coral::ISchema& m_schema;
00139
00140 };
00141
00142
00143 class DeleteOperation : public InputRelationalData, public IRelationalOperation {
00144 public:
00145 explicit DeleteOperation( const std::string& tableName, coral::ISchema& schema );
00146 ~DeleteOperation();
00147
00148 public:
00149 bool isRequired();
00150 bool execute();
00151 void reset();
00152 private:
00153 std::string m_tableName;
00154 coral::ISchema& m_schema;
00155
00156 };
00157
00158
00159 class SelectOperation : public IRelationalData {
00160 public:
00161 explicit SelectOperation( const std::string& tableName, coral::ISchema& schema );
00162 ~SelectOperation();
00163
00164 void addOrderId(const std::string& columnName);
00165 bool nextCursorRow();
00166 void clear();
00167 void execute();
00168 coral::AttributeListSpecification& attributeListSpecification();
00169
00170 public:
00171 int addId(const std::string& columnName);
00172
00173 int addData(const std::string& columnName, const std::type_info& columnType );
00174
00175 int addBlobData(const std::string& columnName);
00176
00177
00178
00179 int addWhereId( const std::string& columnName );
00180
00181 coral::AttributeList& data();
00182 coral::AttributeList& whereData();
00183 std::string& whereClause();
00184 private:
00185 coral::AttributeListSpecification* m_spec;
00186 coral::AttributeList m_whereData;
00187 std::string m_whereClause;
00188 std::vector<std::string> m_orderByCols;
00189 std::auto_ptr<coral::IQuery> m_query;
00190 coral::ICursor* m_cursor;
00191 std::string m_tableName;
00192 coral::ISchema& m_schema;
00193 };
00194
00195 }
00196
00197 #endif