00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #if !defined(MYSQLPP_INSERTPOLICY_H)
00057 #define MYSQLPP_INSERTPOLICY_H
00058
00065 template <class AccessController = Transaction>
00066 class MYSQLPP_EXPORT RowCountInsertPolicy
00067 {
00068 public:
00070 RowCountInsertPolicy(unsigned int rows) :
00071 cur_rows_(0),
00072 max_rows_(rows)
00073 {
00074 }
00075
00077 ~RowCountInsertPolicy() { }
00078
00083 template <class RowT>
00084 bool can_add(int, const RowT&)
00085 {
00086 if (++cur_rows_ > max_rows_) {
00087 cur_rows_ = 0;
00088 return false;
00089 }
00090 else {
00091 return true;
00092 }
00093 }
00094
00096 typedef AccessController access_controller;
00097
00098 private:
00099 unsigned int cur_rows_;
00100 unsigned const int max_rows_;
00101 };
00102
00103
00111 template <class AccessController = Transaction>
00112 class MYSQLPP_EXPORT SizeThresholdInsertPolicy
00113 {
00114 public:
00116 SizeThresholdInsertPolicy(int size) :
00117 size_(size)
00118 {
00119 }
00120
00122 ~SizeThresholdInsertPolicy() { }
00123
00131 template <class RowT>
00132 bool can_add(int size, const RowT& object) const
00133 {
00134 return (size < size_);
00135 }
00136
00138 typedef AccessController access_controller;
00139
00140 private:
00141 int size_;
00142 };
00143
00144
00152 template <class AccessController = Transaction>
00153 class MYSQLPP_EXPORT MaxPacketInsertPolicy
00154 {
00155 public:
00161 MaxPacketInsertPolicy(Connection* con, int size) :
00162 conn_(con), size_(size)
00163 {
00164 }
00165
00174 MaxPacketInsertPolicy(int size) :
00175 conn_(0), size_(size)
00176 {
00177 }
00178
00180 ~MaxPacketInsertPolicy() { }
00181
00189 template <class RowT>
00190 bool can_add(int size, const RowT& object) const
00191 {
00192 if (size < size_) {
00193
00194
00195 SQLStream s(conn_);
00196 s << ",(" << object.value_list() << ")";
00197 return (size_ - size) >= static_cast<int>(s.str().size());
00198 }
00199 else {
00200
00201 return false;
00202 }
00203 }
00204
00206 typedef AccessController access_controller;
00207
00208 private:
00209 Connection* conn_;
00210 int size_;
00211 };
00212
00213 #endif // !defined(MYSQLPP_INSERTPOLICY_H)
00214