Skip to content

DATAMONGO-2112 - Allow usage of SpEL expression for index annotation attributes. #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

christophstrobl
Copy link
Member

We added @Indexed.expireAfter() which accepts numeric values followed by the unit of measure d(ays), h(ours), m(inutes), s(econds) or a template expression.

@Indexed(expireAfter = "10s")
String expireAfterTenSeconds;

@Indexed(expireAfter = "1d")
String expireAfterOneDay;

@Indexed(expireAfter = "#{@myBean.timeout}")
String expireAfterTimeoutObtainedFromBean;

The expression used for @Indexed.expireAfter() may not only return a plain String value with the timeout but also a java.time.Duration.

Additionally expressions can now be used for the name attribute of @Indexed, @GeospatialIndexed and @CompoundIndex as well as the def attribute of @CompoundIndex.

@CompoundIndex(name = "#{@myBean.indexName}", 
                def = "#{T(org.bson.Document).parse(\"{ 'first': 1, 'last': -1 }\")}")
class WithCompoundIndexFromExpression {
    // …
}

We added expireAfter which accepts numeric values followed by the unit of measure (d(ays), h(ours), m(inutes), s(econds)) or a Spring template expression to the Indexed annotation.

   @indexed(expireAfter = "10s")
    String expireAfterTenSeconds;

    @indexed(expireAfter = "1d")
    String expireAfterOneDay;

    @indexed(expireAfter = "#{@mySpringBean.timeout}")
    String expireAfterTimeoutObtainedFromSpringBean;
… & geoIndex names as well as compound index definition.

We now also evaluate SpEL expressions for the name of indices as well as the def attribute of the compound index definition.

   @CompoundIndex(name = "#{'cmp' + 2 + 'name‘}“, def = "#{T(org.bson.Document).parse(\"{ 'foo': 1, 'bar': -1 }\")}")
    class WithCompoundIndexFromExpression {
      // …
    }

An expression used for Indexed.expireAfter may now not only return a plain String value with the timeout but also a java.time.Duration.
@mp911de mp911de force-pushed the issue/DATAMONGO-2112 branch from da5a87d to 1a571a1 Compare April 10, 2019 08:19
return Duration.ofHours(timeout);
case "m":
return Duration.ofMinutes(timeout);
case "s":

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

Looks like ms missed here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for having a look. This is intentional uses seconds granularity. We will still get milliseconds through DurationStyle in alignment with Spring Boot's duration style parsing.

Align Indexed(expireAfter) default to empty string according to the documentation. Slightly reword Javadoc.

Import DurationStyle to reuse duration parsing until Spring Framework provides a similar utility. Document ISO-8601 duration style. Prevent null index name evaluation to render "null" as String.

Convert assertions from Hamcrest to AssertJ.
@mp911de mp911de force-pushed the issue/DATAMONGO-2112 branch from 960b24d to a066ee0 Compare April 10, 2019 10:35
mp911de pushed a commit that referenced this pull request Apr 10, 2019
We added expireAfter which accepts numeric values followed by the unit of measure (d(ays), h(ours), m(inutes), s(econds)) or a Spring template expression to the Indexed annotation.

   @indexed(expireAfter = "10s")
    String expireAfterTenSeconds;

    @indexed(expireAfter = "1d")
    String expireAfterOneDay;

    @indexed(expireAfter = "#{@mySpringBean.timeout}")
    String expireAfterTimeoutObtainedFromSpringBean;

Original pull request: #647.
mp911de pushed a commit that referenced this pull request Apr 10, 2019
… & geoIndex names as well as compound index definition.

We now also evaluate SpEL expressions for the name of indices as well as the def attribute of the compound index definition.

   @CompoundIndex(name = "#{'cmp' + 2 + 'name‘}“, def = "#{T(org.bson.Document).parse(\"{ 'foo': 1, 'bar': -1 }\")}")
    class WithCompoundIndexFromExpression {
      // …
    }

An expression used for Indexed.expireAfter may now not only return a plain String value with the timeout but also a java.time.Duration.

Original pull request: #647.
mp911de added a commit that referenced this pull request Apr 10, 2019
Align Indexed(expireAfter) default to empty string according to the documentation. Slightly reword Javadoc.

Import DurationStyle to reuse duration parsing until Spring Framework provides a similar utility. Document ISO-8601 duration style. Prevent null index name evaluation to render "null" as String.

Convert assertions from Hamcrest to AssertJ.

Original pull request: #647.
@mp911de
Copy link
Member

mp911de commented Apr 10, 2019

That's merged and polished now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants