Search in sources :

Example 21 with ColumnElement

use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.

the class UpdateQueryPlan method addColumn.

/**
 * Specifies an field the data for which needs to be updated,
 * and the mapped columns for which therefor need to be updated.
 * For update queries the column will be put in the set lists,
 * and for insert queries the column will be put into the
 * insert values lists.
 *
 * @param fieldDesc Updated field corresponding to a column in the database.
 * @param value New value.
 */
private void addColumn(LocalFieldDesc fieldDesc, Object value) {
    // Ignore secondary tracked fields.
    if ((fieldDesc.sqlProperties & FieldDesc.PROP_SECONDARY_TRACKED_FIELD) > 0) {
        return;
    }
    for (Iterator iter = fieldDesc.getColumnElements(); iter.hasNext(); ) {
        ColumnElement columnElement = (ColumnElement) iter.next();
        TableElement tableElement = columnElement.getDeclaringTable();
        if (tableElement == null) {
            throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
            "core.configuration.fieldnotable", fieldDesc.getName()));
        }
        QueryTable t = findQueryTable(tableElement);
        UpdateStatement s = null;
        if (t == null) {
            t = addQueryTable(tableElement, null);
            s = (UpdateStatement) addStatement(t);
        } else {
            s = (UpdateStatement) getStatement(t);
        }
        if (fieldDesc.isVersion() && action == ACT_UPDATE) {
            // For update, version columns will be flagged specially.
            s.addVersionColumn(columnElement);
        } else {
            s.addColumn(columnElement, value);
        }
    }
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) Iterator(java.util.Iterator) ColumnElement(org.netbeans.modules.dbschema.ColumnElement) TableElement(org.netbeans.modules.dbschema.TableElement)

Example 22 with ColumnElement

use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.

the class UpdateQueryPlan method addConstraints.

private void addConstraints(UpdateStatement statement, ArrayList localFields, ArrayList foreignFields, ArrayList columns) {
    boolean isBeforeImageRequired = updateDesc.isBeforeImageRequired();
    for (int i = 0; i < localFields.size(); i++) {
        LocalFieldDesc lf = (LocalFieldDesc) localFields.get(i);
        LocalFieldDesc ff = (LocalFieldDesc) foreignFields.get(i);
        ColumnElement ce = (ColumnElement) columns.get(i);
        addConstraint(statement, lf, ff, ce, isBeforeImageRequired);
    }
    // Add the constraint on the version field if needed.
    if (getConfig().hasVersionConsistency() && action != ACT_INSERT) {
        QueryTable table = (QueryTable) statement.getQueryTables().get(0);
        LocalFieldDesc versionField = table.getTableDesc().getVersionField();
        ColumnElement ce = (ColumnElement) versionField.getColumnElements().next();
        addConstraint(statement, versionField, versionField, ce, false);
    }
    statement.markConstraintAdded();
}
Also used : ColumnElement(org.netbeans.modules.dbschema.ColumnElement)

Example 23 with ColumnElement

use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.

the class UpdateStatement method addLocalConstraints.

public void addLocalConstraints(int action, ForeignFieldDesc f, SQLStateManager sm) {
    for (int i = 0; i < f.localFields.size(); i++) {
        LocalFieldDesc lf = (LocalFieldDesc) f.localFields.get(i);
        if (action == QueryPlan.ACT_INSERT) {
            // For inserts into the join table, we get the values we are inserting
            // for the parent object and the added object.
            ColumnElement lc = (ColumnElement) f.assocLocalColumns.get(i);
            addColumn(lc, lf.getValue(sm));
        } else if (action == QueryPlan.ACT_DELETE) {
            LocalFieldDesc alf = (LocalFieldDesc) f.assocLocalFields.get(i);
            // For deletes from the join table, we get the constraint values
            // from the parent object and the remove object.
            addConstraint(alf, lf.getValue(sm));
        }
    }
}
Also used : LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc) ColumnElement(org.netbeans.modules.dbschema.ColumnElement)

Example 24 with ColumnElement

use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.

the class UpdateStatement method appendVersionColumnUpdateClause.

/**
 * Appends clause to update version column. The generated clause will be of
 * the following form
 * <code> versionColumnName = versionColumnNane + 1 </code>
 * @param setClause Text for the set clause of update statement
 */
private void appendVersionColumnUpdateClause(StringBuffer setClause) {
    if (UPDATE_VERSION_COL) {
        if (versionColumns != null) {
            for (int i = 0; i < versionColumns.size(); i++) {
                ColumnElement columnElement = (ColumnElement) versionColumns.get(i);
                String columnName = columnElement.getName().getName();
                setClause.append(", ");
                appendQuotedText(setClause, columnName);
                setClause.append(" = ");
                appendQuotedText(setClause, columnName);
                setClause.append(" + ");
                setClause.append("1");
            }
        }
    }
}
Also used : ColumnElement(org.netbeans.modules.dbschema.ColumnElement)

Aggregations

ColumnElement (org.netbeans.modules.dbschema.ColumnElement)24 JDOFatalInternalException (com.sun.jdo.api.persistence.support.JDOFatalInternalException)4 Iterator (java.util.Iterator)4 LocalFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc)3 ArrayList (java.util.ArrayList)3 TableElement (org.netbeans.modules.dbschema.TableElement)3 ColumnPairElement (org.netbeans.modules.dbschema.ColumnPairElement)2 JDOFatalDataStoreException (com.sun.jdo.api.persistence.support.JDOFatalDataStoreException)1 TableDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.TableDesc)1 ResultDesc (com.sun.jdo.spi.persistence.support.sqlstore.sql.ResultDesc)1 UpdateJoinTableDesc (com.sun.jdo.spi.persistence.support.sqlstore.sql.UpdateJoinTableDesc)1 com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint (com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint)1 Collection (java.util.Collection)1