Search in sources :

Example 36 with DBSEntityAttribute

use of org.jkiss.dbeaver.model.struct.DBSEntityAttribute in project dbeaver by dbeaver.

the class MySQLIndexConfigurator method configureObject.

@Override
public MySQLTableIndex configureObject(DBRProgressMonitor monitor, Object parent, MySQLTableIndex index) {
    return UITask.run(() -> {
        MyEditIndexPage editPage = new MyEditIndexPage(index);
        if (!editPage.edit()) {
            return null;
        }
        StringBuilder idxName = new StringBuilder(64);
        idxName.append(CommonUtils.escapeIdentifier(index.getParentObject().getName()));
        int colIndex = 1;
        for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
            if (colIndex == 1) {
                // $NON-NLS-1$
                idxName.append("_").append(CommonUtils.escapeIdentifier(tableColumn.getName()));
            }
            Integer length = (Integer) editPage.getAttributeProperty(tableColumn, MyEditIndexPage.PROP_LENGTH);
            index.addColumn(new MySQLTableIndexColumn(index, (MySQLTableColumn) tableColumn, colIndex++, !Boolean.TRUE.equals(editPage.getAttributeProperty(tableColumn, EditIndexPage.PROP_DESC)), false, length == null ? null : String.valueOf(length)));
        }
        // $NON-NLS-1$
        idxName.append("_IDX");
        index.setName(DBObjectNameCaseTransformer.transformObjectName(index, idxName.toString()));
        index.setName(idxName.toString());
        index.setIndexType(editPage.getIndexType());
        index.setUnique(editPage.isUnique());
        return index;
    });
}
Also used : MySQLTableIndexColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableIndexColumn) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn)

Example 37 with DBSEntityAttribute

use of org.jkiss.dbeaver.model.struct.DBSEntityAttribute in project dbeaver by dbeaver.

the class SQLGeneratorSelect method generateSQL.

@Override
public void generateSQL(DBRProgressMonitor monitor, StringBuilder sql, DBSEntity object) throws DBException {
    sql.append("SELECT ");
    boolean hasAttr = false;
    if (columnList) {
        for (DBSEntityAttribute attr : getAllAttributes(monitor, object)) {
            if (DBUtils.isHiddenObject(attr)) {
                continue;
            }
            if (hasAttr)
                sql.append(", ");
            sql.append(DBUtils.getObjectFullName(attr, DBPEvaluationContext.DML));
            hasAttr = true;
        }
        if (hasAttr) {
            sql.append(getLineSeparator());
        }
    }
    if (!hasAttr) {
        sql.append("* ");
    }
    sql.append("FROM ").append(getEntityName(object));
    sql.append(";\n");
}
Also used : DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute)

Example 38 with DBSEntityAttribute

use of org.jkiss.dbeaver.model.struct.DBSEntityAttribute in project dbeaver by dbeaver.

the class SQLGeneratorUpdate method generateSQL.

@Override
public void generateSQL(DBRProgressMonitor monitor, StringBuilder sql, DBSEntity object) throws DBException {
    Collection<? extends DBSEntityAttribute> keyAttributes = getKeyAttributes(monitor, object);
    sql.append("UPDATE ").append(getEntityName(object)).append(getLineSeparator()).append("SET ");
    boolean hasAttr = false;
    for (DBSAttributeBase attr : getValueAttributes(monitor, object, keyAttributes)) {
        if (DBUtils.isPseudoAttribute(attr) || DBUtils.isHiddenObject(attr)) {
            continue;
        }
        if (hasAttr)
            sql.append(", ");
        sql.append(DBUtils.getObjectFullName(attr, DBPEvaluationContext.DML)).append("=");
        appendDefaultValue(sql, attr);
        hasAttr = true;
    }
    if (!CommonUtils.isEmpty(keyAttributes)) {
        sql.append(getLineSeparator()).append("WHERE ");
        hasAttr = false;
        for (DBSEntityAttribute attr : keyAttributes) {
            if (hasAttr)
                sql.append(" AND ");
            sql.append(DBUtils.getObjectFullName(attr, DBPEvaluationContext.DML)).append("=");
            appendDefaultValue(sql, attr);
            hasAttr = true;
        }
    }
    sql.append(";\n");
}
Also used : DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase)

Example 39 with DBSEntityAttribute

use of org.jkiss.dbeaver.model.struct.DBSEntityAttribute in project dbeaver by dbeaver.

the class SQLGeneratorDelete method generateSQL.

@Override
public void generateSQL(DBRProgressMonitor monitor, StringBuilder sql, DBSEntity object) throws DBException {
    sql.append("DELETE FROM ").append(getEntityName(object)).append(getLineSeparator()).append("WHERE ");
    Collection<? extends DBSEntityAttribute> keyAttributes = getKeyAttributes(monitor, object);
    if (CommonUtils.isEmpty(keyAttributes)) {
        keyAttributes = getAllAttributes(monitor, object);
    }
    boolean hasAttr = false;
    for (DBSEntityAttribute attr : keyAttributes) {
        if (hasAttr)
            sql.append(" AND ");
        sql.append(DBUtils.getObjectFullName(attr, DBPEvaluationContext.DML)).append("=");
        appendDefaultValue(sql, attr);
        hasAttr = true;
    }
    sql.append(";\n");
}
Also used : DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute)

Example 40 with DBSEntityAttribute

use of org.jkiss.dbeaver.model.struct.DBSEntityAttribute in project dbeaver by dbeaver.

the class EditDictionaryPage method handleColumnsChange.

@Override
protected void handleColumnsChange() {
    descColumns = getSelectedAttributes();
    StringBuilder custom = new StringBuilder();
    for (DBSEntityAttribute column : descColumns) {
        if (custom.length() > 0) {
            custom.append(",");
        }
        custom.append(DBUtils.getQuotedIdentifier(column));
    }
    criteriaText.setText(custom.toString());
}
Also used : DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute)

Aggregations

DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)77 DBException (org.jkiss.dbeaver.DBException)25 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)16 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)14 ArrayList (java.util.ArrayList)11 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)10 DBSAttributeBase (org.jkiss.dbeaver.model.struct.DBSAttributeBase)10 EditIndexPage (org.jkiss.dbeaver.ui.editors.object.struct.EditIndexPage)10 DBSEntityAttributeRef (org.jkiss.dbeaver.model.struct.DBSEntityAttributeRef)9 MySQLTableColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn)6 DBDRowIdentifier (org.jkiss.dbeaver.model.data.DBDRowIdentifier)6 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)6 DBSDataType (org.jkiss.dbeaver.model.struct.DBSDataType)6 EditConstraintPage (org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)6 TableItem (org.eclipse.swt.widgets.TableItem)5 BigDecimal (java.math.BigDecimal)4 SQLServerTableColumn (org.jkiss.dbeaver.ext.mssql.model.SQLServerTableColumn)4 KeyAdapter (org.eclipse.swt.events.KeyAdapter)3 KeyEvent (org.eclipse.swt.events.KeyEvent)3 GridData (org.eclipse.swt.layout.GridData)3