This repository has been archived by the owner on Jun 28, 2023. It is now read-only.
forked from apache/incubator-seata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: fix the full table scan issue with 'setDate' condition in Ora…
…cle 10g (apache#5498)
- Loading branch information
Showing
7 changed files
with
172 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* 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.common.util; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
/** | ||
* The type Date util. | ||
* | ||
* @author slievrly | ||
*/ | ||
public class DateUtil { | ||
|
||
/** | ||
* Gets current date. | ||
* | ||
* @return the current date | ||
*/ | ||
public static Date getCurrentDate() { | ||
return new Date(); | ||
} | ||
|
||
/** | ||
* Parse date date. | ||
* | ||
* @param dateStr the date str | ||
* @param format the format | ||
* @return the date | ||
* @throws ParseException the parse exception | ||
*/ | ||
public static Date parseDate(String dateStr, String format) throws ParseException { | ||
if (StringUtils.isBlank(dateStr)) { | ||
return null; | ||
} | ||
SimpleDateFormat sdf = new SimpleDateFormat(format); | ||
return sdf.parse(dateStr); | ||
} | ||
|
||
public static Date parseDateWithoutTime(String dateStr) throws ParseException { | ||
return parseDate(dateStr, "yyyy-MM-dd"); | ||
} | ||
|
||
public static Date getDateNowPlusDays(int days) throws ParseException { | ||
Calendar calendar = Calendar.getInstance(); | ||
calendar.add(Calendar.DATE, days); | ||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
String dateStr = dateFormat.format(calendar.getTime()); | ||
return dateFormat.parse(dateStr); | ||
} | ||
|
||
/** | ||
* Format date string. | ||
* | ||
* @param date the date | ||
* @param format the format | ||
* @return the string | ||
*/ | ||
public static String formatDate(Date date, String format) { | ||
if (date == null) { | ||
return null; | ||
} | ||
SimpleDateFormat sdf = new SimpleDateFormat(format); | ||
return sdf.format(date); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
common/src/test/java/io/seata/common/util/DateUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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.common.util; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* @author slievrly | ||
*/ | ||
public class DateUtilTest { | ||
@Test | ||
public void testGetCurrentDate() { | ||
Date currentDate = DateUtil.getCurrentDate(); | ||
Assertions.assertNotNull(currentDate); | ||
} | ||
|
||
@Test | ||
public void testParseDate() throws ParseException { | ||
String dateStr = "2021-01-01"; | ||
Date date = DateUtil.parseDate(dateStr, "yyyy-MM-dd"); | ||
Assertions.assertNotNull(date); | ||
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | ||
Assertions.assertEquals(dateStr, sdf.format(date)); | ||
} | ||
|
||
@Test | ||
public void testFormatDate() { | ||
Date currentDate = DateUtil.getCurrentDate(); | ||
String dateStr = DateUtil.formatDate(currentDate, "yyyy-MM-dd HH:mm:ss"); | ||
Assertions.assertNotNull(dateStr); | ||
} | ||
|
||
@Test | ||
public void testGetDateNowPlusDays() throws ParseException { | ||
Assertions.assertNotNull(DateUtil.getDateNowPlusDays(2)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
-- for AT mode you must to init this sql for you business database. the seata server not need it. | ||
CREATE TABLE undo_log | ||
( | ||
id NUMBER(19) NOT NULL, | ||
branch_id NUMBER(19) NOT NULL, | ||
xid VARCHAR2(128) NOT NULL, | ||
context VARCHAR2(128) NOT NULL, | ||
rollback_info BLOB NOT NULL, | ||
log_status NUMBER(10) NOT NULL, | ||
log_created TIMESTAMP(0) NOT NULL, | ||
log_modified TIMESTAMP(0) NOT NULL, | ||
PRIMARY KEY (id), | ||
CONSTRAINT ux_undo_log UNIQUE (xid, branch_id) | ||
); | ||
|
||
CREATE INDEX ix_log_created ON undo_log(log_created); | ||
COMMENT ON TABLE undo_log IS 'AT transaction mode undo table'; | ||
|
||
-- Generate ID using sequence and trigger | ||
CREATE SEQUENCE UNDO_LOG_SEQ START WITH 1 INCREMENT BY 1; | ||
COMMENT ON COLUMN undo_log.branch_id is 'branch transaction id'; | ||
COMMENT ON COLUMN undo_log.xid is 'global transaction id'; | ||
COMMENT ON COLUMN undo_log.context is 'undo_log context,such as serialization'; | ||
COMMENT ON COLUMN undo_log.rollback_info is 'rollback info'; | ||
COMMENT ON COLUMN undo_log.log_status is '0:normal status,1:defense status'; | ||
COMMENT ON COLUMN undo_log.log_created is 'create datetime'; | ||
COMMENT ON COLUMN undo_log.log_modified is 'modify datetime'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
-- for AT mode you must to init this sql for you business database. the seata server not need it. | ||
CREATE TABLE IF NOT EXISTS public.undo_log | ||
( | ||
id SERIAL NOT NULL, | ||
branch_id BIGINT NOT NULL, | ||
xid VARCHAR(128) NOT NULL, | ||
context VARCHAR(128) NOT NULL, | ||
rollback_info BYTEA NOT NULL, | ||
log_status INT NOT NULL, | ||
log_created TIMESTAMP(0) NOT NULL, | ||
log_modified TIMESTAMP(0) NOT NULL, | ||
CONSTRAINT pk_undo_log PRIMARY KEY (id), | ||
CONSTRAINT ux_undo_log UNIQUE (xid, branch_id) | ||
); | ||
CREATE INDEX ix_log_created ON undo_log(log_created); | ||
|
||
CREATE SEQUENCE IF NOT EXISTS undo_log_id_seq INCREMENT BY 1 MINVALUE 1 ; | ||
COMMENT ON TABLE public.undo_log IS 'AT transaction mode undo table'; | ||
COMMENT ON COLUMN public.undo_log.branch_id IS 'branch transaction id'; | ||
COMMENT ON COLUMN public.undo_log.xid IS 'global transaction id'; | ||
COMMENT ON COLUMN public.undo_log.context IS 'undo_log context,such as serialization'; | ||
COMMENT ON COLUMN public.undo_log.rollback_info IS 'rollback info'; | ||
COMMENT ON COLUMN public.undo_log.log_status IS '0:normal status,1:defense status'; | ||
COMMENT ON COLUMN public.undo_log.log_created IS 'create datetime'; | ||
COMMENT ON COLUMN public.undo_log.log_modified IS 'modify datetime'; |