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

Commit 27c6e40

Browse files
committed
chore: Cleanup examples-grails3-database-per-tenant
- `AnotherBookService`: Make `save()` method use passed book title - `Application`: Remove unused imports and old comment - `application.yml`: Format properly with 2 spaces and group config settings better - `logback.xml`: Correct faulty pattern - `build.gradle`: Use correct dependencies and narrow the scopes. 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 4cdda71 commit 27c6e40

File tree

5 files changed

+90
-114
lines changed

5 files changed

+90
-114
lines changed
Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,32 @@
1-
group "examples"
2-
3-
configurations.all {
4-
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
5-
}
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'
66
}
77

8-
grails {
9-
agent {
10-
enabled = false
11-
}
12-
}
8+
version = rootProject.version
9+
group = 'examples'
1310

1411
dependencies {
15-
implementation "org.springframework.boot:spring-boot-starter-logging"
16-
implementation "org.springframework.boot:spring-boot-autoconfigure"
17-
implementation "org.springframework.boot:spring-boot-starter-actuator"
18-
implementation "org.springframework.boot:spring-boot-starter-tomcat"
19-
implementation "jakarta.servlet:jakarta.servlet-api"
20-
implementation "org.grails:grails-core"
21-
implementation "org.grails:grails-dependencies", {
22-
exclude module:'grails-datastore-simple'
23-
}
24-
implementation "org.ysb33r.gradle:grolifant80:$grolifantVersion"
25-
implementation "org.grails:grails-web-boot"
26-
implementation project(":grails-plugin")
27-
2812

29-
implementation "org.hibernate:hibernate-core-jakarta:$hibernateVersion"
13+
implementation project(':grails-plugin')
14+
implementation 'org.grails:grails-core'
15+
implementation 'org.grails:grails-plugin-rest'
16+
implementation 'org.grails.plugins:gsp'
3017

31-
runtimeOnly "com.bertramlabs.plugins:asset-pipeline-grails"
32-
runtimeOnly "com.h2database:h2"
33-
runtimeOnly "org.yaml:snakeyaml"
34-
runtimeOnly "org.apache.tomcat:tomcat-jdbc"
35-
runtimeOnly "org.grails.plugins:fields"
36-
runtimeOnly "org.grails.plugins:scaffolding"
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-autoconfigure'
27+
runtimeOnly 'org.springframework.boot:spring-boot-starter-logging'
28+
runtimeOnly 'org.springframework.boot:spring-boot-starter-tomcat'
3729

38-
testImplementation ("org.grails:grails-gorm-testing-support") {
39-
exclude group: "org.spockframework", module: "spock-core"
40-
}
30+
testImplementation 'org.grails:grails-gorm-testing-support'
31+
testImplementation 'org.spockframework:spock-core'
4132
}
Lines changed: 62 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,77 @@
1-
---
2-
grails:
3-
profile: web
4-
codegen:
5-
defaultPackage: datasources
61
info:
7-
app:
8-
name: '@info.app.name@'
9-
version: '@info.app.version@'
10-
grailsVersion: '@info.app.grailsVersion@'
11-
spring:
12-
groovy:
13-
template:
14-
check-template-location: false
15-
main:
16-
allow-circular-references: true
17-
2+
app:
3+
name: '@info.app.name@'
4+
version: '@info.app.version@'
5+
grailsVersion: '@info.app.grailsVersion@'
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:
7664
multiTenancy:
7765
mode: DATABASE
7866
tenantResolverClass: org.grails.datastore.mapping.multitenancy.web.SessionTenantResolver
67+
---
7968
dataSource:
8069
pooled: true
81-
jmxExport: true
8270
driverClassName: org.h2.Driver
8371
dbCreate: create-drop
8472
url: jdbc:h2:mem:books;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
85-
8673
dataSources:
87-
moreBooks:
88-
url: jdbc:h2:mem:moreBooks;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
89-
evenMoreBooks:
90-
url: jdbc:h2:mem:evenMoreBooks;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
74+
moreBooks:
75+
url: jdbc:h2:mem:moreBooks;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
76+
evenMoreBooks:
77+
url: jdbc:h2:mem:evenMoreBooks;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE

examples/grails3-database-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-database-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-database-per-tenant/grails-app/services/example/AnotherBookService.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ 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+
14+
Book saveBook(String title = 'The Stand') {
15+
new Book(title: title).save()
1516
}
1617

1718
@ReadOnly

0 commit comments

Comments
 (0)