Line data Source code
1 : /*
2 : * Header:
3 : * libsnapwebsites/src/libdbproxy/order.h
4 : *
5 : * Description:
6 : * Manager an order to be sent to the snapdbproxy daemon.
7 : *
8 : * Documentation:
9 : * See the corresponding .cpp file.
10 : *
11 : * License:
12 : * Copyright (c) 2011-2019 Made to Order Software Corp. All Rights Reserved
13 : *
14 : * https://snapwebsites.org/
15 : * contact@m2osw.com
16 : *
17 : * Permission is hereby granted, free of charge, to any person obtaining a
18 : * copy of this software and associated documentation files (the
19 : * "Software"), to deal in the Software without restriction, including
20 : * without limitation the rights to use, copy, modify, merge, publish,
21 : * distribute, sublicense, and/or sell copies of the Software, and to
22 : * permit persons to whom the Software is furnished to do so, subject to
23 : * the following conditions:
24 : *
25 : * The above copyright notice and this permission notice shall be included
26 : * in all copies or substantial portions of the Software.
27 : *
28 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
29 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 : * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
31 : * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
32 : * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
33 : * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
34 : * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 : */
36 : #pragma once
37 :
38 : #include "libdbproxy/consistency_level.h"
39 :
40 : #include <vector>
41 :
42 :
43 : namespace libdbproxy
44 : {
45 :
46 0 : class order
47 : {
48 : public:
49 : enum type_of_result_t
50 : {
51 : TYPE_OF_RESULT_CLOSE, // i.e. close a cursor
52 : TYPE_OF_RESULT_BATCH_ADD, // i.e. add to an open batch
53 : TYPE_OF_RESULT_BATCH_COMMIT, // i.e. commit the accumulated batch to the database
54 : TYPE_OF_RESULT_BATCH_DECLARE, // i.e. create a batch
55 : TYPE_OF_RESULT_BATCH_ROLLBACK, // i.e. abort the current batch
56 : TYPE_OF_RESULT_DECLARE, // i.e. create a cursor (SELECT)
57 : TYPE_OF_RESULT_DESCRIBE, // i.e. just whether it worked or not
58 : TYPE_OF_RESULT_FETCH, // i.e. read next page from cursor (nextPage)
59 : TYPE_OF_RESULT_ROWS, // i.e. one SELECT
60 : TYPE_OF_RESULT_SUCCESS // i.e. just whether it worked or not
61 : };
62 :
63 : type_of_result_t get_type_of_result() const;
64 : QString cql() const;
65 : void setCql(QString const & cql_string, type_of_result_t const result_type = type_of_result_t::TYPE_OF_RESULT_SUCCESS);
66 :
67 : bool validOrder() const;
68 : void setValidOrder(bool const valid);
69 :
70 : consistency_level_t consistencyLevel() const;
71 : void setConsistencyLevel(consistency_level_t consistency_level);
72 :
73 : int64_t timestamp() const;
74 : void setTimestamp(int64_t const user_timestamp);
75 :
76 : int32_t timeout() const;
77 : void setTimeout(int32_t const statement_timeout_ms);
78 :
79 : int8_t columnCount() const;
80 : void setColumnCount(int8_t const paging_size);
81 :
82 : int32_t pagingSize() const;
83 : void setPagingSize(int32_t const paging_size);
84 :
85 : int32_t cursorIndex() const;
86 : void setCursorIndex(int32_t const cursor_index);
87 :
88 : int32_t batchIndex() const;
89 : void setBatchIndex(int32_t const batch_index);
90 :
91 : bool clearClusterDescription() const;
92 : void setClearClusterDescription(bool const clear = true);
93 :
94 : bool blocking() const;
95 : void setBlocking(bool const block = true);
96 :
97 : size_t parameterCount() const;
98 : QByteArray const & parameter(int index) const;
99 : void addParameter(QByteArray const & data);
100 :
101 : QByteArray encodeOrder() const;
102 : bool decodeOrder(unsigned char const * encoded_order, size_t size);
103 :
104 : private:
105 : QString f_cql = QString();
106 : bool f_valid = true;
107 : bool f_blocking = true;
108 : bool f_clear_cluster_description = false;
109 : type_of_result_t f_type_of_result = type_of_result_t::TYPE_OF_RESULT_SUCCESS;
110 : consistency_level_t f_consistency_level = CONSISTENCY_LEVEL_ONE; // TBD: can we get the libdbproxy default automatically?
111 : int64_t f_timestamp = 0;
112 : int32_t f_timeout_ms = 0;
113 : int8_t f_column_count = 1;
114 : int32_t f_paging_size = 0;
115 : int32_t f_cursor_index = -1;
116 : int32_t f_batch_index = -1;
117 : std::vector<QByteArray> f_parameter = std::vector<QByteArray>();
118 : };
119 :
120 :
121 : } // namespace libdbproxy
122 : // vim: ts=4 sw=4 et
|