Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 0e908f1

Browse files
committed
chore: Cleanup examples-grails3-schema-per-tenant
- `application.yml`: Format properly with 2 spaces and group config settings better. Remove unused config. - `logback.xml`: Correct faulty pattern - `AnotherBookService`: Make `save()` method use passed book title - `SchemaPerTenantSpec`: Remove unused imports - `Application`: Remove unused imports and old comment - `build.gradle`: Use correct dependencies and narrow the scopes. Switch from `tomcat-jdbc` to `HikariCP` as this will be the new default. Apply Gradle plugins in subproject instead of having logic and conditions in the root build file apply them - much easier to see what's being applied.
1 parent 8e99dac commit 0e908f1

File tree

6 files changed

+83
-100
lines changed

6 files changed

+83
-100
lines changed
Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
group "examples"
1+
plugins {
2+
id 'com.bertramlabs.asset-pipeline' version '5.0.1'
3+
id 'groovy'
4+
id 'org.grails.grails-gsp'
5+
id 'org.grails.grails-web'
6+
}
27

3-
dependencies {
4-
implementation "org.springframework.boot:spring-boot-starter-logging"
5-
implementation "org.springframework.boot:spring-boot-autoconfigure"
6-
implementation "org.springframework.boot:spring-boot-starter-actuator"
7-
implementation "org.springframework.boot:spring-boot-starter-tomcat"
8-
implementation "jakarta.servlet:jakarta.servlet-api"
9-
implementation "org.grails:grails-core"
10-
implementation "org.grails:grails-dependencies", {
11-
exclude module:'grails-datastore-simple'
12-
}
13-
implementation "org.grails:grails-web-boot"
14-
implementation project(":grails-plugin")
8+
version = rootProject.version
9+
group = 'examples'
1510

16-
implementation "org.hibernate:hibernate-core-jakarta:$hibernateVersion"
11+
dependencies {
1712

18-
runtimeOnly "com.bertramlabs.plugins:asset-pipeline-grails"
19-
runtimeOnly "com.h2database:h2"
20-
runtimeOnly "org.yaml:snakeyaml"
21-
runtimeOnly "org.apache.tomcat:tomcat-jdbc"
22-
runtimeOnly "org.grails.plugins:fields"
23-
runtimeOnly "org.grails.plugins:scaffolding"
13+
implementation project(':grails-plugin')
14+
implementation 'org.grails:grails-core'
15+
implementation 'org.grails:grails-plugin-rest'
16+
implementation 'org.grails.plugins:gsp'
2417

25-
testImplementation "org.grails:grails-gorm-testing-support"
18+
runtimeOnly 'com.bertramlabs.plugins:asset-pipeline-grails'
19+
runtimeOnly 'com.h2database:h2'
20+
runtimeOnly 'com.zaxxer:HikariCP'
21+
runtimeOnly 'org.grails:grails-plugin-databinding'
22+
runtimeOnly 'org.grails:grails-plugin-i18n'
23+
runtimeOnly 'org.grails:grails-plugin-services'
24+
runtimeOnly 'org.grails:grails-plugin-url-mappings'
25+
runtimeOnly 'org.grails.plugins:fields'
26+
runtimeOnly 'org.springframework.boot:spring-boot-starter-logging'
27+
runtimeOnly 'org.springframework.boot:spring-boot-autoconfigure'
28+
runtimeOnly 'org.springframework.boot:spring-boot-starter-tomcat'
2629

27-
integrationTestImplementation testFixtures("org.grails.plugins:geb")
30+
testImplementation 'org.grails:grails-testing-support'
2831
}
Lines changed: 54 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,63 @@
1-
---
2-
grails:
3-
profile: web
4-
codegen:
5-
defaultPackage: datasources
61
info:
72
app:
83
name: '@info.app.name@'
94
version: '@info.app.version@'
105
grailsVersion: '@info.app.grailsVersion@'
11-
spring:
12-
groovy:
13-
template:
14-
check-template-location: false
15-
main:
16-
allow-circular-references: true
17-
186
---
197
grails:
20-
mime:
21-
disable:
22-
accept:
23-
header:
24-
userAgents:
25-
- Gecko
26-
- WebKit
27-
- Presto
28-
- Trident
29-
types:
30-
all: '*/*'
31-
atom: application/atom+xml
32-
css: text/css
33-
csv: text/csv
34-
form: application/x-www-form-urlencoded
35-
html:
36-
- text/html
37-
- application/xhtml+xml
38-
js: text/javascript
39-
json:
40-
- application/json
41-
- text/json
42-
multipartForm: multipart/form-data
43-
rss: application/rss+xml
44-
text: text/plain
45-
hal:
46-
- application/hal+json
47-
- application/hal+xml
48-
xml:
49-
- text/xml
50-
- application/xml
51-
urlmapping:
52-
cache:
53-
maxsize: 1000
54-
controllers:
55-
defaultScope: singleton
56-
converters:
57-
encoding: UTF-8
58-
hibernate:
59-
cache:
60-
queries: false
61-
views:
62-
default:
63-
codec: html
64-
gsp:
65-
encoding: UTF-8
66-
htmlcodec: xml
67-
codecs:
68-
expression: html
69-
scriptlets: html
70-
taglib: none
71-
staticparts: none
72-
8+
profile: web
9+
codegen:
10+
defaultPackage: datasources
11+
mime:
12+
disable:
13+
accept:
14+
header:
15+
userAgents:
16+
- Gecko
17+
- WebKit
18+
- Presto
19+
- Trident
20+
types:
21+
all: '*/*'
22+
atom: application/atom+xml
23+
css: text/css
24+
csv: text/csv
25+
form: application/x-www-form-urlencoded
26+
html:
27+
- text/html
28+
- application/xhtml+xml
29+
js: text/javascript
30+
json:
31+
- application/json
32+
- text/json
33+
multipartForm: multipart/form-data
34+
rss: application/rss+xml
35+
text: text/plain
36+
hal:
37+
- application/hal+json
38+
- application/hal+xml
39+
xml:
40+
- text/xml
41+
- application/xml
42+
urlmapping:
43+
cache:
44+
maxsize: 1000
45+
converters:
46+
encoding: UTF-8
47+
hibernate:
48+
cache:
49+
queries: false
50+
views:
51+
default:
52+
codec: html
53+
gsp:
54+
encoding: UTF-8
55+
htmlcodec: xml
56+
codecs:
57+
expression: html
58+
scriptlets: html
59+
taglib: none
60+
staticparts: none
7361
---
7462
grails:
7563
gorm:
@@ -78,8 +66,6 @@ grails:
7866
tenantResolverClass: org.grails.datastore.mapping.multitenancy.web.SessionTenantResolver
7967
dataSource:
8068
pooled: true
81-
jmxExport: true
8269
driverClassName: org.h2.Driver
8370
dbCreate: create-drop
84-
url: jdbc:h2:mem:books;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
85-
71+
url: jdbc:h2:mem:books;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE

examples/grails3-schema-per-tenant/grails-app/conf/logback.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
88
<encoder>
99
<charset>UTF-8</charset>
10-
<pattern>'%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex'</pattern>
10+
<pattern>%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex</pattern>
1111
</encoder>
1212
</appender>
1313

examples/grails3-schema-per-tenant/grails-app/init/datasources/Application.groovy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ package datasources
33
import grails.boot.GrailsApp
44
import grails.boot.config.GrailsAutoConfiguration
55
import groovy.transform.CompileStatic
6-
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
7-
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
86

9-
//@EnableAutoConfiguration(exclude = DataSourceTransactionManagerAutoConfiguration)
107
@CompileStatic
118
class Application extends GrailsAutoConfiguration {
129
static void main(String[] args) {

examples/grails3-schema-per-tenant/grails-app/services/example/AnotherBookService.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import grails.gorm.transactions.Transactional
1010
@CurrentTenant
1111
@Transactional
1212
class AnotherBookService {
13-
Book saveBook(String title) {
14-
new Book(title: "The Stand").save()
13+
Book saveBook(String title = 'The Stand') {
14+
new Book(title: title).save()
1515
}
1616

1717
@ReadOnly

examples/grails3-schema-per-tenant/src/test/groovy/example/SchemaPerTenantSpec.groovy

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
package example
22

3-
4-
import grails.core.GrailsApplication
53
import grails.gorm.transactions.Rollback
64
import grails.test.hibernate.HibernateSpec
75
import org.grails.datastore.mapping.config.Settings
86
import org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException
97
import org.grails.datastore.mapping.multitenancy.resolvers.SystemPropertyTenantResolver
108
import org.grails.testing.GrailsUnitTest
11-
import spock.lang.Ignore
129

1310
/**
1411
* Created by graemerocher on 06/04/2017.
1512
*/
16-
class SchemaPerTenantSpec extends HibernateSpec implements GrailsUnitTest{
13+
class SchemaPerTenantSpec extends HibernateSpec implements GrailsUnitTest {
1714

1815
BookService bookDataService = hibernateDatastore.getService(BookService)
1916

0 commit comments

Comments
 (0)