[#3942] Add support for PostgreSQL functions returning single table records
This commit is contained in:
parent
cc85f94b2a
commit
2d7befeb17
@ -4895,6 +4895,11 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
type = getStrategy().getFullJavaClassName(db.getUDT(schema, u), udtMode);
|
||||
}
|
||||
|
||||
// [#3942] PostgreSQL treats UDTs and table types in similar ways
|
||||
else if (db.getTable(schema, u) != null) {
|
||||
type = getStrategy().getFullJavaClassName(db.getTable(schema, u), udtMode);
|
||||
}
|
||||
|
||||
// Check for custom types
|
||||
else if (db.getConfiguredCustomType(u) != null) {
|
||||
type = u;
|
||||
@ -4944,9 +4949,12 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
sb.append(")");
|
||||
}
|
||||
else if (db.getUDT(schema, u) != null) {
|
||||
UDTDefinition udt = db.getUDT(schema, u);
|
||||
|
||||
sb.append(getStrategy().getFullJavaIdentifier(udt));
|
||||
sb.append(getStrategy().getFullJavaIdentifier(db.getUDT(schema, u)));
|
||||
sb.append(".getDataType()");
|
||||
}
|
||||
// [#3942] PostgreSQL treats UDTs and table types in similar ways
|
||||
else if (db.getTable(schema, u) != null) {
|
||||
sb.append(getStrategy().getFullJavaIdentifier(db.getTable(schema, u)));
|
||||
sb.append(".getDataType()");
|
||||
}
|
||||
else if (db.getEnum(schema, u) != null) {
|
||||
|
||||
@ -109,6 +109,12 @@ public interface Table<R extends Record> extends TableLike<R> {
|
||||
*/
|
||||
Class<? extends R> getRecordType();
|
||||
|
||||
/**
|
||||
* The table's record type as a UDT data type, in case the underlying
|
||||
* database supports table records as UDT records.
|
||||
*/
|
||||
DataType<R> getDataType();
|
||||
|
||||
/**
|
||||
* Create a new {@link Record} of this table's type.
|
||||
*
|
||||
|
||||
@ -110,6 +110,7 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
private final Schema tableschema;
|
||||
private final String tablename;
|
||||
private final String tablecomment;
|
||||
private transient DataType<R> type;
|
||||
|
||||
AbstractTable(String name) {
|
||||
this(name, null, null);
|
||||
@ -148,6 +149,15 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
*/
|
||||
abstract Fields<R> fields0();
|
||||
|
||||
@Override
|
||||
public final DataType<R> getDataType() {
|
||||
if (type == null) {
|
||||
type = new TableDataType<R>(this);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final RecordType<R> recordType() {
|
||||
return fields0();
|
||||
|
||||
73
jOOQ/src/main/java/org/jooq/impl/TableDataType.java
Normal file
73
jOOQ/src/main/java/org/jooq/impl/TableDataType.java
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright (c) 2009-2016, Data Geekery GmbH (http://www.datageekery.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 org.jooq.Record;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.Table;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class TableDataType<R extends Record> extends DefaultDataType<R> {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = 3262508265391094581L;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
TableDataType(Table<R> table) {
|
||||
super(SQLDialect.DEFAULT, (Class<R>) table.getRecordType(), getQualifiedName(table));
|
||||
}
|
||||
|
||||
private static String getQualifiedName(Table<?> table) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (table.getSchema() != null) {
|
||||
sb.append(table.getSchema().getName());
|
||||
sb.append(".");
|
||||
}
|
||||
|
||||
sb.append(table.getName());
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user