use of org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer in project dbeaver by dbeaver.
the class DataImportHandler method adaptTransferNode.
@Override
protected IDataTransferNode adaptTransferNode(Object object) {
final DBSDataManipulator adapted = RuntimeUtils.getObjectAdapter(object, DBSDataManipulator.class);
if (adapted != null) {
return new DatabaseTransferConsumer(adapted);
} else {
IFile file = RuntimeUtils.getObjectAdapter(object, IFile.class);
if (file != null) {
return getNodeByFile(file);
}
DBSObjectContainer objectContainer = RuntimeUtils.getObjectAdapter(object, DBSObjectContainer.class);
if (objectContainer == null) {
if (object instanceof DBSWrapper) {
object = ((DBSWrapper) object).getObject();
}
if (object instanceof DBPObject) {
object = DBUtils.getPublicObject((DBSObject) object);
}
if (object instanceof DBSObjectContainer) {
objectContainer = (DBSObjectContainer) object;
}
}
if (objectContainer != null) {
if (isObjectContainerSupportsImport(objectContainer)) {
return new DatabaseTransferConsumer(objectContainer);
} else {
DBWorkbench.getPlatformUI().showError("Wrong container", objectContainer.getName() + " doesn't support direct data import");
}
}
return null;
}
}
use of org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer 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) {
}
}
}
use of org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer in project dbeaver by serge-rider.
the class DataImportHandler method adaptTransferNode.
@Override
protected IDataTransferNode adaptTransferNode(Object object) {
final DBSDataManipulator adapted = RuntimeUtils.getObjectAdapter(object, DBSDataManipulator.class);
if (adapted != null) {
return new DatabaseTransferConsumer(adapted);
} else {
IFile file = RuntimeUtils.getObjectAdapter(object, IFile.class);
if (file != null) {
return getNodeByFile(file);
}
DBSObjectContainer objectContainer = RuntimeUtils.getObjectAdapter(object, DBSObjectContainer.class);
if (objectContainer == null) {
if (object instanceof DBSWrapper) {
object = ((DBSWrapper) object).getObject();
}
if (object instanceof DBPObject) {
object = DBUtils.getPublicObject((DBSObject) object);
}
if (object instanceof DBSObjectContainer) {
objectContainer = (DBSObjectContainer) object;
}
}
if (objectContainer != null) {
if (isObjectContainerSupportsImport(objectContainer)) {
return new DatabaseTransferConsumer(objectContainer);
} else {
DBWorkbench.getPlatformUI().showError("Wrong container", objectContainer.getName() + " doesn't support direct data import");
}
}
return null;
}
}
use of org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer in project dbeaver by serge-rider.
the class DatabaseProducerPageInputObjects method autoAssignMappings.
private void autoAssignMappings(List<DBSObject> containerObjects) {
boolean chooseConsumer = getWizard().getSettings().isConsumerOptional();
for (TableItem item : mappingTable.getItems()) {
DataTransferPipe pipe = (DataTransferPipe) item.getData();
if ((chooseConsumer && (pipe.getConsumer() == null || pipe.getConsumer().getDatabaseObject() == null)) || (!chooseConsumer && (pipe.getProducer() == null || pipe.getProducer().getDatabaseObject() == null))) {
DBSObject objectToMap = chooseConsumer ? pipe.getProducer().getDatabaseObject() : pipe.getConsumer().getDatabaseObject();
if (objectToMap == null) {
continue;
}
DBSObject object = DBUtils.findObject(containerObjects, objectToMap.getName());
if (object != null) {
if (chooseConsumer) {
if (object instanceof DBSDataManipulator) {
pipe.setConsumer(new DatabaseTransferConsumer((DBSDataManipulator) object));
}
} else {
if (object instanceof DBSDataContainer) {
pipe.setProducer(new DatabaseTransferProducer((DBSDataContainer) object));
}
}
updateItemData(item, pipe);
}
}
}
updatePageCompletion();
}
use of org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferConsumer in project dbeaver by dbeaver.
the class DatabaseProducerPageInputObjects method chooseEntity.
protected boolean chooseEntity(DataTransferPipe pipe) {
DataTransferSettings settings = getWizard().getSettings();
final DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
final DBNNode rootNode = DBWorkbench.getPlatform().getWorkspace().getProjects().size() == 1 ? navigatorModel.getRoot().getProjectNode(DBWorkbench.getPlatform().getWorkspace().getActiveProject()) : navigatorModel.getRoot();
boolean chooseConsumer = settings.isConsumerOptional();
DBNNode node = DBWorkbench.getPlatformUI().selectObject(UIUtils.getActiveWorkbenchShell(), chooseConsumer ? NLS.bind(DTUIMessages.database_producer_page_input_objects_node_select_target, pipe.getProducer().getDatabaseObject().getName()) : NLS.bind(DTUIMessages.database_producer_page_input_objects_node_select_source, pipe.getConsumer().getObjectName()), rootNode, lastSelection, new Class[] { DBSObjectContainer.class, DBSDataContainer.class }, new Class[] { chooseConsumer ? DBSDataManipulator.class : DBSDataContainer.class }, null);
if (node instanceof DBNDatabaseNode) {
lastSelection = (DBNDatabaseNode) node;
DBSObject object = ((DBNDatabaseNode) node).getObject();
if (chooseConsumer) {
if (object instanceof DBSDataManipulator) {
pipe.setConsumer(new DatabaseTransferConsumer((DBSDataManipulator) object));
}
} else {
if (object instanceof DBSDataContainer) {
pipe.setProducer(new DatabaseTransferProducer((DBSDataContainer) object));
}
}
return true;
}
return false;
}
Aggregations