[#6068] Add Name { Field | Table | Schema | Catalog }.getQualifiedName()
This commit is contained in:
parent
a0a0157e7d
commit
e30c3b943d
@ -51,6 +51,11 @@ public interface Catalog extends QueryPart {
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* The qualified name of this catalog.
|
||||
*/
|
||||
Name getQualifiedName();
|
||||
|
||||
/**
|
||||
* List all schemas contained in this catalog.
|
||||
*/
|
||||
|
||||
@ -97,6 +97,11 @@ public interface Field<T> extends SelectField<T>, GroupField, FieldOrRow {
|
||||
@Override
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* The qualified name of this field.
|
||||
*/
|
||||
Name getQualifiedName();
|
||||
|
||||
/**
|
||||
* The comment given to the field.
|
||||
* <p>
|
||||
|
||||
@ -55,6 +55,11 @@ public interface Schema extends QueryPart {
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* The qualified name of this schema.
|
||||
*/
|
||||
Name getQualifiedName();
|
||||
|
||||
/**
|
||||
* Stream all tables contained in this schema.
|
||||
*/
|
||||
|
||||
@ -90,6 +90,11 @@ public interface Table<R extends Record> extends TableLike<R> {
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* The qualified name of this table.
|
||||
*/
|
||||
Name getQualifiedName();
|
||||
|
||||
/**
|
||||
* The comment given to the table.
|
||||
* <p>
|
||||
|
||||
@ -212,6 +212,11 @@ abstract class AbstractField<T> extends AbstractQueryPart implements Field<T> {
|
||||
return StringUtils.defaultIfNull(name.last(), "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Name getQualifiedName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getComment() {
|
||||
return comment;
|
||||
|
||||
@ -107,22 +107,50 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
private static final Clause[] CLAUSES = { TABLE };
|
||||
|
||||
private final Schema tableschema;
|
||||
private final String tablename;
|
||||
private final Name tablename;
|
||||
private final String tablecomment;
|
||||
private transient DataType<R> type;
|
||||
|
||||
/**
|
||||
* @deprecated - 3.10.0 - [#6068] - Use {@link #AbstractTable(Name)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
AbstractTable(String name) {
|
||||
this(name, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated - 3.10.0 - [#6068] - Use {@link #AbstractTable(Name, Schema)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
AbstractTable(String name, Schema schema) {
|
||||
this(name, schema, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated - 3.10.0 - [#6068] - Use {@link #AbstractTable(Name, Schema, String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
AbstractTable(String name, Schema schema, String comment) {
|
||||
super();
|
||||
this(DSL.name(name), schema, comment);
|
||||
}
|
||||
|
||||
AbstractTable(Name name) {
|
||||
this(name, null, null);
|
||||
}
|
||||
|
||||
AbstractTable(Name name, Schema schema) {
|
||||
this(name, schema, null);
|
||||
}
|
||||
|
||||
AbstractTable(Name name, Schema schema, String comment) {
|
||||
this.tableschema =
|
||||
schema != null
|
||||
? schema
|
||||
: name.qualified()
|
||||
? DSL.schema(name.qualifier())
|
||||
: null;
|
||||
|
||||
this.tableschema = schema;
|
||||
this.tablename = name;
|
||||
this.tablecomment = comment;
|
||||
}
|
||||
@ -359,6 +387,11 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
|
||||
@Override
|
||||
public final String getName() {
|
||||
return tablename.last();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Name getQualifiedName() {
|
||||
return tablename;
|
||||
}
|
||||
|
||||
|
||||
@ -62,26 +62,30 @@ public class CatalogImpl extends AbstractQueryPart implements Catalog {
|
||||
*/
|
||||
private static final long serialVersionUID = -3650318934053960244L;
|
||||
private static final Clause[] CLAUSES = { CATALOG, CATALOG_REFERENCE };
|
||||
private final String catalogName;
|
||||
|
||||
CatalogImpl(Name name) {
|
||||
this(name.last());
|
||||
private final Name name;
|
||||
|
||||
public CatalogImpl(Name name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public CatalogImpl(String name) {
|
||||
super();
|
||||
|
||||
this.catalogName = name;
|
||||
this(DSL.name(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getName() {
|
||||
return catalogName;
|
||||
return name.last();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Name getQualifiedName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
ctx.literal(getName());
|
||||
ctx.visit(name.unqualifiedName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -90,12 +94,10 @@ public class CatalogImpl extends AbstractQueryPart implements Catalog {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Schema getSchema(String name) {
|
||||
for (Schema schema : getSchemas()) {
|
||||
if (schema.getName().equals(name)) {
|
||||
public final Schema getSchema(String schemaName) {
|
||||
for (Schema schema : getSchemas())
|
||||
if (schema.getName().equals(schemaName))
|
||||
return schema;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@ -123,20 +125,18 @@ public class CatalogImpl extends AbstractQueryPart implements Catalog {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getName() != null ? getName().hashCode() : 0;
|
||||
return getQualifiedName() != null ? getQualifiedName().hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (this == that) {
|
||||
if (this == that)
|
||||
return true;
|
||||
}
|
||||
|
||||
// [#1626] CatalogImpl equality can be decided without executing the
|
||||
// rather expensive implementation of AbstractQueryPart.equals()
|
||||
if (that instanceof CatalogImpl) {
|
||||
return StringUtils.equals(getName(), (((CatalogImpl) that).getName()));
|
||||
}
|
||||
if (that instanceof CatalogImpl)
|
||||
return StringUtils.equals(getQualifiedName(), (((CatalogImpl) that).getQualifiedName()));
|
||||
|
||||
return super.equals(that);
|
||||
}
|
||||
|
||||
@ -7782,7 +7782,7 @@ public class DSL {
|
||||
*/
|
||||
@Support
|
||||
public static Table<Record> table(Name name) {
|
||||
return new QualifiedTable(name);
|
||||
return new TableImpl<Record>(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Other licenses:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Commercial licenses for this work are available. These replace the above
|
||||
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
|
||||
* database integrations.
|
||||
*
|
||||
* For more information, please visit: http://www.jooq.org/licenses
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import static org.jooq.Clause.TABLE;
|
||||
import static org.jooq.Clause.TABLE_REFERENCE;
|
||||
import static org.jooq.tools.StringUtils.defaultIfNull;
|
||||
|
||||
import org.jooq.Clause;
|
||||
import org.jooq.Context;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.RenderContext;
|
||||
import org.jooq.Table;
|
||||
|
||||
/**
|
||||
* A <code>QualifiedTable</code> is a {@link Table} that always renders a table
|
||||
* name or alias as a literal using {@link RenderContext#literal(String)}
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class QualifiedTable extends AbstractTable<Record> {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = 6937002867156868761L;
|
||||
private static final Clause[] CLAUSES = { TABLE, TABLE_REFERENCE };
|
||||
|
||||
private final Name name;
|
||||
|
||||
QualifiedTable(Name name) {
|
||||
super(
|
||||
defaultIfNull(name.last(), ""),
|
||||
name.qualified()
|
||||
? DSL.schema(name.qualifier())
|
||||
: null
|
||||
);
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Table API
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public final void accept(Context<?> ctx) {
|
||||
ctx.visit(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Clause[] clauses(Context<?> ctx) {
|
||||
return CLAUSES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Class<? extends Record> getRecordType() {
|
||||
return RecordImpl.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Table<Record> as(Name alias) {
|
||||
return new TableAlias<Record>(this, alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Table<Record> as(Name alias, Name... fieldAliases) {
|
||||
return new TableAlias<Record>(this, alias, fieldAliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
final Fields<Record> fields0() {
|
||||
return new Fields<Record>();
|
||||
}
|
||||
}
|
||||
@ -64,25 +64,29 @@ public class SchemaImpl extends AbstractQueryPart implements Schema {
|
||||
private static final long serialVersionUID = -8101463810207566546L;
|
||||
private static final Clause[] CLAUSES = { SCHEMA, SCHEMA_REFERENCE };
|
||||
|
||||
private final Name name;
|
||||
private final Catalog catalog;
|
||||
private final String schemaName;
|
||||
|
||||
SchemaImpl(Name name) {
|
||||
this(
|
||||
name.last(),
|
||||
name.qualified() ? DSL.catalog(name.qualifier()) : null
|
||||
);
|
||||
}
|
||||
|
||||
public SchemaImpl(String name) {
|
||||
this(name, null);
|
||||
}
|
||||
|
||||
public SchemaImpl(String name, Catalog catalog) {
|
||||
super();
|
||||
this(DSL.name(name), catalog);
|
||||
}
|
||||
|
||||
this.schemaName = name;
|
||||
this.catalog = catalog;
|
||||
public SchemaImpl(Name name) {
|
||||
this(name, null);
|
||||
}
|
||||
|
||||
public SchemaImpl(Name name, Catalog catalog) {
|
||||
this.name = name;
|
||||
this.catalog =
|
||||
catalog != null
|
||||
? catalog
|
||||
: name.qualified()
|
||||
? DSL.catalog(name.qualifier())
|
||||
: null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -92,7 +96,12 @@ public class SchemaImpl extends AbstractQueryPart implements Schema {
|
||||
|
||||
@Override
|
||||
public final String getName() {
|
||||
return schemaName;
|
||||
return name.last();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Name getQualifiedName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -104,7 +113,7 @@ public class SchemaImpl extends AbstractQueryPart implements Schema {
|
||||
ctx.sql('.');
|
||||
}
|
||||
|
||||
ctx.literal(getName());
|
||||
ctx.visit(name.unqualifiedName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -113,34 +122,28 @@ public class SchemaImpl extends AbstractQueryPart implements Schema {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Table<?> getTable(String name) {
|
||||
for (Table<?> table : getTables()) {
|
||||
if (table.getName().equals(name)) {
|
||||
public final Table<?> getTable(String tableName) {
|
||||
for (Table<?> table : getTables())
|
||||
if (table.getName().equals(tableName))
|
||||
return table;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final UDT<?> getUDT(String name) {
|
||||
for (UDT<?> udt : getUDTs()) {
|
||||
if (udt.getName().equals(name)) {
|
||||
public final UDT<?> getUDT(String udtName) {
|
||||
for (UDT<?> udt : getUDTs())
|
||||
if (udt.getName().equals(udtName))
|
||||
return udt;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Sequence<?> getSequence(String name) {
|
||||
for (Sequence<?> sequence : getSequences()) {
|
||||
if (sequence.getName().equals(name)) {
|
||||
public final Sequence<?> getSequence(String sequenceName) {
|
||||
for (Sequence<?> sequence : getSequences())
|
||||
if (sequence.getName().equals(sequenceName))
|
||||
return sequence;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ public class TableImpl<R extends Record> extends AbstractTable<R> {
|
||||
}
|
||||
|
||||
public TableImpl(Name name, Schema schema, Table<R> aliased, Field<?>[] parameters, String comment) {
|
||||
super(name.last(), schema, comment);
|
||||
super(name, schema, comment);
|
||||
|
||||
this.fields = new Fields<R>();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user