diff --git a/jOOQ-meta/src/main/java/org/jooq/meta/AbstractDatabase.java b/jOOQ-meta/src/main/java/org/jooq/meta/AbstractDatabase.java index f8bc1d2756..c8d7ae8b8b 100644 --- a/jOOQ-meta/src/main/java/org/jooq/meta/AbstractDatabase.java +++ b/jOOQ-meta/src/main/java/org/jooq/meta/AbstractDatabase.java @@ -1936,6 +1936,19 @@ public abstract class AbstractDatabase implements Database { try { ClassUtils.loadClass("org.jooq.postgres.extensions.types.Hstore"); + getConfiguredForcedTypes().add(new ForcedType() + .withUserType("java.lang.String") + .withBinding("org.jooq.postgres.extensions.bindings.CitextBinding") + .withIncludeTypes("citext") + .withPriority(Integer.MIN_VALUE) + ); + getConfiguredForcedTypes().add(new ForcedType() + .withUserType("java.lang.String[]") + .withBinding("org.jooq.postgres.extensions.bindings.CitextArrayBinding") + .withIncludeTypes("_citext") + .withPriority(Integer.MIN_VALUE) + ); + getConfiguredForcedTypes().add(new ForcedType() .withUserType("org.jooq.postgres.extensions.types.Hstore") .withBinding("org.jooq.postgres.extensions.bindings.HstoreBinding") diff --git a/jOOQ-postgres-extensions/src/main/java/org/jooq/postgres/extensions/bindings/CitextArrayBinding.java b/jOOQ-postgres-extensions/src/main/java/org/jooq/postgres/extensions/bindings/CitextArrayBinding.java new file mode 100644 index 0000000000..f9777035a4 --- /dev/null +++ b/jOOQ-postgres-extensions/src/main/java/org/jooq/postgres/extensions/bindings/CitextArrayBinding.java @@ -0,0 +1,61 @@ +/* + * 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.postgres.extensions.bindings; + +import org.jooq.Converter; +import org.jooq.postgres.extensions.converters.CitextConverter; + +/** + * A binding for the PostgreSQL citext[] data type. + * + * @author Lukas Eder + */ +public class CitextArrayBinding extends AbstractPostgresArrayBinding { + + private static final Converter CONVERTER = new CitextConverter().forArrays(); + + @Override + public Converter converter() { + return CONVERTER; + } + + @Override + protected String castType() { + return "citext[]"; + } +} diff --git a/jOOQ-postgres-extensions/src/main/java/org/jooq/postgres/extensions/bindings/CitextBinding.java b/jOOQ-postgres-extensions/src/main/java/org/jooq/postgres/extensions/bindings/CitextBinding.java new file mode 100644 index 0000000000..bfecc12c7f --- /dev/null +++ b/jOOQ-postgres-extensions/src/main/java/org/jooq/postgres/extensions/bindings/CitextBinding.java @@ -0,0 +1,89 @@ +/* + * 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.postgres.extensions.bindings; + +import java.sql.SQLException; +import java.sql.Types; + +import org.jooq.BindingGetResultSetContext; +import org.jooq.BindingGetStatementContext; +import org.jooq.BindingRegisterContext; +import org.jooq.BindingSetStatementContext; +import org.jooq.Converter; +import org.jooq.postgres.extensions.converters.CitextConverter; + +/** + * A binding for the PostgreSQL citext data type. + * + * @author Lukas Eder + */ +public class CitextBinding extends AbstractPostgresBinding { + + private static final Converter CONVERTER = new CitextConverter(); + + @Override + public Converter converter() { + return CONVERTER; + } + + @Override + protected String castType() { + return "citext"; + } + + @Override + public void register(final BindingRegisterContext ctx) throws SQLException { + ctx.statement().registerOutParameter(ctx.index(), Types.VARCHAR); + } + + @Override + public void set(final BindingSetStatementContext ctx) throws SQLException { + ctx.statement().setString(ctx.index(), ctx.value()); + } + + + @Override + public void get(final BindingGetResultSetContext ctx) throws SQLException { + ctx.value(ctx.resultSet().getString(ctx.index())); + } + + @Override + public void get(final BindingGetStatementContext ctx) throws SQLException { + ctx.value(ctx.statement().getString(ctx.index())); + } +} diff --git a/jOOQ-postgres-extensions/src/main/java/org/jooq/postgres/extensions/converters/CitextConverter.java b/jOOQ-postgres-extensions/src/main/java/org/jooq/postgres/extensions/converters/CitextConverter.java new file mode 100644 index 0000000000..df96e8cb40 --- /dev/null +++ b/jOOQ-postgres-extensions/src/main/java/org/jooq/postgres/extensions/converters/CitextConverter.java @@ -0,0 +1,62 @@ +/* + * 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.postgres.extensions.converters; + +import org.jooq.impl.AbstractConverter; + +/** + * A converter for the PostgreSQL citext data type. + * + * @author Lukas Eder + */ +public class CitextConverter extends AbstractConverter { + + public CitextConverter() { + super(Object.class, String.class); + } + + @Override + public String from(Object t) { + return t == null ? null : t.toString(); + } + + @Override + public Object to(String u) { + return u; + } +}