Skip to content

Commit

Permalink
MARP-305: fix bug "invalid column type" when column is type date and …
Browse files Browse the repository at this point in the history
…db is Oracle (#47)
  • Loading branch information
Phạm Duy Linh authored Jun 10, 2024
1 parent c9f4f65 commit 8fe00a5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.Date;
import java.sql.Timestamp;
import java.util.List;

import org.apache.poi.ss.usermodel.Workbook;
Expand All @@ -27,7 +27,7 @@ void parseColumns_xlsx(@TempDir Path dir) throws IOException {
.contains("Firstname", "Lastname");
assertThat(columns).contains(
new Column("Firstname", String.class, 255), new Column("ZIP", Integer.class),
new Column("Amount", Double.class), new Column("Birthdate", Date.class), // should be a date
new Column("Amount", Double.class), new Column("Birthdate", Timestamp.class), // should be a date
new Column("Note", String.class, 811)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ public void setDatabaseFieldLength(Integer databaseFieldLength) {

@Override
public boolean equals(Object object) {
if (this == object)
if (this == object) {
return true;
if (object == null || getClass() != object.getClass())
}
if (object == null || getClass() != object.getClass()) {
return false;
}

Column column = (Column) object;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -131,7 +132,7 @@ private static Object getValue(Cell cell) {
}
if (cell.getCellType() == CellType.NUMERIC) {
if (DateUtil.isCellDateFormatted(cell)) {
return cell.getDateCellValue();
return new Timestamp(cell.getDateCellValue().getTime());
}
return cell.getNumericCellValue();
} else if (cell.getCellType() == CellType.BOOLEAN) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.axonivy.util.excel.importer;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -62,7 +62,7 @@ private static Column toColumn(String fieldName, Cell cell) {
switch (cell.getCellType()) {
case NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
return new Column(fieldName, Date.class);
return new Column(fieldName, Timestamp.class);
}
if (CellUtils.isInteger(cell)) {
return new Column(fieldName, Integer.class);
Expand Down

0 comments on commit 8fe00a5

Please sign in to comment.