private static void extractPrimaryKey(DatabaseRelationDefinition relation, QuotedIDFactory idfac, RelationID id, ResultSet rs) throws SQLException { Map<Integer, String> primaryKeyAttributes = new HashMap<>(); String currentName = null; while (rs.next()) { // TABLE_CAT is ignored for now; assume here that relation has a fully specified name RelationID id2 = RelationID.createRelationIdFromDatabaseRecord(idfac, rs.getString("TABLE_SCHEM"), rs.getString("TABLE_NAME")); if (id2.equals(id)) { currentName = rs.getString("PK_NAME"); // may be null String attr = rs.getString("COLUMN_NAME"); int seq = rs.getShort("KEY_SEQ"); primaryKeyAttributes.put(seq, attr); } } if (!primaryKeyAttributes.isEmpty()) { // use the KEY_SEQ values to restore the correct order of attributes in the PK UniqueConstraint.Builder builder = UniqueConstraint.builder(relation); for (int i = 1; i <= primaryKeyAttributes.size(); i++) { QuotedID attrId = QuotedID.createIdFromDatabaseRecord(idfac, primaryKeyAttributes.get(i)); builder.add(relation.getAttribute(attrId)); } relation.addUniqueConstraint(builder.build(currentName, true)); } }
QuotedID attrId = QuotedID.createIdFromDatabaseRecord(idfac, rs.getString("FKCOLUMN_NAME")); QuotedID refAttrId = QuotedID.createIdFromDatabaseRecord(idfac, rs.getString("PKCOLUMN_NAME")); builder.add(relation.getAttribute(attrId), ref.getAttribute(refAttrId));
for (int i = 1; i <= primaryKeyAttributes.size(); i++) { QuotedID attrId = QuotedID.createIdFromDatabaseRecord(idfac, primaryKeyAttributes.get(i)); builder.add(relation.getAttribute(attrId));
Attribute attr = relation.getAttribute(attrId); if (attr == null) { // Compensate for the bug in PostgreSQL JBDC driver that attr = relation.getAttribute(attrId);
QuotedID attrId = QuotedID.createIdFromDatabaseRecord(idfac, rs.getString("FKCOLUMN_NAME")); QuotedID refAttrId = QuotedID.createIdFromDatabaseRecord(idfac, rs.getString("PKCOLUMN_NAME")); builder.add(relation.getAttribute(attrId), ref.getAttribute(refAttrId));
Attribute attr = relation.getAttribute(attrId); if (attr == null) { // Compensate for the bug in PostgreSQL JBDC driver that attr = relation.getAttribute(attrId);
for (int i = 0; i < pkAttrs.length; i++) { QuotedID pkAttrId = idfac.createAttributeID(pkAttrs[i]); Attribute pkAttr = pkTable.getAttribute(pkAttrId); if (pkAttr == null) { log.warn("Error in user-supplied foreign key: column " + pkAttrId + " not found in in table " + pkTable + "."); Attribute fkAttr = fkTable.getAttribute(fkAttrId); if (fkAttr == null) { log.warn("Error in user-supplied foreign key: column " + fkAttrId + " not found in table " + fkTable + ".");
for (int i = 0; i < pkAttrs.length; i++) { QuotedID pkAttrId = idfac.createAttributeID(pkAttrs[i]); Attribute pkAttr = pkTable.getAttribute(pkAttrId); if (pkAttr == null) { log.warn("Error in user-supplied foreign key: column " + pkAttrId + " not found in in table " + pkTable + "."); Attribute fkAttr = fkTable.getAttribute(fkAttrId); if (fkAttr == null) { log.warn("Error in user-supplied foreign key: column " + fkAttrId + " not found in table " + fkTable + ".");
for (String attr : attrs) { QuotedID attrId = idfac.createAttributeID(attr); Attribute attribute = td.getAttribute(attrId); if (attribute == null) { log.warn("Error in user-supplied unique constraint: column " + attrId + " not found in table " + tableId + ".");
for (String attr : attrs) { QuotedID attrId = idfac.createAttributeID(attr); Attribute attribute = td.getAttribute(attrId); if (attribute == null) { log.warn("Error in user-supplied unique constraint: column " + attrId + " not found in table " + tableId + ".");