use of de.invesdwin.context.persistence.jpa.api.dao.entity.IEntity in project invesdwin-context-persistence by subes.
the class MySqlLoadDataInfile method stage.
private void stage(final E entity) {
final StringBuilder sb = new StringBuilder();
boolean first = true;
for (final String javaColumnName : javaColumnNames) {
if (skipColumn(javaColumnName)) {
continue;
}
if (!first) {
sb.append(",");
}
first = false;
final Field f = Reflections.findField(genericType, javaColumnName);
Reflections.makeAccessible(f);
Object value = Reflections.getField(f, entity);
if (value instanceof IEntity) {
final IEntity valueEntity = (IEntity) value;
value = valueEntity.getId();
} else if (value instanceof Date) {
value = FDate.valueOf((Date) value).toString(FDate.FORMAT_ISO_DATE_TIME_SPACE);
} else if (value instanceof Calendar) {
value = FDate.valueOf((Calendar) value).toString(FDate.FORMAT_ISO_DATE_TIME_SPACE);
} else if (value instanceof Boolean) {
final Boolean bValue = (Boolean) value;
if (bValue) {
value = 1;
} else {
value = 0;
}
}
final String valueStr = String.valueOf(value).replace("\"", "\\\\\"");
sb.append("\"");
sb.append(valueStr);
sb.append("\"");
}
sb.append("\n");
synchronized (stageLock) {
if (curFileAndOutputStream == null) {
curFileAndOutputStream = new StringBuilder();
}
curFileAndOutputStream.append(sb.toString());
}
}