|
|
|
@ -30,7 +30,6 @@ import org.bson.BsonBinarySubType; |
|
|
|
import org.bson.BsonNull; |
|
|
|
import org.bson.BsonNull; |
|
|
|
import org.bson.Document; |
|
|
|
import org.bson.Document; |
|
|
|
import org.jspecify.annotations.Nullable; |
|
|
|
import org.jspecify.annotations.Nullable; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.data.mongodb.core.mapping.Field; |
|
|
|
import org.springframework.data.mongodb.core.mapping.Field; |
|
|
|
import org.springframework.data.mongodb.core.query.Collation; |
|
|
|
import org.springframework.data.mongodb.core.query.Collation; |
|
|
|
import org.springframework.data.mongodb.core.schema.IdentifiableJsonSchemaProperty; |
|
|
|
import org.springframework.data.mongodb.core.schema.IdentifiableJsonSchemaProperty; |
|
|
|
@ -41,6 +40,7 @@ import org.springframework.data.mongodb.core.schema.MongoJsonSchema; |
|
|
|
import org.springframework.data.mongodb.core.schema.QueryCharacteristic; |
|
|
|
import org.springframework.data.mongodb.core.schema.QueryCharacteristic; |
|
|
|
import org.springframework.data.mongodb.core.timeseries.Granularity; |
|
|
|
import org.springframework.data.mongodb.core.timeseries.Granularity; |
|
|
|
import org.springframework.data.mongodb.core.timeseries.GranularityDefinition; |
|
|
|
import org.springframework.data.mongodb.core.timeseries.GranularityDefinition; |
|
|
|
|
|
|
|
import org.springframework.data.mongodb.core.timeseries.Span; |
|
|
|
import org.springframework.data.mongodb.core.validation.Validator; |
|
|
|
import org.springframework.data.mongodb.core.validation.Validator; |
|
|
|
import org.springframework.data.util.Optionals; |
|
|
|
import org.springframework.data.util.Optionals; |
|
|
|
import org.springframework.lang.CheckReturnValue; |
|
|
|
import org.springframework.lang.CheckReturnValue; |
|
|
|
@ -982,16 +982,24 @@ public class CollectionOptions { |
|
|
|
private @Nullable final String metaField; |
|
|
|
private @Nullable final String metaField; |
|
|
|
|
|
|
|
|
|
|
|
private final GranularityDefinition granularity; |
|
|
|
private final GranularityDefinition granularity; |
|
|
|
|
|
|
|
private final @Nullable Span span; |
|
|
|
|
|
|
|
|
|
|
|
private final Duration expireAfter; |
|
|
|
private final Duration expireAfter; |
|
|
|
|
|
|
|
|
|
|
|
private TimeSeriesOptions(String timeField, @Nullable String metaField, GranularityDefinition granularity, |
|
|
|
private TimeSeriesOptions(String timeField, @Nullable String metaField, GranularityDefinition granularity, |
|
|
|
Duration expireAfter) { |
|
|
|
@Nullable Span span, Duration expireAfter) { |
|
|
|
|
|
|
|
|
|
|
|
Assert.hasText(timeField, "Time field must not be empty or null"); |
|
|
|
Assert.hasText(timeField, "Time field must not be empty or null"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!Granularity.DEFAULT.equals(granularity) && span != null) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException( |
|
|
|
|
|
|
|
"Cannot use granularity [%s] in conjunction with span".formatted(granularity.name())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.timeField = timeField; |
|
|
|
this.timeField = timeField; |
|
|
|
this.metaField = metaField; |
|
|
|
this.metaField = metaField; |
|
|
|
this.granularity = granularity; |
|
|
|
this.granularity = granularity; |
|
|
|
|
|
|
|
this.span = span; |
|
|
|
this.expireAfter = expireAfter; |
|
|
|
this.expireAfter = expireAfter; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1004,7 +1012,7 @@ public class CollectionOptions { |
|
|
|
* @return new instance of {@link TimeSeriesOptions}. |
|
|
|
* @return new instance of {@link TimeSeriesOptions}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static TimeSeriesOptions timeSeries(String timeField) { |
|
|
|
public static TimeSeriesOptions timeSeries(String timeField) { |
|
|
|
return new TimeSeriesOptions(timeField, null, Granularity.DEFAULT, Duration.ofSeconds(-1)); |
|
|
|
return new TimeSeriesOptions(timeField, null, Granularity.DEFAULT, null, Duration.ofSeconds(-1)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -1013,12 +1021,12 @@ public class CollectionOptions { |
|
|
|
* {@link java.util.Collection}. <br /> |
|
|
|
* {@link java.util.Collection}. <br /> |
|
|
|
* {@link Field#name() Annotated fieldnames} will be considered during the mapping process. |
|
|
|
* {@link Field#name() Annotated fieldnames} will be considered during the mapping process. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param metaField must not be {@literal null}. |
|
|
|
* @param metaField use {@literal null} to unset. |
|
|
|
* @return new instance of {@link TimeSeriesOptions}. |
|
|
|
* @return new instance of {@link TimeSeriesOptions}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Contract("_ -> new") |
|
|
|
@Contract("_ -> new") |
|
|
|
public TimeSeriesOptions metaField(String metaField) { |
|
|
|
public TimeSeriesOptions metaField(@Nullable String metaField) { |
|
|
|
return new TimeSeriesOptions(timeField, metaField, granularity, expireAfter); |
|
|
|
return new TimeSeriesOptions(timeField, metaField, granularity, span, expireAfter); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -1030,7 +1038,21 @@ public class CollectionOptions { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Contract("_ -> new") |
|
|
|
@Contract("_ -> new") |
|
|
|
public TimeSeriesOptions granularity(GranularityDefinition granularity) { |
|
|
|
public TimeSeriesOptions granularity(GranularityDefinition granularity) { |
|
|
|
return new TimeSeriesOptions(timeField, metaField, granularity, expireAfter); |
|
|
|
return new TimeSeriesOptions(timeField, metaField, granularity, span, expireAfter); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Select the time between timestamps in the same bucket to define how data in the time series collection is |
|
|
|
|
|
|
|
* organized. Cannot be used in conjunction with {@link #granularity(GranularityDefinition)}. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param span use {@literal null} to unset. |
|
|
|
|
|
|
|
* @return new instance of {@link TimeSeriesOptions}. |
|
|
|
|
|
|
|
* @see Span |
|
|
|
|
|
|
|
* @since 5.0 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Contract("_ -> new") |
|
|
|
|
|
|
|
public TimeSeriesOptions span(@Nullable Span span) { |
|
|
|
|
|
|
|
return new TimeSeriesOptions(timeField, metaField, granularity, span, expireAfter); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -1043,7 +1065,7 @@ public class CollectionOptions { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Contract("_ -> new") |
|
|
|
@Contract("_ -> new") |
|
|
|
public TimeSeriesOptions expireAfter(Duration ttl) { |
|
|
|
public TimeSeriesOptions expireAfter(Duration ttl) { |
|
|
|
return new TimeSeriesOptions(timeField, metaField, granularity, ttl); |
|
|
|
return new TimeSeriesOptions(timeField, metaField, granularity, span, ttl); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -1079,11 +1101,21 @@ public class CollectionOptions { |
|
|
|
return expireAfter; |
|
|
|
return expireAfter; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Get the span that defines a bucket. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @return {@literal null} if not specified. |
|
|
|
|
|
|
|
* @since 5.0 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public @Nullable Span getSpan() { |
|
|
|
|
|
|
|
return span; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
|
|
|
|
|
|
|
|
return "TimeSeriesOptions{" + "timeField='" + timeField + '\'' + ", metaField='" + metaField + '\'' |
|
|
|
return "TimeSeriesOptions{" + "timeField='" + timeField + '\'' + ", metaField='" + metaField + '\'' |
|
|
|
+ ", granularity=" + granularity + '}'; |
|
|
|
+ ", granularity=" + granularity + ", span=" + span + ", expireAfter=" + expireAfter + '}'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@ -1103,6 +1135,13 @@ public class CollectionOptions { |
|
|
|
if (!ObjectUtils.nullSafeEquals(metaField, that.metaField)) { |
|
|
|
if (!ObjectUtils.nullSafeEquals(metaField, that.metaField)) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!ObjectUtils.nullSafeEquals(span, that.span)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!ObjectUtils.nullSafeEquals(expireAfter, that.expireAfter)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ObjectUtils.nullSafeEquals(granularity, that.granularity); |
|
|
|
return ObjectUtils.nullSafeEquals(granularity, that.granularity); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1111,6 +1150,8 @@ public class CollectionOptions { |
|
|
|
int result = ObjectUtils.nullSafeHashCode(timeField); |
|
|
|
int result = ObjectUtils.nullSafeHashCode(timeField); |
|
|
|
result = 31 * result + ObjectUtils.nullSafeHashCode(metaField); |
|
|
|
result = 31 * result + ObjectUtils.nullSafeHashCode(metaField); |
|
|
|
result = 31 * result + ObjectUtils.nullSafeHashCode(granularity); |
|
|
|
result = 31 * result + ObjectUtils.nullSafeHashCode(granularity); |
|
|
|
|
|
|
|
result = 31 * result + ObjectUtils.nullSafeHashCode(span); |
|
|
|
|
|
|
|
result = 31 * result + ObjectUtils.nullSafeHashCode(expireAfter); |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|