Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: support oracle date types #4542

Merged
merged 71 commits into from Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
dd38eae
通用分页计算
doubleDimple Jan 3, 2022
1d2bce2
redis query globalsession(if request param isnull) commit
doubleDimple Jan 9, 2022
7dde6f4
redis query globalsession(if request param isnull) commit
doubleDimple Jan 9, 2022
6c2d330
redis query globalsession third commit
doubleDimple Jan 10, 2022
9c41301
redis query globalsession third commit
doubleDimple Jan 10, 2022
a772160
redis query globalsession third commit
doubleDimple Jan 10, 2022
806f812
Merge branch 'develop' into develop
doubleDimple Jan 11, 2022
edac1e4
redis query globalsession five commit
doubleDimple Jan 11, 2022
143cf18
Merge remote-tracking branch 'origin/develop' into develop
doubleDimple Jan 11, 2022
ff833d1
add test case code
Jan 13, 2022
85b66ec
Merge branch 'seata:develop' into develop
doubleDimple Jan 13, 2022
1429677
add redis query globalSession by page test code
doubleDimple Jan 13, 2022
c6970e6
add redis query globalSession by page test code
doubleDimple Jan 13, 2022
75e2b68
add redis query globalSession by page test code
doubleDimple Jan 13, 2022
02fa91b
Merge branch 'seata:develop' into develop
doubleDimple Jan 13, 2022
3c2c268
add test case code
doubleDimple Jan 14, 2022
ce9886a
add redis mode query globalLock code submit
doubleDimple Jan 14, 2022
0572e16
add globalSessionService test code
doubleDimple Jan 14, 2022
dbb4376
Merge branch 'seata:develop' into develop
doubleDimple Jan 14, 2022
dcceeff
add author
doubleDimple Jan 14, 2022
19bf5a6
Merge remote-tracking branch 'origin/develop' into develop
doubleDimple Jan 14, 2022
db243ec
qery redis globalSession and globalLock optimize
doubleDimple Jan 15, 2022
5c68d2c
add author
doubleDimple Jan 17, 2022
bc04c40
update test case
doubleDimple Jan 17, 2022
2b7edb3
Merge branch 'seata:develop' into develop
doubleDimple Jan 17, 2022
db0326c
code format
doubleDimple Jan 17, 2022
ee798d4
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Jan 22, 2022
348a0a2
update changes.md
doubleDimple Jan 22, 2022
c4993fc
optimize
doubleDimple Jan 22, 2022
4328c07
Merge branch 'develop' into develop
doubleDimple Jan 23, 2022
bf62829
Merge branch 'develop' into develop
funky-eyes Jan 24, 2022
6c87f34
optimize
doubleDimple Jan 25, 2022
1c7b8f7
Merge branch 'seata:develop' into develop
doubleDimple Jan 25, 2022
82580c7
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Jan 26, 2022
e6f8194
global lock 查询增加参数resourceId,pk,tableName
doubleDimple Jan 26, 2022
8e3fa32
Merge branch 'seata:develop' into develop
doubleDimple Jan 26, 2022
f663515
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Feb 7, 2022
4899fa8
optimize
doubleDimple Feb 7, 2022
3d9b17c
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Feb 8, 2022
4baba76
close piplied
doubleDimple Feb 8, 2022
7bba2bb
Merge branch 'develop' into develop
doubleDimple Feb 9, 2022
575c879
add rowLockkey test
doubleDimple Feb 10, 2022
e917094
add rowLockkey test
doubleDimple Feb 10, 2022
ac85f0e
optimize query globalSession condition judge
doubleDimple Feb 13, 2022
d6ee786
Merge branch 'develop' of github.com:seata/seata into develop
doubleDimple Feb 16, 2022
0dbad8b
Resolve code conflicts
doubleDimple Feb 16, 2022
08a0347
Merge branch 'develop' into develop
doubleDimple Feb 17, 2022
8ecea26
Merge branch 'develop' into develop
doubleDimple Feb 22, 2022
20e9318
optimize error prompt
doubleDimple Feb 22, 2022
770bb77
optimize error prompt
doubleDimple Feb 22, 2022
3811a43
optimize code empty line
doubleDimple Feb 23, 2022
5dd5f4d
Merge branch 'develop' into develop
doubleDimple Feb 23, 2022
bf319cc
Merge branch 'develop' into develop
doubleDimple Feb 24, 2022
5dac2cc
update redis local connection
doubleDimple Feb 24, 2022
f35e745
Merge branch 'seata:develop' into develop
doubleDimple Feb 28, 2022
76007c7
Merge branch 'seata:develop' into develop
doubleDimple Mar 3, 2022
e435219
AT mode oracle support some dateTypes
doubleDimple Apr 10, 2022
6f35f45
Merge branch 'develop' into support_oracle_dateTypes_4536
doubleDimple Apr 10, 2022
826c4e1
Merge branch 'develop' into support_oracle_dateTypes_4536
doubleDimple Apr 18, 2022
ae59a06
Merge branch 'develop' into support_oracle_dateTypes_4536
doubleDimple Apr 20, 2022
a24f18c
Merge branch 'develop' into support_oracle_dateTypes_4536
doubleDimple Apr 23, 2022
098ddc8
Merge branch 'develop' into support_oracle_dateTypes_4536
jsbxyyx Apr 29, 2022
b6184eb
optimize
doubleDimple May 6, 2022
8025cbf
Merge branch 'develop' into support_oracle_dateTypes_4536
doubleDimple May 6, 2022
c9fb36c
Merge branch 'develop' into support_oracle_dateTypes_4536
doubleDimple May 9, 2022
9e16549
Merge branch 'develop' into support_oracle_dateTypes_4536
doubleDimple May 21, 2022
922df89
Merge branch 'develop' into support_oracle_dateTypes_4536
slievrly Sep 5, 2022
239c709
Merge branch 'develop' into support_oracle_dateTypes_4536
slievrly Sep 6, 2022
b740f8a
Merge branch 'develop' into support_oracle_dateTypes_4536
funky-eyes Nov 7, 2022
757ae77
add oracle time zone
doubleDimple Nov 13, 2022
7291166
Merge branch 'develop' into support_oracle_dateTypes_4536
funky-eyes Nov 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,26 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.rm.datasource.exec.oracle;

/**
* @author doubleDimple lovele.cn@gmail.com
*/
public class OracleJdbcType {

public static final int TIMESTAMP_WITH_TIME_ZONE = -101;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful not to duplicate the int value of java.sql.Types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following are duplicate types:
image


public static final int TIMESTAMP_WITH_LOCAL_TIME_ZONE = -102;
}
Expand Up @@ -35,6 +35,10 @@
import javax.sql.rowset.serial.SerialRef;
import io.seata.common.exception.ShouldNeverHappenException;
import io.seata.rm.datasource.sql.serial.SerialArray;
import static io.seata.rm.datasource.exec.oracle.OracleJdbcType.TIMESTAMP_WITH_LOCAL_TIME_ZONE;
import static io.seata.rm.datasource.exec.oracle.OracleJdbcType.TIMESTAMP_WITH_TIME_ZONE;
import static io.seata.rm.datasource.util.OffsetTimeUtils.convertOffSetTime;
import static io.seata.rm.datasource.util.OffsetTimeUtils.timeToOffsetDateTime;

/**
* The type Table records.
Expand Down Expand Up @@ -237,6 +241,8 @@ public static TableRecords buildRecords(TableMeta tmeta, ResultSet resultSet) th
if (object != null) {
field.setValue(new SerialJavaObject(object));
}
} else if (dataType == TIMESTAMP_WITH_TIME_ZONE || dataType == TIMESTAMP_WITH_LOCAL_TIME_ZONE) {
field.setValue(convertOffSetTime(timeToOffsetDateTime(resultSet.getBytes(i))));
} else {
// JDBCType.DISTINCT, JDBCType.STRUCT etc...
field.setValue(holdSerialDataType(resultSet.getObject(i)));
Expand Down
@@ -0,0 +1,144 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.seata.rm.datasource.util;

import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

import static java.lang.Short.toUnsignedInt;
import static java.time.ZoneOffset.UTC;

/**
* Currently, common time zones are supported
*
* @see java.time.ZoneId
*
*
* @author doubleDimple
*/
public class OffsetTimeUtils {

public static final String PATTERN_FORMAT_TIME = "yyyy-MM-dd HH:mm:ss.SSS";

private static final byte REGIONIDBIT = (byte)0b1000_0000;

private static final Map<Integer, String> ZONE_ID_MAP = new HashMap<>(36);

public static String getRegion(int code) {
return ZONE_ID_MAP.get(code);
}

public static String convertOffSetTime(OffsetDateTime offsetDateTime) {
if (null != offsetDateTime) {
return offsetDateTime.format(DateTimeFormatter.ofPattern(PATTERN_FORMAT_TIME));
}
return null;
}

public static OffsetDateTime timeToOffsetDateTime(byte[] bytes) {
if (null == bytes || bytes.length == 0) {
return null;
}

OffsetDateTime utc = extractUtc(bytes);
if (bytes.length >= 8) {
if (isFixedOffset(bytes)) {
ZoneOffset offset = extractOffset(bytes);
return utc.withOffsetSameInstant(offset);
} else {
ZoneId zoneId = extractZoneId(bytes);
return utc.atZoneSameInstant(zoneId).toOffsetDateTime();
}
}
return utc.atZoneSameInstant(ZoneId.systemDefault()).toOffsetDateTime();
}

private static boolean isFixedOffset(byte[] bytes) {
return (bytes[11] & REGIONIDBIT) == 0;
}

private static OffsetDateTime extractUtc(byte[] bytes) {
return OffsetDateTime.of(extractLocalDateTime(bytes), UTC);
}

private static ZoneId extractZoneId(byte[] bytes) {
// high order bits
int regionCode = (bytes[11] & 0b1111111) << 6;
// low order bits
regionCode += (bytes[12] & 0b11111100) >> 2;
String regionName = getRegion(regionCode);
return ZoneId.of(regionName);
}

private static ZoneOffset extractOffset(byte[] bytes) {
int hours = bytes[11] - 20;
int minutes = bytes[12] - 60;
if ((hours == 0) && (minutes == 0)) {
return ZoneOffset.UTC;
}
return ZoneOffset.ofHoursMinutes(hours, minutes);
}

private static LocalDateTime extractLocalDateTime(byte[] bytes) {
int year = ((toUnsignedInt(bytes[0]) - 100) * 100) + (toUnsignedInt(bytes[1]) - 100);
int month = bytes[2];
int dayOfMonth = bytes[3];
int hour = bytes[4] - 1;
int minute = bytes[5] - 1;
int second = bytes[6] - 1;
int nanoOfSecond = 0;
if (bytes.length >= 8) {
nanoOfSecond = (toUnsignedInt(bytes[7]) << 24) | (toUnsignedInt(bytes[8]) << 16)
| (toUnsignedInt(bytes[9]) << 8) | toUnsignedInt(bytes[10]);
}
return LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanoOfSecond);
}

static {
ZONE_ID_MAP.put(250, "Asia/Shanghai");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to ensure all the zone id in the ZONE_ID_MAP ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

具体解决办法:1维护常用的时区,其他时区通过在配置文件中配置,实时读取相关配置

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to ensure all the zone id in the ZONE_ID_MAP ?

We first add the commonly used time zones, the remaining open interface allows users to manually add their own, 1. api way to add time zones 2. configuration file to add time zones , both options should be supported

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZONE_ID_MAP.put(345, "Australia/Darwin");
ZONE_ID_MAP.put(352, "Australia/Sydney");
ZONE_ID_MAP.put(687, "America/Argentina/Buenos_Aires");
ZONE_ID_MAP.put(106, "America/Anchorage");
ZONE_ID_MAP.put(188, "America/Sao_Paulo");
ZONE_ID_MAP.put(756, "Asia/Dhaka");
ZONE_ID_MAP.put(80, "Africa/Harare");
ZONE_ID_MAP.put(118, "America/St_Johns");
ZONE_ID_MAP.put(101, "America/Chicago");
ZONE_ID_MAP.put(47, "Africa/Addis_Ababa");
ZONE_ID_MAP.put(382, "Europe/Paris");
ZONE_ID_MAP.put(1647, "America/Indiana/Indianapolis");
ZONE_ID_MAP.put(772, "Asia/Kolkata");
ZONE_ID_MAP.put(267, "Asia/Tokyo");
ZONE_ID_MAP.put(479, "Pacific/Apia");
ZONE_ID_MAP.put(241, "Asia/Yerevan");
ZONE_ID_MAP.put(471, "Pacific/Auckland");
ZONE_ID_MAP.put(284, "Asia/Karachi");
ZONE_ID_MAP.put(109, "America/Phoenix");
ZONE_ID_MAP.put(167, "America/Puerto_Rico");
ZONE_ID_MAP.put(103, "America/Los_Angeles");
ZONE_ID_MAP.put(481, "Pacific/Guadalcanal");
ZONE_ID_MAP.put(813, "Asia/Ho_Chi_Minh");
ZONE_ID_MAP.put(1474, "HST");
ZONE_ID_MAP.put(1636, "EST");
ZONE_ID_MAP.put(2662, "MST");
}
}