Search in sources :

Example 1 with StreamDataImporterColumnInfo

use of org.jkiss.dbeaver.tools.transfer.stream.StreamDataImporterColumnInfo in project dbeaver by dbeaver.

the class StreamImporterAbstract method applyTransformHints.

protected void applyTransformHints(StreamTransferResultSet resultSet, IDataTransferConsumer consumer, Map<String, Object> properties, String formatPropName, String zoneIdPropName) throws DBException {
    DateTimeFormatter tsFormat = formatPropName == null ? null : getTimeStampFormat(properties, formatPropName);
    ZoneId tsZoneId = null;
    if (zoneIdPropName != null) {
        String zoneId = CommonUtils.toString(properties.get(zoneIdPropName));
        if (!CommonUtils.isEmpty(zoneId)) {
            tsZoneId = ZoneId.of(zoneId);
        }
    }
    if (tsFormat != null) {
        resultSet.setDateTimeFormat(tsFormat, tsZoneId);
    }
    // Do it only for valid String mappings
    if (consumer instanceof DatabaseTransferConsumer) {
        for (DatabaseTransferConsumer.ColumnMapping cm : ((DatabaseTransferConsumer) consumer).getColumnMappings()) {
            if (cm == null) {
                continue;
            }
            for (StreamDataImporterColumnInfo attributeMapping : resultSet.getAttributeMappings()) {
                if (cm.targetAttr.getMappingType().isValid()) {
                    if (cm.sourceAttr.getDataKind() == DBPDataKind.STRING && cm.sourceAttr.getName().equals(attributeMapping.getName())) {
                        // Gotcha
                        DBSEntityAttribute targetAttr = cm.targetAttr.getTarget();
                        if (targetAttr != null) {
                            switch(targetAttr.getDataKind()) {
                                case DATETIME:
                                case NUMERIC:
                                case BOOLEAN:
                                    attributeMapping.setDataKind(targetAttr.getDataKind());
                                    break;
                            }
                        }
                    }
                }
            }
        }
        Object targetObject = consumer.getTargetObject();
        if (targetObject instanceof DBSEntity) {
        }
    }
}
Also used : DatabaseTransferConsumer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer) ZoneId(java.time.ZoneId) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) StreamDataImporterColumnInfo(org.jkiss.dbeaver.tools.transfer.stream.StreamDataImporterColumnInfo) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 2 with StreamDataImporterColumnInfo

use of org.jkiss.dbeaver.tools.transfer.stream.StreamDataImporterColumnInfo in project dbeaver by serge-rider.

the class StreamImporterAbstract method applyTransformHints.

protected void applyTransformHints(StreamTransferResultSet resultSet, IDataTransferConsumer consumer, Map<String, Object> properties, String formatPropName, String zoneIdPropName) throws DBException {
    DateTimeFormatter tsFormat = formatPropName == null ? null : getTimeStampFormat(properties, formatPropName);
    ZoneId tsZoneId = null;
    if (zoneIdPropName != null) {
        String zoneId = CommonUtils.toString(properties.get(zoneIdPropName));
        if (!CommonUtils.isEmpty(zoneId)) {
            tsZoneId = ZoneId.of(zoneId);
        }
    }
    if (tsFormat != null) {
        resultSet.setDateTimeFormat(tsFormat, tsZoneId);
    }
    // Do it only for valid String mappings
    if (consumer instanceof DatabaseTransferConsumer) {
        for (DatabaseTransferConsumer.ColumnMapping cm : ((DatabaseTransferConsumer) consumer).getColumnMappings()) {
            if (cm == null) {
                continue;
            }
            for (StreamDataImporterColumnInfo attributeMapping : resultSet.getAttributeMappings()) {
                if (cm.targetAttr.getMappingType().isValid()) {
                    if (cm.sourceAttr.getDataKind() == DBPDataKind.STRING && cm.sourceAttr.getName().equals(attributeMapping.getName())) {
                        // Gotcha
                        DBSEntityAttribute targetAttr = cm.targetAttr.getTarget();
                        if (targetAttr != null) {
                            switch(targetAttr.getDataKind()) {
                                case DATETIME:
                                case NUMERIC:
                                case BOOLEAN:
                                    attributeMapping.setDataKind(targetAttr.getDataKind());
                                    break;
                            }
                        }
                    }
                }
            }
        }
        Object targetObject = consumer.getTargetObject();
        if (targetObject instanceof DBSEntity) {
        }
    }
}
Also used : DatabaseTransferConsumer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer) ZoneId(java.time.ZoneId) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) StreamDataImporterColumnInfo(org.jkiss.dbeaver.tools.transfer.stream.StreamDataImporterColumnInfo) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DateTimeFormatter(java.time.format.DateTimeFormatter)

Aggregations

ZoneId (java.time.ZoneId)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)2 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)2 DatabaseTransferConsumer (org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer)2 StreamDataImporterColumnInfo (org.jkiss.dbeaver.tools.transfer.stream.StreamDataImporterColumnInfo)2