From 4da1c1a17a3cd8298fb65095ff7ab9a3d7b2234e Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Tue, 28 Jul 2020 09:55:34 +0200 Subject: [PATCH] [jOOQ/jOOQ#10438] Factored out duplicate class --- .../jooq/impl/ChainedConverterBinding.java | 114 ++++++++++++++++++ .../java/org/jooq/impl/ConvertedDataType.java | 73 ----------- .../jooq/impl/LegacyConvertedDataType.java | 73 ----------- 3 files changed, 114 insertions(+), 146 deletions(-) create mode 100644 jOOQ/src/main/java/org/jooq/impl/ChainedConverterBinding.java diff --git a/jOOQ/src/main/java/org/jooq/impl/ChainedConverterBinding.java b/jOOQ/src/main/java/org/jooq/impl/ChainedConverterBinding.java new file mode 100644 index 0000000000..506bfbdd1c --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/ChainedConverterBinding.java @@ -0,0 +1,114 @@ +/* + * 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 java.sql.SQLException; + +import org.jooq.Binding; +import org.jooq.BindingGetResultSetContext; +import org.jooq.BindingGetSQLInputContext; +import org.jooq.BindingGetStatementContext; +import org.jooq.BindingRegisterContext; +import org.jooq.BindingSQLContext; +import org.jooq.BindingSetSQLOutputContext; +import org.jooq.BindingSetStatementContext; +import org.jooq.Converter; +import org.jooq.Converters; + +/** + * A binding that chains a new converter to an existing binding / converter. + * + * @author Lukas Eder + */ +class ChainedConverterBinding implements Binding { + + /** + * Generated UID + */ + private static final long serialVersionUID = -5120352678786683423L; + + private final Binding delegate; + private final Converter suffix; + private final Converter chained; + + ChainedConverterBinding(Binding delegate, Converter converter) { + this.delegate = delegate; + this.suffix = converter; + this.chained = Converters.of(delegate.converter(), converter); + } + + @Override + public Converter converter() { + return chained; + } + + @Override + public void sql(BindingSQLContext ctx) throws SQLException { + delegate.sql(ctx.convert(suffix)); + } + + @Override + public void register(BindingRegisterContext ctx) throws SQLException { + delegate.register(ctx.convert(suffix)); + } + + @Override + public void set(BindingSetStatementContext ctx) throws SQLException { + delegate.set(ctx.convert(suffix)); + } + + @Override + public void set(BindingSetSQLOutputContext ctx) throws SQLException { + delegate.set(ctx.convert(suffix)); + } + + @Override + public void get(BindingGetResultSetContext ctx) throws SQLException { + delegate.get(ctx.convert(suffix)); + } + + @Override + public void get(BindingGetStatementContext ctx) throws SQLException { + delegate.get(ctx.convert(suffix)); + } + + @Override + public void get(BindingGetSQLInputContext ctx) throws SQLException { + delegate.get(ctx.convert(suffix)); + } +} \ No newline at end of file diff --git a/jOOQ/src/main/java/org/jooq/impl/ConvertedDataType.java b/jOOQ/src/main/java/org/jooq/impl/ConvertedDataType.java index 24d12403f9..5f5bb161d7 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ConvertedDataType.java +++ b/jOOQ/src/main/java/org/jooq/impl/ConvertedDataType.java @@ -37,21 +37,11 @@ */ package org.jooq.impl; -import java.sql.SQLException; - import org.jooq.Binding; -import org.jooq.BindingGetResultSetContext; -import org.jooq.BindingGetSQLInputContext; -import org.jooq.BindingGetStatementContext; -import org.jooq.BindingRegisterContext; -import org.jooq.BindingSQLContext; -import org.jooq.BindingSetSQLOutputContext; -import org.jooq.BindingSetStatementContext; import org.jooq.CharacterSet; import org.jooq.Collation; import org.jooq.Configuration; import org.jooq.Converter; -import org.jooq.Converters; import org.jooq.DataType; import org.jooq.Field; import org.jooq.Nullability; @@ -211,68 +201,5 @@ final class ConvertedDataType extends AbstractDataType { public final DataType asConvertedDataType(Converter converter) { return super.asConvertedDataType(new ChainedConverterBinding(getBinding(), converter)); } - - /** - * A binding that chains a new converter to an existing binding / converter. - * - * @author Lukas Eder - */ - private static class ChainedConverterBinding implements Binding { - - /** - * Generated UID - */ - private static final long serialVersionUID = -5120352678786683423L; - - private final Binding delegate; - private final Converter suffix; - private final Converter chained; - - ChainedConverterBinding(Binding delegate, Converter converter) { - this.delegate = delegate; - this.suffix = converter; - this.chained = Converters.of(delegate.converter(), converter); - } - - @Override - public Converter converter() { - return chained; - } - - @Override - public void sql(BindingSQLContext ctx) throws SQLException { - delegate.sql(ctx.convert(suffix)); - } - - @Override - public void register(BindingRegisterContext ctx) throws SQLException { - delegate.register(ctx.convert(suffix)); - } - - @Override - public void set(BindingSetStatementContext ctx) throws SQLException { - delegate.set(ctx.convert(suffix)); - } - - @Override - public void set(BindingSetSQLOutputContext ctx) throws SQLException { - delegate.set(ctx.convert(suffix)); - } - - @Override - public void get(BindingGetResultSetContext ctx) throws SQLException { - delegate.get(ctx.convert(suffix)); - } - - @Override - public void get(BindingGetStatementContext ctx) throws SQLException { - delegate.get(ctx.convert(suffix)); - } - - @Override - public void get(BindingGetSQLInputContext ctx) throws SQLException { - delegate.get(ctx.convert(suffix)); - } - } } diff --git a/jOOQ/src/main/java/org/jooq/impl/LegacyConvertedDataType.java b/jOOQ/src/main/java/org/jooq/impl/LegacyConvertedDataType.java index 48ec4b1959..fc72ee4b54 100644 --- a/jOOQ/src/main/java/org/jooq/impl/LegacyConvertedDataType.java +++ b/jOOQ/src/main/java/org/jooq/impl/LegacyConvertedDataType.java @@ -37,19 +37,9 @@ */ package org.jooq.impl; -import java.sql.SQLException; - import org.jooq.Binding; -import org.jooq.BindingGetResultSetContext; -import org.jooq.BindingGetSQLInputContext; -import org.jooq.BindingGetStatementContext; -import org.jooq.BindingRegisterContext; -import org.jooq.BindingSQLContext; -import org.jooq.BindingSetSQLOutputContext; -import org.jooq.BindingSetStatementContext; import org.jooq.Configuration; import org.jooq.Converter; -import org.jooq.Converters; import org.jooq.DataType; import org.jooq.Field; @@ -119,67 +109,4 @@ final class LegacyConvertedDataType extends DefaultDataType { public DataType asConvertedDataType(Converter converter) { return super.asConvertedDataType(new ChainedConverterBinding(getBinding(), converter)); } - - /** - * A binding that chains a new converter to an existing binding / converter. - * - * @author Lukas Eder - */ - private static class ChainedConverterBinding implements Binding { - - /** - * Generated UID - */ - private static final long serialVersionUID = -5120352678786683423L; - - private final Binding delegate; - private final Converter suffix; - private final Converter chained; - - ChainedConverterBinding(Binding delegate, Converter converter) { - this.delegate = delegate; - this.suffix = converter; - this.chained = Converters.of(delegate.converter(), converter); - } - - @Override - public Converter converter() { - return chained; - } - - @Override - public void sql(BindingSQLContext ctx) throws SQLException { - delegate.sql(ctx.convert(suffix)); - } - - @Override - public void register(BindingRegisterContext ctx) throws SQLException { - delegate.register(ctx.convert(suffix)); - } - - @Override - public void set(BindingSetStatementContext ctx) throws SQLException { - delegate.set(ctx.convert(suffix)); - } - - @Override - public void set(BindingSetSQLOutputContext ctx) throws SQLException { - delegate.set(ctx.convert(suffix)); - } - - @Override - public void get(BindingGetResultSetContext ctx) throws SQLException { - delegate.get(ctx.convert(suffix)); - } - - @Override - public void get(BindingGetStatementContext ctx) throws SQLException { - delegate.get(ctx.convert(suffix)); - } - - @Override - public void get(BindingGetSQLInputContext ctx) throws SQLException { - delegate.get(ctx.convert(suffix)); - } - } }