Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package grails.gorm.async

import groovy.transform.CompileStatic

import groovy.transform.Generated
import org.grails.datastore.gorm.GormEnhancer
import org.grails.datastore.gorm.GormEntity
import org.grails.datastore.gorm.async.GormAsyncStaticApi
Expand All @@ -37,6 +37,7 @@ trait AsyncEntity<D> extends GormEntity<D> {
/**
* @return The async version of the GORM static API
*/
@Generated
static GormAsyncStaticApi<D> getAsync() {
return new GormAsyncStaticApi(GormEnhancer.findStaticApi(this))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
*/
package org.grails.datastore.gorm.schemaless

import groovy.transform.Generated
import spock.lang.Issue
import spock.lang.Specification

import java.lang.reflect.Method


class DynamicDomainSpec extends Specification {

Expand All @@ -41,6 +44,12 @@ class DynamicDomainSpec extends Specification {
entity.attributes().foo == 123
}

void "test that all DynamicAttributes trait methods are marked as Generated"() {
expect: "all DynamicAttributes methods are marked as Generated on implementation class"
DynamicAttributes.getMethods().each { Method traitMethod ->
assert DynamicEntity.class.getMethod(traitMethod.name, traitMethod.parameterTypes).isAnnotationPresent(Generated)
}
}
}

class DynamicEntity implements DynamicAttributes {
Expand All @@ -51,4 +60,4 @@ class DynamicEntity implements DynamicAttributes {
"foo"
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package grails.gorm

import groovy.transform.CompileStatic

import groovy.transform.Generated
import grails.gorm.api.GormAllOperations
import org.grails.datastore.gorm.GormEnhancer
import org.grails.datastore.mapping.core.connections.ConnectionSource
Expand All @@ -41,6 +41,7 @@ trait MultiTenant<D> extends Entity {
* @param callable The closure
* @return The result of the closure
*/
@Generated
static <T> T withTenant(Serializable tenantId, Closure<T> callable) {
GormEnhancer.findStaticApi(this).withTenant(tenantId, callable)
}
Expand All @@ -51,6 +52,7 @@ trait MultiTenant<D> extends Entity {
* @param callable The closure
* @return The result of the closure
*/
@Generated
static <D> GormAllOperations eachTenant(Closure callable) {
GormEnhancer.findStaticApi(this, ConnectionSource.DEFAULT).eachTenant(callable)
}
Expand All @@ -61,6 +63,7 @@ trait MultiTenant<D> extends Entity {
* @param tenantId The tenant id
* @return The operations
*/
@Generated
static <D> GormAllOperations<D> withTenant(Serializable tenantId) {
(GormAllOperations<D>) GormEnhancer.findStaticApi(this).withTenant(tenantId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package grails.gorm.time
import java.time.Instant

import groovy.transform.CompileStatic
import groovy.transform.Generated

/**
* A trait to convert a {@link java.time.Instant} to and from a long
Expand All @@ -31,10 +32,12 @@ import groovy.transform.CompileStatic
@CompileStatic
trait InstantConverter {

@Generated
Long convert(Instant value) {
value.toEpochMilli()
}

@Generated
Instant convert(Long value) {
Instant.ofEpochMilli(value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import java.time.ZoneId
import java.time.ZoneOffset

import groovy.transform.CompileStatic
import groovy.transform.Generated

/**
* A trait to convert a {@link LocalDate} to and from a long
Expand All @@ -37,12 +38,14 @@ import groovy.transform.CompileStatic
trait LocalDateConverter extends TemporalConverter<LocalDate> {

@Override
@Generated
Long convert(LocalDate value) {
LocalDateTime localDateTime = LocalDateTime.of(value, LocalTime.MIN)
localDateTime.toInstant(ZoneOffset.UTC).toEpochMilli()
}

@Override
@Generated
LocalDate convert(Long value) {
Instant instant = Instant.ofEpochMilli(value)
LocalDateTime.ofInstant(instant, ZoneId.of('UTC')).toLocalDate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import java.time.ZoneId
import java.time.ZoneOffset

import groovy.transform.CompileStatic
import groovy.transform.Generated

/**
* A trait to convert a {@link java.time.LocalDateTime} to and from a long
Expand All @@ -35,11 +36,13 @@ import groovy.transform.CompileStatic
trait LocalDateTimeConverter implements TemporalConverter<LocalDateTime> {

@Override
@Generated
Long convert(LocalDateTime value) {
value.toInstant(ZoneOffset.UTC).toEpochMilli()
}

@Override
@Generated
LocalDateTime convert(Long value) {
LocalDateTime.ofInstant(Instant.ofEpochMilli(value), ZoneId.of('UTC'))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package grails.gorm.time
import java.time.LocalTime

import groovy.transform.CompileStatic
import groovy.transform.Generated

/**
* A trait to convert a {@link LocalTime} to and from a long
Expand All @@ -32,11 +33,13 @@ import groovy.transform.CompileStatic
trait LocalTimeConverter implements TemporalConverter<LocalTime> {

@Override
@Generated
Long convert(LocalTime value) {
value.toNanoOfDay()
}

@Override
@Generated
LocalTime convert(Long value) {
LocalTime.ofNanoOfDay(value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import java.time.Instant
import java.time.OffsetDateTime

import groovy.transform.CompileStatic
import groovy.transform.Generated

/**
* A trait to convert a {@link java.time.OffsetDateTime} to and from a long
Expand All @@ -33,11 +34,13 @@ import groovy.transform.CompileStatic
trait OffsetDateTimeConverter implements TemporalConverter<OffsetDateTime> {

@Override
@Generated
Long convert(OffsetDateTime value) {
value.toInstant().toEpochMilli()
}

@Override
@Generated
OffsetDateTime convert(Long value) {
OffsetDateTime.ofInstant(Instant.ofEpochMilli(value), systemOffset)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import java.time.OffsetTime
import java.time.ZoneOffset

import groovy.transform.CompileStatic
import groovy.transform.Generated

/**
* A trait to convert a {@link java.time.OffsetTime} to and from a long
Expand All @@ -34,11 +35,13 @@ import groovy.transform.CompileStatic
trait OffsetTimeConverter implements TemporalConverter<OffsetTime> {

@Override
@Generated
Long convert(OffsetTime value) {
value.withOffsetSameInstant(ZoneOffset.UTC).toLocalTime().toNanoOfDay()
}

@Override
@Generated
OffsetTime convert(Long value) {
OffsetTime.of(LocalTime.ofNanoOfDay(value), ZoneOffset.UTC).withOffsetSameInstant(systemOffset)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package grails.gorm.time
import java.time.Period

import groovy.transform.CompileStatic
import groovy.transform.Generated

/**
* A trait to convert a {@link java.time.Period} to and from a String
Expand All @@ -31,10 +32,12 @@ import groovy.transform.CompileStatic
@CompileStatic
trait PeriodConverter {

@Generated
String convert(Period value) {
value.toString()
}

@Generated
Period convert(String value) {
Period.parse(value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package grails.gorm.time

import groovy.transform.Generated

import java.time.Instant
import java.time.ZoneId
import java.time.ZoneOffset
Expand All @@ -29,6 +31,7 @@ trait TemporalConverter<T> {

abstract T convert(Long value)

@Generated
ZoneOffset getSystemOffset() {
Instant instant = Instant.now()
ZoneId systemZone = ZoneId.systemDefault()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import java.time.Instant
import java.time.ZonedDateTime

import groovy.transform.CompileStatic
import groovy.transform.Generated

/**
* A trait to convert a {@link java.time.ZonedDateTime} to and from a long
Expand All @@ -32,11 +33,13 @@ import groovy.transform.CompileStatic
@CompileStatic
trait ZonedDateTimeConverter implements TemporalConverter<ZonedDateTime> {

@Generated
@Override
Long convert(ZonedDateTime value) {
value.toInstant().toEpochMilli()
}

@Generated
@Override
ZonedDateTime convert(Long value) {
ZonedDateTime.ofInstant(Instant.ofEpochMilli(value), systemOffset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import static org.grails.datastore.mapping.reflect.AstUtils.ZERO_PARAMETERS
import static org.grails.datastore.mapping.reflect.AstUtils.addAnnotationIfNecessary
import static org.grails.datastore.mapping.reflect.AstUtils.hasAnnotation
import static org.grails.datastore.mapping.reflect.AstUtils.isDomainClass
import static org.apache.groovy.ast.tools.AnnotatedNodeUtils.markAsGenerated

/**
*
Expand Down Expand Up @@ -217,6 +218,8 @@ class DirtyCheckingTransformer implements CompilationUnitAware {
null,
GeneralUtils.returnS(GeneralUtils.varX(propertyField))
)

markAsGenerated(classNode, getIdMethod)
classNode.addMethod(getIdMethod)
getIdMethod.addAnnotation(GormEntityTransformation.JPA_TRANSIENT_ANNOTATION_NODE)
}
Expand All @@ -237,6 +240,7 @@ class DirtyCheckingTransformer implements CompilationUnitAware {
null,
GeneralUtils.returnS(GeneralUtils.varX(propertyField))
)
markAsGenerated(classNode, getVersionMethod)
classNode.addMethod(getVersionMethod)
getVersionMethod.addAnnotation(GormEntityTransformation.JPA_TRANSIENT_ANNOTATION_NODE)
}
Expand All @@ -262,13 +266,15 @@ class DirtyCheckingTransformer implements CompilationUnitAware {
if (getter == null) {

getter = classNode.addMethod(getterName, PUBLIC, returnType, ZERO_PARAMETERS, null, returnS(varX(fieldName)))
markAsGenerated(classNode, getter)

getter.addAnnotation(DIRTY_CHECKED_PROPERTY_ANNOTATION_NODE)
staticCompilationVisitor.visitMethod(
getter
)
if (booleanProperty) {
classNode.addMethod(NameUtils.getGetterName(propertyName, true), PUBLIC, returnType, ZERO_PARAMETERS, null, returnS(varX(fieldName)))
MethodNode methodNode = classNode.addMethod(NameUtils.getGetterName(propertyName, true), PUBLIC, returnType, ZERO_PARAMETERS, null, returnS(varX(fieldName)))
markAsGenerated(classNode, methodNode)
}
}

Expand Down Expand Up @@ -309,6 +315,7 @@ class DirtyCheckingTransformer implements CompilationUnitAware {
null,
GeneralUtils.returnS(GeneralUtils.constX(0))
)
markAsGenerated(classNode, getVersionMethod)
classNode.addMethod(getVersionMethod)
getVersionMethod.addAnnotation(GormEntityTransformation.JPA_TRANSIENT_ANNOTATION_NODE)
}
Expand Down Expand Up @@ -362,6 +369,7 @@ class DirtyCheckingTransformer implements CompilationUnitAware {
setterBody.addStatement(assignS(propX(varX('this'), fieldName), varX(setterParameter)))

setter = classNode.addMethod(setterName, PUBLIC, ClassHelper.VOID_TYPE, params(setterParameter), null, setterBody)
markAsGenerated(classNode, setter)
setter.addAnnotation(DIRTY_CHECKED_PROPERTY_ANNOTATION_NODE)
staticCompilationVisitor.visitMethod(
setter
Expand Down
Loading
Loading