Skip to content

Conversation

@codeconsole
Copy link
Contributor

@codeconsole codeconsole commented Oct 6, 2025

Introduce @CreatedDate, @LastModifiedDate, @CreatedBy, and @LastModifiedBy similar to Spring Data

Introduce grails.importGrailsCommonAnnotations to automatically import common grails annotations and jakarta.validation.constraints.*

build.gradle

grails {
    importJavaTime = true
    importGrailsCommonAnnotations = true // kitchen sink
    starImports = ['java.util.concurrent', 'groovy.transform'] // fully customizable
}

allows the following with no imports

class User {
    String firstName
    String lastName
    String email
    @CreatedDate Instant created
    @LastModifiedDate Instant modified
}

class Car {
    String make
    String model
    @CreatedBy User owner
    @LastModifiedBy User driver
    @CreatedDate Instant purchased
    @LastModifiedDate Instant lastDriven
}
    @Bean
    AuditorAware<User> springSecurityAuditorAware() {
        return new AuditorAware< User >() {
            @Override
            Optional<String> getCurrentAuditor() {
                Optional.ofNullable(SecurityContextHolder.context)
                        .map { it.authentication }
                        .filter { it?.authenticated }
                        .map { (User) it.principal }
            }
        }
    }
@Scaffold(GormService<User>)
class UserService implements UserDetailsService {
    @Override
    UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return User.findByEmail(username)
    }
}
import grails.plugin.scaffolding.RestfulServiceController

@Scaffold(RestfulServiceController<User>)
class UserController {}

…erties will only be marked dirty if other updates exist. This mimics the behavior in hibernate. Fixes apache#15120
@jdaugherty
Copy link
Contributor

Per the weekly meeting, we'll merge this into 7.1. The vote to create that branch is going now - once 72 hrs have passed, we'll create the branch.

@jdaugherty
Copy link
Contributor

@codeconsole Can you update this PR now that you've made your mongo update date fixes?

@codeconsole
Copy link
Contributor Author

@codeconsole Can you update this PR now that you've made your mongo update date fixes?

Done

@jdaugherty
Copy link
Contributor

I've updated 7.1.x with the latest 7.0.x changes. Can you please merge 7.1.x into this PR so the changes are reflected?

Copy link
Contributor

@jdaugherty jdaugherty left a comment

Choose a reason for hiding this comment

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

My largest problem is the breaking change with the isDevelopmentMode(). We need a better solution here. Can you give your reasoning for disabling the caching in development mode?

}
else {
// Check if property has @CreatedDate or @LastModifiedDate annotations
if (AutoTimestampUtils.hasAutoTimestampAnnotation(persistentProperty)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't constraints be added for the auditor type? It's perfectly reasonable if the auditor is a String, to set a max string (i.e. if you wanted a value greater than 255)

Copy link
Contributor

Choose a reason for hiding this comment

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

This is true, as auditor can be different types, and constraints influence the database schema.

/**
* Enum representing the type of auto-timestamp annotation on a property
*/
static enum AutoTimestampType {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Can we pull this into it's own file?
  2. Is "AutoTimestamp" really a good name for createdBy / updatedBy? Would Tracked or TrackedEntityType be a better name?

@codeconsole
Copy link
Contributor Author

My largest problem is the breaking change with the isDevelopmentMode(). We need a better solution here. Can you give your reasoning for disabling the caching in development mode?

@jdaugherty You are looking at it from the wrong perspective. I am introducing caching when not in development mode. The current implementation has no caching. The performance benefit is so negligible that I suspect you wouldn't even notice.

@jdaugherty
Copy link
Contributor

We should just always cache. We don't need the dependency that way.

@codeconsole codeconsole changed the title 7.0.x AutoTmestamp Enhancements + grails.importGrailsAnnotations GrailsExtension 7.1.x AutoTmestamp Enhancements + grails.importGrailsAnnotations GrailsExtension Nov 2, 2025
}
else {
// Check if property has @CreatedDate or @LastModifiedDate annotations
if (AutoTimestampUtils.hasAutoTimestampAnnotation(persistentProperty)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is true, as auditor can be different types, and constraints influence the database schema.

Comment on lines 620 to +622
properties = list ? domainModelService.getListOutputProperties(domainClass) : domainModelService.getInputProperties(domainClass,
exclusionType == ExclusionType.Input ? exclusionsInput : exclusionsDisplay)
exclusionType == ExclusionType.Input ? exclusionsInput : exclusionsDisplay,
exclusionType == ExclusionType.Input)
Copy link
Contributor

Choose a reason for hiding this comment

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

getInputProperties(PersistenProperty, List<String>, boolean) is not part of the DomainModelService interface.

Copy link
Contributor

Choose a reason for hiding this comment

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

This class is no longer implementing getInputProperties(PersistentEntity, List) from the DomainModelService interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants