From 72b98851f3c331a23d2cff2ff147e7ac7ffbb18c Mon Sep 17 00:00:00 2001 From: Dongmin Kim <49967405+Srltas@users.noreply.github.com> Date: Fri, 23 Feb 2024 10:16:41 +0900 Subject: [PATCH 1/3] [TOOLS-4552] Incorrect query generation when creating a view without column information (#139) http://jira.cubrid.org/browse/TOOLS-4552 --- .../cubrid/CUBRIDSQLHelper.java | 55 +++++-------------- 1 file changed, 13 insertions(+), 42 deletions(-) diff --git a/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/cubrid/CUBRIDSQLHelper.java b/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/cubrid/CUBRIDSQLHelper.java index 110a722c..7f8e36e9 100644 --- a/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/cubrid/CUBRIDSQLHelper.java +++ b/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/cubrid/CUBRIDSQLHelper.java @@ -613,54 +613,25 @@ public String getViewDDL(View view, boolean addUserSchema) { sb.append(getOwnerNameWithDot(view.getOwner(), addUserSchema)); sb.append(getQuotedObjName(viewName)); - // Column definitions are not necessarily. - // sb.append("("); - // List list = view.getColumns(); - // - // for (Iterator iterator = list.iterator(); iterator.hasNext();) { - // Column column = (Column) iterator.next(); - // - // String type = column.getShownDataType(); - // sb.append(NEWLINE).append(" ").append( - // getDBQualifier(column.getName())).append(" ").append(type); - // String defaultv = column.getDefaultValue(); - // - // if (defaultv != null) { - // defaultv = CUBRIDFormator.formatValue(column.getDataType(), - // column.getSubDataType(), column.getScale(), defaultv).getFormatResult(); - // - // if (defaultv != null) { - // sb.append(" DEFAULT ").append(defaultv); - // } - // } - // - // sb.append(","); - // } - // - // if (!list.isEmpty() && sb.length() > 0) { - // sb.deleteCharAt(sb.length() - 1); - // } - // - // sb.append(")").append(NEWLINE); - List columnList = view.getColumns(); + if (!columnList.isEmpty()) { + sb.append("(").append(NEWLINE); + for (int i = 0; i < columnList.size(); i++) { + Column col = columnList.get(i); - sb.append("(").append(NEWLINE); - for (int i = 0; i < columnList.size(); i++) { - Column col = columnList.get(i); - - if (i > 0) { - sb.append(",").append(NEWLINE); - } + if (i > 0) { + sb.append(",").append(NEWLINE); + } - sb.append(getQuotedObjName(col.getName())); - sb.append(" ").append(col.getShownDataType()); + sb.append(getQuotedObjName(col.getName())); + sb.append(" ").append(col.getShownDataType()); - if (col.getComment() != null) { - sb.append(" COMMENT ").append(col.getComment()); + if (col.getComment() != null) { + sb.append(" COMMENT ").append(col.getComment()); + } } + sb.append(NEWLINE).append(")"); } - sb.append(NEWLINE).append(")"); if (view.getComment() != null) { sb.append(" ").append("COMMENT \'" + view.getComment() + "\'"); From 57abc99e7dec17aa7d66604d1ee262919e2e4b7e Mon Sep 17 00:00:00 2001 From: hwany7seo Date: Fri, 23 Feb 2024 11:10:37 +0900 Subject: [PATCH 2/3] [TOOLS-4559] When exporting to local xls files, an error occurs if the data is large. (#142) http://jira.cubrid.org/browse/TOOLS-4559 - If the data is large, it is displayed as blank and a list of errors is displayed in the 'no support' tab. --- .../event/MigrationXLSNoSupportEvent.java | 72 +++++++++++++++++++ .../engine/importer/impl/OfflineImporter.java | 19 ++++- .../report/DefaultMigrationReporter.java | 6 ++ 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/core/engine/event/MigrationXLSNoSupportEvent.java diff --git a/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/core/engine/event/MigrationXLSNoSupportEvent.java b/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/core/engine/event/MigrationXLSNoSupportEvent.java new file mode 100644 index 00000000..b3dde264 --- /dev/null +++ b/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/core/engine/event/MigrationXLSNoSupportEvent.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2016 CUBRID Corporation. All rights reserved by Search Solution. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * - Neither the name of the nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + */ +package com.cubrid.cubridmigration.core.engine.event; + +public class MigrationXLSNoSupportEvent extends MigrationEvent { + + private String tableName = ""; + private int rowIndex = 0; + private int columIndex = 0; + private String errMsg = ""; + + public MigrationXLSNoSupportEvent( + String tableName, int rowIndex, int columindex, String errMsg) { + this.tableName = tableName; + this.rowIndex = rowIndex; + this.columIndex = columindex; + this.errMsg = errMsg; + } + + /** + * Event to string. + * + * @return event string + */ + public String toString() { + return "Row Index : " + + rowIndex + + " Colum Index : " + + columIndex + + " in " + + tableName + + "[" + + errMsg + + "]"; + } + + /** + * The event's importance level + * + * @return level + */ + public int getLevel() { + return 1; + } +} diff --git a/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/core/engine/importer/impl/OfflineImporter.java b/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/core/engine/importer/impl/OfflineImporter.java index 924eaa04..8bff8ec3 100644 --- a/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/core/engine/importer/impl/OfflineImporter.java +++ b/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/core/engine/importer/impl/OfflineImporter.java @@ -51,6 +51,7 @@ import com.cubrid.cubridmigration.core.engine.config.SourceColumnConfig; import com.cubrid.cubridmigration.core.engine.config.SourceTableConfig; import com.cubrid.cubridmigration.core.engine.event.ImportRecordsEvent; +import com.cubrid.cubridmigration.core.engine.event.MigrationXLSNoSupportEvent; import com.cubrid.cubridmigration.core.engine.event.SingleRecordErrorEvent; import com.cubrid.cubridmigration.core.engine.exception.BreakMigrationException; import com.cubrid.cubridmigration.core.engine.exception.NormalMigrationException; @@ -94,6 +95,8 @@ public abstract class OfflineImporter extends Importer { protected static final int FILE_SCHEMA_IDX = 2; protected static final int FILE_DATA_LOB = 3; + private static final int MAX_EXCEL_CELL_LENGTH = 32767; + protected MigrationConfiguration config; // LoadDB command can not support multi-thread. LoadDBFile task runs in this pool. @@ -271,6 +274,7 @@ public int writeData( try { List lobFiles = new ArrayList(); int total = 0; + int fail = 0; for (Record re : records) { if (re == null) { continue; @@ -282,14 +286,25 @@ public int writeData( int index = 0; for (String val : res) { - sheet.addCell(new jxl.write.Label(index++, total, val)); + if (val.length() > MAX_EXCEL_CELL_LENGTH) { + sheet.addCell(new jxl.write.Label(index++, total, "")); + eventHandler.handleEvent( + new MigrationXLSNoSupportEvent( + tt.getName(), + total, + index, + "Too long data (data length in xml must be less than 32768.)")); + fail++; + } else { + sheet.addCell(new jxl.write.Label(index++, total, val)); + } } total++; } workbook.write(); - return total; + return total - fail; } finally { workbook.close(); } diff --git a/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/core/engine/report/DefaultMigrationReporter.java b/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/core/engine/report/DefaultMigrationReporter.java index 8a64fcb5..9f6c4ed2 100644 --- a/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/core/engine/report/DefaultMigrationReporter.java +++ b/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/core/engine/report/DefaultMigrationReporter.java @@ -48,6 +48,7 @@ import com.cubrid.cubridmigration.core.engine.event.MigrationFinishedEvent; import com.cubrid.cubridmigration.core.engine.event.MigrationNoSupportEvent; import com.cubrid.cubridmigration.core.engine.event.MigrationStartEvent; +import com.cubrid.cubridmigration.core.engine.event.MigrationXLSNoSupportEvent; import com.cubrid.cubridmigration.core.engine.event.StartExpTableEvent; import com.cubrid.cubridmigration.core.engine.template.MigrationTemplateParser; import com.cubrid.cubridmigration.cubrid.CUBRIDTimeUtil; @@ -215,6 +216,11 @@ public void addEvent(MigrationEvent event) { pwNonsupport.append(dbObject.getDDL()); pwNonsupport.append("\n"); pwNonsupport.flush(); + } else if (event instanceof MigrationXLSNoSupportEvent) { + MigrationXLSNoSupportEvent ev = (MigrationXLSNoSupportEvent) event; + pwNonsupport.append(ev.toString()); + pwNonsupport.append("\n"); + pwNonsupport.flush(); } else if (event instanceof MigrationFinishedEvent) { report.setTotalEndTime(eventTime); } else if (event instanceof ImportSQLsEvent) { From b47f438fd709e5aa9a5a0f253a6cdaa237ad263c Mon Sep 17 00:00:00 2001 From: Dongmin Kim <49967405+Srltas@users.noreply.github.com> Date: Fri, 23 Feb 2024 11:14:57 +0900 Subject: [PATCH 3/3] [TOOLS-4556] Oracle 'SYSDATE' type conversion error (#140) http://jira.cubrid.org/browse/TOOLS-4556 --- .../cubrid/CUBRIDSQLHelper.java | 9 +-- .../cubrid/CUBRIDTimeUtil.java | 79 +++++++++++++++++++ .../trans/Oracle2CUBRIDTranformHelper.java | 34 +++++++- 3 files changed, 112 insertions(+), 10 deletions(-) diff --git a/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/cubrid/CUBRIDSQLHelper.java b/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/cubrid/CUBRIDSQLHelper.java index 7f8e36e9..6662da23 100644 --- a/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/cubrid/CUBRIDSQLHelper.java +++ b/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/cubrid/CUBRIDSQLHelper.java @@ -119,14 +119,7 @@ private String getColumnDDL(Column column, PK pk) { bf.append(" SHARED ").append(defaultv); } else if ((column.getDataType().equals("datetime") || column.getDataType().equals("timestamp")) - && ("CURRENT_TIMESTAMP".equalsIgnoreCase(value) - || "SYS_TIMESTAMP".equalsIgnoreCase(value) - || "SYSTIMESTAMP".equalsIgnoreCase(value) - || "SYS_DATETIME".equalsIgnoreCase(value) - || "SYSDATETIME".equalsIgnoreCase(value) - || "CURRENT_DATETIME".equalsIgnoreCase(value) - || "CURRENT_DATETIME()".equalsIgnoreCase(value) - || "NOW()".equalsIgnoreCase(value))) { + && CUBRIDTimeUtil.validateDateTimeFunction(value)) { bf.append(" DEFAULT ").append(value); } else { String defaultv = column.getDefaultValue(); diff --git a/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/cubrid/CUBRIDTimeUtil.java b/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/cubrid/CUBRIDTimeUtil.java index e73491b6..11bb9a7d 100644 --- a/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/cubrid/CUBRIDTimeUtil.java +++ b/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/cubrid/CUBRIDTimeUtil.java @@ -161,6 +161,67 @@ public class CUBRIDTimeUtil { // NOPMD "''MM-dd-yyyy HH:mm:ss''" }; + private static String[] dateTimeFunctions = { + "ADDDATE", + "DATE_ADD", + "ADDTIME", + "ADD_MONTHS", + "CURDATE", + "CURRENT_DATE", + "CURRENT_DATETIME", + "NOW", + "CURTIME", + "CURRENT_TIME", + "CURRENT_TIMESTAMP", + "LOCALTIME", + "LOCALTIMESTAMP", + "DATE", + "DATEDIFF", + "DATE_SUB", + "SUBDATE", + "DAY", + "DAYOFMONTH", + "DAYOFWEEK", + "DAYOFYEAR", + "EXTRACT", + "FROM_DAYS", + "FROM_TZ", + "FROM_UNIXTIME", + "HOUR", + "LAST_DAY", + "MAKEDATE", + "MAKETIME", + "MINUTE", + "MONTH", + "MONTHS_BETWEEN", + "NEW_TIME", + "QUARTER", + "ROUND", + "SEC_TO_TIME", + "SECOND", + "SYS_DATE", + "SYSDATE", + "SYS_DATETIME", + "SYSDATETIME", + "SYS_TIME", + "SYSTIME", + "SYS_TIMESTAMP", + "SYSTIMESTAMP", + "TIME", + "TIME_TO_SEC", + "TIMEDIFF", + "TIMESTAMP", + "TO_DAYS", + "TRUNC", + "TZ_OFFSET", + "UNIX_TIMESTAMP", + "UTC_DATE", + "UTC_TIME", + "WEEK", + "WEEKDAY", + "YEAR" + }; + /** * Format date into yyyy-MM-dd with default time zone and default format * @@ -518,4 +579,22 @@ public static boolean validateDateString(String datestring, String datepattern) return pp.getIndex() == datestring.length(); } + + /** + * validate of date/time functions supported by CUBRID + * + * @param dateTime date/time function that requires verification + * @return boolean true: CUBRID support; false: CUBRID not support + */ + public static boolean validateDateTimeFunction(String dateTime) { + String upperDateTime = dateTime.toUpperCase(Locale.US); + + for (String function : dateTimeFunctions) { + if (upperDateTime.startsWith(function)) { + return true; + } + } + + return false; + } } diff --git a/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/oracle/trans/Oracle2CUBRIDTranformHelper.java b/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/oracle/trans/Oracle2CUBRIDTranformHelper.java index 8037540b..50e5360b 100644 --- a/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/oracle/trans/Oracle2CUBRIDTranformHelper.java +++ b/com.cubrid.cubridmigration.core/src/com/cubrid/cubridmigration/oracle/trans/Oracle2CUBRIDTranformHelper.java @@ -59,6 +59,18 @@ */ public class Oracle2CUBRIDTranformHelper extends DBTransformHelper { + private static final String[] ORACLE_DATETIME_FUNCTION = { + "CURDATE", + "CURRENT_DATE", + "CURTIME", + "CURRENT_TIMESTAMP", + "DBTIMEZONE", + "LOCALTIMESTAMP", + "SESSIONTIMEZONE", + "SYSDATE", + "SYSTIMESTAMP" + }; + public Oracle2CUBRIDTranformHelper( AbstractDataTypeMappingHelper dataTypeMapping, ToCUBRIDDataConverterFacade cf) { super(dataTypeMapping, cf); @@ -306,8 +318,8 @@ protected void adjustDefaultValue(Column srcColumn, Column cubridColumn) { } if ((dataType.indexOf("TIMESTAMP") > -1 || "DATE".equalsIgnoreCase(dataType)) - && defaultValue.toLowerCase(Locale.US).startsWith("sysdate")) { - cubridColumn.setDefaultValue("CURRENT_TIMESTAMP"); + && isDefaultDateTimeFunction(defaultValue)) { + cubridColumn.setDefaultValue(defaultValue); return; } @@ -391,6 +403,24 @@ private boolean isDefaultValueExpression(String defaultValue) { return false; } + /** + * Oracle date/time function validation + * + * @param defaultValue + * @return true: Oracle support; false: Oracle not support + */ + private boolean isDefaultDateTimeFunction(String defaultValue) { + String upperCaseDefaultValue = defaultValue.toUpperCase(Locale.US); + + for (String function : ORACLE_DATETIME_FUNCTION) { + if (upperCaseDefaultValue.startsWith(function)) { + return true; + } + } + + return false; + } + /** * verify the length that numeric convert to varchar *