|
@@ -1,17 +1,11 @@
|
|
|
package org.dbsyncer.connector.oracle.logminer.parser;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.math.BigInteger;
|
|
|
-import java.sql.Date;
|
|
|
-import java.sql.Time;
|
|
|
-import java.sql.Timestamp;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
import net.sf.jsqlparser.expression.Expression;
|
|
|
import net.sf.jsqlparser.expression.Function;
|
|
|
import net.sf.jsqlparser.expression.NullValue;
|
|
|
import net.sf.jsqlparser.expression.StringValue;
|
|
|
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
|
|
|
+import net.sf.jsqlparser.expression.operators.relational.IsNullExpression;
|
|
|
import org.dbsyncer.common.column.AbstractColumnValue;
|
|
|
import org.dbsyncer.common.util.CollectionUtils;
|
|
|
import org.dbsyncer.common.util.DateFormatUtil;
|
|
@@ -19,6 +13,14 @@ import org.dbsyncer.common.util.StringUtil;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.sql.Date;
|
|
|
+import java.sql.Time;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
public class OracleColumnValue extends AbstractColumnValue<Expression> {
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
|
@@ -52,6 +54,9 @@ public class OracleColumnValue extends AbstractColumnValue<Expression> {
|
|
|
|
|
|
@Override
|
|
|
public Integer asInteger() {
|
|
|
+ if (asString() == null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
return Integer.valueOf(asString());
|
|
|
}
|
|
|
|
|
@@ -77,6 +82,9 @@ public class OracleColumnValue extends AbstractColumnValue<Expression> {
|
|
|
|
|
|
@Override
|
|
|
public BigDecimal asBigDecimal() {
|
|
|
+ if (asString() == null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
return new BigDecimal(asString());
|
|
|
}
|
|
|
|
|
@@ -87,6 +95,12 @@ public class OracleColumnValue extends AbstractColumnValue<Expression> {
|
|
|
|
|
|
@Override
|
|
|
public Timestamp asTimestamp() {
|
|
|
+ if (getValue() instanceof IsNullExpression){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (getValue() instanceof NullValue){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
Function function = (Function) getValue();
|
|
|
List<String> multipartName = function.getMultipartName();
|
|
|
ExpressionList parameters = function.getParameters();
|
|
@@ -111,6 +125,7 @@ public class OracleColumnValue extends AbstractColumnValue<Expression> {
|
|
|
return toDate(value);
|
|
|
case "TO_TIMESTAMP":
|
|
|
return toTimestamp(value);
|
|
|
+
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
@@ -125,7 +140,17 @@ public class OracleColumnValue extends AbstractColumnValue<Expression> {
|
|
|
|
|
|
@Override
|
|
|
public BigInteger asBigInteger() {
|
|
|
- return new BigInteger(asString());
|
|
|
+ if (getValue() instanceof IsNullExpression){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (getValue() instanceof NullValue){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Object ob = asString();
|
|
|
+ if (ob == null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return new BigInteger(ob.toString());
|
|
|
}
|
|
|
|
|
|
private Timestamp toDate(Object value) {
|
|
@@ -135,4 +160,5 @@ public class OracleColumnValue extends AbstractColumnValue<Expression> {
|
|
|
private Timestamp toTimestamp(Object value) {
|
|
|
return DateFormatUtil.stringToTimestamp(StringUtil.replace(Objects.toString(value), StringUtil.POINT, StringUtil.EMPTY));
|
|
|
}
|
|
|
+
|
|
|
}
|