diff --git a/.gitignore b/.gitignore
index 4e247ee..186e4da 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@
/target
/.classpath
/.project
+.~users.xlsx
+users.xlsx
diff --git a/README.md b/README.md
index 0e775b7..61e32ed 100644
--- a/README.md
+++ b/README.md
@@ -238,3 +238,22 @@ Add xcelite as a dependency:
1.0.4
```
+### OR
+Add this repository as dependency, if you want support for Jpa data export.
+```xml
+
+
+ Github
+ Github repository
+ https://raw.github.com/boriswaguia/xcelite/release
+
+
+```
+
+```xml
+
+ com.ebay
+ xcelite
+ 1.0.5-SNAPSHOT
+
+```
diff --git a/pom.xml b/pom.xml
index 65eb216..a7dcdc6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
4.0.0
com.ebay
xcelite
- 1.0.5-SNAPSHOT
+ 1.0.8-SNAPSHOT
jar
xcelite
Xcelite is an ORM like Java library which allows you to easily serialize and deserialize Java beans to/from Excel spreadsheets
@@ -74,6 +74,9 @@
org.apache.maven.plugins
maven-javadoc-plugin
2.9.1
+
+ -Xdoclint:none
+
attach-javadocs
@@ -120,5 +123,18 @@
commons-collections
3.2.1
+
+
+ org.hibernate.javax.persistence
+ hibernate-jpa-2.0-api
+ 1.0.1.Final
+
+
+
+ junit
+ junit
+ 4.12
+ test
+
\ No newline at end of file
diff --git a/src/main/java/com/ebay/xcelite/column/Col.java b/src/main/java/com/ebay/xcelite/column/Col.java
index f4e5afa..45e44a6 100644
--- a/src/main/java/com/ebay/xcelite/column/Col.java
+++ b/src/main/java/com/ebay/xcelite/column/Col.java
@@ -38,10 +38,16 @@ public Col(String name) {
}
public Col(String name, String fieldName) {
+ this(name, fieldName, String.class);
+ }
+
+
+ public Col(String name, String fieldName, Class> type) {
this.name = name;
this.fieldName = fieldName;
- type = String.class;
+ this.type = type;
}
+
@Override
public String toString() {
diff --git a/src/main/java/com/ebay/xcelite/column/ColumnsExtractor.java b/src/main/java/com/ebay/xcelite/column/ColumnsExtractor.java
index 6c0186e..f2ce899 100644
--- a/src/main/java/com/ebay/xcelite/column/ColumnsExtractor.java
+++ b/src/main/java/com/ebay/xcelite/column/ColumnsExtractor.java
@@ -22,6 +22,9 @@
import java.util.Map;
import java.util.Set;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+
import org.reflections.ReflectionUtils;
import com.ebay.xcelite.annotate.NoConverterClass;
@@ -79,7 +82,7 @@ public void extract() {
col.setConverter(annotation.converter());
}
columns.add(col);
- }
+ }
if (colsOrdering != null) {
orderColumns();
@@ -88,6 +91,48 @@ public void extract() {
extractAnyColumn();
}
+
+ @SuppressWarnings("unchecked")
+ public void extractJpa() {
+ Set idFields = ReflectionUtils.getAllFields(type, withAnnotation(javax.persistence.Id.class));
+ Set columnFields = ReflectionUtils.getAllFields(type, withAnnotation(javax.persistence.Column.class));
+ Set manyToOneFields = ReflectionUtils.getAllFields(type, withAnnotation(javax.persistence.ManyToOne.class));
+
+ for (Field columnField : idFields) {
+ javax.persistence.Id annotation = columnField.getAnnotation(javax.persistence.Id.class);
+ if(annotation == null) continue;
+ Col col = null;
+ col = new Col(columnField.getName(), columnField.getName(), columnField.getType());
+ columns.add(col);
+ }
+
+ for (Field columnField : columnFields) {
+ javax.persistence.Column annotation = columnField.getAnnotation(javax.persistence.Column.class);
+ if(annotation == null) continue;
+ Col col = null;
+ if (annotation.name().isEmpty()) {
+ col = new Col(columnField.getName(), columnField.getName(), columnField.getType());
+ } else {
+ col = new Col(annotation.name(), columnField.getName(), columnField.getType());
+ }
+ columns.add(col);
+ }
+
+ for (Field columnField : manyToOneFields) {
+ ManyToOne annotation = columnField.getAnnotation(javax.persistence.ManyToOne.class);
+ Col col = null;
+ if(annotation == null) continue;
+ JoinColumn joinColumn = columnField.getAnnotation(javax.persistence.JoinColumn.class);
+ if (joinColumn.name().isEmpty()) {
+ col = new Col(columnField.getName(), columnField.getName(), columnField.getType());
+ } else {
+ col = new Col(joinColumn.name(), columnField.getName(), columnField.getType());
+ }
+ columns.add(col);
+ }
+ }
+
+
@SuppressWarnings("unchecked")
private void extractAnyColumn() {
Set anyColumnFields = ReflectionUtils.getAllFields(type, withAnnotation(AnyColumn.class));
@@ -108,7 +153,7 @@ private void extractAnyColumn() {
if (annotation.converter() != NoConverterClass.class) {
anyColumn.setConverter(annotation.converter());
}
- }
+ }
}
private void orderColumns() {
diff --git a/src/main/java/com/ebay/xcelite/reader/BeanSheetReader.java b/src/main/java/com/ebay/xcelite/reader/BeanSheetReader.java
index bed8edb..94d2f4b 100644
--- a/src/main/java/com/ebay/xcelite/reader/BeanSheetReader.java
+++ b/src/main/java/com/ebay/xcelite/reader/BeanSheetReader.java
@@ -26,6 +26,7 @@
import java.util.Map;
import java.util.Set;
+import org.apache.poi.ss.format.CellFormatType;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row;
@@ -63,6 +64,7 @@ public BeanSheetReader(XceliteSheet sheet, Class type) {
this.type = type;
ColumnsExtractor extractor = new ColumnsExtractor(type);
extractor.extract();
+ extractor.extractJpa();
columns = extractor.getColumns();
anyColumn = extractor.getAnyColumn();
mapper = new ColumnsMapper(columns);
@@ -164,18 +166,41 @@ private void writeToAnyColumnField(Field field, T object, Cell cell, String colu
@SuppressWarnings("unchecked")
private void writeToField(Field field, T object, Cell cell, Col column) {
try {
- Object cellValue = readValueFromCell(cell);
+ Object cellValue = readValueFromCell(cell);
+ if(cellValue == null && (field.getType() == Boolean.class || field.getType() == boolean.class)) {
+ cellValue = Boolean.FALSE;
+ }
if (cellValue != null) {
if (column.getConverter() != null) {
ColumnValueConverter