[jOOQ/jOOQ#13188] Added support for the ltree type

This commit is contained in:
Lukas Eder 2022-03-03 09:32:47 +01:00
parent 4118a5bba4
commit 81f1094c9d
16 changed files with 28 additions and 227 deletions

View File

@ -1949,6 +1949,19 @@ public abstract class AbstractDatabase implements Database {
.withPriority(Integer.MIN_VALUE)
);
getConfiguredForcedTypes().add(new ForcedType()
.withUserType("org.jooq.postgres.extensions.types.Ltree")
.withBinding("org.jooq.postgres.extensions.bindings.LtreeBinding")
.withIncludeTypes("ltree")
.withPriority(Integer.MIN_VALUE)
);
getConfiguredForcedTypes().add(new ForcedType()
.withUserType("org.jooq.postgres.extensions.types.Ltree[]")
.withBinding("org.jooq.postgres.extensions.bindings.LtreeArrayBinding")
.withIncludeTypes("_ltree")
.withPriority(Integer.MIN_VALUE)
);
getConfiguredForcedTypes().add(new ForcedType()
.withUserType("org.jooq.postgres.extensions.types.Hstore")
.withBinding("org.jooq.postgres.extensions.bindings.HstoreBinding")

View File

@ -1,78 +0,0 @@
/*
* 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.postgres.extensions.types.AbstractInet;
/**
* A binding for the PostgreSQL <code>inet</code> or <code>cidr</code> data
* type.
*
* @author Lukas Eder
*/
abstract class AbstractInetBinding<U extends AbstractInet> extends AbstractPostgresBinding<Object, U> {
@Override
public void register(final BindingRegisterContext<U> ctx) throws SQLException {
ctx.statement().registerOutParameter(ctx.index(), Types.VARCHAR);
}
@Override
public void set(final BindingSetStatementContext<U> ctx) throws SQLException {
Object value = ctx.convert(converter()).value();
ctx.statement().setString(ctx.index(), value == null ? null : "" + value);
}
@Override
public void get(final BindingGetResultSetContext<U> ctx) throws SQLException {
ctx.convert(converter()).value(ctx.resultSet().getString(ctx.index()));
}
@Override
public void get(final BindingGetStatementContext<U> ctx) throws SQLException {
ctx.convert(converter()).value(ctx.statement().getString(ctx.index()));
}
}

View File

@ -1,79 +0,0 @@
/*
* 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.postgres.extensions.types.Range;
/**
* A binding for the PostgreSQL <code>range</code> data types.
*
* @author Lukas Eder
*/
abstract class AbstractRangeBinding<U extends Range<?>> extends AbstractPostgresBinding<Object, U> {
// TODO: This looks just like the AbstractInetBinding. Perhaps rename?
@Override
public void register(final BindingRegisterContext<U> ctx) throws SQLException {
ctx.statement().registerOutParameter(ctx.index(), Types.VARCHAR);
}
@Override
public void set(final BindingSetStatementContext<U> ctx) throws SQLException {
Object value = ctx.convert(converter()).value();
ctx.statement().setString(ctx.index(), value == null ? null : "" + value);
}
@Override
public void get(final BindingGetResultSetContext<U> ctx) throws SQLException {
ctx.convert(converter()).value(ctx.resultSet().getString(ctx.index()));
}
@Override
public void get(final BindingGetStatementContext<U> ctx) throws SQLException {
ctx.convert(converter()).value(ctx.statement().getString(ctx.index()));
}
}

View File

@ -46,7 +46,7 @@ import org.jooq.postgres.extensions.types.BigDecimalRange;
*
* @author Lukas Eder
*/
public class BigDecimalRangeBinding extends AbstractRangeBinding<BigDecimalRange> {
public class BigDecimalRangeBinding extends AbstractPostgresVarcharBinding<BigDecimalRange> {
private static final Converter<Object, BigDecimalRange> CONVERTER = new BigDecimalRangeConverter();

View File

@ -46,7 +46,7 @@ import org.jooq.postgres.extensions.types.Cidr;
*
* @author Lukas Eder
*/
public class CidrBinding extends AbstractInetBinding<Cidr> {
public class CidrBinding extends AbstractPostgresVarcharBinding<Cidr> {
private static final Converter<Object, Cidr> CONVERTER = new CidrConverter();

View File

@ -37,13 +37,6 @@
*/
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;
@ -52,7 +45,7 @@ import org.jooq.postgres.extensions.converters.CitextConverter;
*
* @author Lukas Eder
*/
public class CitextBinding extends AbstractPostgresBinding<Object, String> {
public class CitextBinding extends AbstractPostgresVarcharBinding<String> {
private static final Converter<Object, String> CONVERTER = new CitextConverter();
@ -65,25 +58,4 @@ public class CitextBinding extends AbstractPostgresBinding<Object, String> {
protected String castType() {
return "citext";
}
@Override
public void register(final BindingRegisterContext<String> ctx) throws SQLException {
ctx.statement().registerOutParameter(ctx.index(), Types.VARCHAR);
}
@Override
public void set(final BindingSetStatementContext<String> ctx) throws SQLException {
ctx.statement().setString(ctx.index(), ctx.value());
}
@Override
public void get(final BindingGetResultSetContext<String> ctx) throws SQLException {
ctx.value(ctx.resultSet().getString(ctx.index()));
}
@Override
public void get(final BindingGetStatementContext<String> ctx) throws SQLException {
ctx.value(ctx.statement().getString(ctx.index()));
}
}

View File

@ -46,7 +46,7 @@ import org.jooq.postgres.extensions.types.DateRange;
*
* @author Lukas Eder
*/
public class DateRangeBinding extends AbstractRangeBinding<DateRange> {
public class DateRangeBinding extends AbstractPostgresVarcharBinding<DateRange> {
private static final Converter<Object, DateRange> CONVERTER = new DateRangeConverter();

View File

@ -37,13 +37,6 @@
*/
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.HstoreConverter;
import org.jooq.postgres.extensions.types.Hstore;
@ -54,7 +47,7 @@ import org.jooq.postgres.extensions.types.Hstore;
* @author Dmitry Baev
* @author Lukas Eder
*/
public class HstoreBinding extends AbstractPostgresBinding<Object, Hstore> {
public class HstoreBinding extends AbstractPostgresVarcharBinding<Hstore> {
private static final Converter<Object, Hstore> CONVERTER = new HstoreConverter();
@ -67,27 +60,4 @@ public class HstoreBinding extends AbstractPostgresBinding<Object, Hstore> {
protected String castType() {
return "hstore";
}
@Override
public void register(final BindingRegisterContext<Hstore> ctx) throws SQLException {
ctx.statement().registerOutParameter(ctx.index(), Types.VARCHAR);
}
@Override
public void set(final BindingSetStatementContext<Hstore> ctx) throws SQLException {
Object value = ctx.convert(converter()).value();
ctx.statement().setString(ctx.index(), value == null ? null : "" + value);
}
@Override
public void get(final BindingGetResultSetContext<Hstore> ctx) throws SQLException {
ctx.convert(converter()).value(ctx.resultSet().getString(ctx.index()));
}
@Override
public void get(final BindingGetStatementContext<Hstore> ctx) throws SQLException {
ctx.convert(converter()).value(ctx.statement().getString(ctx.index()));
}
}

View File

@ -46,7 +46,7 @@ import org.jooq.postgres.extensions.types.Inet;
*
* @author Lukas Eder
*/
public class InetBinding extends AbstractInetBinding<Inet> {
public class InetBinding extends AbstractPostgresVarcharBinding<Inet> {
private static final Converter<Object, Inet> CONVERTER = new InetConverter();

View File

@ -46,7 +46,7 @@ import org.jooq.postgres.extensions.types.IntegerRange;
*
* @author Lukas Eder
*/
public class IntegerRangeBinding extends AbstractRangeBinding<IntegerRange> {
public class IntegerRangeBinding extends AbstractPostgresVarcharBinding<IntegerRange> {
private static final Converter<Object, IntegerRange> CONVERTER = new IntegerRangeConverter();

View File

@ -46,7 +46,7 @@ import org.jooq.postgres.extensions.types.LocalDateRange;
*
* @author Lukas Eder
*/
public class LocalDateRangeBinding extends AbstractRangeBinding<LocalDateRange> {
public class LocalDateRangeBinding extends AbstractPostgresVarcharBinding<LocalDateRange> {
private static final Converter<Object, LocalDateRange> CONVERTER = new LocalDateRangeConverter();

View File

@ -46,7 +46,7 @@ import org.jooq.postgres.extensions.types.LocalDateTimeRange;
*
* @author Lukas Eder
*/
public class LocalDateTimeRangeBinding extends AbstractRangeBinding<LocalDateTimeRange> {
public class LocalDateTimeRangeBinding extends AbstractPostgresVarcharBinding<LocalDateTimeRange> {
private static final Converter<Object, LocalDateTimeRange> CONVERTER = new LocalDateTimeRangeConverter();

View File

@ -46,7 +46,7 @@ import org.jooq.postgres.extensions.types.LongRange;
*
* @author Lukas Eder
*/
public class LongRangeBinding extends AbstractRangeBinding<LongRange> {
public class LongRangeBinding extends AbstractPostgresVarcharBinding<LongRange> {
private static final Converter<Object, LongRange> CONVERTER = new LongRangeConverter();

View File

@ -46,7 +46,7 @@ import org.jooq.postgres.extensions.types.OffsetDateTimeRange;
*
* @author Lukas Eder
*/
public class OffsetDateTimeRangeBinding extends AbstractRangeBinding<OffsetDateTimeRange> {
public class OffsetDateTimeRangeBinding extends AbstractPostgresVarcharBinding<OffsetDateTimeRange> {
private static final Converter<Object, OffsetDateTimeRange> CONVERTER = new OffsetDateTimeRangeConverter();

View File

@ -46,7 +46,7 @@ import org.jooq.postgres.extensions.types.TimestampRange;
*
* @author Lukas Eder
*/
public class TimestampRangeBinding extends AbstractRangeBinding<TimestampRange> {
public class TimestampRangeBinding extends AbstractPostgresVarcharBinding<TimestampRange> {
private static final Converter<Object, TimestampRange> CONVERTER = new TimestampRangeConverter();

View File

@ -37,6 +37,9 @@
*/
package org.jooq.postgres.extensions.types;
import static org.jooq.impl.DSL.lower;
import static org.jooq.impl.DSL.upper;
import java.util.Objects;
import org.jooq.exception.DataTypeException;