use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class ClassDesc method createSecondaryTableKey.
private void createSecondaryTableKey(TableDesc table, MappingReferenceKeyElementImpl mappingSecondaryKey) {
ColumnPairElement[] pairs = mappingSecondaryKey.getColumnPairs();
KeyDesc referencingKey = new KeyDesc();
KeyDesc referencedKey = new KeyDesc();
TableDesc secondaryTable = findTableDesc(((MappingTableElementImpl) mappingSecondaryKey.getTable()).getTableObject());
for (int i = 0; i < pairs.length; i++) {
ColumnPairElement pair = pairs[i];
ColumnElement lc = pair.getLocalColumn();
ColumnElement fc = pair.getReferencedColumn();
referencingKey.addColumn(lc);
FieldDesc lf = getLocalFieldDesc(lc);
referencingKey.addField(lf);
// We need to force field for the referencing key to be in the DFG
// so it will always be loaded. This is to facilitate updating
// secondary tables that requires this field to be loaded
// for constraint purposes.
lf.fetchGroup = FieldDesc.GROUP_DEFAULT;
referencedKey.addColumn(fc);
referencedKey.addField(getLocalFieldDesc(fc));
}
table.addSecondaryTableKey(new ReferenceKeyDesc(secondaryTable, referencingKey, referencedKey));
secondaryTable.setPrimaryTableKey(new ReferenceKeyDesc(table, referencedKey, referencingKey));
}
use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class ClassDesc method registerVersionFieldWithTable.
/**
* Registers the version field <cod>versionField</code> with the
* corresponding table.
*
* @param versionField Field used in version consistency check.
*/
private void registerVersionFieldWithTable(LocalFieldDesc versionField) {
// Version field must be mapped to exactly one column.
ColumnElement ce = (ColumnElement) versionField.getColumnElements().next();
Iterator iter = tables.iterator();
while (iter.hasNext()) {
TableDesc table = (TableDesc) iter.next();
if (!table.isJoinTable()) {
if (ce.getDeclaringTable() == table.getTableElement()) {
table.setVersionField(versionField);
break;
}
}
}
}
use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class FieldDesc method compareColumns.
/**
* This method compares the column lists between to fields to see if they match.
* If f1 and f2 are both primitive fields, we do an exact match.
* If f1 is primitve and f2 is a relationship field, we do an at-least-one match.
* If both f1 and f2 are relationship fields, we do an exact match.
* @return <code>true</code> if there is a match, <code>false</code>, otherwise.
*/
static boolean compareColumns(FieldDesc f1, FieldDesc f2) {
ArrayList columnList1 = null;
ArrayList columnList2 = null;
ArrayList columnList3 = null;
ArrayList columnList4 = null;
boolean exactMatch = false;
// Otherwise, we use localColumns for comparison.
if (f1 instanceof LocalFieldDesc) {
columnList1 = ((LocalFieldDesc) f1).columnDescs;
if (f2 instanceof LocalFieldDesc) {
columnList2 = ((LocalFieldDesc) f2).columnDescs;
// Not sure yet whether we need to a exact match
// here yet.
exactMatch = true;
} else {
// We are comparing LocalFieldDesc and ForeignFieldDesc.
// We do not need an exact match. The relationship must change,
// if one of the LocalFieldDesc's columns is changed.
columnList2 = ((ForeignFieldDesc) f2).localColumns;
}
} else {
if (f2 instanceof LocalFieldDesc) {
return false;
} else {
ForeignFieldDesc ff1 = (ForeignFieldDesc) f1;
ForeignFieldDesc ff2 = (ForeignFieldDesc) f2;
if (ff1.useJoinTable() && ff2.useJoinTable()) {
columnList1 = ff1.assocLocalColumns;
columnList2 = ff2.assocLocalColumns;
columnList3 = ff1.assocForeignColumns;
columnList4 = ff2.assocForeignColumns;
} else if (!ff1.useJoinTable() && !ff2.useJoinTable()) {
columnList1 = ff1.localColumns;
columnList2 = ff2.localColumns;
columnList3 = ff1.foreignColumns;
columnList4 = ff2.foreignColumns;
} else {
return false;
}
exactMatch = true;
}
}
boolean found = false;
for (int k = 0; k < 2; k++) {
if (k == 1) {
if (columnList3 != null) {
columnList1 = columnList3;
columnList2 = columnList4;
} else {
break;
}
}
int size1 = columnList1.size();
int size2 = columnList2.size();
if (exactMatch && (size1 != size2)) {
return false;
}
for (int i = 0; i < size1; i++) {
found = false;
ColumnElement c1 = (ColumnElement) columnList1.get(i);
// Find if any column of columnList2 matches with c1.
for (int j = 0; j < size2; j++) {
ColumnElement c2 = (ColumnElement) columnList2.get(j);
if (c1.getName().getFullName().equals(c2.getName().getFullName())) {
found = true;
}
}
// we return false.
if (exactMatch && !found) {
return false;
}
// we return true;
if (!exactMatch && found) {
return true;
}
}
}
// exactly. Otherwise, the two column lists don't match at all.
return found;
}
use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class ForeignFieldDesc method initializeFieldLists.
/**
* Initialize the field lists based on column list information.
*/
private void initializeFieldLists() {
ClassDesc theConfig = classDesc;
for (int i = 0; i < 4; i++) {
ArrayList fields = null;
ArrayList columns = null;
switch(i) {
case 0:
columns = localColumns;
fields = getLocalFields();
break;
case 1:
columns = assocLocalColumns;
fields = getAssocLocalFields();
break;
case 2:
columns = assocForeignColumns;
fields = getAssocForeignFields();
break;
case 3:
columns = foreignColumns;
fields = getForeignFields();
theConfig = foreignConfig;
break;
}
if (columns == null)
continue;
for (int j = 0; j < columns.size(); j++) {
ColumnElement ce = (ColumnElement) columns.get(j);
TableElement te = ce.getDeclaringTable();
if (te == null) {
throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
"core.configuration.columnnotable"));
}
fields.add(theConfig.getLocalFieldDesc(ce));
}
}
}
use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.
the class LocalFieldDesc method isPrimitiveMappedToNullableColumn.
public boolean isPrimitiveMappedToNullableColumn() {
if (primitiveMappedToNullableColumn == null) {
boolean rc = getType().isPrimitive();
for (Iterator iter = columnDescs.iterator(); iter.hasNext() && rc; ) {
ColumnElement c = (ColumnElement) iter.next();
rc = c.isNullable();
}
primitiveMappedToNullableColumn = new Boolean(rc);
}
return primitiveMappedToNullableColumn.booleanValue();
}
Aggregations