From 5d93131197ab779d1227ab01ec78e1c99bea0fec Mon Sep 17 00:00:00 2001 From: Sergio del Amo Date: Tue, 11 Oct 2022 06:27:54 +0200 Subject: [PATCH] BREAKING: remove GORM (#414) Micronaut Framework 4 uses Groovy 4 and **it does not support GORM 7**. Micronaut Groovy will support GORM once there is a GORM version built with Groovy 4. --- gorm-common/build.gradle | 17 -- .../annotation/EntityAnnotationMapper.java | 45 ---- .../GormPropertyResolverAdapter.java | 53 ---- .../gorm/configuration/package-info.java | 22 -- .../ConfigurableEventPublisherAdapter.java | 88 ------- .../gorm/event/package-info.java | 22 -- .../ValidationExceptionHandler.java | 81 ------ ...cronaut.inject.annotation.AnnotationMapper | 1 - gradle.properties | 4 +- gradle/libs.versions.toml | 6 - graphql-gorm/build.gradle | 23 -- .../gorm/DefaultGraphQLDataBinder.groovy | 46 ---- .../graphql/gorm/GraphQLFactory.groovy | 172 ------------- .../gorm/GraphqlGormConfiguration.groovy | 34 --- .../graphql/gorm/package-info.groovy | 31 --- .../configuration/graphql/gorm/Author.groovy | 16 -- .../graphql/gorm/GraphQLFactorySpec.groovy | 64 ----- groovy-bom/build.gradle | 11 + hibernate-gorm/build.gradle | 26 -- .../gorm/HibernateDatastoreFactory.groovy | 113 --------- .../hibernate/gorm/package-info.java | 32 --- .../hibernate/gorm/GormConfigSpec.groovy | 232 ------------------ .../MockPlatformTransactionManager.groovy | 27 -- mongo-gorm/build.gradle | 27 -- .../mongo/gorm/MongoDatastoreFactory.java | 90 ------- .../mongo/gorm/package-info.java | 32 --- .../gorm/MongoDatastoreFactorySpec.groovy | 87 ------- multitenancy-gorm/build.gradle | 9 - .../gorm/CookieTenantResolver.java | 45 ---- .../gorm/FixedTenantResolver.java | 45 ---- .../gorm/HttpHeaderTenantResolver.java | 45 ---- .../gorm/PrincipalTenantResolver.java | 44 ---- .../gorm/SessionTenantResolver.java | 44 ---- .../gorm/SubdomainTenantResolver.java | 45 ---- .../gorm/SystemPropertyTenantResolver.java | 45 ---- .../gorm/TenantResolverAdapter.java | 53 ---- .../multitenancy/gorm/package-info.java | 22 -- neo4j-gorm/.gitignore | 1 - neo4j-gorm/build.gradle | 25 -- .../neo4j/gorm/Neo4jDatastoreFactory.groovy | 80 ------ .../GormPropertyResolverAdapter.java | 57 ----- .../gorm/configuration/package-info.java | 23 -- .../gorm/Neo4jDatastoreFactorySpec.groovy | 77 ------ settings.gradle | 6 - src/main/docs/guide/gorm.adoc | 186 +------------- .../docs/guide/gorm/multitenancyGorm.adoc | 56 ----- src/main/docs/guide/toc.yml | 6 +- 47 files changed, 15 insertions(+), 2301 deletions(-) delete mode 100644 gorm-common/build.gradle delete mode 100644 gorm-common/src/main/java/io/micronaut/configuration/gorm/annotation/EntityAnnotationMapper.java delete mode 100644 gorm-common/src/main/java/io/micronaut/configuration/gorm/configuration/GormPropertyResolverAdapter.java delete mode 100644 gorm-common/src/main/java/io/micronaut/configuration/gorm/configuration/package-info.java delete mode 100644 gorm-common/src/main/java/io/micronaut/configuration/gorm/event/ConfigurableEventPublisherAdapter.java delete mode 100644 gorm-common/src/main/java/io/micronaut/configuration/gorm/event/package-info.java delete mode 100644 gorm-common/src/main/java/io/micronaut/configuration/gorm/validation/ValidationExceptionHandler.java delete mode 100644 gorm-common/src/main/resources/META-INF/services/io.micronaut.inject.annotation.AnnotationMapper delete mode 100644 graphql-gorm/build.gradle delete mode 100644 graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/DefaultGraphQLDataBinder.groovy delete mode 100644 graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/GraphQLFactory.groovy delete mode 100644 graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/GraphqlGormConfiguration.groovy delete mode 100644 graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/package-info.groovy delete mode 100644 graphql-gorm/src/test/groovy/io/micronaut/configuration/graphql/gorm/Author.groovy delete mode 100644 graphql-gorm/src/test/groovy/io/micronaut/configuration/graphql/gorm/GraphQLFactorySpec.groovy delete mode 100644 hibernate-gorm/build.gradle delete mode 100644 hibernate-gorm/src/main/groovy/io/micronaut/configuration/hibernate/gorm/HibernateDatastoreFactory.groovy delete mode 100644 hibernate-gorm/src/main/groovy/io/micronaut/configuration/hibernate/gorm/package-info.java delete mode 100644 hibernate-gorm/src/test/groovy/io/micronaut/configuration/hibernate/gorm/GormConfigSpec.groovy delete mode 100644 hibernate-gorm/src/test/groovy/io/micronaut/configuration/hibernate/gorm/MockPlatformTransactionManager.groovy delete mode 100644 mongo-gorm/build.gradle delete mode 100644 mongo-gorm/src/main/java/io/micronaut/configuration/mongo/gorm/MongoDatastoreFactory.java delete mode 100644 mongo-gorm/src/main/java/io/micronaut/configuration/mongo/gorm/package-info.java delete mode 100644 mongo-gorm/src/test/groovy/io/micronaut/configuration/mongo/gorm/MongoDatastoreFactorySpec.groovy delete mode 100644 multitenancy-gorm/build.gradle delete mode 100644 multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/CookieTenantResolver.java delete mode 100644 multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/FixedTenantResolver.java delete mode 100644 multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/HttpHeaderTenantResolver.java delete mode 100644 multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/PrincipalTenantResolver.java delete mode 100644 multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/SessionTenantResolver.java delete mode 100644 multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/SubdomainTenantResolver.java delete mode 100644 multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/SystemPropertyTenantResolver.java delete mode 100644 multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/TenantResolverAdapter.java delete mode 100644 multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/package-info.java delete mode 100644 neo4j-gorm/.gitignore delete mode 100644 neo4j-gorm/build.gradle delete mode 100644 neo4j-gorm/src/main/groovy/io/micronaut/configuration/neo4j/gorm/Neo4jDatastoreFactory.groovy delete mode 100644 neo4j-gorm/src/main/groovy/io/micronaut/configuration/neo4j/gorm/configuration/GormPropertyResolverAdapter.java delete mode 100644 neo4j-gorm/src/main/groovy/io/micronaut/configuration/neo4j/gorm/configuration/package-info.java delete mode 100644 neo4j-gorm/src/test/groovy/io/micronaut/configuration/neo4j/gorm/Neo4jDatastoreFactorySpec.groovy delete mode 100644 src/main/docs/guide/gorm/multitenancyGorm.adoc diff --git a/gorm-common/build.gradle b/gorm-common/build.gradle deleted file mode 100644 index 0f404b6d..00000000 --- a/gorm-common/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -plugins { - id 'io.micronaut.build.internal.groovy-module' -} - -dependencies { - annotationProcessor mn.micronaut.inject.java - - api "org.grails:grails-datastore-gorm:$gormVersion" - - compileOnly mn.micronaut.http.server - - implementation(platform(mn.micronaut.bom)) - implementation mn.micronaut.spring - - implementation mn.micronaut.inject - implementation mn.groovy -} diff --git a/gorm-common/src/main/java/io/micronaut/configuration/gorm/annotation/EntityAnnotationMapper.java b/gorm-common/src/main/java/io/micronaut/configuration/gorm/annotation/EntityAnnotationMapper.java deleted file mode 100644 index 378dfa60..00000000 --- a/gorm-common/src/main/java/io/micronaut/configuration/gorm/annotation/EntityAnnotationMapper.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.configuration.gorm.annotation; - -import grails.gorm.annotation.Entity; -import io.micronaut.core.annotation.AnnotationValue; -import io.micronaut.core.annotation.Introspected; -import io.micronaut.inject.annotation.TypedAnnotationMapper; -import io.micronaut.inject.visitor.VisitorContext; - -import java.util.Collections; -import java.util.List; - -/** - * Ensures all GORM entities are introspected to allow for them to be found - * via introspection scanning instead of traditional classpath scanning. - * - * @author James Kleeh - * @since 3.0.0 - */ -public class EntityAnnotationMapper implements TypedAnnotationMapper { - - @Override - public Class annotationType() { - return Entity.class; - } - - @Override - public List> map(AnnotationValue annotation, VisitorContext visitorContext) { - return Collections.singletonList(AnnotationValue.builder(Introspected.class).build()); - } -} diff --git a/gorm-common/src/main/java/io/micronaut/configuration/gorm/configuration/GormPropertyResolverAdapter.java b/gorm-common/src/main/java/io/micronaut/configuration/gorm/configuration/GormPropertyResolverAdapter.java deleted file mode 100644 index 835b045c..00000000 --- a/gorm-common/src/main/java/io/micronaut/configuration/gorm/configuration/GormPropertyResolverAdapter.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.configuration.gorm.configuration; - -import io.micronaut.context.env.PropertyPlaceholderResolver; -import io.micronaut.core.naming.conventions.StringConvention; -import io.micronaut.core.value.PropertyResolver; -import io.micronaut.spring.core.env.PropertyResolverAdapter; -import org.grails.datastore.mapping.config.Settings; - -import java.util.Map; - -/** - * @author graemerocher - * @since 1.0 - */ -public class GormPropertyResolverAdapter extends PropertyResolverAdapter { - - /** - * Constructor. - * - * @param propertyResolver The property resolver - * @param placeholderResolver The property placeholder resolver - */ - public GormPropertyResolverAdapter(PropertyResolver propertyResolver, PropertyPlaceholderResolver placeholderResolver) { - super(propertyResolver, placeholderResolver); - } - - @SuppressWarnings("unchecked") - @Override - public T getProperty(String key, Class targetType, T defaultValue) { - if ("hibernate".equalsIgnoreCase(key) && targetType == Map.class) { - return (T) super.getPropertyResolver().getProperties(key, StringConvention.UNDER_SCORE_SEPARATED_LOWER_CASE); - } else if (Settings.SETTING_FAIL_ON_ERROR.equals(key) && defaultValue == null) { - return (T) super.getProperty(key, Boolean.class, Boolean.TRUE); - } else { - return super.getProperty(key, targetType, defaultValue); - } - } -} diff --git a/gorm-common/src/main/java/io/micronaut/configuration/gorm/configuration/package-info.java b/gorm-common/src/main/java/io/micronaut/configuration/gorm/configuration/package-info.java deleted file mode 100644 index 0402c260..00000000 --- a/gorm-common/src/main/java/io/micronaut/configuration/gorm/configuration/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2017-2020 original 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. - */ -/** - * Common GORM configuration used across the framework. - * - * @author graemerocher - * @since 1.0 - */ -package io.micronaut.configuration.gorm.configuration; diff --git a/gorm-common/src/main/java/io/micronaut/configuration/gorm/event/ConfigurableEventPublisherAdapter.java b/gorm-common/src/main/java/io/micronaut/configuration/gorm/event/ConfigurableEventPublisherAdapter.java deleted file mode 100644 index 6b7896ff..00000000 --- a/gorm-common/src/main/java/io/micronaut/configuration/gorm/event/ConfigurableEventPublisherAdapter.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.configuration.gorm.event; - -import io.micronaut.context.ApplicationContext; -import io.micronaut.context.Qualifier; -import io.micronaut.context.event.ApplicationEventListener; -import io.micronaut.inject.qualifiers.Qualifiers; -import io.micronaut.spring.core.event.ApplicationEventPublisherAdapter; -import org.grails.datastore.gorm.events.ConfigurableApplicationEventPublisher; -import org.springframework.context.ApplicationEvent; -import org.springframework.context.ApplicationListener; -import org.springframework.context.event.SmartApplicationListener; - -/** - * Adapts Spring event model. - * - * @author graemerocher - * @since 1.0 - */ -public class ConfigurableEventPublisherAdapter extends ApplicationEventPublisherAdapter implements ConfigurableApplicationEventPublisher { - private final ApplicationContext applicationContext; - - /** - * Constructor. - * @param applicationContext applicationContext - */ - public ConfigurableEventPublisherAdapter(ApplicationContext applicationContext) { - super(applicationContext); - this.applicationContext = applicationContext; - } - - @Override - public void addApplicationListener(ApplicationListener listener) { - if (listener instanceof SmartApplicationListener) { - SmartApplicationListener smartApplicationListener = (SmartApplicationListener) listener; - Qualifier qualifier = resolveQualifier(smartApplicationListener); - this.applicationContext.registerSingleton( - ApplicationEventListener.class, - new ApplicationEventListener() { - @Override - public void onApplicationEvent(Object event) { - if (event instanceof ApplicationEvent) { - smartApplicationListener.onApplicationEvent((ApplicationEvent) event); - } - } - - @Override - public boolean supports(Object event) { - if (event instanceof ApplicationEvent) { - ApplicationEvent applicationEvent = (ApplicationEvent) event; - - Object source = applicationEvent.getSource(); - return smartApplicationListener.supportsEventType(applicationEvent.getClass()) - && (source == null || smartApplicationListener.supportsSourceType(source.getClass())); - } - return false; - } - - @Override - public String toString() { - return "Adapted: " + smartApplicationListener; - } - }, - qualifier, - false - ); - - } - } - - private Qualifier resolveQualifier(SmartApplicationListener smartApplicationListener) { - return Qualifiers.byName(smartApplicationListener.getClass().getSimpleName()); - } -} diff --git a/gorm-common/src/main/java/io/micronaut/configuration/gorm/event/package-info.java b/gorm-common/src/main/java/io/micronaut/configuration/gorm/event/package-info.java deleted file mode 100644 index 8c590f0d..00000000 --- a/gorm-common/src/main/java/io/micronaut/configuration/gorm/event/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2017-2020 original 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. - */ -/** - * GORM event model. - * - * @author graemerocher - * @since 1.0 - */ -package io.micronaut.configuration.gorm.event; diff --git a/gorm-common/src/main/java/io/micronaut/configuration/gorm/validation/ValidationExceptionHandler.java b/gorm-common/src/main/java/io/micronaut/configuration/gorm/validation/ValidationExceptionHandler.java deleted file mode 100644 index 2cdf1aae..00000000 --- a/gorm-common/src/main/java/io/micronaut/configuration/gorm/validation/ValidationExceptionHandler.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.configuration.gorm.validation; - -import io.micronaut.context.annotation.Requires; -import io.micronaut.http.HttpRequest; -import io.micronaut.http.HttpResponse; -import io.micronaut.http.MutableHttpResponse; -import io.micronaut.http.hateoas.JsonError; -import io.micronaut.http.hateoas.Link; -import io.micronaut.http.server.exceptions.ExceptionHandler; -import io.micronaut.http.server.exceptions.response.ErrorContext; -import io.micronaut.http.server.exceptions.response.Error; -import io.micronaut.http.server.exceptions.response.ErrorResponseProcessor; -import jakarta.inject.Singleton; -import org.grails.datastore.mapping.validation.ValidationException; -import org.springframework.validation.Errors; -import org.springframework.validation.FieldError; - -import java.util.Optional; - -/** - * Default Exception handler for GORM validation errors. - * - * @author graemerocher - * @since 1.0 - */ -@Singleton -@Requires(classes = ExceptionHandler.class) -public class ValidationExceptionHandler implements ExceptionHandler> { - - private final ErrorResponseProcessor responseProcessor; - - /** - * Constructor. - * @param responseProcessor Error Response Processor - */ - public ValidationExceptionHandler(ErrorResponseProcessor responseProcessor) { - this.responseProcessor = responseProcessor; - } - - @Override - public HttpResponse handle(HttpRequest request, ValidationException exception) { - Errors errors = exception.getErrors(); - FieldError fieldError = errors.getFieldError(); - MutableHttpResponse response = HttpResponse.badRequest(); - if (responseProcessor != null) { - return responseProcessor.processResponse(ErrorContext.builder(request) - .cause(exception) - .error(new Error() { - @Override - public String getMessage() { - return exception.getMessage(); - } - - @Override - public Optional getPath() { - return Optional.ofNullable(fieldError).map(FieldError::getField); - } - }) - .build(), response); - } else { - return response.body(new JsonError(exception.getMessage()) - .path(fieldError != null ? fieldError.getField() : null) - .link(Link.SELF, Link.of(request.getUri()))); - } - } -} diff --git a/gorm-common/src/main/resources/META-INF/services/io.micronaut.inject.annotation.AnnotationMapper b/gorm-common/src/main/resources/META-INF/services/io.micronaut.inject.annotation.AnnotationMapper deleted file mode 100644 index eabb51c4..00000000 --- a/gorm-common/src/main/resources/META-INF/services/io.micronaut.inject.annotation.AnnotationMapper +++ /dev/null @@ -1 +0,0 @@ -io.micronaut.configuration.gorm.annotation.EntityAnnotationMapper diff --git a/gradle.properties b/gradle.properties index 224a6993..9a9ea77c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,8 +6,6 @@ micronautTestVersion=3.5.0 groovyVersion=4.0.5 spockVersion=2.2-groovy-4.0 -gormVersion=7.3.2 -gormHibernateVersion=7.3.0 graphqlJavaVersion=14.1 title=Micronaut Groovy @@ -19,6 +17,6 @@ developers=Graeme Rocher githubBranch=master githubCoreBranch=4.0.x bomProperty=micronautGroovyVersion -bomProperties=spockVersion,gormHibernateVersion,gormVersion +bomProperties=spockVersion org.gradle.caching=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 57b0233d..a57f279b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,4 @@ [versions] -gorm-graphql = '2.0.0' -gorm-mongo = '7.3.0' -gorm-neo4j = '7.3.0' h2 = '1.4.200' hibernate-ehcache = '5.6.12.Final' javaparser = '3.24.4' @@ -15,9 +12,6 @@ tomcat-jdbc = '10.0.23' micronaut-gradle-plugin = "3.6.2" [libraries] -gorm-graphql = { module = 'org.grails:gorm-graphql', version.ref = 'gorm-graphql' } -gorm-mongo = { module = 'org.grails:grails-datastore-gorm-mongodb', version.ref = 'gorm-mongo' } -gorm-neo4j = { module = 'org.grails:grails-datastore-gorm-neo4j', version.ref = 'gorm-neo4j' } h2 = { module = 'com.h2database:h2', version.ref = 'h2' } hibernate-ehcache = { module = 'org.hibernate:hibernate-ehcache', version.ref = 'hibernate-ehcache' } javaparser = { module = 'com.github.javaparser:javaparser-core', version.ref = 'javaparser' } diff --git a/graphql-gorm/build.gradle b/graphql-gorm/build.gradle deleted file mode 100644 index 656364a7..00000000 --- a/graphql-gorm/build.gradle +++ /dev/null @@ -1,23 +0,0 @@ -plugins { - id 'io.micronaut.build.internal.groovy-module' -} - -dependencies { - api projects.gormCommon - api "com.graphql-java:graphql-java:$graphqlJavaVersion" - api mn.micronaut.inject - api(libs.gorm.graphql) - api("org.grails:grails-datastore-gorm:$gormVersion") - - compileOnly mn.micronaut.inject.groovy - - implementation mn.groovy - - testCompileOnly mn.micronaut.inject.groovy -} - -micronautBuild { - resolutionStrategy { - force "com.graphql-java:graphql-java:$graphqlJavaVersion" - } -} diff --git a/graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/DefaultGraphQLDataBinder.groovy b/graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/DefaultGraphQLDataBinder.groovy deleted file mode 100644 index 84814c61..00000000 --- a/graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/DefaultGraphQLDataBinder.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.configuration.graphql.gorm - -import groovy.transform.CompileStatic -import io.micronaut.core.bind.BeanPropertyBinder -import org.grails.gorm.graphql.binding.GraphQLDataBinder - -/** - * Default data binder that delegates to {@link BeanPropertyBinder}. - * - * @author James Kleeh - * @since 1.1.0 - */ -@CompileStatic -class DefaultGraphQLDataBinder implements GraphQLDataBinder { - - private final BeanPropertyBinder beanPropertyBinder - - /** - * Default constructor. - * - * @param beanPropertyBinder The bean property binder - */ - DefaultGraphQLDataBinder(BeanPropertyBinder beanPropertyBinder) { - this.beanPropertyBinder = beanPropertyBinder - } - - @Override - void bind(Object object, Map data) { - beanPropertyBinder.bind(object, data) - } -} diff --git a/graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/GraphQLFactory.groovy b/graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/GraphQLFactory.groovy deleted file mode 100644 index 0e3b9260..00000000 --- a/graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/GraphQLFactory.groovy +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.configuration.graphql.gorm - -import graphql.GraphQL -import graphql.schema.GraphQLCodeRegistry -import graphql.schema.GraphQLSchema -import groovy.transform.CompileStatic -import io.micronaut.context.annotation.Factory -import io.micronaut.context.annotation.Requires -import io.micronaut.core.annotation.Nullable -import io.micronaut.core.bind.BeanPropertyBinder -import io.micronaut.core.util.StringUtils -import jakarta.inject.Singleton -import org.grails.datastore.mapping.core.Datastore -import org.grails.datastore.mapping.model.MappingContext -import org.grails.gorm.graphql.GraphQLServiceManager -import org.grails.gorm.graphql.Schema -import org.grails.gorm.graphql.binding.GraphQLDataBinder -import org.grails.gorm.graphql.binding.manager.DefaultGraphQLDataBinderManager -import org.grails.gorm.graphql.binding.manager.GraphQLDataBinderManager -import org.grails.gorm.graphql.entity.GraphQLEntityNamingConvention -import org.grails.gorm.graphql.entity.property.manager.DefaultGraphQLDomainPropertyManager -import org.grails.gorm.graphql.entity.property.manager.GraphQLDomainPropertyManager -import org.grails.gorm.graphql.fetcher.manager.DefaultGraphQLDataFetcherManager -import org.grails.gorm.graphql.fetcher.manager.GraphQLDataFetcherManager -import org.grails.gorm.graphql.interceptor.manager.DefaultGraphQLInterceptorManager -import org.grails.gorm.graphql.interceptor.manager.GraphQLInterceptorManager -import org.grails.gorm.graphql.response.delete.DefaultGraphQLDeleteResponseHandler -import org.grails.gorm.graphql.response.delete.GraphQLDeleteResponseHandler -import org.grails.gorm.graphql.response.errors.DefaultGraphQLErrorsResponseHandler -import org.grails.gorm.graphql.response.errors.GraphQLErrorsResponseHandler -import org.grails.gorm.graphql.response.pagination.DefaultGraphQLPaginationResponseHandler -import org.grails.gorm.graphql.response.pagination.GraphQLPaginationResponseHandler -import org.grails.gorm.graphql.types.DefaultGraphQLTypeManager -import org.grails.gorm.graphql.types.GraphQLTypeManager -import org.springframework.context.MessageSource -import org.springframework.context.support.StaticMessageSource - -/** - * Constructs all beans required to build the schema. - * - * @author James Kleeh - * @since 1.1.0 - */ -@CompileStatic -@Factory -@Requires(property = "graphql.enabled", notEquals = StringUtils.FALSE) -class GraphQLFactory { - - @Singleton - GraphQLCodeRegistry.Builder codeRegistry() { - GraphQLCodeRegistry.newCodeRegistry() - } - - @Singleton - GraphQLEntityNamingConvention namingConvention() { - new GraphQLEntityNamingConvention() - } - - @Singleton - GraphQLDomainPropertyManager propertyManager() { - new DefaultGraphQLDomainPropertyManager() - } - - @Singleton - GraphQLPaginationResponseHandler paginationResponseHandler() { - new DefaultGraphQLPaginationResponseHandler() - } - - @Singleton - GraphQLDataFetcherManager dataFetcherManager() { - new DefaultGraphQLDataFetcherManager() - } - - @Singleton - GraphQLDeleteResponseHandler deleteResponseHandler() { - new DefaultGraphQLDeleteResponseHandler() - } - - @Singleton - GraphQLInterceptorManager interceptorManager() { - new DefaultGraphQLInterceptorManager() - } - - @Singleton - GraphQLServiceManager serviceManager() { - new GraphQLServiceManager() - } - - @Singleton - GraphQLTypeManager typeManager(GraphQLCodeRegistry.Builder codeRegistry, - GraphQLEntityNamingConvention namingConvention, - GraphQLErrorsResponseHandler errorsResponseHandler, - GraphQLDomainPropertyManager domainPropertyManager, - GraphQLPaginationResponseHandler paginationResponseHandler) { - new DefaultGraphQLTypeManager(codeRegistry, namingConvention, errorsResponseHandler, domainPropertyManager, paginationResponseHandler) - } - - @Singleton - GraphQLDataBinder dataBinder(BeanPropertyBinder beanPropertyBinder) { - new DefaultGraphQLDataBinder(beanPropertyBinder) - } - - @Singleton - GraphQLDataBinderManager dataBinderManager(GraphQLDataBinder dataBinder) { - new DefaultGraphQLDataBinderManager(dataBinder) - } - - @Singleton - GraphQLErrorsResponseHandler errorsResponseHandler(@Nullable MessageSource messageSource, GraphQLCodeRegistry.Builder codeRegistry) { - new DefaultGraphQLErrorsResponseHandler(messageSource ?: new StaticMessageSource(), codeRegistry) - } - - @Singleton - Schema schema(Datastore[] datastores, - GraphQLCodeRegistry.Builder codeRegistry, - GraphQLDeleteResponseHandler deleteResponseHandler, - GraphQLEntityNamingConvention entityNamingConvention, - GraphQLTypeManager typeManager, - GraphQLDataBinderManager dataBinderManager, - GraphQLDataFetcherManager dataFetcherManager, - GraphQLInterceptorManager interceptorManager, - GraphQLPaginationResponseHandler paginationResponseHandler, - GraphQLServiceManager serviceManager, - GraphqlGormConfiguration configuration) { - - MappingContext[] mappingContexts = new MappingContext[datastores.length] - for (int i = 0; i < datastores.length; i++) { - mappingContexts[i] = datastores[i].mappingContext - } - - Schema schema = new Schema(mappingContexts) - schema.codeRegistry = codeRegistry - schema.deleteResponseHandler = deleteResponseHandler - schema.namingConvention = entityNamingConvention - schema.typeManager = typeManager - schema.dataBinderManager = dataBinderManager - schema.dataFetcherManager = dataFetcherManager - schema.interceptorManager = interceptorManager - schema.paginationResponseHandler = paginationResponseHandler - schema.serviceManager = serviceManager - schema.dateFormats = configuration.dateFormats.orElse(null) - schema.dateFormatLenient = configuration.dateFormatLenient - schema.listArguments = configuration.listArguments.orElse(null) - schema - } - - @Singleton - GraphQLSchema graphQLSchema(Schema schema) { - schema.generate() - } - - @Singleton - GraphQL graphQL(GraphQLSchema schema) { - new GraphQL(schema) - } - -} diff --git a/graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/GraphqlGormConfiguration.groovy b/graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/GraphqlGormConfiguration.groovy deleted file mode 100644 index b355c75d..00000000 --- a/graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/GraphqlGormConfiguration.groovy +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.configuration.graphql.gorm - -import groovy.transform.CompileStatic -import io.micronaut.context.annotation.ConfigurationProperties - -/** - * Configuration properties specific to GraphQL GORM. - * - * @author James Kleeh - * @since 1.1.0 - */ -@CompileStatic -@ConfigurationProperties("graphql.gorm") -class GraphqlGormConfiguration { - - Optional> dateFormats = Optional.empty() - boolean dateFormatLenient = false - Optional> listArguments = Optional.empty() -} diff --git a/graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/package-info.groovy b/graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/package-info.groovy deleted file mode 100644 index 9e97a36b..00000000 --- a/graphql-gorm/src/main/groovy/io/micronaut/configuration/graphql/gorm/package-info.groovy +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2017-2020 original 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. - */ -/** - * Configuration for GraphQL GORM. - * - * @author James Kleeh - * @since 1.1.0 - */ -@Configuration -@Requires(classes = [Datastore]) -@Requires(entities = [Entity]) -package io.micronaut.configuration.graphql.gorm - -import grails.gorm.annotation.Entity -import io.micronaut.context.annotation.Configuration -import io.micronaut.context.annotation.Requirements -import io.micronaut.context.annotation.Requires -import org.grails.datastore.mapping.core.Datastore \ No newline at end of file diff --git a/graphql-gorm/src/test/groovy/io/micronaut/configuration/graphql/gorm/Author.groovy b/graphql-gorm/src/test/groovy/io/micronaut/configuration/graphql/gorm/Author.groovy deleted file mode 100644 index f85a5491..00000000 --- a/graphql-gorm/src/test/groovy/io/micronaut/configuration/graphql/gorm/Author.groovy +++ /dev/null @@ -1,16 +0,0 @@ -package io.micronaut.configuration.graphql.gorm - -import grails.gorm.annotation.Entity -import org.grails.gorm.graphql.entity.dsl.GraphQLMapping -import org.grails.gorm.graphql.fetcher.impl.ClosureDataFetchingEnvironment - -@Entity -class Author { - - String name - - static graphql = true - - static constraints = { - } -} diff --git a/graphql-gorm/src/test/groovy/io/micronaut/configuration/graphql/gorm/GraphQLFactorySpec.groovy b/graphql-gorm/src/test/groovy/io/micronaut/configuration/graphql/gorm/GraphQLFactorySpec.groovy deleted file mode 100644 index 71da14ca..00000000 --- a/graphql-gorm/src/test/groovy/io/micronaut/configuration/graphql/gorm/GraphQLFactorySpec.groovy +++ /dev/null @@ -1,64 +0,0 @@ -package io.micronaut.configuration.graphql.gorm - -import graphql.GraphQL -import graphql.schema.GraphQLCodeRegistry -import graphql.schema.GraphQLSchema -import io.micronaut.test.extensions.spock.annotation.MicronautTest -import jakarta.inject.Inject -import org.grails.gorm.graphql.GraphQLServiceManager -import org.grails.gorm.graphql.Schema -import org.grails.gorm.graphql.binding.GraphQLDataBinder -import org.grails.gorm.graphql.binding.manager.GraphQLDataBinderManager -import org.grails.gorm.graphql.entity.GraphQLEntityNamingConvention -import org.grails.gorm.graphql.entity.property.manager.GraphQLDomainPropertyManager -import org.grails.gorm.graphql.fetcher.manager.GraphQLDataFetcherManager -import org.grails.gorm.graphql.interceptor.manager.GraphQLInterceptorManager -import org.grails.gorm.graphql.response.delete.GraphQLDeleteResponseHandler -import org.grails.gorm.graphql.response.errors.GraphQLErrorsResponseHandler -import org.grails.gorm.graphql.response.pagination.GraphQLPaginationResponseHandler -import org.grails.gorm.graphql.types.DefaultGraphQLTypeManager -import org.grails.gorm.graphql.types.GraphQLTypeManager -import spock.lang.Specification - -@MicronautTest -class GraphQLFactorySpec extends Specification { - - @Inject GraphQLCodeRegistry.Builder codeRegistry - @Inject GraphQLEntityNamingConvention namingConvention - @Inject GraphQLDomainPropertyManager domainPropertyManager - @Inject GraphQLPaginationResponseHandler paginationResponseHandler - @Inject GraphQLDataFetcherManager dataFetcherManager - @Inject GraphQLDeleteResponseHandler deleteResponseHandler - @Inject GraphQLInterceptorManager interceptorManager - @Inject GraphQLServiceManager serviceManager - @Inject GraphQLTypeManager typeManager - @Inject GraphQLDataBinder dataBinder - @Inject GraphQLDataBinderManager dataBinderManager - @Inject GraphQLErrorsResponseHandler errorsResponseHandler - @Inject Schema schema - @Inject GraphQLSchema graphQLSchema - @Inject GraphQL graphQL - - void "all beans used are generated by micronaut and not local init methods"() { - expect: - typeManager.codeRegistry == codeRegistry - typeManager.namingConvention == namingConvention - ((DefaultGraphQLTypeManager)typeManager).errorsResponseHandler == errorsResponseHandler - ((DefaultGraphQLTypeManager)typeManager).propertyManager == domainPropertyManager - ((DefaultGraphQLTypeManager)typeManager).paginationResponseHandler == paginationResponseHandler - - and: - dataBinderManager.getDataBinder(GraphQLDataBinder) == dataBinder - - and: - schema.codeRegistry == codeRegistry - schema.deleteResponseHandler == deleteResponseHandler - schema.namingConvention == namingConvention - schema.typeManager == typeManager - schema.dataBinderManager == dataBinderManager - schema.dataFetcherManager == dataFetcherManager - schema.interceptorManager == interceptorManager - schema.paginationResponseHandler == paginationResponseHandler - schema.serviceManager == serviceManager - } -} diff --git a/groovy-bom/build.gradle b/groovy-bom/build.gradle index 3c0f201d..4bd86ccc 100644 --- a/groovy-bom/build.gradle +++ b/groovy-bom/build.gradle @@ -5,3 +5,14 @@ plugins { dependencies { api platform("org.apache.groovy:groovy-bom:$groovyVersion") } +micronautBom { + suppressions { + // GORM does not yet work with Groovy 4 + acceptedLibraryRegressions.add("micronaut-mongo-gorm") + acceptedLibraryRegressions.add("micronaut-graphql-gorm") + acceptedLibraryRegressions.add("micronaut-hibernate-gorm") + acceptedLibraryRegressions.add("micronaut-neo4j-gorm") + acceptedLibraryRegressions.add("micronaut-multitenancy-gorm") + acceptedLibraryRegressions.add("micronaut-gorm-common") + } +} diff --git a/hibernate-gorm/build.gradle b/hibernate-gorm/build.gradle deleted file mode 100644 index f3ec8e7c..00000000 --- a/hibernate-gorm/build.gradle +++ /dev/null @@ -1,26 +0,0 @@ -plugins { - id 'io.micronaut.build.internal.groovy-module' -} - -dependencies { - annotationProcessor mn.micronaut.inject.java - - api projects.gormCommon - api "org.grails:grails-datastore-gorm-hibernate5:$gormHibernateVersion" - - compileOnly mn.micronaut.inject.groovy - - implementation(platform(mn.micronaut.bom)) - implementation projects.runtimeGroovy - implementation mn.micronaut.spring - implementation mn.groovy - - runtimeOnly libs.jaxb.api // included for Java 11 - - testCompileOnly mn.micronaut.inject.groovy - - testRuntimeOnly libs.h2 - testRuntimeOnly libs.tomcat.jdbc - testRuntimeOnly libs.hibernate.ehcache -} -//compileTestGroovy.groovyOptions.forkOptions.jvmArgs = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005'] diff --git a/hibernate-gorm/src/main/groovy/io/micronaut/configuration/hibernate/gorm/HibernateDatastoreFactory.groovy b/hibernate-gorm/src/main/groovy/io/micronaut/configuration/hibernate/gorm/HibernateDatastoreFactory.groovy deleted file mode 100644 index 9491c814..00000000 --- a/hibernate-gorm/src/main/groovy/io/micronaut/configuration/hibernate/gorm/HibernateDatastoreFactory.groovy +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.configuration.hibernate.gorm - -import grails.gorm.annotation.Entity -import groovy.transform.CompileStatic -import groovy.util.logging.Slf4j -import io.micronaut.configuration.gorm.configuration.GormPropertyResolverAdapter -import io.micronaut.configuration.gorm.event.ConfigurableEventPublisherAdapter -import io.micronaut.context.ApplicationContext -import io.micronaut.context.annotation.Bean -import io.micronaut.context.annotation.Context -import io.micronaut.context.annotation.Factory -import io.micronaut.context.annotation.Primary -import io.micronaut.context.annotation.Prototype -import io.micronaut.context.event.BeanInitializedEventListener -import io.micronaut.context.event.BeanInitializingEvent -import io.micronaut.core.annotation.Internal -import io.micronaut.inject.qualifiers.Qualifiers -import jakarta.inject.Named -import jakarta.inject.Singleton -import org.grails.datastore.mapping.services.Service -import org.grails.orm.hibernate.HibernateDatastore -import org.grails.orm.hibernate.connections.HibernateConnectionSource -import org.hibernate.SessionFactory -import org.springframework.transaction.PlatformTransactionManager - -import javax.sql.DataSource -import java.util.stream.Stream - -/** - *

A factory for configuring GORM for Hibernate 5 within Micronaut

. - * - * @author Graeme Rocher - * @since 1.0 - */ -@Factory -@CompileStatic -@Slf4j -class HibernateDatastoreFactory { - - final ApplicationContext applicationContext - - HibernateDatastoreFactory(ApplicationContext applicationContext) { - this.applicationContext = applicationContext - } - - @Bean(preDestroy = "close") - @Context - HibernateDatastore hibernateDatastore() { - log.info("Starting GORM for Hibernate") - Stream> entities = applicationContext.environment.scan(Entity) - Class[] classes = entities.toArray() as Class[] - return new HibernateDatastore( - new GormPropertyResolverAdapter(applicationContext, applicationContext), - new ConfigurableEventPublisherAdapter(applicationContext), - classes - ) - } - - @Bean - @Context - Dummy postHibernateDatastore(HibernateDatastore hibernateDatastore) { - // Create dummy context bean to inject services after HibernateDatastore is created to avoid circular problems - Collection> gormServices = hibernateDatastore.getServices().split { - !it.class.isAnnotationPresent(grails.gorm.services.Service) - } - for (services in gormServices) { - for (o in services) { - applicationContext.registerSingleton(o, false) - } - for (o in services) { - applicationContext.inject(o) - } - } - return new Dummy() - } - - @Singleton - SessionFactory sessionFactory(HibernateDatastore hibernateDatastore) { - hibernateDatastore.getSessionFactory() - } - - @Singleton - DataSource dataSource(HibernateDatastore hibernateDatastore) { - ((HibernateConnectionSource) hibernateDatastore.getConnectionSources().defaultConnectionSource).getDataSource() - } - - @Primary - @Named("hibernate") - @Singleton - PlatformTransactionManager transactionManager(HibernateDatastore hibernateDatastore) { - hibernateDatastore.getTransactionManager() - } - -} - -@Internal -class Dummy { -} diff --git a/hibernate-gorm/src/main/groovy/io/micronaut/configuration/hibernate/gorm/package-info.java b/hibernate-gorm/src/main/groovy/io/micronaut/configuration/hibernate/gorm/package-info.java deleted file mode 100644 index 0942046b..00000000 --- a/hibernate-gorm/src/main/groovy/io/micronaut/configuration/hibernate/gorm/package-info.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2017-2020 original 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. - */ -/** - * Configuration for GORM for Hibernate. - * - * @author graemerocher - * @since 1.0 - */ -@Configuration -@Requires(classes = HibernateDatastore.class) -@Requires(classes = SessionFactory.class) -@Requires(entities = Entity.class) -package io.micronaut.configuration.hibernate.gorm; - -import grails.gorm.annotation.Entity; -import io.micronaut.context.annotation.Configuration; -import io.micronaut.context.annotation.Requires; -import org.grails.orm.hibernate.HibernateDatastore; -import org.hibernate.SessionFactory; diff --git a/hibernate-gorm/src/test/groovy/io/micronaut/configuration/hibernate/gorm/GormConfigSpec.groovy b/hibernate-gorm/src/test/groovy/io/micronaut/configuration/hibernate/gorm/GormConfigSpec.groovy deleted file mode 100644 index 89fee9c1..00000000 --- a/hibernate-gorm/src/test/groovy/io/micronaut/configuration/hibernate/gorm/GormConfigSpec.groovy +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright 2017-2019 original 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 io.micronaut.configuration.hibernate.gorm - -import grails.gorm.annotation.Entity -import grails.gorm.services.Service -import grails.gorm.transactions.TransactionService -import io.micronaut.context.annotation.Primary -import io.micronaut.inject.qualifiers.Qualifiers -import jakarta.inject.Inject -import jakarta.inject.Singleton -import org.grails.datastore.mapping.validation.ValidationException -import org.grails.orm.hibernate.GrailsHibernateTransactionManager -import org.grails.orm.hibernate.cfg.Settings -import io.micronaut.context.ApplicationContext -import io.micronaut.context.DefaultApplicationContext -import io.micronaut.context.annotation.Value -import io.micronaut.context.env.PropertySource -import org.springframework.transaction.PlatformTransactionManager -import spock.lang.Shared -import spock.lang.Specification - -import javax.annotation.PostConstruct -import javax.sql.DataSource - -/** - * @author Graeme Rocher - * @since 1.0 - */ -class GormConfigSpec extends Specification { - - @Shared Map sharedConfig = ['hibernate.cache.use_second_level_cache':true, - 'hibernate.cache.use_query_cache':false, - 'hibernate.cache.region.factory_class':'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' - ] - - void "verity PlatformTransactionManager is qualified with name hibernate"() { - given: - ApplicationContext applicationContext = ApplicationContext.builder(applicationContextConfig) - .mainClass(GormConfigSpec) - .start() - - expect: - applicationContext.containsBean(PlatformTransactionManager) - - and: - applicationContext.containsBean(PlatformTransactionManager, Qualifiers.byName("hibernate")) - - and: - applicationContext.containsBean(PlatformTransactionManager, Qualifiers.byStereotype(Primary)) - - and: 'two beans: one created by the factory and the MockPlatformTransactionManager' - applicationContext.getBeansOfType(PlatformTransactionManager).size() == 2 - - when: - PlatformTransactionManager platformTransactionManager = applicationContext.getBean(PlatformTransactionManager) - - then: 'GrailsHibernateTransactionManager because the factory annotates with @Primary' - noExceptionThrown() - - and: - platformTransactionManager instanceof GrailsHibernateTransactionManager - - cleanup: - applicationContext.close() - } - - private Map getApplicationContextConfig() { - [ - (Settings.SETTING_DB_CREATE):'create-drop', - 'dataSource.url':'jdbc:h2:mem:someOtherDb', - 'dataSource.properties.initialSize':25 - ] + sharedConfig - } - - void "test beans for custom data source"() { - given: - ApplicationContext applicationContext = ApplicationContext.builder(applicationContextConfig) - .mainClass(GormConfigSpec) - .start() - - DataSource dataSource = applicationContext.getBean(DataSource).targetDataSource.targetDataSource - - expect: - dataSource.poolProperties.url == 'jdbc:h2:mem:someOtherDb' - dataSource.poolProperties.initialSize == 25 - - cleanup: - applicationContext.close() - } - - void "test gorm configured correctly"() { - - given: - def config = [(Settings.SETTING_DB_CREATE): 'create-drop'] + sharedConfig - ApplicationContext applicationContext = ApplicationContext.builder(config) - .mainClass(GormConfigSpec) - .start() - - when: - TransactionService transactionService = applicationContext.getBean(TransactionService) - int count = transactionService.withTransaction { - Book.count - } - - then: - applicationContext.containsBean(PlatformTransactionManager) - applicationContext.containsBean(DataSource) - count == 0 - - when: - BookService bookService = applicationContext.getBean(BookService) - - then: - bookService.dbCreate == 'create-drop' - bookService.list().size() == 0 - bookService.initCalled - - cleanup: - applicationContext.stop() - } - - void "test gorm configured correctly again"() { - given: - ApplicationContext applicationContext = new DefaultApplicationContext("test") - applicationContext.environment - .addPackage(getClass().getPackage()) - .addPropertySource(PropertySource.of("test",[(Settings.SETTING_DB_CREATE):'create-drop'] + sharedConfig)) - applicationContext.start() - - when: - TransactionService transactionService = applicationContext.getBean(TransactionService) - int count = transactionService.withTransaction { - Book.count - } - - then: - applicationContext.containsBean(PlatformTransactionManager) - applicationContext.containsBean(DataSource) - count == 0 - - when: - Book.withNewSession { - new Book(title: "").save() - } - - then: - def e = thrown(ValidationException) - - when: - count = transactionService.withTransaction { - new Book(title: "the stand").save() - Book.count - } - - then: - count == 1 - - when: - Book book = transactionService.withTransaction { - Book.first() - } - - then: - book - book.dateCreated - book.title == 'the stand' - - when: - Book updatedBook = transactionService.withTransaction { - def b = Book.first() - b.title = 'the shining' - b.save(flush:true) - } - - then: - updatedBook - updatedBook.dateCreated - updatedBook.dateCreated < updatedBook.lastUpdated - - cleanup: - applicationContext.stop() - } -} - -@Entity -class Book { - String title - Date dateCreated - Date lastUpdated - - static constraints = { - title blank:false - } - - static mapping = { - cache true - } -} - -@Service(Book) -@Singleton -abstract class BookService { - - @Inject DataSource dataSource - @Inject TransactionService transactionService - - @Value('${data-source.db-create}') - String dbCreate - - boolean initCalled = false - - @PostConstruct - void init() { - initCalled = true - } - - abstract List list() -} diff --git a/hibernate-gorm/src/test/groovy/io/micronaut/configuration/hibernate/gorm/MockPlatformTransactionManager.groovy b/hibernate-gorm/src/test/groovy/io/micronaut/configuration/hibernate/gorm/MockPlatformTransactionManager.groovy deleted file mode 100644 index 096835c0..00000000 --- a/hibernate-gorm/src/test/groovy/io/micronaut/configuration/hibernate/gorm/MockPlatformTransactionManager.groovy +++ /dev/null @@ -1,27 +0,0 @@ -package io.micronaut.configuration.hibernate.gorm - -import jakarta.inject.Singleton -import org.springframework.lang.Nullable -import org.springframework.transaction.PlatformTransactionManager -import org.springframework.transaction.TransactionDefinition -import org.springframework.transaction.TransactionException -import org.springframework.transaction.TransactionStatus - -@Singleton -class MockPlatformTransactionManager implements PlatformTransactionManager { - - @Override - TransactionStatus getTransaction(@Nullable TransactionDefinition definition) throws TransactionException { - return null - } - - @Override - void commit(TransactionStatus status) throws TransactionException { - - } - - @Override - void rollback(TransactionStatus status) throws TransactionException { - - } -} diff --git a/mongo-gorm/build.gradle b/mongo-gorm/build.gradle deleted file mode 100644 index 28c32a99..00000000 --- a/mongo-gorm/build.gradle +++ /dev/null @@ -1,27 +0,0 @@ -plugins { - id 'io.micronaut.build.internal.groovy-module' -} - -dependencies { - annotationProcessor mn.micronaut.inject.java - - api libs.gorm.mongo - - compileOnly mn.micronaut.http.server - compileOnly mn.micronaut.inject.groovy - - implementation(platform(mn.micronaut.bom)) - implementation projects.runtimeGroovy - implementation projects.gormCommon - implementation mn.micronaut.hibernate.validator - implementation mn.micronaut.mongo.sync - implementation mn.micronaut.spring - implementation mn.groovy - implementation libs.mongodb.driver.sync - - testCompileOnly mn.micronaut.inject.groovy - - testImplementation mn.micronaut.http.client - testImplementation mn.micronaut.http.server - testImplementation libs.testcontainers.spock -} diff --git a/mongo-gorm/src/main/java/io/micronaut/configuration/mongo/gorm/MongoDatastoreFactory.java b/mongo-gorm/src/main/java/io/micronaut/configuration/mongo/gorm/MongoDatastoreFactory.java deleted file mode 100644 index 578968cf..00000000 --- a/mongo-gorm/src/main/java/io/micronaut/configuration/mongo/gorm/MongoDatastoreFactory.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.configuration.mongo.gorm; - -import com.mongodb.client.MongoClient; -import grails.gorm.annotation.Entity; -import grails.mongodb.MongoEntity; -import io.micronaut.configuration.gorm.configuration.GormPropertyResolverAdapter; -import io.micronaut.configuration.gorm.event.ConfigurableEventPublisherAdapter; -import io.micronaut.context.ApplicationContext; -import io.micronaut.context.annotation.Bean; -import io.micronaut.context.annotation.Context; -import io.micronaut.context.annotation.Factory; -import io.micronaut.context.annotation.Primary; -import io.micronaut.context.annotation.Secondary; -import io.micronaut.context.env.Environment; -import io.micronaut.spring.core.env.PropertyResolverAdapter; -import jakarta.inject.Named; -import jakarta.inject.Singleton; -import org.grails.datastore.mapping.mongo.MongoDatastore; -import org.springframework.transaction.PlatformTransactionManager; - -/** - * Sets up GORM for MongoDB. - * - * @author graemerocher - * @since 1.0 - */ -@Factory -public class MongoDatastoreFactory { - - /** - * Factory method that will return the datastore. - * @param applicationContext applicationContext - * @param mongoClient mongoClient - * @return mongoDatastore - */ - @Context - @Bean - @Primary - MongoDatastore mongoDatastore(ApplicationContext applicationContext, MongoClient mongoClient) { - Environment environment = applicationContext.getEnvironment(); - Class[] entities = environment.scan(Entity.class) - .filter(MongoEntity.class::isAssignableFrom) - .toArray(Class[]::new); - - PropertyResolverAdapter propertyResolver = new GormPropertyResolverAdapter( - applicationContext, - applicationContext - ); - MongoDatastore datastore = new MongoDatastore(mongoClient, propertyResolver, - new ConfigurableEventPublisherAdapter(applicationContext), - entities); - Iterable services = datastore.getServices(); - for (Object service : services) { - applicationContext.registerSingleton( - service, false - ); - } - for (Object service : services) { - applicationContext.inject(service); - } - return datastore; - } - - /** - * Return the transaction manager for the database. - * @param datastore datastore - * @return transactionManager - */ - @Singleton - @Named("mongo") - @Secondary - PlatformTransactionManager transactionManager(MongoDatastore datastore) { - return datastore.getTransactionManager(); - } -} diff --git a/mongo-gorm/src/main/java/io/micronaut/configuration/mongo/gorm/package-info.java b/mongo-gorm/src/main/java/io/micronaut/configuration/mongo/gorm/package-info.java deleted file mode 100644 index 5379c9cd..00000000 --- a/mongo-gorm/src/main/java/io/micronaut/configuration/mongo/gorm/package-info.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2017-2020 original 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. - */ -/** - * GORM for MongoDB. - * - * @author graemerocher - * @since 1.0 - */ -@Configuration -@Requires(classes = MongoClient.class) -@Requires(property = MongoSettings.PREFIX) -@Requires(entities = Entity.class) -package io.micronaut.configuration.mongo.gorm; - -import com.mongodb.client.MongoClient; -import grails.gorm.annotation.Entity; -import io.micronaut.configuration.mongo.core.MongoSettings; -import io.micronaut.context.annotation.Configuration; -import io.micronaut.context.annotation.Requires; diff --git a/mongo-gorm/src/test/groovy/io/micronaut/configuration/mongo/gorm/MongoDatastoreFactorySpec.groovy b/mongo-gorm/src/test/groovy/io/micronaut/configuration/mongo/gorm/MongoDatastoreFactorySpec.groovy deleted file mode 100644 index ae824701..00000000 --- a/mongo-gorm/src/test/groovy/io/micronaut/configuration/mongo/gorm/MongoDatastoreFactorySpec.groovy +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2017-2019 original 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 io.micronaut.configuration.mongo.gorm - -import com.mongodb.client.MongoClient -import grails.gorm.annotation.Entity -import grails.gorm.transactions.Rollback -import io.micronaut.configuration.mongo.core.MongoSettings -import io.micronaut.context.ApplicationContext -import org.grails.datastore.mapping.mongo.MongoDatastore -import org.grails.datastore.mapping.validation.ValidationException -import org.testcontainers.containers.GenericContainer -import spock.lang.AutoCleanup -import spock.lang.Shared -import spock.lang.Specification - -import javax.validation.constraints.NotBlank - -/** - * @author graemerocher* @since 1.0 - */ -class MongoDatastoreFactorySpec extends Specification { - - @Shared - @AutoCleanup - GenericContainer mongo = - new GenericContainer("mongo:4.0") - .withExposedPorts(27017) - - @Shared - @AutoCleanup - ApplicationContext applicationContext - - def setupSpec() { - mongo.start() - applicationContext = ApplicationContext.builder((MongoSettings.MONGODB_URI): "mongodb://${mongo.containerIpAddress}:${mongo.getMappedPort(27017)}") - .mainClass(MongoDatastoreFactorySpec) - .start() - } - - @Rollback - void "test configure GORM for MongoDB"() { - when: - new Team(name: "United").save(flush: true) - - then: - Team.count() == old(Team.count()) + 1 - Team.last().name == "United" - Team.last().dateCreated != null - } - - @Rollback - void "test validation errors"() { - when: - new Team(name: "").save(failOnError: true) - - then: - thrown(ValidationException) - } - - void "test MongoClient is available"() { - expect: - applicationContext.containsBean(MongoClient) - applicationContext.getBean(MongoClient) - applicationContext.getBean(MongoDatastore) - } -} - -@Entity -class Team { - @NotBlank - String name - Date dateCreated -} diff --git a/multitenancy-gorm/build.gradle b/multitenancy-gorm/build.gradle deleted file mode 100644 index 9cae2a40..00000000 --- a/multitenancy-gorm/build.gradle +++ /dev/null @@ -1,9 +0,0 @@ -plugins { - id 'io.micronaut.build.internal.groovy-module' -} - -dependencies { - api "org.grails:grails-datastore-core:$gormVersion" - implementation(platform(mn.micronaut.bom)) - implementation mn.micronaut.multitenancy -} diff --git a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/CookieTenantResolver.java b/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/CookieTenantResolver.java deleted file mode 100644 index b8248865..00000000 --- a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/CookieTenantResolver.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.multitenancy.gorm; - -import io.micronaut.multitenancy.tenantresolver.CookieTenantResolverConfigurationProperties; -import org.grails.datastore.mapping.multitenancy.TenantResolver; -import org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException; - -import java.io.Serializable; - -/** - * A tenant resolver that resolves the tenant from the request HTTP Header. - * - * @author Sergio del Amo - * @since 1.0.0 - */ -public class CookieTenantResolver implements TenantResolver { - - protected final TenantResolver delegate = new TenantResolverAdapter(new io.micronaut.multitenancy.tenantresolver.CookieTenantResolver(new CookieTenantResolverConfigurationProperties())); - - /** - * Constructs a HTTP Header tenant resolver. - */ - public CookieTenantResolver() { - - } - - @Override - public Serializable resolveTenantIdentifier() throws TenantNotFoundException { - return delegate.resolveTenantIdentifier(); - } -} diff --git a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/FixedTenantResolver.java b/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/FixedTenantResolver.java deleted file mode 100644 index dc080fc7..00000000 --- a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/FixedTenantResolver.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.multitenancy.gorm; - -import io.micronaut.multitenancy.tenantresolver.FixedTenantResolverConfigurationProperties; -import org.grails.datastore.mapping.multitenancy.TenantResolver; -import org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException; - -import java.io.Serializable; - -/** - * A tenant resolver that resolves the tenant from the request HTTP Header. - * - * @author Sergio del Amo - * @since 1.0.0 - */ -public class FixedTenantResolver implements TenantResolver { - - protected final TenantResolver delegate = new TenantResolverAdapter(new io.micronaut.multitenancy.tenantresolver.FixedTenantResolver(new FixedTenantResolverConfigurationProperties())); - - /** - * Constructs a FixedTenantResolver. - */ - public FixedTenantResolver() { - - } - - @Override - public Serializable resolveTenantIdentifier() throws TenantNotFoundException { - return delegate.resolveTenantIdentifier(); - } -} diff --git a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/HttpHeaderTenantResolver.java b/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/HttpHeaderTenantResolver.java deleted file mode 100644 index cd6ace8a..00000000 --- a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/HttpHeaderTenantResolver.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.multitenancy.gorm; - -import io.micronaut.multitenancy.tenantresolver.HttpHeaderTenantResolverConfigurationProperties; -import org.grails.datastore.mapping.multitenancy.TenantResolver; -import org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException; - -import java.io.Serializable; - -/** - * A tenant resolver that resolves the tenant from the request HTTP Header. - * - * @author Sergio del Amo - * @since 1.0.0 - */ -public class HttpHeaderTenantResolver implements TenantResolver { - - protected final TenantResolver delegate = new TenantResolverAdapter(new io.micronaut.multitenancy.tenantresolver.HttpHeaderTenantResolver(new HttpHeaderTenantResolverConfigurationProperties())); - - /** - * Constructs a HTTP Header tenant resolver. - */ - public HttpHeaderTenantResolver() { - - } - - @Override - public Serializable resolveTenantIdentifier() throws TenantNotFoundException { - return delegate.resolveTenantIdentifier(); - } -} diff --git a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/PrincipalTenantResolver.java b/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/PrincipalTenantResolver.java deleted file mode 100644 index 1dde3350..00000000 --- a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/PrincipalTenantResolver.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.multitenancy.gorm; - -import org.grails.datastore.mapping.multitenancy.TenantResolver; -import org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException; - -import java.io.Serializable; - -/** - * A tenant resolver that resolves the tenant from the authenticated principal. - * - * @author Sergio del Amo - * @since 1.0.0 - */ -public class PrincipalTenantResolver implements TenantResolver { - - protected final TenantResolver delegate = new TenantResolverAdapter(new io.micronaut.multitenancy.tenantresolver.PrincipalTenantResolver()); - - /** - * Constructs a Principal Tenant Resolver. - */ - public PrincipalTenantResolver() { - - } - - @Override - public Serializable resolveTenantIdentifier() throws TenantNotFoundException { - return delegate.resolveTenantIdentifier(); - } -} diff --git a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/SessionTenantResolver.java b/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/SessionTenantResolver.java deleted file mode 100644 index 99bf8dc7..00000000 --- a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/SessionTenantResolver.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.multitenancy.gorm; - -import io.micronaut.multitenancy.tenantresolver.SessionTenantResolverConfigurationProperties; -import org.grails.datastore.mapping.multitenancy.TenantResolver; -import org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException; -import java.io.Serializable; - -/** - * Resolves the tenant id from the user HTTP session. - * - * @author Sergio del Amo - * @since 1.0.0 - */ -public class SessionTenantResolver implements TenantResolver { - - protected final TenantResolver delegate = new TenantResolverAdapter(new io.micronaut.multitenancy.tenantresolver.SessionTenantResolver(new SessionTenantResolverConfigurationProperties())); - - /** - * Constructs a Session Tenant Resolver. - */ - public SessionTenantResolver() { - - } - - @Override - public Serializable resolveTenantIdentifier() throws TenantNotFoundException { - return delegate.resolveTenantIdentifier(); - } -} diff --git a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/SubdomainTenantResolver.java b/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/SubdomainTenantResolver.java deleted file mode 100644 index 8c1899d0..00000000 --- a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/SubdomainTenantResolver.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.multitenancy.gorm; - -import org.grails.datastore.mapping.multitenancy.TenantResolver; -import org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException; - -import java.io.Serializable; - -/** - * A tenant resolver that resolves the tenant from the Subdomain. - * - * - * @author Sergio del Amo - * @since 1.0.0 - */ -public class SubdomainTenantResolver implements TenantResolver { - - protected final TenantResolver delegate = new TenantResolverAdapter(new io.micronaut.multitenancy.tenantresolver.SubdomainTenantResolver()); - - /** - * Constructs a Subdomain Tenant Resolver. - */ - public SubdomainTenantResolver() { - - } - - @Override - public Serializable resolveTenantIdentifier() throws TenantNotFoundException { - return delegate.resolveTenantIdentifier(); - } -} diff --git a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/SystemPropertyTenantResolver.java b/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/SystemPropertyTenantResolver.java deleted file mode 100644 index e2efd187..00000000 --- a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/SystemPropertyTenantResolver.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.multitenancy.gorm; - -import io.micronaut.multitenancy.tenantresolver.SystemPropertyTenantResolverConfigurationProperties; -import org.grails.datastore.mapping.multitenancy.TenantResolver; -import org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException; - -import java.io.Serializable; - -/** - * A tenant resolver that resolves the tenant from the request HTTP Header. - * - * @author Sergio del Amo - * @since 1.0.0 - */ -public class SystemPropertyTenantResolver implements TenantResolver { - - protected final TenantResolver delegate = new TenantResolverAdapter(new io.micronaut.multitenancy.tenantresolver.SystemPropertyTenantResolver(new SystemPropertyTenantResolverConfigurationProperties())); - - /** - * Constructs a System property Tenant Resolver. - */ - public SystemPropertyTenantResolver() { - - } - - @Override - public Serializable resolveTenantIdentifier() throws TenantNotFoundException { - return delegate.resolveTenantIdentifier(); - } -} diff --git a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/TenantResolverAdapter.java b/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/TenantResolverAdapter.java deleted file mode 100644 index afc6c33b..00000000 --- a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/TenantResolverAdapter.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.multitenancy.gorm; - -import io.micronaut.multitenancy.exceptions.TenantException; -import io.micronaut.multitenancy.exceptions.TenantNotFoundException; -import io.micronaut.multitenancy.tenantresolver.TenantResolver; - -import java.io.Serializable; - -/** - * An adapter between GORM {@link org.grails.datastore.mapping.multitenancy.TenantResolver} and Micronaut {@link io.micronaut.multitenancy.tenantresolver.TenantResolver}. - * - * @author Sergio del Amo - * @since 1.0.0 - */ -public class TenantResolverAdapter implements org.grails.datastore.mapping.multitenancy.TenantResolver { - - private final TenantResolver tenantResolver; - - /** - * - * @param tenantResolver a Micronaut {@link io.micronaut.multitenancy.tenantresolver.TenantResolver}. - */ - public TenantResolverAdapter(TenantResolver tenantResolver) { - this.tenantResolver = tenantResolver; - } - - @Override - public Serializable resolveTenantIdentifier() throws org.grails.datastore.mapping.multitenancy.exceptions.TenantException { - try { - return tenantResolver.resolveTenantIdentifier(); - } catch (TenantException e) { - if (e instanceof TenantNotFoundException) { - throw new org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException(e.getMessage(), e.getCause()); - } - throw new org.grails.datastore.mapping.multitenancy.exceptions.TenantException(e.getMessage(), e.getCause()); - } - } -} diff --git a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/package-info.java b/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/package-info.java deleted file mode 100644 index 39da7fc9..00000000 --- a/multitenancy-gorm/src/main/java/io/micronaut/multitenancy/gorm/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2017-2020 original 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. - */ -/** - * GORM Multitenancy - Micronaut Multitenancy Bridge. - * - * @author Sergio del Amo - * @since 1.0 - */ -package io.micronaut.multitenancy.gorm; diff --git a/neo4j-gorm/.gitignore b/neo4j-gorm/.gitignore deleted file mode 100644 index adbb97d2..00000000 --- a/neo4j-gorm/.gitignore +++ /dev/null @@ -1 +0,0 @@ -data/ \ No newline at end of file diff --git a/neo4j-gorm/build.gradle b/neo4j-gorm/build.gradle deleted file mode 100644 index 25ac0d2e..00000000 --- a/neo4j-gorm/build.gradle +++ /dev/null @@ -1,25 +0,0 @@ -plugins { - id 'io.micronaut.build.internal.groovy-module' -} - -dependencies { - annotationProcessor mn.micronaut.inject.java - api libs.gorm.neo4j - compileOnly mn.micronaut.inject.groovy - - implementation(platform(mn.micronaut.bom)) - implementation projects.gormCommon - implementation projects.runtimeGroovy - implementation mn.micronaut.hibernate.validator - implementation mn.micronaut.neo4j - implementation mn.micronaut.spring - - testImplementation mn.micronaut.http.client - testImplementation mn.micronaut.http.server - testImplementation mn.micronaut.inject.groovy - - testRuntimeOnly libs.netty.native - testRuntimeOnly('org.neo4j.test:neo4j-harness') { - exclude group: 'io.netty', module: 'netty-all' - } -} diff --git a/neo4j-gorm/src/main/groovy/io/micronaut/configuration/neo4j/gorm/Neo4jDatastoreFactory.groovy b/neo4j-gorm/src/main/groovy/io/micronaut/configuration/neo4j/gorm/Neo4jDatastoreFactory.groovy deleted file mode 100644 index 37b7ea27..00000000 --- a/neo4j-gorm/src/main/groovy/io/micronaut/configuration/neo4j/gorm/Neo4jDatastoreFactory.groovy +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.configuration.neo4j.gorm - -import grails.gorm.annotation.Entity -import grails.neo4j.Neo4jEntity -import groovy.transform.CompileStatic -import io.micronaut.configuration.gorm.event.ConfigurableEventPublisherAdapter -import io.micronaut.configuration.neo4j.gorm.configuration.GormPropertyResolverAdapter -import io.micronaut.context.ApplicationContext -import io.micronaut.context.annotation.Bean -import io.micronaut.context.annotation.Context -import io.micronaut.context.annotation.Factory -import io.micronaut.context.annotation.Requires -import io.micronaut.context.env.Environment -import io.micronaut.neo4j.bolt.condition.RequiresNeo4j -import jakarta.inject.Named -import jakarta.inject.Singleton -import org.grails.datastore.gorm.neo4j.Neo4jDatastore -import org.grails.datastore.gorm.neo4j.Neo4jDatastoreTransactionManager -import org.neo4j.driver.Driver - -import java.util.stream.Stream - -/** - * A factory for configuring GORM for Neo4j - * - * @author graemerocher - * @since 1.0 - */ -@CompileStatic -@Factory -@RequiresNeo4j -@Requires(beans = Driver) -class Neo4jDatastoreFactory { - - @Context - @Bean(preDestroy = "close") - Neo4jDatastore neo4jDatastore(Driver driver, ApplicationContext applicationContext) { - Environment environment = applicationContext.getEnvironment() - Stream> entities = environment.scan(Entity) - .filter({ Class c -> Neo4jEntity.isAssignableFrom(c) }) - Class[] classes = entities.toArray() as Class[] - Neo4jDatastore datastore = new Neo4jDatastore( - driver, - new GormPropertyResolverAdapter(applicationContext, applicationContext), - new ConfigurableEventPublisherAdapter(applicationContext), - classes - ) - for (o in datastore.getServices()) { - applicationContext.registerSingleton( - o, - false - ) - } - for (o in datastore.getServices()) { - applicationContext.inject(o) - } - return datastore - } - - @Singleton - @Named("neo4j") - Neo4jDatastoreTransactionManager neo4jDatastoreTransactionManager(Neo4jDatastore datastore) { - return datastore.getTransactionManager() - } -} diff --git a/neo4j-gorm/src/main/groovy/io/micronaut/configuration/neo4j/gorm/configuration/GormPropertyResolverAdapter.java b/neo4j-gorm/src/main/groovy/io/micronaut/configuration/neo4j/gorm/configuration/GormPropertyResolverAdapter.java deleted file mode 100644 index 60ff2c3b..00000000 --- a/neo4j-gorm/src/main/groovy/io/micronaut/configuration/neo4j/gorm/configuration/GormPropertyResolverAdapter.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2017-2020 original 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 io.micronaut.configuration.neo4j.gorm.configuration; - -import io.micronaut.context.env.PropertyPlaceholderResolver; -import io.micronaut.core.value.PropertyResolver; -import io.micronaut.spring.core.env.PropertyResolverAdapter; -import org.grails.datastore.mapping.config.Settings; - -/** - * Resolves default settings for GORM. - * - * @author graemerocher - * @since 1.0 - */ -public class GormPropertyResolverAdapter extends PropertyResolverAdapter { - /** - * Constructor. - * @param propertyResolver propertyResolver - * @param placeholderResolver placeholderResolver - */ - public GormPropertyResolverAdapter(PropertyResolver propertyResolver, PropertyPlaceholderResolver placeholderResolver) { - super(propertyResolver, placeholderResolver); - } - - @SuppressWarnings("unchecked") - @Override - public T getProperty(String key, Class targetType, T defaultValue) { - T v = super.getProperty(key, targetType, defaultValue); - if (v == null && isKeyFailedOnError(key) && boolean.class.isAssignableFrom(targetType)) { - return (T) Boolean.TRUE; - } - return v; - } - - /** - * Is the failed on error key set. - * @param key key - * @return boolean - */ - protected boolean isKeyFailedOnError(String key) { - return key.equalsIgnoreCase(Settings.SETTING_FAIL_ON_ERROR) || key.equalsIgnoreCase(org.grails.datastore.gorm.neo4j.config.Settings.PREFIX + ".failOnError"); - } -} diff --git a/neo4j-gorm/src/main/groovy/io/micronaut/configuration/neo4j/gorm/configuration/package-info.java b/neo4j-gorm/src/main/groovy/io/micronaut/configuration/neo4j/gorm/configuration/package-info.java deleted file mode 100644 index 21d70b2e..00000000 --- a/neo4j-gorm/src/main/groovy/io/micronaut/configuration/neo4j/gorm/configuration/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2017-2020 original 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. - */ -/** - * Neo4j GORM configuration. - * - * @author Sergio del Amo - * @since 1.0 - */ -package io.micronaut.configuration.neo4j.gorm.configuration; - diff --git a/neo4j-gorm/src/test/groovy/io/micronaut/configuration/neo4j/gorm/Neo4jDatastoreFactorySpec.groovy b/neo4j-gorm/src/test/groovy/io/micronaut/configuration/neo4j/gorm/Neo4jDatastoreFactorySpec.groovy deleted file mode 100644 index ffe98908..00000000 --- a/neo4j-gorm/src/test/groovy/io/micronaut/configuration/neo4j/gorm/Neo4jDatastoreFactorySpec.groovy +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2017-2019 original 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 io.micronaut.configuration.neo4j.gorm - -import grails.gorm.annotation.Entity -import grails.gorm.transactions.Rollback -import io.micronaut.inject.qualifiers.Qualifiers -import io.micronaut.neo4j.bolt.Neo4jBoltSettings -import org.grails.datastore.gorm.neo4j.Neo4jDatastoreTransactionManager -import org.grails.datastore.mapping.validation.ValidationException -import io.micronaut.context.ApplicationContext -import spock.lang.AutoCleanup -import spock.lang.Requires -import spock.lang.Shared -import spock.lang.Specification - -import javax.validation.constraints.NotBlank - -/** - * @author graemerocher - * @since 1.0 - */ -@Requires({ !jvm.isJava9Compatible() }) -class Neo4jDatastoreFactorySpec extends Specification { - - @Shared @AutoCleanup ApplicationContext applicationContext = ApplicationContext.run('neo4j.uri': Neo4jBoltSettings.DEFAULT_URI) - - void "verify Neo4jDatastoreTransactionManager is qualified with name neo4j"() { - expect: - applicationContext.containsBean(Neo4jDatastoreTransactionManager) - - and: - applicationContext.containsBean(Neo4jDatastoreTransactionManager, Qualifiers.byName("neo4j")) - } - - @Rollback - void "test configure GORM for Neo4j"() { - when: - new Team(name: "United").save(flush:true) - - then: - Team.count() == 1 - Team.first().name == "United" - Team.first().dateCreated != null - - } - - @Rollback - void "test validation errors"() { - when: - new Team(name: "").save(failOnError:true) - - then: - thrown(ValidationException) - - } -} - -@Entity -class Team { - @NotBlank - String name - Date dateCreated -} diff --git a/settings.gradle b/settings.gradle index d3d9d8d3..3106282a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,13 +22,7 @@ micronautBuild { rootProject.name = 'groovy-parent' include 'function-groovy' -include 'gorm-common' -include 'graphql-gorm' include 'groovy-bom' -include 'hibernate-gorm' -include 'mongo-gorm' -include 'multitenancy-gorm' -include 'neo4j-gorm' include 'runtime-groovy' enableFeaturePreview 'TYPESAFE_PROJECT_ACCESSORS' diff --git a/src/main/docs/guide/gorm.adoc b/src/main/docs/guide/gorm.adoc index bca78940..1b6162bf 100644 --- a/src/main/docs/guide/gorm.adoc +++ b/src/main/docs/guide/gorm.adoc @@ -1,185 +1 @@ -The table summarizes the GORM modules and the dependencies you should add to your build to enable them. - -.Data Access Configuration Modules -|=== -|Dependency|Description - -|`io.micronaut.groovy:micronaut-hibernate-gorm` -|Configures http://gorm.grails.org/latest/hibernate/manual[GORM for Hibernate] for Groovy applications - -|`io.micronaut.groovy:micronaut-mongo-gorm` -|Configures http://gorm.grails.org/latest/mongodb/manual[GORM for MongoDB] for Groovy applications - -|`io.micronaut.groovy:micronaut-neo4j-gorm` -|Configures http://gorm.grails.org/latest/neo4j/manual[GORM for Neo4j] for Groovy applications - -|=== - -== Using GORM for Hibernate - -[TIP] -.Using the CLI -==== -If you are creating your project using the Micronaut CLI, supply the `hibernate-gorm` feature to include GORM, a basic connection pool configuration, and a default H2 database driver in your project: ----- -$ mn create-app my-app --features hibernate-gorm ----- -==== - -For Groovy users and users familiar with the Grails framework, special support for http://gorm.grails.org[GORM for Hibernate] is available. To use GORM for Hibernate you *should not* include Micronaut's built in <> or the `hibernate-jpa` dependency since GORM itself takes responsibility for creating the `DataSource`, `SessionFactory` etc. - -Rather, you only need to include the `hibernate-gorm` dependency in your project, a connection pool implementation, and the desired JDBC driver. For example: - -dependency:micronaut-hibernate-gorm[groupId="io.micronaut.groovy"] - -You will likely want to add a connection pool implementation and potentially the `h2` database for in-memory testing: - -.Configuring GORM for Hibernate -[source,groovy] ----- - // Use Tomcat connection pool - runtime 'org.apache.tomcat:tomcat-jdbc' - // Use H2 database driver - runtime 'com.h2database:h2' ----- - -You can now use the same http://gorm.grails.org/latest/hibernate/manual/index.html#configuration[configuration properties described in the GORM documentation]. For example: - -.Configuring GORM for Hibernate -[source,yaml] ----- -dataSource: - pooled: true - dbCreate: create-drop - url: jdbc:h2:mem:devDb - driverClassName: org.h2.Driver - username: sa - password: -hibernate: - cache: - queries: false - use_second_level_cache: true - use_query_cache: false - region.factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory ----- - -The following should be noted regarding using GORM for Hibernate in Micronaut: - -* Each class you wish to be a GORM entity should be annotated with the `grails.gorm.annotation.Entity` annotation. -* Each method that interacts with GORM should be annotated with GORM's `grails.gorm.transactions.Transactional` to ensure a session is present. You can also add the `@Transactional` annotation to the class. -* By default Micronaut will scan for entities relative to your `Application` class. If you wish to customize this specify additional packages via the https://docs.micronaut.io/latest/api/io/micronaut/context/ApplicationContextBuilder.html[ApplicationContextBuilder] when starting your application. - -=== Package scan - -For example, if all your GORM entities are in the package `example.micronaut.entities`. - -Instead of: - -[source,groovy] ----- -import io.micronaut.runtime.Micronaut -import groovy.transform.CompileStatic - -@CompileStatic -class Application { - static void main(String[] args) { - Micronaut.run(Application) - } -} ----- - -Use: - -[source,groovy] ----- -import io.micronaut.runtime.Micronaut -import groovy.transform.CompileStatic - -@CompileStatic -class Application { - static void main(String[] args) { - Micronaut.build(args) - .packages("example.micronaut.entities") - .mainClass(Application.class) - .start() - } -} ----- - -In tests, where you start manually an `ApplicationContext`, use: - -[source, groovy] ----- -class BookServiceSpec extends Specification { - - @AutoCleanup - @Shared - ApplicationContext applicationContext = ApplicationContext.build() - .packages("example.micronaut.entities") - .build() - .start() - - @Shared - @Subject - BookService bookService = applicationContext.getBean(BookService) ----- - -In tests, where you use `@MicronautTest`, use: - -[source, groovy] ----- -@MicronautTest(packages = "example.micronaut.entities") -class MicronautTestBookServiceSpec extends Specification { - - @Inject - BookService bookService - ----- - -== Using GORM for MongoDB - -[TIP] -.Using the CLI -==== -If you are creating your project using the Micronaut CLI, supply the `mongo-gorm` feature to configure GORM for MongoDB in your project: ----- -$ mn create-app my-app --features mongo-gorm ----- -==== - -For Groovy users and users familiar with Grails, special support has been added to Micronaut for using http://gorm.grails.org/latest/mongodb/manual[GORM for MongoDB]. - -To add support for GORM for MongoDB, first configure the MongoDB connection as per instructions earlier in the guide, then add the following dependency to your application: - -dependency:micronaut-mongo-gorm[groupId="io.micronaut.groovy"] - -WARNING: For GORM for MongoDB you will need to configure the database name separately as the `grails.mongodb.datataseName` property in `application.yml`. - -The following should be noted regarding using GORM for MongoDB in Micronaut: - -* Each class you wish to be a GORM entity should be annotated with the `grails.gorm.annotation.Entity` annotation. -* Each method that interacts with GORM should be annotated with GORM's `grails.gorm.transactions.Transactional` to ensure a session is present. You can also add the `@Transactional` annotation to the class. -* By default Micronaut will scan for entities relative to your `Application` class. If you wish to customize this specify additional packages via the https://docs.micronaut.io/latest/api/io/micronaut/context/ApplicationContextBuilder.html[ApplicationContextBuilder] when starting your application. - -== Using GORM for Neo4j - -[TIP] -.Using the CLI -==== -If you are creating your project using the Micronaut CLI, supply the `neo4j-gorm` feature to configure GORM for Neo4j in your project: ----- -$ mn create-app my-app --features neo4j-gorm ----- -==== - -For Groovy users and users familiar with Grails, special support has been added to Micronaut for using http://gorm.grails.org/latest/neo4j/manual[GORM for Neo4j]. - -To add support for GORM for Neo4j, first configure the Neo4j connection as per instructions earlier in the guide, then add the following dependency to your application: - -dependency:micronaut-neo4j-gorm[groupId="io.micronaut.groovy"] - -The following should be noted regarding using GORM for Neo4j in Micronaut: - -* Each class you wish to be a GORM entity should be annotated with the `grails.gorm.annotation.Entity` annotation. -* Each method that interacts with GORM should be annotated with GORM's `grails.gorm.transactions.Transactional` to ensure a session is present. You can also add the `@Transactional` annotation to the class. -* By default Micronaut will scan for entities relative to your `Application` class. If you wish to customize this specify additional packages via the api:context.ApplicationContextBuilder[] when starting your application. +WARNING: Micronaut Framework 4 uses Groovy 4 and **it does not support GORM 7**. Micronaut Groovy will support GORM once there is a GORM version built with Groovy 4. diff --git a/src/main/docs/guide/gorm/multitenancyGorm.adoc b/src/main/docs/guide/gorm/multitenancyGorm.adoc deleted file mode 100644 index 52080763..00000000 --- a/src/main/docs/guide/gorm/multitenancyGorm.adoc +++ /dev/null @@ -1,56 +0,0 @@ -http://gorm.grails.org[GORM] supports Multi-tenancy and integrates with https://docs.micronaut.io/latest/guide/index.html#multitenancy[Micronaut Multi-tenancy] support. - -To use Micronaut and GORM multitenancy capabilities you must have the `multitenancy-gorm` dependency on your classpath. For example in `build.gradle`: - -.build.gradle -[source,groovy] ----- -compile "io.micronaut.configuration:micronaut-multitenancy-gorm" ----- - -GORM is a powerful Groovy-based data access toolkit for the JVM with implementations several data access technologies (Hibernate, Neo4j, MongoDB, GraphQL ...). - -GORM supports the following different multitenancy modes: - -- `DATABASE` - A separate database with a separate connection pool is used to store each tenants data. - -- `SCHEMA` - The same database, but different schemas are used to store each tenants data. - -- `DISCRIMINATOR` - The same database is used with a discriminator used to partition and isolate data. - -In order to use GORM - Multitenancy you will need to configure the following properties: `grails.gorm.multiTenancy.mode` and `grails.gorm.multiTenancy.tenantResolverClass`. - -Micronaut support for Multi-tenancy integrates with GORM. - -The following table contains all of the `TenantResolver implementations that ship with `multitenancy-gorm` module and are usable out of the box. - -|=== -| name|description -| api:multitenancy.gorm.CookieTenantResolver[] -| Resolves the current tenant from an HTTP cookie. -| api:multitenancy.gorm.FixedTenantResolver[] -| Resolves against a fixed tenant id -| api:multitenancy.gorm.HttpHeaderTenantResolver[] -| Resolves the current tenant from the request HTTP Header. -| api:multitenancy.gorm.PrincipalTenantResolver[] -| Resolves the current tenant from the authenticated username. -| api:multitenancy.gorm.SessionTenantResolver[] -| Resolves the current tenant from the HTTP session. -| api:multitenancy.gorm.SubdomainTenantResolver[] -| Resolves the tenant id from the subdomain. -| api:multitenancy.gorm.SystemPropertyTenantResolver[] -| Resolves the tenant id from a system property. -|=== - -You will need to add something like the following snippet to your app configuration: - -[source, yaml] ----- -grails: - gorm: - multiTenancy: - mode: DISCRIMINATOR - tenantResolverClass: 'io.micronaut.multitenancy.gorm.PrincipalTenantResolver' ----- - -Please, read http://gorm.grails.org/latest/hibernate/manual/index.html#multiTenancy[GORM Multi-tenancy documentation] to learn more. diff --git a/src/main/docs/guide/toc.yml b/src/main/docs/guide/toc.yml index 075a302f..ebdcd432 100644 --- a/src/main/docs/guide/toc.yml +++ b/src/main/docs/guide/toc.yml @@ -2,7 +2,5 @@ introduction: Introduction releaseHistory: Release History config: Groovy Configuration functions: Groovy Functions -gorm: - title: GORM Modules - multitenancyGorm: Multi-tenancy GORM -repository: Repository \ No newline at end of file +gorm: GORM +repository: Repository