[jOOQ/jOOQ#10511] Add <embeddableDomains/> to allow for wrapping all
DOMAIN types in embeddables This includes [jOOQ/jOOQ#10481] removing replaced getters / setters from generated records
This commit is contained in:
parent
bb16438f07
commit
a742cffe27
@ -151,6 +151,7 @@ import org.jooq.meta.IndexDefinition;
|
||||
import org.jooq.meta.JavaTypeResolver;
|
||||
import org.jooq.meta.PackageDefinition;
|
||||
import org.jooq.meta.ParameterDefinition;
|
||||
import org.jooq.meta.PositionedDefinition;
|
||||
import org.jooq.meta.RoutineDefinition;
|
||||
import org.jooq.meta.SchemaDefinition;
|
||||
import org.jooq.meta.SequenceDefinition;
|
||||
@ -1314,10 +1315,6 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
else
|
||||
baseClass = TableRecordImpl.class;
|
||||
|
||||
Map<TypedElementDefinition<?>, Integer> columnIndexes = new LinkedHashMap<>();
|
||||
for (int i = 0; i < columns.size(); i++)
|
||||
columnIndexes.put(columns.get(i), i);
|
||||
|
||||
List<Definition> columnsOrReplacingEmbeddables = columnsOrReplacingEmbeddables(tableUdtOrEmbeddable);
|
||||
|
||||
int degree = columns.size();
|
||||
@ -1763,10 +1760,10 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
|
||||
|
||||
generateRecordConstructor(tableUdtOrEmbeddable, out, columnIndexes, columns);
|
||||
generateRecordConstructor(tableUdtOrEmbeddable, out, columns);
|
||||
|
||||
if (!columns.equals(columnsOrReplacingEmbeddables))
|
||||
generateRecordConstructor(tableUdtOrEmbeddable, out, columnIndexes, columnsOrReplacingEmbeddables);
|
||||
generateRecordConstructor(tableUdtOrEmbeddable, out, columnsOrReplacingEmbeddables);
|
||||
|
||||
if (tableUdtOrEmbeddable instanceof TableDefinition)
|
||||
generateRecordClassFooter((TableDefinition) tableUdtOrEmbeddable, out);
|
||||
@ -1803,7 +1800,6 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
private void generateRecordConstructor(
|
||||
Definition tableUdtOrEmbeddable,
|
||||
JavaWriter out,
|
||||
Map<TypedElementDefinition<?>, Integer> columnIndexes,
|
||||
Collection<? extends Definition> columns
|
||||
) {
|
||||
final String className = getStrategy().getJavaClassName(tableUdtOrEmbeddable, Mode.RECORD);
|
||||
@ -1863,7 +1859,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
out.println();
|
||||
}
|
||||
|
||||
for (Definition column : columns)
|
||||
for (Definition column : columns) {
|
||||
if (column instanceof EmbeddableDefinition)
|
||||
|
||||
// TODO: Setters of X properties cannot accept X? in Kotlin: https://twitter.com/lukaseder/status/1296371561214234624
|
||||
@ -1875,12 +1871,9 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
Collections.nCopies(((EmbeddableDefinition) column).getColumns().size(), "null"));
|
||||
else
|
||||
out.println("%s(%s)%s", getStrategy().getJavaSetterName(column, Mode.RECORD), getStrategy().getJavaMemberName(column, Mode.DEFAULT), semicolon);
|
||||
else if (kotlin)
|
||||
out.println("this.%s = %s",
|
||||
getStrategy().getJavaMemberName(column, Mode.POJO),
|
||||
getStrategy().getJavaMemberName(column, Mode.POJO));
|
||||
else
|
||||
out.println("set(%s, %s)%s", columnIndexes.get(column), getStrategy().getJavaMemberName(column, Mode.DEFAULT), semicolon);
|
||||
out.println("set(%s, %s)%s", ((PositionedDefinition) column).getPosition() - 1, getStrategy().getJavaMemberName(column, Mode.POJO), semicolon);
|
||||
}
|
||||
|
||||
out.println("}");
|
||||
}
|
||||
@ -2047,25 +2040,25 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
out.tab(1).println("set(value) {");
|
||||
}
|
||||
else {
|
||||
final String nonnullAnnotation = nonnullAnnotation(out);
|
||||
|
||||
out.overrideIf(override);
|
||||
out.println("public %s %s([[before=@][after= ][%s]]%s value) {", setterReturnType, setter, list(nonnullAnnotation), type);
|
||||
out.println("public %s %s([[before=@][after= ][%s]]%s value) {", setterReturnType, setter, list(nonnullAnnotation(out)), type);
|
||||
}
|
||||
|
||||
for (EmbeddableColumnDefinition column : embeddable.getColumns()) {
|
||||
if (kotlin) {
|
||||
final String s = getStrategy().getJavaMemberName(column.getReferencingColumn(), Mode.POJO);
|
||||
final String g = getStrategy().getJavaMemberName(column, Mode.POJO);
|
||||
final int position = column.getReferencingColumnPosition() - 1;
|
||||
|
||||
out.tab(1).println("%s = value.%s", s, g);
|
||||
}
|
||||
else {
|
||||
final String s = getStrategy().getJavaSetterName(column.getReferencingColumn(), Mode.RECORD);
|
||||
final String g = getStrategy().getJavaGetterName(column, Mode.RECORD);
|
||||
|
||||
out.println("%s(value.%s%s)%s", s, g, emptyparens, semicolon);
|
||||
}
|
||||
if (kotlin)
|
||||
out.tab(1).println("set(%s, value.%s)",
|
||||
position,
|
||||
getStrategy().getJavaMemberName(column, Mode.POJO)
|
||||
);
|
||||
else
|
||||
out.println("set(%s, value.%s%s)%s",
|
||||
position,
|
||||
getStrategy().getJavaGetterName(column, Mode.RECORD),
|
||||
emptyparens,
|
||||
semicolon
|
||||
);
|
||||
}
|
||||
|
||||
if (generateFluentSetters())
|
||||
@ -2171,10 +2164,21 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
String separator = " ";
|
||||
|
||||
for (EmbeddableColumnDefinition column : embeddable.getColumns()) {
|
||||
if (kotlin)
|
||||
out.tab(1).println("%s%s", separator, getStrategy().getJavaMemberName(column.getReferencingColumn(), Mode.POJO));
|
||||
else
|
||||
out.println("%s%s%s", separator, getStrategy().getJavaGetterName(column.getReferencingColumn(), Mode.RECORD), emptyparens);
|
||||
final String columnType = out.ref(getJavaType(column.getReferencingColumn().getType(resolver())));
|
||||
final int position = column.getReferencingColumnPosition() - 1;
|
||||
|
||||
if (scala)
|
||||
out.println("%sget(%s).asInstanceOf[%s]", separator, position, columnType);
|
||||
else if (kotlin)
|
||||
out.tab(1).println("%sget(%s) as %s?", separator, position, columnType);
|
||||
else {
|
||||
|
||||
// [#6705] Avoid generating code with a redundant (Object) cast
|
||||
if (Object.class.getName().equals(typeFull))
|
||||
out.println("%sget(%s)", separator, position);
|
||||
else
|
||||
out.println("%s(%s) get(%s)", separator, columnType, position);
|
||||
}
|
||||
|
||||
separator = ", ";
|
||||
}
|
||||
|
||||
@ -64,6 +64,11 @@ public class DefaultEmbeddableColumnDefinition
|
||||
return referencingColumn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getReferencingColumnPosition() {
|
||||
return getReferencingColumn().getPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataTypeDefinition getType() {
|
||||
return getReferencingColumn().getType();
|
||||
|
||||
@ -84,7 +84,7 @@ public class DefaultEmbeddableDefinition
|
||||
log.info("Commercial feature", "Embeddables replacing fields is a commercial only feature. Please upgrade to the jOOQ Professional Edition");
|
||||
|
||||
for (int i = 0; i < referencingColumns.size(); i++)
|
||||
embeddableColumns.add(new DefaultEmbeddableColumnDefinition(this, definingColumnNames.get(i), referencingColumns.get(i), i));
|
||||
embeddableColumns.add(new DefaultEmbeddableColumnDefinition(this, definingColumnNames.get(i), referencingColumns.get(i), i + 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -64,7 +64,6 @@ public class DefaultMetaTableDefinition extends AbstractTableDefinition {
|
||||
public List<ColumnDefinition> getElements0() throws SQLException {
|
||||
List<ColumnDefinition> result = new ArrayList<>();
|
||||
|
||||
int ordinal = 0;
|
||||
for (Field<?> field : table.fields()) {
|
||||
DataType<?> dataType = field.getDataType();
|
||||
|
||||
@ -80,18 +79,14 @@ public class DefaultMetaTableDefinition extends AbstractTableDefinition {
|
||||
(Name) null
|
||||
);
|
||||
|
||||
ColumnDefinition column = new DefaultColumnDefinition(
|
||||
result.add(new DefaultColumnDefinition(
|
||||
getDatabase().getTable(getSchema(), getName()),
|
||||
field.getName(),
|
||||
ordinal,
|
||||
result.size() + 1,
|
||||
type,
|
||||
false,
|
||||
null
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
|
||||
ordinal++;
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -50,4 +50,10 @@ public interface EmbeddableColumnDefinition extends TypedElementDefinition<Embed
|
||||
*/
|
||||
ColumnDefinition getReferencingColumn();
|
||||
|
||||
/**
|
||||
* The {@link PositionedDefinition#getPosition()} of
|
||||
* {@link #getReferencingColumn()} within its defining table.
|
||||
*/
|
||||
int getReferencingColumnPosition();
|
||||
|
||||
}
|
||||
|
||||
@ -38,14 +38,14 @@
|
||||
package org.jooq.meta;
|
||||
|
||||
/**
|
||||
* A definition that is positioned at an index within its parent.
|
||||
* A definition that is positioned at a 1-based index within its parent.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public interface PositionedDefinition extends Definition {
|
||||
|
||||
/**
|
||||
* The object position in the parent.
|
||||
* The object's 1-based position in the parent.
|
||||
*/
|
||||
int getPosition();
|
||||
|
||||
|
||||
@ -69,7 +69,7 @@ public class CUBRIDTableDefinition extends AbstractTableDefinition {
|
||||
for (Record record : create()
|
||||
.select(
|
||||
DB_ATTRIBUTE.ATTR_NAME,
|
||||
DB_ATTRIBUTE.DEF_ORDER,
|
||||
DB_ATTRIBUTE.DEF_ORDER,
|
||||
DB_ATTRIBUTE.DATA_TYPE,
|
||||
DB_ATTRIBUTE.PREC,
|
||||
DB_ATTRIBUTE.SCALE,
|
||||
@ -81,8 +81,7 @@ public class CUBRIDTableDefinition extends AbstractTableDefinition {
|
||||
DB_ATTRIBUTE.ATTR_NAME.equal(DB_SERIAL.ATT_NAME).and(
|
||||
DB_ATTRIBUTE.CLASS_NAME.equal(DB_SERIAL.CLASS_NAME)))
|
||||
.where(DB_ATTRIBUTE.CLASS_NAME.equal(getName()))
|
||||
.orderBy(DB_ATTRIBUTE.DEF_ORDER)
|
||||
.fetch()) {
|
||||
.orderBy(DB_ATTRIBUTE.DEF_ORDER)) {
|
||||
|
||||
String dataType = record.get(DB_ATTRIBUTE.DATA_TYPE);
|
||||
|
||||
@ -98,16 +97,14 @@ public class CUBRIDTableDefinition extends AbstractTableDefinition {
|
||||
getName() + "_" + record.get(DB_ATTRIBUTE.ATTR_NAME)
|
||||
);
|
||||
|
||||
ColumnDefinition column = new DefaultColumnDefinition(
|
||||
result.add(new DefaultColumnDefinition(
|
||||
getDatabase().getTable(getSchema(), getName()),
|
||||
record.get(DB_ATTRIBUTE.ATTR_NAME),
|
||||
record.get(DB_ATTRIBUTE.DEF_ORDER),
|
||||
result.size() + 1,
|
||||
type,
|
||||
record.get(DB_SERIAL.NAME) != null,
|
||||
null
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -83,8 +83,7 @@ public class DerbyTableDefinition extends AbstractTableDefinition {
|
||||
// [#1241] Suddenly, bind values didn't work any longer, here...
|
||||
// [#6797] The cast is necessary if a non-standard collation is used
|
||||
.where(SYSCOLUMNS.REFERENCEID.cast(VARCHAR(32672)).equal(inline(tableid)))
|
||||
.orderBy(SYSCOLUMNS.COLUMNNUMBER)
|
||||
.fetch()) {
|
||||
.orderBy(SYSCOLUMNS.COLUMNNUMBER)) {
|
||||
|
||||
String columnDataType = record.get(SYSCOLUMNS.COLUMNDATATYPE, String.class);
|
||||
String typeName = parseTypeName(columnDataType);
|
||||
@ -104,16 +103,14 @@ public class DerbyTableDefinition extends AbstractTableDefinition {
|
||||
record.get(SYSCOLUMNS.COLUMNDEFAULT)
|
||||
);
|
||||
|
||||
ColumnDefinition column = new DefaultColumnDefinition(
|
||||
result.add(new DefaultColumnDefinition(
|
||||
getDatabase().getTable(getSchema(), getName()),
|
||||
record.get(SYSCOLUMNS.COLUMNNAME),
|
||||
record.get(SYSCOLUMNS.COLUMNNUMBER),
|
||||
result.size() + 1,
|
||||
type,
|
||||
null != record.get(SYSCOLUMNS.AUTOINCREMENTINC),
|
||||
null
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -123,16 +123,14 @@ public class FirebirdTableDefinition extends AbstractTableDefinition {
|
||||
record.get("DOMAIN_NAME") == null ? null : DSL.name(record.get("DOMAIN_NAME", String.class))
|
||||
);
|
||||
|
||||
ColumnDefinition column = new DefaultColumnDefinition(
|
||||
result.add(new DefaultColumnDefinition(
|
||||
getDatabase().getTable(getSchema(), getName()),
|
||||
record.get(r.RDB$FIELD_NAME),
|
||||
record.get(r.RDB$FIELD_POSITION),
|
||||
result.size() + 1,
|
||||
type,
|
||||
false,
|
||||
record.get(r.RDB$DESCRIPTION)
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -107,26 +107,24 @@ public class FirebirdTableValuedFunction extends AbstractTableDefinition {
|
||||
.orderBy(p.RDB$PARAMETER_NUMBER)) {
|
||||
|
||||
DefaultDataTypeDefinition type = new DefaultDataTypeDefinition(
|
||||
getDatabase(),
|
||||
getSchema(),
|
||||
record.get("FIELD_TYPE", String.class),
|
||||
record.get("CHAR_LEN", short.class),
|
||||
record.get(f.RDB$FIELD_PRECISION),
|
||||
record.get("FIELD_SCALE", Integer.class),
|
||||
record.get(p.RDB$NULL_FLAG) == 0,
|
||||
record.get(p.RDB$DEFAULT_SOURCE)
|
||||
getDatabase(),
|
||||
getSchema(),
|
||||
record.get("FIELD_TYPE", String.class),
|
||||
record.get("CHAR_LEN", short.class),
|
||||
record.get(f.RDB$FIELD_PRECISION),
|
||||
record.get("FIELD_SCALE", Integer.class),
|
||||
record.get(p.RDB$NULL_FLAG) == 0,
|
||||
record.get(p.RDB$DEFAULT_SOURCE)
|
||||
);
|
||||
|
||||
ColumnDefinition column = new DefaultColumnDefinition(
|
||||
getDatabase().getTable(getSchema(), getName()),
|
||||
record.get(p.RDB$PARAMETER_NAME.trim()),
|
||||
record.get(p.RDB$PARAMETER_NUMBER),
|
||||
type,
|
||||
false,
|
||||
null
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
result.add(new DefaultColumnDefinition(
|
||||
getDatabase().getTable(getSchema(), getName()),
|
||||
record.get(p.RDB$PARAMETER_NAME.trim()),
|
||||
result.size() + 1,
|
||||
type,
|
||||
false,
|
||||
null
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -151,15 +151,14 @@ public class H2TableDefinition extends AbstractTableDefinition {
|
||||
userType
|
||||
);
|
||||
|
||||
ColumnDefinition column = new DefaultColumnDefinition(
|
||||
result.add(new DefaultColumnDefinition(
|
||||
getDatabase().getTable(getSchema(), getName()),
|
||||
record.get(COLUMNS.COLUMN_NAME),
|
||||
record.get(COLUMNS.ORDINAL_POSITION),
|
||||
result.size() + 1,
|
||||
type,
|
||||
isIdentity,
|
||||
record.get(COLUMNS.REMARKS));
|
||||
|
||||
result.add(column);
|
||||
record.get(COLUMNS.REMARKS))
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -128,16 +128,14 @@ public class HSQLDBTableDefinition extends AbstractTableDefinition {
|
||||
DSL.name(record.get(COLUMNS.UDT_SCHEMA), record.get(COLUMNS.UDT_NAME))
|
||||
);
|
||||
|
||||
ColumnDefinition column = new DefaultColumnDefinition(
|
||||
result.add(new DefaultColumnDefinition(
|
||||
getDatabase().getTable(getSchema(), getName()),
|
||||
record.get(COLUMNS.COLUMN_NAME),
|
||||
record.get(COLUMNS.ORDINAL_POSITION, int.class),
|
||||
result.size() + 1,
|
||||
type,
|
||||
null != record.get(COLUMNS.IDENTITY_GENERATION),
|
||||
record.get(SYSTEM_COLUMNS.REMARKS)
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -90,16 +90,14 @@ public class HSQLDBTableValuedFunction extends AbstractTableDefinition {
|
||||
(String) null
|
||||
);
|
||||
|
||||
ColumnDefinition column = new DefaultColumnDefinition(
|
||||
result.add(new DefaultColumnDefinition(
|
||||
getDatabase().getTable(getSchema(), getName()),
|
||||
field.getName(),
|
||||
i + 1,
|
||||
result.size() + 1,
|
||||
type,
|
||||
false,
|
||||
null
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -131,16 +131,14 @@ public class MySQLTableDefinition extends AbstractTableDefinition {
|
||||
name(getSchema().getName(), getName() + "_" + record.get(COLUMNS.COLUMN_NAME))
|
||||
);
|
||||
|
||||
ColumnDefinition column = new DefaultColumnDefinition(
|
||||
result.add(new DefaultColumnDefinition(
|
||||
getDatabase().getTable(getSchema(), getName()),
|
||||
record.get(COLUMNS.COLUMN_NAME),
|
||||
record.get(COLUMNS.ORDINAL_POSITION, int.class),
|
||||
result.size() + 1,
|
||||
type,
|
||||
"auto_increment".equalsIgnoreCase(record.get(COLUMNS.EXTRA)),
|
||||
record.get(COLUMNS.COLUMN_COMMENT)
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -184,16 +184,14 @@ public class PostgresMaterializedViewDefinition extends AbstractTableDefinition
|
||||
)
|
||||
);
|
||||
|
||||
ColumnDefinition column = new DefaultColumnDefinition(
|
||||
result.add(new DefaultColumnDefinition(
|
||||
getDatabase().getTable(getSchema(), getName()),
|
||||
record.get(COLUMNS.COLUMN_NAME),
|
||||
record.get(COLUMNS.ORDINAL_POSITION, int.class),
|
||||
result.size() + 1,
|
||||
type,
|
||||
defaultString(record.get(COLUMNS.COLUMN_DEFAULT)).startsWith("nextval"),
|
||||
record.get(PG_DESCRIPTION.DESCRIPTION)
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -143,8 +143,7 @@ public class PostgresTableDefinition extends AbstractTableDefinition {
|
||||
|
||||
|
||||
|
||||
.orderBy(COLUMNS.ORDINAL_POSITION)
|
||||
.fetch()) {
|
||||
.orderBy(COLUMNS.ORDINAL_POSITION)) {
|
||||
|
||||
SchemaDefinition typeSchema = null;
|
||||
|
||||
|
||||
@ -198,16 +198,14 @@ public class PostgresTableValuedFunction extends AbstractTableDefinition {
|
||||
)
|
||||
);
|
||||
|
||||
ColumnDefinition column = new DefaultColumnDefinition(
|
||||
result.add(new DefaultColumnDefinition(
|
||||
getDatabase().getTable(getSchema(), getName()),
|
||||
record.get(p.PARAMETER_NAME),
|
||||
record.get(p.ORDINAL_POSITION, int.class),
|
||||
result.size() + 1,
|
||||
type,
|
||||
defaultString(record.get(c.COLUMN_DEFAULT)).startsWith("nextval"),
|
||||
null
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@ -89,11 +89,11 @@ public class SQLiteTableDefinition extends AbstractTableDefinition {
|
||||
Field<String> fDefaultValue = field(name("dflt_value"), String.class);
|
||||
Field<Integer> fPk = field(name("pk"), int.class);
|
||||
|
||||
int position = 0;
|
||||
Table<?> interpreted = null;
|
||||
for (Record record : create().select(fName, fType, fNotnull, fDefaultValue, fPk)
|
||||
.from("pragma_table_info({0})", inline(getName())).fetch()) {
|
||||
position++;
|
||||
for (Record record : create()
|
||||
.select(fName, fType, fNotnull, fDefaultValue, fPk)
|
||||
.from("pragma_table_info({0})", inline(getName()))
|
||||
) {
|
||||
|
||||
String name = record.get(fName);
|
||||
String dataType = record.get(fType)
|
||||
@ -160,16 +160,14 @@ public class SQLiteTableDefinition extends AbstractTableDefinition {
|
||||
record.get(fDefaultValue)
|
||||
);
|
||||
|
||||
ColumnDefinition column = new DefaultColumnDefinition(
|
||||
result.add(new DefaultColumnDefinition(
|
||||
getDatabase().getTable(getSchema(), getName()),
|
||||
name,
|
||||
position,
|
||||
result.size() + 1,
|
||||
type,
|
||||
identity,
|
||||
null
|
||||
);
|
||||
|
||||
result.add(column);
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user