Search in sources :

Example 6 with DBSEntity

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

the class ResultSetFilterPanel method openEditorForActiveQuery.

private void openEditorForActiveQuery() {
    DBSDataContainer dataContainer = viewer.getDataContainer();
    String editorName;
    if (dataContainer instanceof DBSEntity) {
        editorName = dataContainer.getName();
    } else {
        editorName = "Query";
    }
    OpenHandler.openSQLConsole(DBeaverUI.getActiveWorkbenchWindow(), dataContainer == null ? null : dataContainer.getDataSource().getContainer(), editorName, getActiveQueryText());
}
Also used : DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer)

Example 7 with DBSEntity

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

the class SQLAttributeResolver method resolveAll.

@Override
protected String[] resolveAll(final TemplateContext context) {
    final DBCExecutionContext executionContext = ((DBPContextProvider) context).getExecutionContext();
    if (executionContext == null) {
        return super.resolveAll(context);
    }
    TemplateVariable tableVariable = ((SQLContext) context).getTemplateVariable("table");
    final String tableName = tableVariable == null ? null : tableVariable.getDefaultValue();
    if (!CommonUtils.isEmpty(tableName)) {
        final List<DBSEntityAttribute> attributes = new ArrayList<>();
        DBRRunnableWithProgress runnable = new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    List<DBSEntity> entities = new ArrayList<>();
                    SQLEntityResolver.resolveTables(monitor, executionContext, context, entities);
                    if (!CommonUtils.isEmpty(entities)) {
                        DBSEntity table = DBUtils.findObject(entities, tableName);
                        if (table != null) {
                            attributes.addAll(CommonUtils.safeCollection(table.getAttributes(monitor)));
                        }
                    }
                } catch (DBException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        RuntimeUtils.runTask(runnable, "Resolve attributes", 1000);
        if (!CommonUtils.isEmpty(attributes)) {
            String[] result = new String[attributes.size()];
            for (int i = 0; i < attributes.size(); i++) {
                DBSEntityAttribute entity = attributes.get(i);
                result[i] = entity.getName();
            }
            return result;
        }
    }
    return super.resolveAll(context);
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) TemplateVariable(org.eclipse.jface.text.templates.TemplateVariable) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity)

Example 8 with DBSEntity

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

the class MySQLTableManager method createDatabaseObject.

@Override
protected MySQLTable createDatabaseObject(DBRProgressMonitor monitor, DBECommandContext context, MySQLCatalog parent, Object copyFrom) throws DBException {
    final MySQLTable table;
    if (copyFrom instanceof DBSEntity) {
        table = new MySQLTable(monitor, parent, (DBSEntity) copyFrom);
        table.setName(getTableName(monitor, parent, ((DBSEntity) copyFrom).getName()));
    } else if (copyFrom == null) {
        table = new MySQLTable(parent);
        setTableName(monitor, parent, table);
        final MySQLTable.AdditionalInfo additionalInfo = table.getAdditionalInfo(monitor);
        additionalInfo.setEngine(parent.getDataSource().getDefaultEngine());
        additionalInfo.setCharset(parent.getDefaultCharset());
        additionalInfo.setCollation(parent.getDefaultCollation());
    } else {
        throw new DBException("Can't create MySQL table from '" + copyFrom + "'");
    }
    return table;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity)

Example 9 with DBSEntity

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

the class ResultSetModel method updateColorMapping.

void updateColorMapping() {
    colorMapping.clear();
    DBSEntity entity = getSingleSource();
    if (entity == null) {
        return;
    }
    DBVEntity virtualEntity = DBVUtils.findVirtualEntity(entity, false);
    if (virtualEntity != null) {
        List<DBVColorOverride> coList = virtualEntity.getColorOverrides();
        if (!CommonUtils.isEmpty(coList)) {
            for (DBVColorOverride co : coList) {
                DBDAttributeBinding binding = getAttributeBinding(entity, co.getAttributeName());
                if (binding != null) {
                    List<AttributeColorSettings> cmList = colorMapping.get(binding);
                    if (cmList == null) {
                        cmList = new ArrayList<>();
                        colorMapping.put(binding, cmList);
                    }
                    cmList.add(new AttributeColorSettings(co));
                }
            }
        }
    }
    updateRowColors(curRows);
}
Also used : DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity)

Example 10 with DBSEntity

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

the class ResultSetPersister method prepareUpdateStatements.

private void prepareUpdateStatements() throws DBException {
    // Make statements
    for (ResultSetRow row : this.rowIdentifiers.keySet()) {
        if (row.changes == null)
            continue;
        DBDRowIdentifier rowIdentifier = this.rowIdentifiers.get(row);
        DBSEntity table = rowIdentifier.getEntity();
        {
            DataStatementInfo statement = new DataStatementInfo(DBSManipulationType.UPDATE, row, table);
            // Updated columns
            for (DBDAttributeBinding changedAttr : row.changes.keySet()) {
                statement.updateAttributes.add(new DBDAttributeValue(changedAttr, model.getCellValue(changedAttr, row)));
            }
            // Key columns
            List<DBDAttributeBinding> idColumns = rowIdentifier.getAttributes();
            for (DBDAttributeBinding metaColumn : idColumns) {
                Object keyValue = model.getCellValue(metaColumn, row);
                // Try to find old key oldValue
                if (row.changes != null && row.changes.containsKey(metaColumn)) {
                    keyValue = row.changes.get(metaColumn);
                }
                statement.keyAttributes.add(new DBDAttributeValue(metaColumn, keyValue));
            }
            updateStatements.add(statement);
        }
    }
}
Also used : DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity)

Aggregations

DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)12 DBException (org.jkiss.dbeaver.DBException)4 ArrayList (java.util.ArrayList)3 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)3 DBSDataType (org.jkiss.dbeaver.model.struct.DBSDataType)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BigDecimal (java.math.BigDecimal)1 LinkedHashSet (java.util.LinkedHashSet)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 PaletteDrawer (org.eclipse.gef.palette.PaletteDrawer)1 TemplateVariable (org.eclipse.jface.text.templates.TemplateVariable)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 TableItem (org.eclipse.swt.widgets.TableItem)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 DiagramPart (org.jkiss.dbeaver.ext.erd.part.DiagramPart)1