@Override public RelationID getTableID(ResultSet rs) throws SQLException { return RelationID.createRelationIdFromDatabaseRecord(idfac, defaultTableOwner, rs.getString("object_name")); } };
@Override public RelationID getTableID(ResultSet rs) throws SQLException { return RelationID.createRelationIdFromDatabaseRecord(idfac, defaultTableOwner, rs.getString("object_name")); } };
/** * * @param predicate a predicate-name rendering of a possibly qualified table name * @return */ public static RelationID createRelationFromPredicateName(QuotedIDFactory idfac, Predicate predicate) { String s = predicate.getName(); // ROMAN (7 Oct 2015): a better way of splitting is probably needed here // String[] names = s.split("\\."); int position = s.indexOf('.'); if (position == -1) return RelationID.createRelationIdFromDatabaseRecord(idfac, null, s); else { return RelationID.createRelationIdFromDatabaseRecord(idfac, s.substring(0, position), s.substring(position + 1, s.length())); } } }
/** * * @param predicate a predicate-name rendering of a possibly qualified table name * @return */ @Deprecated public RelationID createRelationFromPredicateName(QuotedIDFactory idfac, Predicate predicate) { String s = predicate.getName(); // ROMAN (7 Oct 2015): a better way of splitting is probably needed here // String[] names = s.split("\\."); int position = s.indexOf('.'); if (position == -1) return RelationID.createRelationIdFromDatabaseRecord(idfac, null, s); else { return RelationID.createRelationIdFromDatabaseRecord(idfac, s.substring(0, position), s.substring(position + 1, s.length())); } } }
/** * Retrieve the table and view list from the JDBC driver (works for most database engines, e.g., MySQL and PostgreSQL) */ private static List<RelationID> getTableListDefault(DatabaseMetaData md, ImmutableSet<String> ignoredSchemas, QuotedIDFactory idfac) throws SQLException { List<RelationID> relationIds = new LinkedList<>(); try (ResultSet rs = md.getTables(null, null, null, new String[] { "TABLE", "VIEW" })) { while (rs.next()) { // String catalog = rs.getString("TABLE_CAT"); // not used String schema = rs.getString("TABLE_SCHEM"); String table = rs.getString("TABLE_NAME"); if (ignoredSchemas.contains(schema)) { continue; } RelationID id = RelationID.createRelationIdFromDatabaseRecord(idfac, schema, table); relationIds.add(id); } } return relationIds; }
/** * Retrieve the table and view list from the JDBC driver (works for most database engines, e.g., MySQL and PostgreSQL) */ private static List<RelationID> getTableListDefault(DatabaseMetaData md, ImmutableSet<String> ignoredSchemas, QuotedIDFactory idfac) throws SQLException { List<RelationID> relationIds = new LinkedList<>(); try (ResultSet rs = md.getTables(null, null, null, new String[] { "TABLE", "VIEW" })) { while (rs.next()) { // String catalog = rs.getString("TABLE_CAT"); // not used String schema = rs.getString("TABLE_SCHEM"); String table = rs.getString("TABLE_NAME"); if (ignoredSchemas.contains(schema)) { continue; } RelationID id = RelationID.createRelationIdFromDatabaseRecord(idfac, schema, table); relationIds.add(id); } } return relationIds; }
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)); } }
while (rs.next()) { RelationID id2 = RelationID.createRelationIdFromDatabaseRecord(idfac, rs.getString("TABLE_SCHEM"), rs.getString("TABLE_NAME")); if (id2.equals(id)) {
RelationID refId = RelationID.createRelationIdFromDatabaseRecord(idfac, schemaName, rs.getString("PKTABLE_NAME")); DatabaseRelationDefinition ref = metadata.getDatabaseRelation(refId);
schema = rs.getString("TABLE_CAT"); RelationID relationId = RelationID.createRelationIdFromDatabaseRecord(idfac, schema, rs.getString("TABLE_NAME")); QuotedID attributeId = QuotedID.createIdFromDatabaseRecord(idfac, rs.getString("COLUMN_NAME"));
schema = rs.getString("TABLE_CAT"); RelationID relationId = RelationID.createRelationIdFromDatabaseRecord(idfac, schema, rs.getString("TABLE_NAME")); QuotedID attributeId = QuotedID.createIdFromDatabaseRecord(idfac, rs.getString("COLUMN_NAME"));
String currentName = null; while (rs.next()) { RelationID refId = RelationID.createRelationIdFromDatabaseRecord(idfac, rs.getString("PKTABLE_SCHEM"), rs.getString("PKTABLE_NAME")); DatabaseRelationDefinition ref = metadata.getDatabaseRelation(refId);