Remove support for Joda Time and ThreeTenBackport.

See #1170.
This commit is contained in:
John Blum
2021-09-20 20:02:54 -07:00
committed by Mark Paluch
parent 03c4ef9553
commit 967f67449e
14 changed files with 86 additions and 1005 deletions

14
pom.xml
View File

@@ -129,20 +129,6 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${jodatime}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>${threetenbp}</version>
<optional>true</optional>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>org.apache.cassandra</groupId>

View File

@@ -61,18 +61,6 @@
<version>${springdata.commons}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<optional>true</optional>
</dependency>
<!-- Cassandra driver -->
<dependency>
<groupId>com.datastax.oss</groupId>

View File

@@ -47,9 +47,7 @@ public class CassandraCustomConversions extends org.springframework.data.convert
List<Object> converters = new ArrayList<>();
converters.addAll(CassandraConverters.getConvertersToRegister());
converters.addAll(CassandraJodaTimeConverters.getConvertersToRegister());
converters.addAll(CassandraJsr310Converters.getConvertersToRegister());
converters.addAll(CassandraThreeTenBackPortConverters.getConvertersToRegister());
STORE_CONVERTERS = Collections.unmodifiableList(converters);
STORE_CONVERSIONS = StoreConversions.of(CassandraSimpleTypeHolder.HOLDER, STORE_CONVERTERS);

View File

@@ -1,242 +0,0 @@
/*
* Copyright 2016-2021 the original author or authors.
*
* 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
*
* https://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.
*/
package org.springframework.data.cassandra.core.convert;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.joda.time.LocalTime;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.WritingConverter;
import org.springframework.util.ClassUtils;
/**
* Helper class to register JSR-310 specific {@link Converter} implementations to convert between Cassandra types in
* case the library is present on the classpath.
*
* @author Mark Paluch
* @since 1.5
* @deprecated since 3.0, use JSR-310 types as replacement for Joda-Time.
*/
@Deprecated
public abstract class CassandraJodaTimeConverters {
private static final boolean JODA_TIME_IS_PRESENT = ClassUtils.isPresent("org.joda.time.LocalDate", null);
private CassandraJodaTimeConverters() {}
/**
* Returns the converters to be registered. Will only return converters in case JodaTime is present on the class path.
*
* @return a {@link Collection} of Joda Time {@link Converter Converters} to register.
* @see org.springframework.core.convert.converter.Converter
* @see java.util.Collection
*/
public static Collection<Converter<?, ?>> getConvertersToRegister() {
if (!JODA_TIME_IS_PRESENT) {
return Collections.emptySet();
}
List<Converter<?, ?>> converters = new ArrayList<>();
converters.add(MillisOfDayToLocalTimeConverter.INSTANCE);
converters.add(FromJodaLocalTimeConverter.INSTANCE);
converters.add(ToJodaLocalTimeConverter.INSTANCE);
converters.add(FromJodaLocalDateConverter.INSTANCE);
converters.add(ToJodaLocalDateConverter.INSTANCE);
converters.add(LocalDateTimeToInstantConverter.INSTANCE);
converters.add(InstantToLocalDateTimeConverter.INSTANCE);
converters.add(DateTimeToInstantConverter.INSTANCE);
converters.add(InstantToDateTimeConverter.INSTANCE);
return converters;
}
/**
* Simple singleton to convert {@link Long}s to their {@link LocalTime} representation.
*
* @author Mark Paluch
*/
@Deprecated
public enum MillisOfDayToLocalTimeConverter implements Converter<Long, LocalTime> {
INSTANCE;
@Override
public LocalTime convert(Long source) {
return LocalTime.fromMillisOfDay(source);
}
}
/**
* Simple singleton to convert {@link LocalTime}s to their {@link Long} representation.
*
* @author Mark Paluch
*/
@Deprecated
public enum LocalTimeToMillisOfDayConverter implements Converter<LocalTime, Long> {
INSTANCE;
@Override
public Long convert(LocalTime source) {
return (long) source.getMillisOfDay();
}
}
/**
* Simple singleton to convert {@link LocalTime}s to their {@link java.time.LocalTime} representation.
*
* @author Mark Paluch
*/
@WritingConverter
@Deprecated
public enum FromJodaLocalTimeConverter implements Converter<LocalTime, java.time.LocalTime> {
INSTANCE;
@Override
public java.time.LocalTime convert(LocalTime source) {
return java.time.LocalTime.ofNanoOfDay(TimeUnit.MILLISECONDS.toNanos(source.getMillisOfDay()));
}
}
/**
* Simple singleton to convert {@link java.time.LocalTime}s to their {@link LocalTime} representation.
*
* @author Mark Paluch
*/
@Deprecated
public enum ToJodaLocalTimeConverter implements Converter<java.time.LocalTime, LocalTime> {
INSTANCE;
@Override
public LocalTime convert(java.time.LocalTime source) {
return LocalTime.fromMillisOfDay(TimeUnit.NANOSECONDS.toMillis(source.toNanoOfDay()));
}
}
/**
* Simple singleton to convert {@link LocalTime}s to their {@link java.time.LocalDate} representation.
*
* @author Mark Paluch
*/
@WritingConverter
@Deprecated
public enum FromJodaLocalDateConverter implements Converter<LocalDate, java.time.LocalDate> {
INSTANCE;
@Override
public java.time.LocalDate convert(LocalDate date) {
return java.time.LocalDate.of(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
}
}
/**
* Simple singleton to convert {@link java.time.LocalTime}s to their {@link LocalDate} representation.
*
* @author Mark Paluch
*/
@Deprecated
public enum ToJodaLocalDateConverter implements Converter<java.time.LocalDate, LocalDate> {
INSTANCE;
@Override
public LocalDate convert(java.time.LocalDate date) {
return new LocalDate(date.getYear(), date.getMonthValue(), date.getDayOfMonth());
}
}
/**
* Simple singleton to convert {@link LocalDateTime}s to their {@link java.time.Instant} representation.
*
* @since 3.0
*/
@Deprecated
public enum LocalDateTimeToInstantConverter implements Converter<LocalDateTime, java.time.Instant> {
INSTANCE;
@Override
public java.time.Instant convert(LocalDateTime source) {
return source.toDate().toInstant();
}
}
/**
* Simple singleton to convert {@link java.time.Instant}s to their {@link LocalDateTime} representation.
*
* @since 3.0
*/
@Deprecated
public enum InstantToLocalDateTimeConverter implements Converter<java.time.Instant, LocalDateTime> {
INSTANCE;
@Override
public LocalDateTime convert(java.time.Instant source) {
return new LocalDateTime(Date.from(source));
}
}
/**
* Simple singleton to convert {@link DateTime}s to their {@link java.time.Instant} representation.
*
* @since 3.0
*/
@Deprecated
public enum DateTimeToInstantConverter implements Converter<DateTime, java.time.Instant> {
INSTANCE;
@Override
public java.time.Instant convert(DateTime source) {
return source.toDate().toInstant();
}
}
/**
* Simple singleton to convert {@link java.time.Instant}s to their {@link DateTime} representation.
*
* @since 3.0
*/
@Deprecated
public enum InstantToDateTimeConverter implements Converter<java.time.Instant, DateTime> {
INSTANCE;
@Override
public DateTime convert(java.time.Instant source) {
return new DateTime(Date.from(source));
}
}
}

View File

@@ -1,307 +0,0 @@
/*
* Copyright 2016-2021 the original author or authors.
*
* 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
*
* https://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.
*/
package org.springframework.data.cassandra.core.convert;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.ThreeTenBackPortConverters;
import org.springframework.data.convert.WritingConverter;
import org.springframework.util.ClassUtils;
import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalDateTime;
import org.threeten.bp.LocalTime;
import org.threeten.bp.ZoneId;
import org.threeten.bp.temporal.ChronoField;
/**
* Helper class to register {@link Converter} implementations for the ThreeTen Backport project in case it's present on
* the classpath.
*
* @author Mark Paluch
* @see <a href="https://www.threeten.org/threetenbp">Threeten Backport</a>
* @since 1.5
* @deprecated since 3.0, use JSR-310 types as replacement for ThreeTen Backport.
*/
@Deprecated
public abstract class CassandraThreeTenBackPortConverters {
private static final boolean THREE_TEN_BACK_PORT_IS_PRESENT = ClassUtils.isPresent("org.threeten.bp.LocalDateTime",
ThreeTenBackPortConverters.class.getClassLoader());
private CassandraThreeTenBackPortConverters() {}
/**
* Returns the converters to be registered. Will only return converters in case ThreeTen Backport is on the class
* path.
*
* @return a {@link Collection} of ThreeTen Backport {@link Converter Converters} to register.
* @see org.springframework.core.convert.converter.Converter
* @see java.util.Collection
*/
public static Collection<Converter<?, ?>> getConvertersToRegister() {
if (!THREE_TEN_BACK_PORT_IS_PRESENT) {
return Collections.emptySet();
}
List<Converter<?, ?>> converters = new ArrayList<>();
converters.add(MillisOfDayToLocalTimeConverter.INSTANCE);
converters.add(LocalTimeToMillisOfDayConverter.INSTANCE);
converters.add(FromBpLocalTimeConverter.INSTANCE);
converters.add(ToBpLocalTimeConverter.INSTANCE);
converters.add(FromBpLocalDateConverter.INSTANCE);
converters.add(ToBpLocalDateConverter.INSTANCE);
converters.add(FromBpLocalDateTimeConverter.INSTANCE);
converters.add(ToBpLocalDateTimeConverter.INSTANCE);
converters.add(LocalDateTimeToInstantConverter.INSTANCE);
converters.add(BpInstantToInstantConverter.INSTANCE);
converters.add(InstantToBpInstantConverter.INSTANCE);
converters.add(ZoneIdToStringConverter.INSTANCE);
converters.add(StringToZoneIdConverter.INSTANCE);
return converters;
}
/**
* Simple singleton to convert {@link Long}s to their {@link LocalTime} representation.
*
* @author Mark Paluch
* @since 2.1
*/
@Deprecated
public enum MillisOfDayToLocalTimeConverter implements Converter<Long, LocalTime> {
INSTANCE;
@Override
public LocalTime convert(Long source) {
return LocalTime.ofNanoOfDay(TimeUnit.MILLISECONDS.toNanos(source));
}
}
/**
* Simple singleton to convert {@link LocalTime}s to their {@link Long} representation.
*
* @author Mark Paluch
* @since 2.1
*/
@ReadingConverter
@Deprecated
public enum LocalTimeToMillisOfDayConverter implements Converter<LocalTime, Long> {
INSTANCE;
@Override
public Long convert(LocalTime source) {
return source.getLong(ChronoField.MILLI_OF_DAY);
}
}
/**
* Simple singleton to convert {@link LocalTime}s to their {@link java.time.LocalTime} representation.
*
* @since 3.0
*/
@WritingConverter
@Deprecated
public enum FromBpLocalTimeConverter implements Converter<LocalTime, java.time.LocalTime> {
INSTANCE;
@Override
public java.time.LocalTime convert(LocalTime source) {
return java.time.LocalTime.ofNanoOfDay(source.toNanoOfDay());
}
}
/**
* Simple singleton to convert {@link java.time.LocalTime}s to their {@link LocalTime} representation.
*
* @since 3.0
*/
@Deprecated
public enum ToBpLocalTimeConverter implements Converter<java.time.LocalTime, LocalTime> {
INSTANCE;
@Override
public LocalTime convert(java.time.LocalTime source) {
return LocalTime.ofNanoOfDay(source.toNanoOfDay());
}
}
/**
* Simple singleton to convert {@link LocalTime}s to their {@link java.time.LocalDate} representation.
*
* @since 3.0
*/
@WritingConverter
@Deprecated
public enum FromBpLocalDateConverter implements Converter<LocalDate, java.time.LocalDate> {
INSTANCE;
@Override
public java.time.LocalDate convert(LocalDate date) {
return java.time.LocalDate.of(date.getYear(), date.getMonthValue(), date.getDayOfMonth());
}
}
/**
* Simple singleton to convert {@link java.time.LocalTime}s to their {@link LocalDate} representation.
*
* @since 3.0
*/
@Deprecated
public enum ToBpLocalDateConverter implements Converter<java.time.LocalDate, LocalDate> {
INSTANCE;
@Override
public LocalDate convert(java.time.LocalDate date) {
return LocalDate.of(date.getYear(), date.getMonthValue(), date.getDayOfMonth());
}
}
/**
* Simple singleton to convert {@link LocalDateTime}s to their {@link java.time.LocalDateTime} representation.
*
* @since 3.0
*/
@ReadingConverter
@Deprecated
public enum FromBpLocalDateTimeConverter implements Converter<LocalDateTime, java.time.LocalDateTime> {
INSTANCE;
@Override
public java.time.LocalDateTime convert(LocalDateTime date) {
return java.time.LocalDateTime.of(date.getYear(), date.getMonthValue(), date.getDayOfMonth(), date.getHour(),
date.getMinute(), date.getSecond(), date.getNano());
}
}
/**
* Simple singleton to convert {@link java.time.LocalDateTime}s to their {@link LocalDateTime} representation.
*
* @since 3.0
*/
@Deprecated
public enum ToBpLocalDateTimeConverter implements Converter<java.time.LocalDateTime, LocalDateTime> {
INSTANCE;
@Override
public LocalDateTime convert(java.time.LocalDateTime date) {
return LocalDateTime.of(date.getYear(), date.getMonthValue(), date.getDayOfMonth(), date.getHour(),
date.getMinute(), date.getSecond(), date.getNano());
}
}
/**
* Convert {@link LocalDateTime} to {@link Instant}.
*
* @since 3.0
*/
@Deprecated
enum LocalDateTimeToInstantConverter implements Converter<LocalDateTime, java.time.Instant> {
INSTANCE;
@Override
public java.time.Instant convert(LocalDateTime source) {
return Instant.ofEpochMilli(source.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
}
}
/**
* Convert {@link org.threeten.bp.Instant} to {@link java.time.Instant}.
*
* @since 3.0
*/
@Deprecated
enum BpInstantToInstantConverter implements Converter<org.threeten.bp.Instant, java.time.Instant> {
INSTANCE;
@Override
public java.time.Instant convert(org.threeten.bp.Instant source) {
return Instant.ofEpochMilli(source.toEpochMilli());
}
}
/**
* Convert {@link java.time.Instant} to {@link org.threeten.bp.Instant}.
*
* @since 3.0
*/
@Deprecated
enum InstantToBpInstantConverter implements Converter<java.time.Instant, org.threeten.bp.Instant> {
INSTANCE;
@Override
public org.threeten.bp.Instant convert(java.time.Instant source) {
return org.threeten.bp.Instant.ofEpochMilli(source.toEpochMilli());
}
}
/**
* Convert {@link ZoneId} to {@link String}.
*
* @since 3.0
*/
@Deprecated
enum ZoneIdToStringConverter implements Converter<ZoneId, String> {
INSTANCE;
@Override
public String convert(ZoneId source) {
return source.toString();
}
}
/**
* Convert {@link String} to {@link ZoneId}.
*
* @since 3.0
*/
@Deprecated
enum StringToZoneIdConverter implements Converter<String, ZoneId> {
INSTANCE;
@Override
public ZoneId convert(String source) {
return ZoneId.of(source);
}
}
}

View File

@@ -1,47 +0,0 @@
/*
* Copyright 2018-2021 the original author or authors.
*
* 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
*
* https://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.
*/
package org.springframework.data.cassandra.core.convert;
import static org.assertj.core.api.Assertions.*;
import org.joda.time.LocalTime;
import org.junit.jupiter.api.Test;
import org.springframework.data.cassandra.core.convert.CassandraJodaTimeConverters.LocalTimeToMillisOfDayConverter;
import org.springframework.data.cassandra.core.convert.CassandraJodaTimeConverters.MillisOfDayToLocalTimeConverter;
/**
* Unit tests for {@link CassandraJodaTimeConverters}.
*
* @author Mark Paluch
*/
class CassandraJodaTimeConvertersUnitTests {
@Test // DATACASS-302
void shouldConvertLongToLocalTime() {
assertThat(MillisOfDayToLocalTimeConverter.INSTANCE.convert(3723000L))
.isEqualTo(LocalTime.fromMillisOfDay(3723000L));
}
@Test // DATACASS-302
void shouldConvertLocalTimeToLong() {
assertThat(LocalTimeToMillisOfDayConverter.INSTANCE.convert(LocalTime.MIDNIGHT)).isZero();
assertThat(LocalTimeToMillisOfDayConverter.INSTANCE.convert(LocalTime.fromMillisOfDay(3723000L)))
.isEqualTo(3723000L);
}
}

View File

@@ -1,48 +0,0 @@
/*
* Copyright 2018-2021 the original author or authors.
*
* 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
*
* https://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.
*/
package org.springframework.data.cassandra.core.convert;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.springframework.data.cassandra.core.convert.CassandraThreeTenBackPortConverters.LocalTimeToMillisOfDayConverter;
import org.springframework.data.cassandra.core.convert.CassandraThreeTenBackPortConverters.MillisOfDayToLocalTimeConverter;
import org.threeten.bp.LocalTime;
/**
* Unit tests for {@link CassandraThreeTenBackPortConverters}.
*
* @author Mark Paluch
*/
class CassandraThreeTenBackPortConvertersUnitTests {
@Test // DATACASS-302
void shouldConvertLongToLocalTime() {
assertThat(MillisOfDayToLocalTimeConverter.INSTANCE.convert(3723000L))
.isEqualTo(LocalTime.of(1, 2, 3));
}
@Test // DATACASS-302
void shouldConvertLocalTimeToLong() {
assertThat(LocalTimeToMillisOfDayConverter.INSTANCE.convert(LocalTime.MIDNIGHT)).isZero();
assertThat(LocalTimeToMillisOfDayConverter.INSTANCE.convert(LocalTime.of(1, 2, 3)))
.isEqualTo(3723000L);
}
}

View File

@@ -15,12 +15,8 @@
*/
package org.springframework.data.cassandra.core.convert;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -59,6 +55,10 @@ import com.datastax.oss.driver.api.core.data.TupleValue;
import com.datastax.oss.driver.api.core.type.DataTypes;
import com.datastax.oss.driver.api.core.type.TupleType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Integration tests for type mapping using {@link CassandraOperations}.
*
@@ -589,22 +589,6 @@ public class CassandraTypeMappingIntegrationTests extends AbstractKeyspaceCreati
assertThat(entity.getTime()).isEqualTo(LocalTime.of(1, 2, 3, 0));
}
@Test // DATACASS-296, DATACASS-563
void shouldReadAndWriteJodaLocalTime() {
assumeTrue(cassandraVersion.isGreaterThanOrEqualTo(VERSION_3_10));
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setJodaLocalTime(org.joda.time.LocalTime.fromMillisOfDay(50000));
operations.insert(entity);
AllPossibleTypes loaded = load(entity);
assertThat(loaded.getJodaLocalTime()).isEqualTo(entity.getJodaLocalTime());
}
@Test // DATACASS-296
void shouldReadAndWriteInstant() {
@@ -634,106 +618,6 @@ public class CassandraTypeMappingIntegrationTests extends AbstractKeyspaceCreati
assertThat(loaded.getZoneId()).isEqualTo(entity.getZoneId());
}
@Test // DATACASS-296
void shouldReadAndWriteJodaLocalDate() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setJodaLocalDate(new org.joda.time.LocalDate(2010, 7, 4));
operations.insert(entity);
AllPossibleTypes loaded = load(entity);
assertThat(loaded.getJodaLocalDate()).isEqualTo(entity.getJodaLocalDate());
}
@Test // DATACASS-296, DATACASS-727
void shouldReadAndWriteJodaDateTime() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setJodaDateTime(new org.joda.time.DateTime(2010, 7, 4, 1, 2, 3));
operations.insert(entity);
AllPossibleTypes loaded = load(entity);
assertThat(loaded.getJodaDateTime()).isEqualTo(entity.getJodaDateTime());
}
@Test // DATACASS-296
void shouldReadAndWriteBpLocalDate() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setBpLocalDate(org.threeten.bp.LocalDate.of(2010, 7, 4));
operations.insert(entity);
AllPossibleTypes loaded = load(entity);
assertThat(loaded.getBpLocalDate()).isEqualTo(entity.getBpLocalDate());
}
@Test // DATACASS-296
void shouldReadAndWriteBpLocalDateTime() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setBpLocalDateTime(org.threeten.bp.LocalDateTime.of(2010, 7, 4, 1, 2, 3));
operations.insert(entity);
AllPossibleTypes loaded = load(entity);
assertThat(loaded.getBpLocalDateTime()).isEqualTo(entity.getBpLocalDateTime());
}
@Test // DATACASS-296, DATACASS-563
void shouldReadAndWriteBpLocalTime() {
assumeTrue(cassandraVersion.isGreaterThanOrEqualTo(VERSION_3_10));
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setBpLocalTime(org.threeten.bp.LocalTime.of(1, 2, 3));
operations.insert(entity);
AllPossibleTypes loaded = load(entity);
assertThat(loaded.getBpLocalTime()).isEqualTo(entity.getBpLocalTime());
}
@Test // DATACASS-296, DATACASS-727
void shouldReadAndWriteBpInstant() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setBpInstant(org.threeten.bp.Instant.now());
operations.insert(entity);
AllPossibleTypes loaded = load(entity);
assertThat(loaded.getBpInstant()).isEqualTo(entity.getBpInstant());
}
@Test // DATACASS-296
void shouldReadAndWriteBpZoneId() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setBpZoneId(org.threeten.bp.ZoneId.of("Europe/Paris"));
operations.insert(entity);
AllPossibleTypes loaded = load(entity);
assertThat(loaded.getBpZoneId()).isEqualTo(entity.getBpZoneId());
}
@Test // DATACASS-429, DATACASS-727
void shouldReadAndWriteDuration() {

View File

@@ -15,16 +15,10 @@
*/
package org.springframework.data.cassandra.core.convert;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.cassandra.core.mapping.BasicMapId.*;
import static org.springframework.data.cassandra.test.util.RowMockUtil.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.springframework.data.cassandra.core.mapping.BasicMapId.id;
import static org.springframework.data.cassandra.test.util.RowMockUtil.column;
import java.io.Serializable;
import java.math.BigDecimal;
@@ -34,10 +28,20 @@ import java.net.UnknownHostException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@@ -51,8 +55,18 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.ReadOnlyProperty;
import org.springframework.data.annotation.Transient;
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.data.cassandra.core.mapping.*;
import org.springframework.data.cassandra.core.mapping.BasicMapId;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraType;
import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.Element;
import org.springframework.data.cassandra.core.mapping.Embedded;
import org.springframework.data.cassandra.core.mapping.MapId;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyClass;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.core.mapping.Table;
import org.springframework.data.cassandra.core.mapping.Tuple;
import org.springframework.data.cassandra.domain.AllPossibleTypes;
import org.springframework.data.cassandra.domain.CompositeKey;
import org.springframework.data.cassandra.domain.TypeWithCompositeKey;
@@ -71,6 +85,13 @@ import com.datastax.oss.driver.api.core.type.DataTypes;
import com.datastax.oss.driver.internal.core.data.DefaultTupleValue;
import com.datastax.oss.driver.internal.core.type.DefaultTupleType;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
/**
* Unit tests for {@link MappingCassandraConverter}.
*
@@ -347,37 +368,6 @@ public class MappingCassandraConverterUnitTests {
assertThat(insert.get(CqlIdentifier.fromCql("timestamp"))).isInstanceOf(Instant.class);
}
@Test // DATACASS-656, DATACASS-727
void shouldReadAndWriteTimestampFromObjectWithConversion() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setInstant(Instant.now());
entity.setTimestamp(new Date(1));
entity.setJodaDateTime(new org.joda.time.DateTime(2010, 7, 4, 1, 2, 3));
entity.setBpInstant(org.threeten.bp.Instant.now());
Map<CqlIdentifier, Object> insert = new LinkedHashMap<>();
mappingCassandraConverter.write(entity, insert);
assertThat(insert.get(CqlIdentifier.fromCql("jodadatetime"))).isInstanceOf(Instant.class);
assertThat(insert.get(CqlIdentifier.fromCql("bpinstant"))).isInstanceOf(Instant.class);
}
@Test // DATACASS-656
void shouldReadAndWriteTimeFromObjectWithConversion() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setJodaLocalTime(org.joda.time.LocalTime.fromMillisOfDay(50000));
Map<CqlIdentifier, Object> insert = new LinkedHashMap<>();
mappingCassandraConverter.write(entity, insert);
assertThat(insert.get(CqlIdentifier.fromCql("jodalocaltime"))).isInstanceOf(LocalTime.class);
}
@Test // DATACASS-271
void shouldReadDateCorrectly() {
@@ -568,88 +558,6 @@ public class MappingCassandraConverterUnitTests {
assertThat(result.zoneId.getId()).isEqualTo("Europe/Paris");
}
@Test // DATACASS-296
void shouldReadJodaLocalDateTimeUsingCassandraDateCorrectly() {
rowMock = RowMockUtil.newRowMock(column("id", "my-id", DataTypes.ASCII),
column("localDate", LocalDate.of(2010, 7, 4), DataTypes.DATE));
TypeWithJodaLocalDateMappedToDate result = mappingCassandraConverter
.readRow(TypeWithJodaLocalDateMappedToDate.class, rowMock);
assertThat(result.localDate).isNotNull();
assertThat(result.localDate.getYear()).isEqualTo(2010);
assertThat(result.localDate.getMonthOfYear()).isEqualTo(7);
assertThat(result.localDate.getDayOfMonth()).isEqualTo(4);
}
@Test // DATACASS-296
void shouldCreateInsertWithJodaLocalDateUsingCassandraDateCorrectly() {
TypeWithJodaLocalDateMappedToDate typeWithLocalDate = new TypeWithJodaLocalDateMappedToDate();
typeWithLocalDate.localDate = new org.joda.time.LocalDate(2010, 7, 4);
Map<CqlIdentifier, Object> insert = new LinkedHashMap<>();
mappingCassandraConverter.write(typeWithLocalDate, insert);
assertThat(getValues(insert)).contains(LocalDate.of(2010, 7, 4));
}
@Test // DATACASS-296
void shouldCreateUpdateWithJodaLocalDateUsingCassandraDateCorrectly() {
TypeWithJodaLocalDateMappedToDate typeWithLocalDate = new TypeWithJodaLocalDateMappedToDate();
typeWithLocalDate.localDate = new org.joda.time.LocalDate(2010, 7, 4);
Map<CqlIdentifier, Object> update = new LinkedHashMap<>();
mappingCassandraConverter.write(typeWithLocalDate, update);
assertThat(getValues(update)).contains(LocalDate.of(2010, 7, 4));
}
@Test // DATACASS-296
void shouldReadThreeTenBpLocalDateTimeUsingCassandraDateCorrectly() {
rowMock = RowMockUtil.newRowMock(column("id", "my-id", DataTypes.ASCII),
column("localDate", LocalDate.of(2010, 7, 4), DataTypes.DATE));
TypeWithThreeTenBpLocalDateMappedToDate result = mappingCassandraConverter
.readRow(TypeWithThreeTenBpLocalDateMappedToDate.class, rowMock);
assertThat(result.localDate).isNotNull();
assertThat(result.localDate.getYear()).isEqualTo(2010);
assertThat(result.localDate.getMonthValue()).isEqualTo(7);
assertThat(result.localDate.getDayOfMonth()).isEqualTo(4);
}
@Test // DATACASS-296
void shouldCreateInsertWithThreeTenBpLocalDateUsingCassandraDateCorrectly() {
TypeWithThreeTenBpLocalDateMappedToDate typeWithLocalDate = new TypeWithThreeTenBpLocalDateMappedToDate();
typeWithLocalDate.localDate = org.threeten.bp.LocalDate.of(2010, 7, 4);
Map<CqlIdentifier, Object> insert = new LinkedHashMap<>();
mappingCassandraConverter.write(typeWithLocalDate, insert);
assertThat(getValues(insert)).contains(LocalDate.of(2010, 7, 4));
}
@Test // DATACASS-296
void shouldCreateUpdateWithThreeTenBpLocalDateUsingCassandraDateCorrectly() {
TypeWithThreeTenBpLocalDateMappedToDate typeWithLocalDate = new TypeWithThreeTenBpLocalDateMappedToDate();
typeWithLocalDate.localDate = org.threeten.bp.LocalDate.of(2010, 7, 4);
Map<CqlIdentifier, Object> update = new LinkedHashMap<>();
mappingCassandraConverter.write(typeWithLocalDate, update);
assertThat(getValues(update)).contains(LocalDate.of(2010, 7, 4));
}
@Test // DATACASS-206
void updateShouldUseSpecifiedColumnNames() {
@@ -1244,28 +1152,6 @@ public class MappingCassandraConverterUnitTests {
@CassandraType(type = CassandraType.Name.DATE) java.time.LocalDate localDate;
}
/**
* Uses Cassandra's {@link Name#DATE} which maps by default to Joda {@link LocalDate}
*/
@Table
private static class TypeWithJodaLocalDateMappedToDate {
@PrimaryKey private String id;
@CassandraType(type = CassandraType.Name.DATE) private org.joda.time.LocalDate localDate;
}
/**
* Uses Cassandra's {@link Name#DATE} which maps by default to Joda {@link LocalDate}
*/
@Table
private static class TypeWithThreeTenBpLocalDateMappedToDate {
@PrimaryKey private String id;
@CassandraType(type = CassandraType.Name.DATE) private org.threeten.bp.LocalDate localDate;
}
@Table
private static class TypeWithInstant {

View File

@@ -19,9 +19,8 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.domain.Sort.Order.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Collection;
import java.util.Collections;
import java.util.Currency;
@@ -30,8 +29,6 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.joda.time.LocalDate;
import org.joda.time.LocalTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -68,6 +65,9 @@ import com.datastax.oss.driver.api.core.data.TupleValue;
import com.datastax.oss.driver.api.core.data.UdtValue;
import com.datastax.oss.driver.api.core.type.DataTypes;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* Unit tests for {@link QueryMapper}.
*
@@ -370,7 +370,7 @@ public class QueryMapperUnitTests {
@Test // DATACASS-302
void shouldMapTime() {
Filter filter = Filter.from(Criteria.where("localTime").gt(LocalTime.fromMillisOfDay(1000)));
Filter filter = Filter.from(Criteria.where("localTime").gt(LocalTime.ofNanoOfDay(1000)));
Filter mappedObject = this.queryMapper.getMappedObject(filter,
this.mappingContext.getRequiredPersistentEntity(Person.class));

View File

@@ -15,14 +15,13 @@
*/
package org.springframework.data.cassandra.core.convert;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.cassandra.core.mapping.CassandraType.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.springframework.data.cassandra.core.mapping.CassandraType.Name;
import java.io.IOException;
import java.io.Serializable;
@@ -35,6 +34,7 @@ import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.core.cql.Ordering;
@@ -43,7 +43,18 @@ import org.springframework.data.cassandra.core.cql.keyspace.ColumnSpecification;
import org.springframework.data.cassandra.core.cql.keyspace.CreateIndexSpecification;
import org.springframework.data.cassandra.core.cql.keyspace.CreateIndexSpecification.ColumnFunction;
import org.springframework.data.cassandra.core.cql.keyspace.CreateTableSpecification;
import org.springframework.data.cassandra.core.mapping.*;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.mapping.CassandraType;
import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.Element;
import org.springframework.data.cassandra.core.mapping.Embedded;
import org.springframework.data.cassandra.core.mapping.Indexed;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyClass;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.core.mapping.Table;
import org.springframework.data.cassandra.core.mapping.Tuple;
import org.springframework.data.cassandra.domain.AllPossibleTypes;
import org.springframework.data.cassandra.support.UserDefinedTypeBuilder;
import org.springframework.data.mapping.MappingException;
@@ -61,6 +72,10 @@ import com.datastax.oss.driver.api.core.type.UserDefinedType;
import com.datastax.oss.protocol.internal.ProtocolConstants;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Unit tests for {@link SchemaFactory}.
*
@@ -501,15 +516,6 @@ public class SchemaFactoryUnitTests {
assertThat(getColumnType("bpInstant", specification)).isEqualTo(DataTypes.TIMESTAMP);
}
@Test // DATACASS-296
void columnsShouldMapToTimestampUsingOverrides() {
CreateTableSpecification specification = getCreateTableSpecificationFor(TypeWithOverrides.class);
assertThat(getColumnType("localDate", specification)).isEqualTo(DataTypes.TIMESTAMP);
assertThat(getColumnType("jodaLocalDate", specification)).isEqualTo(DataTypes.TIMESTAMP);
}
@Test // DATACASS-296
void columnsShouldMapToBlob() {
@@ -688,16 +694,6 @@ public class SchemaFactoryUnitTests {
String lastname;
}
@Data
@Table
private static class TypeWithOverrides {
@Id String id;
@CassandraType(type = Name.TIMESTAMP) java.time.LocalDate localDate;
@CassandraType(type = Name.TIMESTAMP) org.joda.time.LocalDate jodaLocalDate;
}
private static class PersonReadConverter implements Converter<String, Human> {
public Human convert(String source) {

View File

@@ -15,12 +15,7 @@
*/
package org.springframework.data.cassandra.domain;
import static org.springframework.data.cassandra.core.mapping.CassandraType.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import static org.springframework.data.cassandra.core.mapping.CassandraType.Name;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -39,6 +34,11 @@ import org.springframework.data.cassandra.core.mapping.Table;
import com.datastax.oss.driver.api.core.data.TupleValue;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
/**
* @author Mark Paluch
*/
@@ -101,15 +101,4 @@ public class AllPossibleTypes {
java.time.LocalDateTime localDateTime;
java.time.ZoneId zoneId;
org.joda.time.DateTime jodaDateTime;
org.joda.time.LocalDate jodaLocalDate;
org.joda.time.LocalDateTime jodaLocalDateTime;
org.joda.time.LocalTime jodaLocalTime;
org.threeten.bp.Instant bpInstant;
org.threeten.bp.LocalDate bpLocalDate;
org.threeten.bp.LocalDateTime bpLocalDateTime;
org.threeten.bp.LocalTime bpLocalTime;
org.threeten.bp.ZoneId bpZoneId;
}

View File

@@ -15,10 +15,11 @@
*/
package org.springframework.data.cassandra.repository.query;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.cassandra.core.mapping.CassandraType.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.data.cassandra.core.mapping.CassandraType.Name;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.util.List;
import org.junit.jupiter.api.Test;
@@ -35,8 +36,6 @@ import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.threeten.bp.LocalDateTime;
import com.datastax.oss.driver.api.core.type.DataTypes;
/**

View File

@@ -15,21 +15,20 @@
*/
package org.springframework.data.cassandra.repository.query;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.cassandra.core.mapping.CassandraType.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.data.cassandra.core.mapping.CassandraType.Name;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import rx.Single;
import java.lang.reflect.Method;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.CassandraType;
import org.springframework.data.cassandra.domain.AllPossibleTypes;
@@ -38,10 +37,10 @@ import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.threeten.bp.LocalDateTime;
import com.datastax.oss.driver.api.core.type.DataTypes;
import rx.Single;
/**
* Unit tests for {@link ReactiveCassandraParameterAccessor}.
*