/** * creates relation id from the database record (as though it is quoted) * * @param schema as is in DB (possibly null) * @param table as is in DB * @return */ public static RelationID createRelationIdFromDatabaseRecord(QuotedIDFactory idfac, String schema, String table) { // both IDs are as though they are quoted -- DB stores names as is return new RelationID(QuotedID.createIdFromDatabaseRecord(idfac, schema), QuotedID.createIdFromDatabaseRecord(idfac, table)); }
/** * creates relation id from the database record (as though it is quoted) * * @param schema as is in DB (possibly null) * @param table as is in DB * @return */ public static RelationID createRelationIdFromDatabaseRecord(QuotedIDFactory idfac, String schema, String table) { // both IDs are as though they are quoted -- DB stores names as is return new RelationID(QuotedID.createIdFromDatabaseRecord(idfac, schema), QuotedID.createIdFromDatabaseRecord(idfac, table)); }
.map(v -> QuotedID.createIdFromDatabaseRecord(idfac, v.getName())) .collect(ImmutableCollectors.toList());
.map(v -> QuotedID.createIdFromDatabaseRecord(idfac, v.getName())) .collect(ImmutableCollectors.toList());
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, primaryKeyAttributes.get(i)); builder.add(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));
QuotedID attrId = QuotedID.createIdFromDatabaseRecord(idfac, rs.getString("COLUMN_NAME")); if (attr == null) { // Compensate for the bug in PostgreSQL JBDC driver that attrId = QuotedID.createIdFromDatabaseRecord(idfac, "\"" + rs.getString("COLUMN_NAME") + "\""); 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));
QuotedID attrId = QuotedID.createIdFromDatabaseRecord(idfac, rs.getString("COLUMN_NAME")); if (attr == null) { // Compensate for the bug in PostgreSQL JBDC driver that attrId = QuotedID.createIdFromDatabaseRecord(idfac, "\"" + rs.getString("COLUMN_NAME") + "\""); attr = relation.getAttribute(attrId);
QuotedID quotedAttribute = QuotedID.createIdFromDatabaseRecord(idfac, var.getName()); newTerm = attributes.get(new QualifiedAttributeID(null, quotedAttribute));
QuotedID quotedAttribute = QuotedID.createIdFromDatabaseRecord(idfac, var.getName()); newTerm = attributes.get(new QualifiedAttributeID(null, quotedAttribute));
QuotedID attributeId = QuotedID.createIdFromDatabaseRecord(idfac, rs.getString("COLUMN_NAME")); if (printouts) System.out.println(" " + relationId + "." + attributeId);
QuotedID attributeId = QuotedID.createIdFromDatabaseRecord(idfac, rs.getString("COLUMN_NAME")); if (printouts) System.out.println(" " + relationId + "." + attributeId);