forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathob_sequence_option.cpp
More file actions
130 lines (110 loc) · 4.38 KB
/
Copy pathob_sequence_option.cpp
File metadata and controls
130 lines (110 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#define USING_LOG_PREFIX SHARE
#include "share/sequence/ob_sequence_option.h"
#include "share/ob_define.h"
using namespace oceanbase::common;
using namespace oceanbase::common::number;
using namespace oceanbase::share;
OB_SERIALIZE_MEMBER(ObSequenceValue,
val_);
OB_SERIALIZE_MEMBER(ObSequenceOption,
increment_by_,
start_with_,
maxvalue_,
minvalue_,
cache_,
cycle_,
order_);
ObSequenceMaxMinInitializer::ObSequenceMaxMinInitializer()
{
int ret = OB_SUCCESS;
if (OB_FAIL(MAX_VALUE.set("9999999999999999999999999999"))) {
LOG_ERROR("fail set max value", K(ret));
} else if (OB_FAIL(MIN_VALUE.set("-999999999999999999999999999"))) {
LOG_ERROR("fail set min value", K(ret));
} else if (OB_FAIL(NO_MAX_VALUE.set("10000000000000000000000000000"))) {
LOG_ERROR("fail set max value", K(ret));
} else if (OB_FAIL(NO_MIN_VALUE.set("-1000000000000000000000000000"))) {
LOG_ERROR("fail set min value", K(ret));
} else if (OB_FAIL(MYSQL_MAX_VALUE.set("9223372036854775807"))) {
LOG_ERROR("fail set max value", K(ret));
} else if (OB_FAIL(MYSQL_MIN_VALUE.set("-9223372036854775808"))) {
LOG_ERROR("fail set min value", K(ret));
} else if (OB_FAIL(MYSQL_NO_MAX_VALUE.set("9223372036854775808"))) {
LOG_ERROR("fail set max value", K(ret));
} else if (OB_FAIL(MYSQL_NO_MIN_VALUE.set("-9223372036854775809"))) {
LOG_ERROR("fail set min value", K(ret));
}
}
// for Oracle Mode
ObSequenceValue ObSequenceMaxMinInitializer::NO_MAX_VALUE;
ObSequenceValue ObSequenceMaxMinInitializer::NO_MIN_VALUE;
ObSequenceValue ObSequenceMaxMinInitializer::MAX_VALUE;
ObSequenceValue ObSequenceMaxMinInitializer::MIN_VALUE;
// for MySQL Mode (only support values range in MIN_INT64 ~ MAX_INT64)
ObSequenceValue ObSequenceMaxMinInitializer::MYSQL_NO_MAX_VALUE;
ObSequenceValue ObSequenceMaxMinInitializer::MYSQL_NO_MIN_VALUE;
ObSequenceValue ObSequenceMaxMinInitializer::MYSQL_MAX_VALUE;
ObSequenceValue ObSequenceMaxMinInitializer::MYSQL_MIN_VALUE;
// You only need to initialize one copy globally, which is used to assign values to MIN_VALUE and MAX_VALUE
static ObSequenceMaxMinInitializer max_min_intializer_;
ObSequenceValue::ObSequenceValue()
{
}
ObSequenceValue::ObSequenceValue(int64_t int_val)
{
int ret = OB_SUCCESS;
ObDataBuffer allocator(static_cast<char *>(buf_), ObNumber::MAX_BYTE_LEN);
if (OB_SUCCESS != (ret = val_.from(int_val, allocator))) {
LOG_ERROR("set a int value to number should never fail with current allocator",
K(int_val), K(ret));
}
}
int ObSequenceValue::assign(const ObSequenceValue &other)
{
ObDataBuffer allocator(static_cast<char *>(buf_), ObNumber::MAX_BYTE_LEN);
return val_.from(other.val_, allocator);
}
int ObSequenceValue::set(const common::number::ObNumber &val)
{
ObDataBuffer allocator(static_cast<char *>(buf_), ObNumber::MAX_BYTE_LEN);
return val_.from(val, allocator);
}
int ObSequenceValue::set(int64_t val)
{
int ret = OB_SUCCESS;
ObDataBuffer allocator(static_cast<char *>(buf_), ObNumber::MAX_BYTE_LEN);
if (OB_SUCCESS != (ret = val_.from(val, allocator))) {
LOG_ERROR("set a int value to number should never fail with current allocator",
K(val), K(ret));
}
return ret;
}
// for init a very big int (28 of 9)
int ObSequenceValue::set(const char *val)
{
ObDataBuffer allocator(static_cast<char *>(buf_), ObNumber::MAX_BYTE_LEN);
return val_.from(val, allocator);
}
int ObSequenceOption::assign(const share::ObSequenceOption &from)
{
int ret = common::OB_SUCCESS;
OZ(increment_by_.assign(from.increment_by_));
OZ(start_with_.assign(from.start_with_));
OZ(maxvalue_.assign(from.maxvalue_));
OZ(minvalue_.assign(from.minvalue_));
OZ(cache_.assign(from.cache_));
cycle_ = from.cycle_;
order_ = from.order_;
return ret;
}