Search in sources :

Example 61 with DBSEntityAttribute

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

the class SQLGeneratorInsert method generateSQL.

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

Example 62 with DBSEntityAttribute

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

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 63 with DBSEntityAttribute

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

the class DBDAttributeBindingMeta method lateBinding.

@Override
public void lateBinding(@NotNull DBCSession session, List<Object[]> rows) throws DBException {
    DBSEntityAttribute entityAttribute = getEntityAttribute();
    if (entityAttribute != null) {
        referrers = DBUtils.getAttributeReferrers(session.getProgressMonitor(), entityAttribute, true);
    }
    super.lateBinding(session, rows);
}
Also used : DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute)

Example 64 with DBSEntityAttribute

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

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)

Example 65 with DBSEntityAttribute

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

the class SQLServerIndexConfigurator method configureObject.

@Override
public SQLServerTableIndex configureObject(DBRProgressMonitor monitor, Object container, SQLServerTableIndex index) {
    return UITask.run(() -> {
        EditIndexPage editPage = new EditIndexPage("Create index", index, Arrays.asList(SQLSERVER_INDEX_TYPES));
        if (!editPage.edit()) {
            return null;
        }
        index.setUnique(editPage.isUnique());
        index.setIndexType(editPage.getIndexType());
        index.setDescription(editPage.getDescription());
        StringBuilder idxName = new StringBuilder(64);
        idxName.append(CommonUtils.escapeIdentifier(index.getTable().getName()));
        int colIndex = 1;
        for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
            if (colIndex == 1) {
                idxName.append("_").append(CommonUtils.escapeIdentifier(tableColumn.getName()));
            }
            index.addColumn(new SQLServerTableIndexColumn(index, 0, (SQLServerTableColumn) tableColumn, colIndex++, !Boolean.TRUE.equals(editPage.getAttributeProperty(tableColumn, EditIndexPage.PROP_DESC))));
        }
        idxName.append("_IDX");
        index.setName(DBObjectNameCaseTransformer.transformObjectName(index, idxName.toString()));
        return index;
    });
}
Also used : SQLServerTableIndexColumn(org.jkiss.dbeaver.ext.mssql.model.SQLServerTableIndexColumn) SQLServerTableColumn(org.jkiss.dbeaver.ext.mssql.model.SQLServerTableColumn) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) EditIndexPage(org.jkiss.dbeaver.ui.editors.object.struct.EditIndexPage)

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