Skip to content

Commit

Permalink
Refactor errorcode (#1132)
Browse files Browse the repository at this point in the history
1. Rename CommonErrorCode to ErrorCode and remove the original ErrorCode interface.
2. Eliminate all other implementations of ErrorCode.
3. Update all plugins and libraries to use the unified ErrorCode class.
4. Optimize log messages for clarity and consistency.
5. Replace System.out with logging framework to capture logo and version output.
  • Loading branch information
wgzhao authored Sep 21, 2024
1 parent a891423 commit 4eef124
Show file tree
Hide file tree
Showing 217 changed files with 1,758 additions and 4,673 deletions.
15 changes: 15 additions & 0 deletions build-module.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ MODULE_NAME=$1

cd $SRC_DIR
mvn package -B --quiet -pl :$MODULE_NAME -am -Dmaven.test.skip=true || exit 1

if [ "$MODULE_NAME" == "addax-core" ]; then
cp -a core/target/${MODULE_NAME}-${version}.jar ${ADDAX_HOME}/lib
exit 0
fi

if [ "$MODULE_NAME" == "addax-common" ];then
cp -a common/target/${MODULE_NAME}-${version}.jar ${ADDAX_HOME}/lib
exit 0
fi

if [ "$MODULE_NAME" == "addax-rdbms" -o "$MODULE_NAME" == "addax-storage" -o "$MODULE_NAME" == "addax-transformer" ]; then
cp -a lib/${MODULE_NAME}/target/${MODULE_NAME}-${version}.jar ${ADDAX_HOME}/lib
exit 0
fi
# if the module nam ends with reader, then the module base directory is plugin/reader,
# else the directory is plugin/writer
if [[ $MODULE_NAME =~ .*"reader" ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package com.wgzhao.addax.common.element;

import com.wgzhao.addax.common.exception.CommonErrorCode;
import com.wgzhao.addax.common.spi.ErrorCode;
import com.wgzhao.addax.common.exception.AddaxException;

import java.math.BigDecimal;
Expand Down Expand Up @@ -122,21 +122,21 @@ public BigDecimal asBigDecimal()
public Date asDate()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, "Bool type cannot be converted to Date.");
ErrorCode.CONVERT_NOT_SUPPORT, "Bool type cannot be converted to Date.");
}

@Override
public byte[] asBytes()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, "Bool type cannot be converted to Bytes.");
ErrorCode.CONVERT_NOT_SUPPORT, "Bool type cannot be converted to Bytes.");
}

@Override
public Timestamp asTimestamp()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, "Bool type cannot be converted to Timestamp.");
ErrorCode.CONVERT_NOT_SUPPORT, "Bool type cannot be converted to Timestamp.");
}

private void validate(final String data)
Expand All @@ -150,7 +150,7 @@ private void validate(final String data)
}

throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT,
ErrorCode.CONVERT_NOT_SUPPORT,
String.format("String [%s] cannot be converted to Bool .", data));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package com.wgzhao.addax.common.element;

import com.wgzhao.addax.common.exception.CommonErrorCode;
import com.wgzhao.addax.common.spi.ErrorCode;
import com.wgzhao.addax.common.exception.AddaxException;
import org.apache.commons.lang3.ArrayUtils;

Expand Down Expand Up @@ -68,7 +68,7 @@ public String asString()
}
catch (Exception e) {
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT,
ErrorCode.CONVERT_NOT_SUPPORT,
String.format("Bytes[%s] cannot be converted to String .", this.toString()));
}
}
Expand All @@ -89,41 +89,41 @@ public Long asLong()
public BigDecimal asBigDecimal()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, "Bytes type cannot converted to BigDecimal.");
ErrorCode.CONVERT_NOT_SUPPORT, "Bytes type cannot converted to BigDecimal.");
}

@Override
public BigInteger asBigInteger()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, "Bytes type cannot converted to BigInteger.");
ErrorCode.CONVERT_NOT_SUPPORT, "Bytes type cannot converted to BigInteger.");
}

@Override
public Timestamp asTimestamp()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, "Bytes type cannot converted to Timestamp.");
ErrorCode.CONVERT_NOT_SUPPORT, "Bytes type cannot converted to Timestamp.");
}

@Override
public Double asDouble()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, "Bytes type cannot converted to Long.");
ErrorCode.CONVERT_NOT_SUPPORT, "Bytes type cannot converted to Long.");
}

@Override
public Date asDate()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, "Bytes type cannot converted to Date.");
ErrorCode.CONVERT_NOT_SUPPORT, "Bytes type cannot converted to Date.");
}

@Override
public Boolean asBoolean()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, "Bytes type cannot converted to Boolean.");
ErrorCode.CONVERT_NOT_SUPPORT, "Bytes type cannot converted to Boolean.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package com.wgzhao.addax.common.element;

import com.wgzhao.addax.common.exception.CommonErrorCode;
import com.wgzhao.addax.common.spi.ErrorCode;
import com.wgzhao.addax.common.exception.AddaxException;
import com.wgzhao.addax.common.util.Configuration;
import org.apache.commons.lang3.time.DateFormatUtils;
Expand Down Expand Up @@ -207,7 +207,7 @@ static String asString(final DateColumn column)
DateCast.datetimeFormat, DateCast.timeZoner);
default:
throw AddaxException
.asAddaxException(CommonErrorCode.CONVERT_NOT_SUPPORT,
.asAddaxException(ErrorCode.CONVERT_NOT_SUPPORT,
"An unsupported type occurred for the date type. Currently, only DATE/TIME/DATETIME are supported.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package com.wgzhao.addax.common.element;

import com.wgzhao.addax.common.exception.CommonErrorCode;
import com.wgzhao.addax.common.spi.ErrorCode;
import com.wgzhao.addax.common.exception.AddaxException;

import java.math.BigDecimal;
Expand Down Expand Up @@ -141,7 +141,7 @@ public String asString()
}
catch (Exception e) {
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT,
ErrorCode.CONVERT_NOT_SUPPORT,
String.format("Date[%s] type cannot be converted to String .", this));
}
}
Expand All @@ -160,28 +160,28 @@ public Date asDate()
public byte[] asBytes()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Bytes"));
ErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Bytes"));
}

@Override
public Boolean asBoolean()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Boolean"));
ErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Boolean"));
}

@Override
public Double asDouble()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Double"));
ErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Double"));
}

@Override
public BigInteger asBigInteger()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "BigInteger"));
ErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "BigInteger"));
}

@Override
Expand All @@ -197,7 +197,7 @@ public Timestamp asTimestamp()
public BigDecimal asBigDecimal()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "BigDecimal"));
ErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "BigDecimal"));
}

public DateType getSubType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package com.wgzhao.addax.common.element;

import com.wgzhao.addax.common.exception.CommonErrorCode;
import com.wgzhao.addax.common.spi.ErrorCode;
import com.wgzhao.addax.common.exception.AddaxException;

import java.math.BigDecimal;
Expand Down Expand Up @@ -103,7 +103,7 @@ public BigDecimal asBigDecimal()
}
catch (NumberFormatException e) {
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT,
ErrorCode.CONVERT_NOT_SUPPORT,
String.format("String[%s] cannot be converted to Double.",
this.getRawData()));
}
Expand Down Expand Up @@ -166,28 +166,28 @@ public String asString()
public Boolean asBoolean()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Boolean"));
ErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Boolean"));
}

@Override
public Date asDate()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Date"));
ErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Date"));
}

@Override
public byte[] asBytes()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Bytes"));
ErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Bytes"));
}

@Override
public Timestamp asTimestamp()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Timestamp"));
ErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Timestamp"));
}

private void validate( String data)
Expand All @@ -206,7 +206,7 @@ private void validate( String data)
}
catch (Exception e) {
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT,
ErrorCode.CONVERT_NOT_SUPPORT,
String.format("String[%s] cannot be converted to Double.", data));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package com.wgzhao.addax.common.element;

import com.wgzhao.addax.common.exception.AddaxException;
import com.wgzhao.addax.common.exception.CommonErrorCode;
import com.wgzhao.addax.common.spi.ErrorCode;
import org.apache.commons.lang3.math.NumberUtils;

import java.math.BigDecimal;
Expand Down Expand Up @@ -56,7 +56,7 @@ public LongColumn(String data)
}
catch (Exception e) {
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT,
ErrorCode.CONVERT_NOT_SUPPORT,
String.format("Cannot convert the string [%s] to Long.", data));
}
}
Expand Down Expand Up @@ -177,6 +177,6 @@ public Date asDate()
public byte[] asBytes()
{
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, "Long type cannot be converted to Bytes.");
ErrorCode.CONVERT_NOT_SUPPORT, "Long type cannot be converted to Bytes.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package com.wgzhao.addax.common.element;

import com.wgzhao.addax.common.exception.CommonErrorCode;
import com.wgzhao.addax.common.spi.ErrorCode;
import com.wgzhao.addax.common.exception.AddaxException;

import java.math.BigDecimal;
Expand Down Expand Up @@ -50,7 +50,7 @@ public static void validateLongNotOverFlow(final BigInteger integer)

if (isOverFlow) {
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_OVER_FLOW,
ErrorCode.CONVERT_OVER_FLOW,
String.format("An overflow occurred when converting [%s] to Long type.", integer));
}
}
Expand All @@ -76,7 +76,7 @@ public static void validateDoubleNotOverFlow(final BigDecimal decimal)
boolean isOverFlow = OverFlowUtil.isDoubleOverFlow(decimal);
if (isOverFlow) {
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_OVER_FLOW,
ErrorCode.CONVERT_OVER_FLOW,
String.format("An overflow occurred when converting [%s] to Double type.",
decimal.toPlainString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package com.wgzhao.addax.common.element;

import com.wgzhao.addax.common.exception.CommonErrorCode;
import com.wgzhao.addax.common.spi.ErrorCode;
import com.wgzhao.addax.common.exception.AddaxException;

import java.math.BigDecimal;
Expand Down Expand Up @@ -63,7 +63,7 @@ private void validateDoubleSpecific(final String data)
if ("NaN".equals(data) || "Infinity".equals(data)
|| "-Infinity".equals(data)) {
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT,
ErrorCode.CONVERT_NOT_SUPPORT,
String.format("['%s'] belongs to the special Double type and cannot be converted to other type.", data));
}
}
Expand All @@ -82,7 +82,7 @@ public BigInteger asBigInteger()
}
catch (Exception e) {
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(
ErrorCode.CONVERT_NOT_SUPPORT, String.format(
"['%s'] cannot be converted to BigInteger.", this.asString()));
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ public Long asLong()
}
catch (Exception e) {
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Long"));
ErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Long"));
}
}

Expand All @@ -130,7 +130,7 @@ public BigDecimal asBigDecimal()
}
catch (Exception e) {
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "BigDecimal"));
ErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "BigDecimal"));
}
}

Expand Down Expand Up @@ -176,7 +176,7 @@ public Boolean asBoolean()
}

throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Boolean"));
ErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Boolean"));
}

@Override
Expand All @@ -187,7 +187,7 @@ public Date asDate()
}
catch (Exception e) {
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Date"));
ErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Date"));
}
}

Expand All @@ -199,7 +199,7 @@ public byte[] asBytes()
}
catch (Exception e) {
throw AddaxException.asAddaxException(
CommonErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Bytes"));
ErrorCode.CONVERT_NOT_SUPPORT, String.format(errorTemplate, "Bytes"));
}
}
}
Loading

0 comments on commit 4eef124

Please sign in to comment.