Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/CUBRID/cubrid-migration
Browse files Browse the repository at this point in the history
…into TOOLS-4557
  • Loading branch information
Srltas committed Feb 23, 2024
2 parents f5ebe5d + b47f438 commit c9417d9
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -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 <ORGANIZATION> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -271,6 +274,7 @@ public int writeData(
try {
List<String> lobFiles = new ArrayList<String>();
int total = 0;
int fail = 0;
for (Record re : records) {
if (re == null) {
continue;
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -613,54 +606,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<Column> list = view.getColumns();
//
// for (Iterator<Column> 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<Column> 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() + "\'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit c9417d9

Please sign in to comment.