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);
}
}
}
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();
}
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));
}
}
}
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");
}
}
}
}
Aggregations