Search in sources :

Example 1 with IEntity

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());
    }
}
Also used : Field(java.lang.reflect.Field) IEntity(de.invesdwin.context.persistence.jpa.api.dao.entity.IEntity) Calendar(java.util.Calendar) Date(java.util.Date) FDate(de.invesdwin.util.time.date.FDate)

Aggregations

IEntity (de.invesdwin.context.persistence.jpa.api.dao.entity.IEntity)1 FDate (de.invesdwin.util.time.date.FDate)1 Field (java.lang.reflect.Field)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1