Search in sources :

Example 1 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class SQLUtils method getColumnTypeModifiers.

public static String getColumnTypeModifiers(@NotNull DBSTypedObject column, @NotNull String typeName, @NotNull DBPDataKind dataKind) {
    typeName = typeName.toUpperCase(Locale.ENGLISH);
    if (column instanceof DBSObject) {
        // If type is UDT (i.e. we can find it in type list) and type precision == column precision
        // then do not use explicit precision in column definition
        final DBSDataType dataType = DBUtils.getLocalDataType(((DBSObject) column).getDataSource(), column.getTypeName());
        if (dataType != null && dataType.getScale() == column.getScale() && ((dataType.getPrecision() > 0 && dataType.getPrecision() == column.getPrecision()) || (dataType.getMaxLength() > 0 && dataType.getMaxLength() == column.getMaxLength()))) {
            return null;
        }
    }
    if (dataKind == DBPDataKind.STRING) {
        if (typeName.indexOf('(') == -1) {
            final long maxLength = column.getMaxLength();
            if (maxLength > 0) {
                return "(" + maxLength + ")";
            }
        }
    } else if (dataKind == DBPDataKind.CONTENT && !typeName.contains("LOB")) {
        final long maxLength = column.getMaxLength();
        if (maxLength > 0) {
            return "(" + maxLength + ')';
        }
    } else if (dataKind == DBPDataKind.NUMERIC) {
        if (typeName.equals("DECIMAL") || typeName.equals("NUMERIC") || typeName.equals("NUMBER")) {
            int scale = column.getScale();
            int precision = column.getPrecision();
            if (precision == 0) {
                precision = (int) column.getMaxLength();
            }
            if (scale >= 0 && precision >= 0 && !(scale == 0 && precision == 0)) {
                return "(" + precision + ',' + scale + ')';
            }
        } else if (typeName.equals("BIT")) {
            // Bit string?
            int precision = column.getPrecision();
            if (precision > 1) {
                return "(" + precision + ')';
            }
        }
    }
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType)

Example 2 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class DataImportHandler method chooseProducer.

@Override
protected IDataTransferProducer chooseProducer(ExecutionEvent event, IDataTransferConsumer consumer) {
    final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
    final DBNNode rootNode = DBeaverCore.getInstance().getLiveProjects().size() == 1 ? navigatorModel.getRoot().getProject(DBeaverCore.getInstance().getProjectRegistry().getActiveProject()) : navigatorModel.getRoot();
    DBNNode node = BrowseObjectDialog.selectObject(HandlerUtil.getActiveShell(event), "Select source container for '" + consumer.getTargetName() + "'", rootNode, null, new Class[] { DBSObjectContainer.class, DBSDataContainer.class }, new Class[] { DBSDataContainer.class });
    if (node instanceof DBNDatabaseNode) {
        DBSObject object = ((DBNDatabaseNode) node).getObject();
        if (object instanceof DBSDataContainer) {
            return new DatabaseTransferProducer((DBSDataContainer) object);
        }
    }
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DatabaseTransferProducer(org.jkiss.dbeaver.tools.transfer.database.DatabaseTransferProducer) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Example 3 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class DataExporterSQL method exportHeader.

@Override
public void exportHeader(DBCSession session) throws DBException, IOException {
    columns = getSite().getAttributes();
    DBPNamedObject source = getSite().getSource();
    if (source instanceof DBSObject) {
        tableName = omitSchema ? DBUtils.getQuotedIdentifier((DBSObject) source) : DBUtils.getObjectFullName(source, DBPEvaluationContext.UI);
    } else {
        throw new DBException("SQL export may be done only from table object");
    }
    rowCount = 0;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBException(org.jkiss.dbeaver.DBException) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject)

Example 4 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class NavigatorHandlerObjectOpen method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object element = iter.next();
            DBNNode node = null;
            if (element instanceof IResource) {
                openResource((IResource) element, HandlerUtil.getActiveWorkbenchWindow(event));
                continue;
            } else if (element instanceof DBNNode) {
                node = (DBNNode) element;
            } else {
                DBSObject object = RuntimeUtils.getObjectAdapter(element, DBSObject.class);
                if (object != null) {
                    node = getNodeByObject(object);
                }
            }
            if (node != null) {
                NavigatorUtils.openNavigatorNode(node, HandlerUtil.getActiveWorkbenchWindow(event));
            }
        }
    }
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ISelection(org.eclipse.jface.viewers.ISelection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource)

Example 5 with DBSObject

use of org.jkiss.dbeaver.model.struct.DBSObject in project dbeaver by serge-rider.

the class NavigatorHandlerObjectRename method renameDatabaseObject.

public static boolean renameDatabaseObject(IWorkbenchWindow workbenchWindow, DBNDatabaseNode node, String newName) {
    try {
        if (node.getParentNode() instanceof DBNContainer) {
            final DBNContainer container = (DBNContainer) node.getParentNode();
            DBSObject object = node.getObject();
            if (object != null) {
                DBEObjectRenamer objectRenamer = EntityEditorsRegistry.getInstance().getObjectManager(object.getClass(), DBEObjectRenamer.class);
                if (objectRenamer != null) {
                    CommandTarget commandTarget = getCommandTarget(workbenchWindow, container, object.getClass(), false);
                    objectRenamer.renameObject(commandTarget.getContext(), object, newName);
                    if (object.isPersisted() && commandTarget.getEditor() == null) {
                        if (!showScript(workbenchWindow, commandTarget.getContext(), "Rename script")) {
                            commandTarget.getContext().resetChanges();
                            return false;
                        } else {
                            ObjectSaver renamer = new ObjectSaver(commandTarget.getContext());
                            TasksJob.runTask("Rename object '" + object.getName() + "'", renamer);
                        }
                    } else {
                        for (DBECommand command : commandTarget.getContext().getFinalCommands()) {
                        //System.out.println(command);
                        }
                    }
                    return true;
                }
            }
        }
    } catch (Throwable e) {
        UIUtils.showErrorDialog(workbenchWindow.getShell(), "Rename object", "Can't rename object '" + node.getNodeName() + "'", e);
        return false;
    }
    return false;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBECommand(org.jkiss.dbeaver.model.edit.DBECommand) DBNContainer(org.jkiss.dbeaver.model.navigator.DBNContainer) DBEObjectRenamer(org.jkiss.dbeaver.model.edit.DBEObjectRenamer)

Aggregations

DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)374 DBException (org.jkiss.dbeaver.DBException)129 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)66 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)66 ArrayList (java.util.ArrayList)54 InvocationTargetException (java.lang.reflect.InvocationTargetException)52 ISelection (org.eclipse.jface.viewers.ISelection)46 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)46 AbstractObjectReference (org.jkiss.dbeaver.model.impl.struct.AbstractObjectReference)44 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)38 GridData (org.eclipse.swt.layout.GridData)38 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)38 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)30 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)29 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)29 DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)28 Composite (org.eclipse.swt.widgets.Composite)27 IEditorPart (org.eclipse.ui.IEditorPart)26 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)24 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)22