[jOOQ/jOOQ#6188] Add Catalog.getSchema(Name)

This commit is contained in:
Lukas Eder 2020-08-26 10:43:31 +02:00
parent f1eb8ba775
commit 4df803651b
4 changed files with 29 additions and 0 deletions

View File

@ -96,6 +96,13 @@ public interface Catalog extends Named {
@Nullable
Schema getSchema(String name);
/**
* Get a schema by its name in this catalog, or <code>null</code> if no such
* schema exists.
*/
@Nullable
Schema getSchema(Name name);
/**
* Stream all schemas contained in this catalog.

View File

@ -122,4 +122,16 @@ abstract class AbstractNamed extends AbstractQueryPart implements Named {
static Name qualify(Named qualifier, Name name) {
return qualifier == null || name.qualified() ? name : qualifier.getQualifiedName().append(name);
}
static <N extends Named> N find(Name name, Iterable<? extends N> in) {
N unqualified = null;
for (N n : in)
if (n.getQualifiedName().equals(name))
return n;
else if (unqualified == null && n.getUnqualifiedName().equals(name.unqualifiedName()))
unqualified = n;
return unqualified;
}
}

View File

@ -104,6 +104,11 @@ public class CatalogImpl extends AbstractNamed implements Catalog {
return null;
}
@Override
public final Schema getSchema(Name name) {
return find(name, getSchemas());
}
/**
* {@inheritDoc}
* <p>

View File

@ -105,6 +105,11 @@ public final class LazyCatalog extends AbstractNamed implements Catalog {
return catalog().getSchema(name);
}
@Override
public final Schema getSchema(Name name) {
return catalog().getSchema(name);
}
@Override