use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class ClassDesc method createTables.
private void createTables(ArrayList mdTables) {
for (int i = 0; i < mdTables.size(); i++) {
MappingTableElementImpl mdt = (MappingTableElementImpl) mdTables.get(i);
TableDesc t = new TableDesc(mdt.getTableObject());
ArrayList keys = mdt.getKeyObjects();
KeyDesc key = new KeyDesc();
t.setKey(key);
key.addColumns(keys);
for (int j = 0; j < keys.size(); j++) {
ColumnElement c = (ColumnElement) keys.get(j);
if (c != null) {
key.addField(getLocalFieldDesc(c));
}
}
addTableDesc(t);
}
}
use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class LocalFieldDesc method computeTypePrecedence.
/**
* This method computes the type precedence for the given field f.
* @return an integer value indicating the precedence. 0 indicates
* highest precedence and Integer.MAX_VALUE indicates lowest.
*/
private int computeTypePrecedence() {
ColumnElement c = (ColumnElement) columnDescs.get(0);
int sqlType = c.getType();
Class type = getType();
boolean isNullable = c.isNullable();
int precedence = Integer.MAX_VALUE;
switch(sqlType) {
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
case Types.BIGINT:
if (isNullable) {
precedence = lookupTypePrecedence(type, nullableNonScaledTypes);
} else {
precedence = lookupTypePrecedence(type, nonNullableNonScaledTypes);
}
break;
case Types.REAL:
case Types.FLOAT:
case Types.DOUBLE:
if (isNullable) {
precedence = lookupTypePrecedence(type, nullableScaledTypes);
} else {
precedence = lookupTypePrecedence(type, nonNullableScaledTypes);
}
break;
case Types.NUMERIC:
case Types.DECIMAL:
int scale = -1;
if ((scale = c.getScale().intValue()) == 0) {
// non scaled type
if (isNullable) {
precedence = lookupTypePrecedence(type, nullableNonScaledTypes);
} else {
precedence = lookupTypePrecedence(type, nonNullableNonScaledTypes);
}
} else if (scale > 0) {
// scaled type
if (isNullable) {
precedence = lookupTypePrecedence(type, nullableScaledTypes);
} else {
precedence = lookupTypePrecedence(type, nonNullableScaledTypes);
}
}
break;
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
if (type == String.class) {
precedence = 0;
}
break;
case Types.DATE:
case Types.TIMESTAMP:
if (java.util.Date.class.isAssignableFrom(type)) {
precedence = 0;
}
break;
case Types.BIT:
if (type == Boolean.class) {
if (isNullable) {
precedence = 0;
} else {
precedence = 1;
}
} else if (type == Boolean.TYPE) {
if (isNullable) {
precedence = 1;
} else {
precedence = 0;
}
}
break;
}
return precedence;
}
use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class UpdateQueryPlan method processJoinTables.
private void processJoinTables() {
Collection fields = updateDesc.getUpdatedJoinTableFields();
if (fields == null)
return;
Iterator fieldIter = fields.iterator();
ArrayList deleteStatements = new ArrayList();
ArrayList insertStatements = new ArrayList();
while (fieldIter.hasNext()) {
ForeignFieldDesc f = (ForeignFieldDesc) fieldIter.next();
Collection descs = updateDesc.getUpdateJoinTableDescs(f);
Iterator descIter = descs.iterator();
ColumnElement c = (ColumnElement) f.assocLocalColumns.get(0);
QueryTable t = addQueryTable(config.findTableDesc(c.getDeclaringTable()));
while (descIter.hasNext()) {
UpdateJoinTableDesc desc = (UpdateJoinTableDesc) descIter.next();
int action = getAction(desc.getAction());
UpdateStatement s = (UpdateStatement) createStatement(t);
s.setAction(action);
if (action == ACT_INSERT) {
insertStatements.add(s);
} else if (action == ACT_DELETE) {
// RESOLVE: There are redundant deletes from join tables that causes
// update to fail with no rows affected. To work around this problem
// for now, we set the minAffectedRows to 0.
// We need to figure out why there are redundant deletes.
s.minAffectedRows = 0;
deleteStatements.add(s);
}
s.addLocalConstraints(action, f, desc.getParentStateManager());
s.addForeignConstraints(action, f, desc.getForeignStateManager());
}
}
// All join table delete statements have to go first and all
// join table insert statements have to go last.
ArrayList oldStatements = statements;
statements = deleteStatements;
statements.addAll(oldStatements);
statements.addAll(insertStatements);
}
use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class UpdateStatement method addForeignConstraints.
public void addForeignConstraints(int action, ForeignFieldDesc f, SQLStateManager sm) {
for (int i = 0; i < f.foreignFields.size(); i++) {
LocalFieldDesc ff = (LocalFieldDesc) f.foreignFields.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 fc = (ColumnElement) f.assocForeignColumns.get(i);
addColumn(fc, ff.getValue(sm));
} else if (action == QueryPlan.ACT_DELETE) {
LocalFieldDesc aff = (LocalFieldDesc) f.assocForeignFields.get(i);
// For deletes from the join table, we get the constraint values
// from the parent object and the remove object.
addConstraint(aff, ff.getValue(sm));
}
}
}
use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class CorrelatedSelectPlan method addQueryTables.
/**
* Adds the query tables corresponding to the columns in <code>columnList</code>.
*
* @param columnList List of columns.
* @param config Class configuration corresponding to columns.
*/
protected void addQueryTables(ArrayList columnList, ClassDesc config) {
for (int i = 0; i < columnList.size(); i++) {
ColumnElement col = (ColumnElement) columnList.get(i);
addQueryTable(col.getDeclaringTable(), config);
}
}
Aggregations