[jOOQ/jOOQ#9404] AbstractKey and subtypes should accept Name instead of
string in constructors
This commit is contained in:
parent
580ea3e837
commit
18b394b47e
@ -63,6 +63,14 @@ public interface Named extends QueryPart {
|
||||
|
||||
/**
|
||||
* The comment on this object.
|
||||
* <p>
|
||||
* This is the same as calling {@link #getCommentPart()} and then
|
||||
* {@link Comment#getComment()}.
|
||||
*/
|
||||
String getComment();
|
||||
|
||||
/**
|
||||
* The comment on this object as a {@link QueryPart}.
|
||||
*/
|
||||
Comment getCommentPart();
|
||||
}
|
||||
|
||||
@ -44,6 +44,7 @@ import org.jooq.Constraint;
|
||||
import org.jooq.ConstraintEnforcementStep;
|
||||
import org.jooq.Context;
|
||||
import org.jooq.Key;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableField;
|
||||
@ -68,8 +69,8 @@ abstract class AbstractKey<R extends Record> extends AbstractNamed implements Ke
|
||||
this(table, null, fields, enforced);
|
||||
}
|
||||
|
||||
AbstractKey(Table<R> table, String name, TableField<R, ?>[] fields, boolean enforced) {
|
||||
super(name == null ? null : DSL.name(name), null);
|
||||
AbstractKey(Table<R> table, Name name, TableField<R, ?>[] fields, boolean enforced) {
|
||||
super(name, null);
|
||||
|
||||
this.table = table;
|
||||
this.fields = fields;
|
||||
|
||||
@ -82,6 +82,11 @@ abstract class AbstractNamed extends AbstractQueryPart implements Named {
|
||||
return comment.getComment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Comment getCommentPart() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// The Object API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@ -55,7 +55,7 @@ final class CollatedField extends AbstractField<String> {
|
||||
private final Collation collation;
|
||||
|
||||
CollatedField(Field<?> field, Collation collation) {
|
||||
super(field.getQualifiedName(), type(field), DSL.comment(field.getComment()), binding(field));
|
||||
super(field.getQualifiedName(), type(field), field.getCommentPart(), binding(field));
|
||||
|
||||
this.field = field;
|
||||
this.collation = collation;
|
||||
|
||||
@ -58,6 +58,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jooq.Check;
|
||||
import org.jooq.Comment;
|
||||
import org.jooq.Constraint;
|
||||
import org.jooq.ConstraintEnforcementStep;
|
||||
import org.jooq.CreateDomainAsStep;
|
||||
@ -303,18 +304,18 @@ final class DDL {
|
||||
List<Query> result = new ArrayList<>();
|
||||
|
||||
if (configuration.flags().contains(COMMENT)) {
|
||||
String tComment = table.getComment();
|
||||
Comment tComment = table.getCommentPart();
|
||||
|
||||
if (!StringUtils.isEmpty(tComment))
|
||||
if (!StringUtils.isEmpty(tComment.getComment()))
|
||||
if (table.getType().isView())
|
||||
result.add(ctx.commentOnView(table).is(tComment));
|
||||
else
|
||||
result.add(ctx.commentOnTable(table).is(tComment));
|
||||
|
||||
for (Field<?> field : sortIf(Arrays.asList(table.fields()), !configuration.respectColumnOrder())) {
|
||||
String fComment = field.getComment();
|
||||
Comment fComment = field.getCommentPart();
|
||||
|
||||
if (!StringUtils.isEmpty(fComment))
|
||||
if (!StringUtils.isEmpty(fComment.getComment()))
|
||||
result.add(ctx.commentOnColumn(field).is(fComment));
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,6 +47,7 @@ import org.jooq.BindContext;
|
||||
import org.jooq.Binding;
|
||||
import org.jooq.Clause;
|
||||
import org.jooq.Collation;
|
||||
import org.jooq.Comment;
|
||||
import org.jooq.Comparator;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.Configuration;
|
||||
@ -147,6 +148,11 @@ final class FieldProxy<T> implements TableField<Record, T>, QueryPartInternal {
|
||||
return delegate.getComment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Comment getCommentPart() {
|
||||
return delegate.getCommentPart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return delegate.hashCode();
|
||||
|
||||
@ -78,13 +78,6 @@ public final class Internal {
|
||||
return new EmbeddableTableField<>(name, recordType, table, fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for indexes.
|
||||
*/
|
||||
public static final Index createIndex(String name, Table<?> table, OrderField<?>[] sortFields, boolean unique) {
|
||||
return createIndex(DSL.name(name), table, sortFields, unique);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for indexes.
|
||||
*/
|
||||
@ -104,21 +97,21 @@ public final class Internal {
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static final <R extends Record> UniqueKey<R> createUniqueKey(Table<R> table, TableField<R, ?>... fields) {
|
||||
return createUniqueKey(table, null, fields, true);
|
||||
return createUniqueKey(table, (Name) null, fields, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for unique keys.
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static final <R extends Record> UniqueKey<R> createUniqueKey(Table<R> table, String name, TableField<R, ?>... fields) {
|
||||
public static final <R extends Record> UniqueKey<R> createUniqueKey(Table<R> table, Name name, TableField<R, ?>... fields) {
|
||||
return createUniqueKey(table, name, fields, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for unique keys.
|
||||
*/
|
||||
public static final <R extends Record> UniqueKey<R> createUniqueKey(Table<R> table, String name, TableField<R, ?>[] fields, boolean enforced) {
|
||||
public static final <R extends Record> UniqueKey<R> createUniqueKey(Table<R> table, Name name, TableField<R, ?>[] fields, boolean enforced) {
|
||||
return new UniqueKeyImpl<>(table, name, fields, enforced);
|
||||
}
|
||||
|
||||
@ -127,21 +120,21 @@ public final class Internal {
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static final <R extends Record, U extends Record> ForeignKey<R, U> createForeignKey(UniqueKey<U> key, Table<R> table, TableField<R, ?>... fields) {
|
||||
return createForeignKey(key, table, null, fields);
|
||||
return createForeignKey(key, table, (Name) null, fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for foreign keys.
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static final <R extends Record, U extends Record> ForeignKey<R, U> createForeignKey(UniqueKey<U> key, Table<R> table, String name, TableField<R, ?>... fields) {
|
||||
public static final <R extends Record, U extends Record> ForeignKey<R, U> createForeignKey(UniqueKey<U> key, Table<R> table, Name name, TableField<R, ?>... fields) {
|
||||
return createForeignKey(key, table, name, fields, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for foreign keys.
|
||||
*/
|
||||
public static final <R extends Record, U extends Record> ForeignKey<R, U> createForeignKey(UniqueKey<U> key, Table<R> table, String name, TableField<R, ?>[] fields, boolean enforced) {
|
||||
public static final <R extends Record, U extends Record> ForeignKey<R, U> createForeignKey(UniqueKey<U> key, Table<R> table, Name name, TableField<R, ?>[] fields, boolean enforced) {
|
||||
ForeignKey<R, U> result = new ReferenceImpl<>(key, table, name, fields, enforced);
|
||||
|
||||
if (key instanceof UniqueKeyImpl)
|
||||
@ -256,4 +249,56 @@ public final class Internal {
|
||||
|
||||
|
||||
private Internal() {}
|
||||
|
||||
/**
|
||||
* Factory method for indexes.
|
||||
*
|
||||
* @deprecated - 3.14.0 - [#9404] - Please re-generate your code.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Index createIndex(String name, Table<?> table, OrderField<?>[] sortFields, boolean unique) {
|
||||
return createIndex(DSL.name(name), table, sortFields, unique);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for unique keys.
|
||||
*
|
||||
* @deprecated - 3.14.0 - [#9404] - Please re-generate your code.
|
||||
*/
|
||||
@Deprecated
|
||||
@SafeVarargs
|
||||
public static final <R extends Record> UniqueKey<R> createUniqueKey(Table<R> table, String name, TableField<R, ?>... fields) {
|
||||
return createUniqueKey(table, name, fields, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for unique keys.
|
||||
*
|
||||
* @deprecated - 3.14.0 - [#9404] - Please re-generate your code.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final <R extends Record> UniqueKey<R> createUniqueKey(Table<R> table, String name, TableField<R, ?>[] fields, boolean enforced) {
|
||||
return createUniqueKey(table, DSL.name(name), fields, enforced);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for foreign keys.
|
||||
*
|
||||
* @deprecated - 3.14.0 - [#9404] - Please re-generate your code.
|
||||
*/
|
||||
@Deprecated
|
||||
@SafeVarargs
|
||||
public static final <R extends Record, U extends Record> ForeignKey<R, U> createForeignKey(UniqueKey<U> key, Table<R> table, String name, TableField<R, ?>... fields) {
|
||||
return createForeignKey(key, table, name, fields, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for foreign keys.
|
||||
*
|
||||
* @deprecated - 3.14.0 - [#9404] - Please re-generate your code.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final <R extends Record, U extends Record> ForeignKey<R, U> createForeignKey(UniqueKey<U> key, Table<R> table, String name, TableField<R, ?>[] fields, boolean enforced) {
|
||||
return createForeignKey(key, table, DSL.name(name), fields, enforced);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2047,7 +2047,7 @@ final class Interpreter {
|
||||
f[i] = (TableField<Record, ?>) t.field(fields.get(i).name());
|
||||
|
||||
// Add to map before adding bi-directionality to avoid StackOverflowErrors
|
||||
interpretedUniqueKeys.put(qualifiedName, result = new UniqueKeyImpl<>(t, name().last(), f, enforced));
|
||||
interpretedUniqueKeys.put(qualifiedName, result = new UniqueKeyImpl<>(t, name(), f, enforced));
|
||||
for (MutableForeignKey referencingKey : referencingKeys)
|
||||
result.references.add((ForeignKey) referencingKey.interpretedKey());
|
||||
}
|
||||
@ -2106,7 +2106,7 @@ final class Interpreter {
|
||||
for (int i = 0; i < f.length; i++)
|
||||
f[i] = (TableField<Record, ?>) t.field(fields.get(i).name());
|
||||
|
||||
interpretedForeignKeys.put(qualifiedName, result = new ReferenceImpl<>(referencedKey.interpretedKey(), t, name().last(), f, enforced));
|
||||
interpretedForeignKeys.put(qualifiedName, result = new ReferenceImpl<>(referencedKey.interpretedKey(), t, name(), f, enforced));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -707,7 +707,7 @@ final class MetaImpl extends AbstractMeta {
|
||||
fkFields[i] = (TableField<Record, ?>) field(record.get(7, String.class));
|
||||
}
|
||||
|
||||
references.add(new ReferenceImpl<>(new MetaPrimaryKey(pkTable, pkName, pkFields), this, fkName, fkFields, true));
|
||||
references.add(new ReferenceImpl<>(new MetaPrimaryKey(pkTable, pkName, pkFields), this, DSL.name(fkName), fkFields, true));
|
||||
}
|
||||
|
||||
return references;
|
||||
@ -1002,7 +1002,7 @@ final class MetaImpl extends AbstractMeta {
|
||||
for (int i = 0; i < value.size(); i++)
|
||||
fkFields[i] = (TableField<Record, ?>) fkTable.field(value.get(i).get(7, String.class));
|
||||
|
||||
references.add(new ReferenceImpl<>(this, fkTable, fkName, fkFields, true));
|
||||
references.add(new ReferenceImpl<>(this, fkTable, DSL.name(fkName), fkFields, true));
|
||||
}
|
||||
|
||||
return references;
|
||||
|
||||
@ -50,6 +50,7 @@ import org.jooq.ConstraintEnforcementStep;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.ForeignKey;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Result;
|
||||
import org.jooq.RowN;
|
||||
@ -70,7 +71,7 @@ final class ReferenceImpl<R extends Record, O extends Record> extends AbstractKe
|
||||
|
||||
private final UniqueKey<O> key;
|
||||
|
||||
ReferenceImpl(UniqueKey<O> key, Table<R> table, String name, TableField<R, ?>[] fields, boolean enforced) {
|
||||
ReferenceImpl(UniqueKey<O> key, Table<R> table, Name name, TableField<R, ?>[] fields, boolean enforced) {
|
||||
super(table, name, fields, enforced);
|
||||
|
||||
this.key = key;
|
||||
|
||||
@ -97,7 +97,7 @@ final class TableAlias<R extends Record> extends AbstractTable<R> {
|
||||
? fieldAliases[i]
|
||||
: field.getUnqualifiedName();
|
||||
|
||||
result.add(new TableFieldImpl(name, field.getDataType(), this, DSL.comment(field.getComment()), field.getBinding()));
|
||||
result.add(new TableFieldImpl(name, field.getDataType(), this, field.getCommentPart(), field.getBinding()));
|
||||
}
|
||||
|
||||
return new Fields<>(result);
|
||||
|
||||
@ -170,7 +170,7 @@ public class TableImpl<R extends Record> extends AbstractTable<R> {
|
||||
}
|
||||
|
||||
public TableImpl(Table<?> child, ForeignKey<?, R> path, Table<R> parent) {
|
||||
this(createPathAlias(child, path), null, child, path, parent, null, DSL.comment(parent.getComment()));
|
||||
this(createPathAlias(child, path), null, child, path, parent, null, parent.getCommentPart());
|
||||
}
|
||||
|
||||
public TableImpl(Name name, Schema schema, Table<?> child, ForeignKey<?, R> path, Table<R> aliased, Field<?>[] parameters, Comment comment) {
|
||||
|
||||
@ -43,6 +43,7 @@ import java.util.List;
|
||||
|
||||
import org.jooq.ConstraintEnforcementStep;
|
||||
import org.jooq.ForeignKey;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableField;
|
||||
@ -64,7 +65,7 @@ final class UniqueKeyImpl<R extends Record> extends AbstractKey<R> implements Un
|
||||
this(table, null, fields, enforced);
|
||||
}
|
||||
|
||||
UniqueKeyImpl(Table<R> table, String name, TableField<R, ?>[] fields, boolean enforced) {
|
||||
UniqueKeyImpl(Table<R> table, Name name, TableField<R, ?>[] fields, boolean enforced) {
|
||||
super(table, name, fields, enforced);
|
||||
|
||||
this.references = new ArrayList<>();
|
||||
|
||||
@ -65,4 +65,4 @@ Authors and contributors of jOOQ or parts of jOOQ in alphabetical order:
|
||||
- Zoltan Tamasi
|
||||
|
||||
See the following website for details about contributing to jOOQ:
|
||||
https://github.com/jOOQ/jOOQ/blob/master/CONTRIBUTING.md
|
||||
https://github.com/jOOQ/jOOQ/blob/main/CONTRIBUTING.md
|
||||
|
||||
Loading…
Reference in New Issue
Block a user