[jOOQ/jOOQ#2968] Support tsrange and tstzrange
This commit is contained in:
parent
29ced91a54
commit
4551d364f9
@ -2027,6 +2027,19 @@ public abstract class AbstractDatabase implements Database {
|
||||
.withIncludeTypes("_daterange")
|
||||
.withPriority(Integer.MIN_VALUE)
|
||||
);
|
||||
|
||||
getConfiguredForcedTypes().add(new ForcedType()
|
||||
.withUserType("org.jooq.postgres.extensions.types.LocalDateTimeRange")
|
||||
.withBinding("org.jooq.postgres.extensions.bindings.LocalDateTimeRangeBinding")
|
||||
.withIncludeTypes("tsrange")
|
||||
.withPriority(Integer.MIN_VALUE)
|
||||
);
|
||||
getConfiguredForcedTypes().add(new ForcedType()
|
||||
.withUserType("org.jooq.postgres.extensions.types.LocalDateTimeRange[]")
|
||||
.withBinding("org.jooq.postgres.extensions.bindings.LocalDateTimeRangeArrayBinding")
|
||||
.withIncludeTypes("_tsrange")
|
||||
.withPriority(Integer.MIN_VALUE)
|
||||
);
|
||||
}
|
||||
else {
|
||||
getConfiguredForcedTypes().add(new ForcedType()
|
||||
@ -2041,7 +2054,33 @@ public abstract class AbstractDatabase implements Database {
|
||||
.withIncludeTypes("_daterange")
|
||||
.withPriority(Integer.MIN_VALUE)
|
||||
);
|
||||
|
||||
getConfiguredForcedTypes().add(new ForcedType()
|
||||
.withUserType("org.jooq.postgres.extensions.types.TimestampRange")
|
||||
.withBinding("org.jooq.postgres.extensions.bindings.TimestampRangeBinding")
|
||||
.withIncludeTypes("tsrange")
|
||||
.withPriority(Integer.MIN_VALUE)
|
||||
);
|
||||
getConfiguredForcedTypes().add(new ForcedType()
|
||||
.withUserType("org.jooq.postgres.extensions.types.TimestampRange[]")
|
||||
.withBinding("org.jooq.postgres.extensions.bindings.TimestampRangeArrayBinding")
|
||||
.withIncludeTypes("_tsrange")
|
||||
.withPriority(Integer.MIN_VALUE)
|
||||
);
|
||||
}
|
||||
|
||||
getConfiguredForcedTypes().add(new ForcedType()
|
||||
.withUserType("org.jooq.postgres.extensions.types.OffsetDateTimeRange")
|
||||
.withBinding("org.jooq.postgres.extensions.bindings.OffsetDateTimeRangeBinding")
|
||||
.withIncludeTypes("tstzrange")
|
||||
.withPriority(Integer.MIN_VALUE)
|
||||
);
|
||||
getConfiguredForcedTypes().add(new ForcedType()
|
||||
.withUserType("org.jooq.postgres.extensions.types.OffsetDateTimeRange[]")
|
||||
.withBinding("org.jooq.postgres.extensions.bindings.OffsetDateTimeRangeArrayBinding")
|
||||
.withIncludeTypes("_tstzrange")
|
||||
.withPriority(Integer.MIN_VALUE)
|
||||
);
|
||||
}
|
||||
catch (ClassNotFoundException ignore) {
|
||||
log.debug("Built in data types", "org.jooq.postgres.extensions.types.Hstore not found on classpath, ignoring built in data type extensions");
|
||||
|
||||
@ -44,10 +44,7 @@ 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.InetConverter;
|
||||
import org.jooq.postgres.extensions.types.AbstractInet;
|
||||
import org.jooq.postgres.extensions.types.Inet;
|
||||
|
||||
/**
|
||||
* A binding for the PostgreSQL <code>inet</code> or <code>cidr</code> data
|
||||
|
||||
@ -39,17 +39,12 @@ package org.jooq.postgres.extensions.bindings;
|
||||
|
||||
import java.sql.Array;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.sql.Types;
|
||||
|
||||
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.impl.AbstractBinding;
|
||||
|
||||
/**
|
||||
* A common base class for bindings in this module.
|
||||
|
||||
@ -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.bindings;
|
||||
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.postgres.extensions.converters.LocalDateTimeRangeConverter;
|
||||
import org.jooq.postgres.extensions.types.LocalDateTimeRange;
|
||||
|
||||
/**
|
||||
* A binding for the PostgreSQL <code>tsrange[]</code> data type.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class LocalDateTimeRangeArrayBinding extends AbstractPostgresArrayBinding<LocalDateTimeRange> {
|
||||
|
||||
private static final Converter<Object[], LocalDateTimeRange[]> CONVERTER = new LocalDateTimeRangeConverter().forArrays();
|
||||
|
||||
@Override
|
||||
public Converter<Object[], LocalDateTimeRange[]> converter() {
|
||||
return CONVERTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String castType() {
|
||||
return "tsrange[]";
|
||||
}
|
||||
}
|
||||
@ -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.bindings;
|
||||
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.postgres.extensions.converters.LocalDateTimeRangeConverter;
|
||||
import org.jooq.postgres.extensions.types.LocalDateTimeRange;
|
||||
|
||||
/**
|
||||
* A binding for the PostgreSQL <code>tsrange</code> data type.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class LocalDateTimeRangeBinding extends AbstractRangeBinding<LocalDateTimeRange> {
|
||||
|
||||
private static final Converter<Object, LocalDateTimeRange> CONVERTER = new LocalDateTimeRangeConverter();
|
||||
|
||||
@Override
|
||||
public Converter<Object, LocalDateTimeRange> converter() {
|
||||
return CONVERTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String castType() {
|
||||
return "tsrange";
|
||||
}
|
||||
}
|
||||
@ -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.bindings;
|
||||
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.postgres.extensions.converters.OffsetDateTimeRangeConverter;
|
||||
import org.jooq.postgres.extensions.types.OffsetDateTimeRange;
|
||||
|
||||
/**
|
||||
* A binding for the PostgreSQL <code>tstzrange[]</code> data type.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class OffsetDateTimeRangeArrayBinding extends AbstractPostgresArrayBinding<OffsetDateTimeRange> {
|
||||
|
||||
private static final Converter<Object[], OffsetDateTimeRange[]> CONVERTER = new OffsetDateTimeRangeConverter().forArrays();
|
||||
|
||||
@Override
|
||||
public Converter<Object[], OffsetDateTimeRange[]> converter() {
|
||||
return CONVERTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String castType() {
|
||||
return "tstzrange[]";
|
||||
}
|
||||
}
|
||||
@ -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.bindings;
|
||||
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.postgres.extensions.converters.OffsetDateTimeRangeConverter;
|
||||
import org.jooq.postgres.extensions.types.OffsetDateTimeRange;
|
||||
|
||||
/**
|
||||
* A binding for the PostgreSQL <code>tstzrange</code> data type.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class OffsetDateTimeRangeBinding extends AbstractRangeBinding<OffsetDateTimeRange> {
|
||||
|
||||
private static final Converter<Object, OffsetDateTimeRange> CONVERTER = new OffsetDateTimeRangeConverter();
|
||||
|
||||
@Override
|
||||
public Converter<Object, OffsetDateTimeRange> converter() {
|
||||
return CONVERTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String castType() {
|
||||
return "tstzrange";
|
||||
}
|
||||
}
|
||||
@ -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.bindings;
|
||||
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.postgres.extensions.converters.TimestampRangeConverter;
|
||||
import org.jooq.postgres.extensions.types.TimestampRange;
|
||||
|
||||
/**
|
||||
* A binding for the PostgreSQL <code>tsrange[]</code> data type.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class TimestampRangeArrayBinding extends AbstractPostgresArrayBinding<TimestampRange> {
|
||||
|
||||
private static final Converter<Object[], TimestampRange[]> CONVERTER = new TimestampRangeConverter().forArrays();
|
||||
|
||||
@Override
|
||||
public Converter<Object[], TimestampRange[]> converter() {
|
||||
return CONVERTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String castType() {
|
||||
return "tsrange[]";
|
||||
}
|
||||
}
|
||||
@ -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.bindings;
|
||||
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.postgres.extensions.converters.TimestampRangeConverter;
|
||||
import org.jooq.postgres.extensions.types.TimestampRange;
|
||||
|
||||
/**
|
||||
* A binding for the PostgreSQL <code>tsrange</code> data type.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class TimestampRangeBinding extends AbstractRangeBinding<TimestampRange> {
|
||||
|
||||
private static final Converter<Object, TimestampRange> CONVERTER = new TimestampRangeConverter();
|
||||
|
||||
@Override
|
||||
public Converter<Object, TimestampRange> converter() {
|
||||
return CONVERTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String castType() {
|
||||
return "tsrange";
|
||||
}
|
||||
}
|
||||
@ -70,9 +70,13 @@ abstract class AbstractRangeConverter<X, U extends AbstractRange<X>> extends Abs
|
||||
String s1 = a[1];
|
||||
|
||||
String lower = s0.substring(1);
|
||||
if (lower.startsWith("\""))
|
||||
lower = lower.substring(1, lower.length() - 1);
|
||||
boolean lowerIncluding = s0.charAt(0) == '[';
|
||||
int l = s1.length() - 1;
|
||||
String upper = s1.substring(0, l);
|
||||
if (upper.startsWith("\""))
|
||||
upper = upper.substring(1, upper.length() - 1);
|
||||
boolean upperIncluding = s1.charAt(l) == ']';
|
||||
|
||||
return construct(
|
||||
|
||||
@ -38,17 +38,13 @@
|
||||
package org.jooq.postgres.extensions.converters;
|
||||
|
||||
import static org.jooq.postgres.extensions.types.DateRange.dateRange;
|
||||
import static org.jooq.postgres.extensions.types.LocalDateRange.localDateRange;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
|
||||
import org.jooq.postgres.extensions.types.DateRange;
|
||||
import org.jooq.postgres.extensions.types.IntegerRange;
|
||||
import org.jooq.postgres.extensions.types.LocalDateRange;
|
||||
|
||||
/**
|
||||
* A converter for {@link IntegerRange}.
|
||||
* A converter for {@link DateRange}.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
|
||||
@ -37,18 +37,14 @@
|
||||
*/
|
||||
package org.jooq.postgres.extensions.converters;
|
||||
|
||||
import static org.jooq.postgres.extensions.types.DateRange.dateRange;
|
||||
import static org.jooq.postgres.extensions.types.LocalDateRange.localDateRange;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
|
||||
import org.jooq.postgres.extensions.types.DateRange;
|
||||
import org.jooq.postgres.extensions.types.IntegerRange;
|
||||
import org.jooq.postgres.extensions.types.LocalDateRange;
|
||||
|
||||
/**
|
||||
* A converter for {@link IntegerRange}.
|
||||
* A converter for {@link LocalDateRange}.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
|
||||
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 static org.jooq.postgres.extensions.types.LocalDateTimeRange.localDateTimeRange;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.impl.DefaultConverterProvider;
|
||||
import org.jooq.postgres.extensions.types.LocalDateTimeRange;
|
||||
|
||||
/**
|
||||
* A converter for {@link LocalDateTimeRange}.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class LocalDateTimeRangeConverter extends AbstractRangeConverter<LocalDateTime, LocalDateTimeRange> {
|
||||
|
||||
private static final LocalDateTime EPOCH = LocalDateTime.parse("1970-01-01T00:00:00");
|
||||
private static final LocalDateTimeRange EMPTY = localDateTimeRange(EPOCH, EPOCH);
|
||||
private static final Converter<String, LocalDateTime> CONVERTER = new DefaultConverterProvider().provide(String.class, LocalDateTime.class);
|
||||
|
||||
public LocalDateTimeRangeConverter() {
|
||||
super(LocalDateTimeRange.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
final LocalDateTimeRange construct(String lower, boolean lowerIncluding, String upper, boolean upperIncluding) {
|
||||
return localDateTimeRange(
|
||||
CONVERTER.from(lower),
|
||||
lowerIncluding,
|
||||
CONVERTER.from(upper),
|
||||
upperIncluding
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
final LocalDateTimeRange empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
}
|
||||
@ -37,14 +37,12 @@
|
||||
*/
|
||||
package org.jooq.postgres.extensions.converters;
|
||||
|
||||
import static org.jooq.postgres.extensions.types.IntegerRange.integerRange;
|
||||
import static org.jooq.postgres.extensions.types.LongRange.longRange;
|
||||
|
||||
import org.jooq.postgres.extensions.types.IntegerRange;
|
||||
import org.jooq.postgres.extensions.types.LongRange;
|
||||
|
||||
/**
|
||||
* A converter for {@link IntegerRange}.
|
||||
* A converter for {@link LongRange}.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
|
||||
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 static org.jooq.postgres.extensions.types.OffsetDateTimeRange.offsetDateTimeRange;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.impl.DefaultConverterProvider;
|
||||
import org.jooq.postgres.extensions.types.OffsetDateTimeRange;
|
||||
|
||||
/**
|
||||
* A converter for {@link OffsetDateTimeRange}.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class OffsetDateTimeRangeConverter extends AbstractRangeConverter<OffsetDateTime, OffsetDateTimeRange> {
|
||||
|
||||
private static final OffsetDateTime EPOCH = OffsetDateTime.parse("1970-01-01T00:00:00Z");
|
||||
private static final OffsetDateTimeRange EMPTY = offsetDateTimeRange(EPOCH, EPOCH);
|
||||
private static final Converter<String, OffsetDateTime> CONVERTER = new DefaultConverterProvider().provide(String.class, OffsetDateTime.class);
|
||||
|
||||
public OffsetDateTimeRangeConverter() {
|
||||
super(OffsetDateTimeRange.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
final OffsetDateTimeRange construct(String lower, boolean lowerIncluding, String upper, boolean upperIncluding) {
|
||||
return offsetDateTimeRange(
|
||||
CONVERTER.from(lower),
|
||||
lowerIncluding,
|
||||
CONVERTER.from(upper),
|
||||
upperIncluding
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
final OffsetDateTimeRange empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 static org.jooq.postgres.extensions.types.TimestampRange.timestampRange;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.impl.DefaultConverterProvider;
|
||||
import org.jooq.postgres.extensions.types.TimestampRange;
|
||||
|
||||
/**
|
||||
* A converter for {@link TimestampRange}.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class TimestampRangeConverter extends AbstractRangeConverter<Timestamp, TimestampRange> {
|
||||
|
||||
private static final Timestamp EPOCH = Timestamp.valueOf("1970-01-01 00:00:00");
|
||||
private static final TimestampRange EMPTY = timestampRange(EPOCH, EPOCH);
|
||||
private static final Converter<String, Timestamp> CONVERTER = new DefaultConverterProvider().provide(String.class, Timestamp.class);
|
||||
|
||||
public TimestampRangeConverter() {
|
||||
super(TimestampRange.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
final TimestampRange construct(String lower, boolean lowerIncluding, String upper, boolean upperIncluding) {
|
||||
return timestampRange(
|
||||
CONVERTER.from(lower),
|
||||
lowerIncluding,
|
||||
CONVERTER.from(upper),
|
||||
upperIncluding
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
final TimestampRange empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
}
|
||||
@ -72,7 +72,8 @@ abstract class AbstractDiscreteRange<T, R extends AbstractDiscreteRange<T, R>> e
|
||||
abstract R construct(T lower, T upper);
|
||||
|
||||
final boolean isCanonical() {
|
||||
return lowerIncluding() && !upperIncluding();
|
||||
return (lower() == null || lowerIncluding())
|
||||
&& (upper() == null || !upperIncluding());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@ -50,15 +50,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
public abstract class AbstractRange<T> implements Serializable {
|
||||
|
||||
private final T lower;
|
||||
private final boolean lowerIncluding;
|
||||
private final T upper;
|
||||
private final boolean lowerIncluding;
|
||||
private final boolean upperIncluding;
|
||||
|
||||
AbstractRange(T lower, boolean lowerIncluding, T upper, boolean upperIncluding) {
|
||||
this.lower = lower;
|
||||
this.lowerIncluding = lowerIncluding;
|
||||
this.upper = upper;
|
||||
this.upperIncluding = upperIncluding;
|
||||
|
||||
// In PostgreSQL, there is no [,] range, only (,)
|
||||
this.lowerIncluding = lower != null && lowerIncluding;
|
||||
this.upperIncluding = upper != null && upperIncluding;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.types;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* A data type representing the PostgreSQL <code>tsrange</code> type.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public final class LocalDateTimeRange extends AbstractRange<LocalDateTime> {
|
||||
|
||||
private LocalDateTimeRange(LocalDateTime lower, boolean lowerIncluding, LocalDateTime upper, boolean upperIncluding) {
|
||||
super(lower, lowerIncluding, upper, upperIncluding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link LocalDateTimeRange} with a inclusive lower bound and an
|
||||
* exclusive upper bound.
|
||||
*/
|
||||
public static final LocalDateTimeRange localDateTimeRange(LocalDateTime lower, LocalDateTime upper) {
|
||||
return new LocalDateTimeRange(lower, true, upper, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link LocalDateTimeRange}.
|
||||
*/
|
||||
public static final LocalDateTimeRange localDateTimeRange(LocalDateTime lower, boolean lowerIncluding, LocalDateTime upper, boolean upperIncluding) {
|
||||
return new LocalDateTimeRange(lower, lowerIncluding, upper, upperIncluding);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.types;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
/**
|
||||
* A data type representing the PostgreSQL <code>tsrange</code> type.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public final class OffsetDateTimeRange extends AbstractRange<OffsetDateTime> {
|
||||
|
||||
private OffsetDateTimeRange(OffsetDateTime lower, boolean lowerIncluding, OffsetDateTime upper, boolean upperIncluding) {
|
||||
super(lower, lowerIncluding, upper, upperIncluding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link OffsetDateTimeRange} with a inclusive lower bound and an
|
||||
* exclusive upper bound.
|
||||
*/
|
||||
public static final OffsetDateTimeRange offsetDateTimeRange(OffsetDateTime lower, OffsetDateTime upper) {
|
||||
return new OffsetDateTimeRange(lower, true, upper, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link OffsetDateTimeRange}.
|
||||
*/
|
||||
public static final OffsetDateTimeRange offsetDateTimeRange(OffsetDateTime lower, boolean lowerIncluding, OffsetDateTime upper, boolean upperIncluding) {
|
||||
return new OffsetDateTimeRange(lower, lowerIncluding, upper, upperIncluding);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.types;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* A data type representing the PostgreSQL <code>tsrange</code> type.
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public final class TimestampRange extends AbstractRange<Timestamp> {
|
||||
|
||||
private TimestampRange(Timestamp lower, boolean lowerIncluding, Timestamp upper, boolean upperIncluding) {
|
||||
super(lower, lowerIncluding, upper, upperIncluding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link TimestampRange} with a inclusive lower bound and an
|
||||
* exclusive upper bound.
|
||||
*/
|
||||
public static final TimestampRange timestampRange(Timestamp lower, Timestamp upper) {
|
||||
return new TimestampRange(lower, true, upper, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link TimestampRange}.
|
||||
*/
|
||||
public static final TimestampRange timestampRange(Timestamp lower, boolean lowerIncluding, Timestamp upper, boolean upperIncluding) {
|
||||
return new TimestampRange(lower, lowerIncluding, upper, upperIncluding);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user