diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java index 667be6d6dd..ff09257919 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java @@ -117,6 +117,7 @@ import org.jooq.SQLDialect; import org.jooq.Schema; import org.jooq.Scope; import org.jooq.UDTRecord; +import org.jooq.exception.DataTypeException; import org.jooq.exception.SQLDialectNotSupportedException; import org.jooq.tools.Convert; import org.jooq.tools.JooqLogger; @@ -1389,10 +1390,10 @@ public class DefaultBinding implements Binding { else if (EnumType.class.isAssignableFrom(type)) { result = getEnumType(type, ctx.resultSet().getString(ctx.index())); } - else if (UDTRecord.class.isAssignableFrom(type)) { + else if (Record.class.isAssignableFrom(type)) { switch (ctx.family()) { case POSTGRES: - result = (T) pgNewUDTRecord(type, ctx.resultSet().getObject(ctx.index())); + result = (T) pgNewRecord(type, null, ctx.resultSet().getObject(ctx.index())); break; default: @@ -1540,10 +1541,10 @@ public class DefaultBinding implements Binding { else if (EnumType.class.isAssignableFrom(type)) { result = getEnumType(type, ctx.statement().getString(ctx.index())); } - else if (UDTRecord.class.isAssignableFrom(type)) { + else if (Record.class.isAssignableFrom(type)) { switch (ctx.family()) { case POSTGRES: - result = (T) pgNewUDTRecord(type, ctx.statement().getObject(ctx.index())); + result = (T) pgNewRecord(type, null, ctx.statement().getObject(ctx.index())); break; default: @@ -1747,7 +1748,7 @@ public class DefaultBinding implements Binding { } @SuppressWarnings("unchecked") - private static final T getEnumType(Class type, String literal) throws SQLException { + private static final T getEnumType(Class type, String literal) { try { Object[] list = (Object[]) type.getMethod("values").invoke(type); @@ -1760,7 +1761,7 @@ public class DefaultBinding implements Binding { } } catch (Exception e) { - throw new SQLException("Unknown enum literal found : " + literal); + throw new DataTypeException("Unknown enum literal found : " + literal); } return null; @@ -1894,7 +1895,7 @@ public class DefaultBinding implements Binding { // ------------------------------------------------------------------------- @SuppressWarnings("unchecked") - private static final T pgFromString(Class type, String string) throws SQLException { + private static final T pgFromString(Class type, String string) { if (string == null) { return null; } @@ -1975,19 +1976,19 @@ public class DefaultBinding implements Binding { else if (EnumType.class.isAssignableFrom(type)) { return getEnumType(type, string); } - else if (UDTRecord.class.isAssignableFrom(type)) { - return (T) pgNewUDTRecord(type, string); + else if (Record.class.isAssignableFrom(type)) { + return (T) pgNewRecord(type, null, string); } throw new UnsupportedOperationException("Class " + type + " is not supported"); } - private static final java.util.Date pgParseDate(String string, SimpleDateFormat f) throws SQLException { + private static final java.util.Date pgParseDate(String string, SimpleDateFormat f) { try { return f.parse(string); } catch (ParseException e) { - throw new SQLException(e); + throw new DataTypeException("Error while converting date", e); } } @@ -2003,16 +2004,16 @@ public class DefaultBinding implements Binding { * @return The converted {@link UDTRecord} */ @SuppressWarnings("unchecked") - static final UDTRecord pgNewUDTRecord(Class type, final Object object) throws SQLException { + static final Record pgNewRecord(Class type, Field[] fields, final Object object) { if (object == null) { return null; } - return Utils.newRecord(true, (Class>) type) - .operate(new RecordOperation, SQLException>() { + return Utils.newRecord(true, (Class) type, fields) + .operate(new RecordOperation() { @Override - public UDTRecord operate(UDTRecord record) throws SQLException { + public Record operate(Record record) { List values = PostgresUtils.toPGObject(object.toString()); Row row = record.fieldsRow(); @@ -2095,7 +2096,7 @@ public class DefaultBinding implements Binding { * @param string A String representation of an array * @return The converted array */ - private static final Object[] pgNewArray(Class type, String string) throws SQLException { + private static final Object[] pgNewArray(Class type, String string) { if (string == null) { return null; } @@ -2119,11 +2120,11 @@ public class DefaultBinding implements Binding { } } catch (Exception e) { - throw new SQLException(e); + throw new DataTypeException("Error while creating array", e); } } - static final void pgSetValue(Record record, Field field, String value) throws SQLException { + static final void pgSetValue(Record record, Field field, String value) { record.setValue(field, pgFromString(field.getType(), value)); } diff --git a/jOOQ/src/main/java/org/jooq/impl/RowField.java b/jOOQ/src/main/java/org/jooq/impl/RowField.java index ce2b9d7912..dfc358da80 100644 --- a/jOOQ/src/main/java/org/jooq/impl/RowField.java +++ b/jOOQ/src/main/java/org/jooq/impl/RowField.java @@ -42,16 +42,12 @@ package org.jooq.impl; import static org.jooq.impl.Utils.DATA_LIST_ALREADY_INDENTED; -import java.sql.SQLException; -import java.util.List; - import org.jooq.Context; import org.jooq.Converter; import org.jooq.DataType; import org.jooq.Field; import org.jooq.Record; import org.jooq.Row; -import org.jooq.util.postgres.PostgresUtils; /** * @author Lukas Eder @@ -64,39 +60,24 @@ class RowField extends AbstractField { private static final long serialVersionUID = -2065258332642911588L; private final ROW row; - private final String as; private final Field[] emulatedFields; RowField(ROW row) { this(row, "row"); } + @SuppressWarnings({ "serial", "unchecked", "rawtypes" }) RowField(final ROW row, String as) { super(as, (DataType) SQLDataType.RECORD, "", new DefaultBinding(new Converter() { - @Override public REC from(final Object t) { - return t == null ? null : Utils.newRecord(true, (Class) RecordImpl.class, row.fields()).operate(new RecordOperation() { - - @Override - public REC operate(REC record) { - List values = PostgresUtils.toPGObject(t.toString()); - - for (int i = 0; i < row.size(); i++) { - try { - DefaultBinding.pgSetValue(record, row.field(i), values.get(i)); - } - catch (SQLException ignore) {} - } - - return record; - } - }); + // So far, this is only supported for PostgreSQL + return (REC) (t == null ? null : DefaultBinding.pgNewRecord(Record.class, row.fields(), t)); } @Override public Object to(REC u) { - return null; + throw new UnsupportedOperationException("Converting from nested records to bind values is not yet supported"); } @Override @@ -107,10 +88,10 @@ class RowField extends AbstractField { @Override public Class toType() { return (Class) RecordImpl.class; - }})); + } + })); this.row = row; - this.as = as; this.emulatedFields = new Field[row.fields().length]; for (int i = 0; i < emulatedFields.length; i++)