Search in sources :

Example 51 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 52 with DBSEntityAttribute

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

the class MySQLConstraintConfigurator method configureObject.

@Override
public MySQLTableConstraint configureObject(DBRProgressMonitor monitor, Object parent, MySQLTableConstraint constraint) {
    MySQLDataSource dataSource = constraint.getDataSource();
    return UITask.run(() -> {
        EditConstraintPage editPage;
        if (dataSource.supportsCheckConstraints()) {
            editPage = new EditConstraintPage(MySQLUIMessages.edit_constraint_manager_title, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY, DBSEntityConstraintType.CHECK });
        } else {
            editPage = new EditConstraintPage(MySQLUIMessages.edit_constraint_manager_title, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY });
        }
        if (!editPage.edit()) {
            return null;
        }
        constraint.setName(editPage.getConstraintName());
        constraint.setConstraintType(editPage.getConstraintType());
        if (editPage.getConstraintType() == DBSEntityConstraintType.CHECK && dataSource.supportsCheckConstraints()) {
            constraint.setCheckClause(editPage.getConstraintExpression());
        } else {
            int colIndex = 1;
            for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
                constraint.addColumn(new MySQLTableConstraintColumn(constraint, (MySQLTableColumn) tableColumn, colIndex++));
            }
        }
        return constraint;
    });
}
Also used : MySQLDataSource(org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) DBSEntityConstraintType(org.jkiss.dbeaver.model.struct.DBSEntityConstraintType) MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn) EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage) MySQLTableConstraint(org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraint) MySQLTableConstraintColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraintColumn)

Example 53 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 54 with DBSEntityAttribute

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

the class ComplexTypeAttributeTransformer method createNestedTypeBindings.

static void createNestedTypeBindings(DBCSession session, DBDAttributeBinding attribute, List<Object[]> rows, DBSEntity dataType) throws DBException {
    List<DBDAttributeBinding> nestedBindings = new ArrayList<>();
    for (DBSEntityAttribute nestedAttr : CommonUtils.safeCollection(dataType.getAttributes(session.getProgressMonitor()))) {
        DBDAttributeBindingType nestedBinding = new DBDAttributeBindingType(attribute, nestedAttr, nestedBindings.size());
        nestedBinding.lateBinding(session, rows);
        nestedBindings.add(nestedBinding);
    }
    if (!nestedBindings.isEmpty()) {
        attribute.setNestedBindings(nestedBindings);
    }
}
Also used : DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) ArrayList(java.util.ArrayList) DBDAttributeBindingType(org.jkiss.dbeaver.model.data.DBDAttributeBindingType) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding)

Aggregations

DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)54 DBException (org.jkiss.dbeaver.DBException)22 ArrayList (java.util.ArrayList)11 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)11 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)11 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)8 DBSEntityAttributeRef (org.jkiss.dbeaver.model.struct.DBSEntityAttributeRef)8 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)5 DBSAttributeBase (org.jkiss.dbeaver.model.struct.DBSAttributeBase)5 EditIndexPage (org.jkiss.dbeaver.ui.editors.object.struct.EditIndexPage)5 BigDecimal (java.math.BigDecimal)4 TableItem (org.eclipse.swt.widgets.TableItem)4 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)4 DBSEntityConstraint (org.jkiss.dbeaver.model.struct.DBSEntityConstraint)4 EditConstraintPage (org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 KeyAdapter (org.eclipse.swt.events.KeyAdapter)3 KeyEvent (org.eclipse.swt.events.KeyEvent)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3