Skip to content

Commit 26f35c4

Browse files
committed
Decouple grace-datastore-gorm-support from Grace framework
- Move EntityTraitInjector and GormTransformer to `grace-plugin-domain-class` - Move ProxyHandler and PersistenceContextInterceptor to `grace-datastore-gorm-support` - Remove unused ConfigSupport - Relocate GrailsVersionSpec.groovy to `grace-datastore-core` - Relocate GormEntityTraitSpec.groovy to `grace-datastore-gorm` - Remove dependencies on `grace-bootstrap` and `grace-core` Closes gh-73
2 parents eb351ee + d15e021 commit 26f35c4

File tree

14 files changed

+379
-190
lines changed

14 files changed

+379
-190
lines changed

grace-datastore-gorm-support/src/test/groovy/org/grails/datastore/mapping/core/grailsversion/GrailsVersionSpec.groovy renamed to grace-datastore-core/src/test/groovy/org/grails/datastore/mapping/core/grailsversion/GrailsVersionSpec.groovy

File renamed without changes.
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
dependencies {
2+
api project(':grace-datastore-core')
23
api project(':grace-datastore-gorm')
3-
api "org.graceframework:grace-core", {
4-
exclude group: 'org.graceframework', module: 'grace-datastore-core'
5-
}
6-
api("org.graceframework:grace-bootstrap")
7-
}
8-
9-
project.tasks.withType(Jar) {
10-
configure {
11-
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
12-
}
134
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2004-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package grails.core.support.proxy;
17+
18+
/**
19+
* Trivial default implementation that always returns true and the object.
20+
*
21+
* @author Graeme Rocher
22+
* @author Michael Yan
23+
* @since 1.2.2
24+
*/
25+
public class DefaultProxyHandler implements ProxyHandler {
26+
27+
public boolean isInitialized(Object o) {
28+
return true;
29+
}
30+
31+
public boolean isInitialized(Object obj, String associationName) {
32+
return true;
33+
}
34+
35+
public Object unwrapIfProxy(Object instance) {
36+
return instance;
37+
}
38+
39+
public boolean isProxy(Object o) {
40+
return false;
41+
}
42+
43+
public void initialize(Object o) {
44+
// do nothing
45+
}
46+
47+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2010-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package grails.core.support.proxy;
17+
18+
/**
19+
* Methods specified to proxied entities
20+
*
21+
* @author Graeme Rocher
22+
* @author Michael Yan
23+
* @since 1.3.6
24+
*/
25+
public interface EntityProxyHandler extends ProxyHandler {
26+
27+
/**
28+
* This method returns the identifier of the proxy or null if the
29+
* object is not a proxy
30+
*
31+
* @return The identifier of the identity
32+
*/
33+
Object getProxyIdentifier(Object o);
34+
35+
/**
36+
* Returns the proxied class without initializing the proxy
37+
*
38+
* @param o The object
39+
* @return The class
40+
*/
41+
Class<?> getProxiedClass(Object o);
42+
43+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2004-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package grails.core.support.proxy;
17+
18+
/**
19+
* Interface that defines logic for handling proxied instances
20+
*
21+
* @author Graeme Rocher
22+
* @author Michael Yan
23+
* @since 1.2.2
24+
*/
25+
public interface ProxyHandler {
26+
27+
/**
28+
* Returns true if the specified object is a proxy.
29+
* @param o The object in question
30+
* @return true if it is a proxy
31+
*/
32+
boolean isProxy(Object o);
33+
34+
/**
35+
* Returns the unwrapped proxy instance or the original object if not proxied.
36+
*
37+
* @param instance The instance to unwrap
38+
* @return The unwrapped instance
39+
*/
40+
Object unwrapIfProxy(Object instance);
41+
42+
/**
43+
* Returns whether a lazy proxied instance has been initialized.
44+
*
45+
* @param o The instance to test
46+
* @return true if it has been initialized false otherwise
47+
*/
48+
boolean isInitialized(Object o);
49+
50+
/**
51+
* Initializes an existing uninitialized proxy instance.
52+
* @param o The proxy instance
53+
*/
54+
void initialize(Object o);
55+
56+
/**
57+
* Tests whether an association of the given object has been initialized.
58+
* @param obj The object to check
59+
* @param associationName The association
60+
* @return true if has been init
61+
*/
62+
boolean isInitialized(Object obj, String associationName);
63+
64+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2004-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package grails.persistence.support;
17+
18+
/**
19+
* A dummy persistence context interceptor that does nothing.
20+
*
21+
* @author Graeme Rocher
22+
* @author Michael Yan
23+
* @since 1.1.1
24+
*/
25+
public class NullPersistentContextInterceptor implements PersistenceContextInterceptor {
26+
27+
public void init() {
28+
// NOOP
29+
}
30+
31+
public void destroy() {
32+
// NOOP
33+
}
34+
35+
public void disconnect() {
36+
// NOOP
37+
}
38+
39+
public void reconnect() {
40+
// NOOP
41+
}
42+
43+
public void flush() {
44+
// NOOP
45+
}
46+
47+
public void clear() {
48+
// NOOP
49+
}
50+
51+
public void setReadOnly() {
52+
// NOOP
53+
}
54+
55+
public void setReadWrite() {
56+
// NOOP
57+
}
58+
59+
public boolean isOpen() {
60+
return false;
61+
}
62+
63+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2004-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package grails.persistence.support;
17+
18+
/**
19+
* Sets up the persistent context before and after a Grails operation is invoked.
20+
*
21+
* @author Graeme Rocher
22+
* @author Michael Yan
23+
* @since 0.4
24+
*/
25+
public interface PersistenceContextInterceptor {
26+
27+
/**
28+
* Called to intialisation the persistent context.
29+
*/
30+
void init();
31+
32+
/**
33+
* Called to finalize the persistent context.
34+
*/
35+
void destroy();
36+
37+
/**
38+
* Disconnects the persistence context.
39+
*/
40+
void disconnect();
41+
42+
/**
43+
* Reconnects the persistence context.
44+
*/
45+
void reconnect();
46+
47+
/**
48+
* Flushes any pending changes to the DB.
49+
*/
50+
void flush();
51+
52+
/**
53+
* Clear any pending changes.
54+
*/
55+
void clear();
56+
57+
/**
58+
* Sets the persistence context to read-only mode.
59+
*/
60+
void setReadOnly();
61+
62+
/**
63+
* Sets the persistence context to read-write mode.
64+
*/
65+
void setReadWrite();
66+
67+
/**
68+
* Checks whether the persistence context is open.
69+
* @return Returns whether the persistence context is open
70+
*/
71+
boolean isOpen();
72+
73+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2013-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package grails.persistence.support
17+
18+
import groovy.transform.CompileStatic
19+
import org.springframework.context.ApplicationContext
20+
21+
/**
22+
* Executes persistence context interceptors phases.
23+
*
24+
* @author Graeme Rocher
25+
* @author Michael Yan
26+
* @since 2.3
27+
*/
28+
@CompileStatic
29+
class PersistenceContextInterceptorExecutor {
30+
31+
Collection<PersistenceContextInterceptor> persistenceContextInterceptors
32+
33+
PersistenceContextInterceptorExecutor(Collection<PersistenceContextInterceptor> persistenceContextInterceptors) {
34+
this.persistenceContextInterceptors = persistenceContextInterceptors
35+
}
36+
37+
void initPersistenceContext() {
38+
initPersistenceContextInternal(persistenceContextInterceptors)
39+
}
40+
41+
void destroyPersistenceContext() {
42+
destroyPersistenceContextInternal(persistenceContextInterceptors)
43+
}
44+
45+
static void initPersistenceContext(ApplicationContext appCtx) {
46+
if (appCtx) {
47+
Collection<PersistenceContextInterceptor> interceptors = appCtx.getBeansOfType(PersistenceContextInterceptor).values()
48+
initPersistenceContextInternal(interceptors)
49+
}
50+
}
51+
52+
private static void initPersistenceContextInternal(Collection<PersistenceContextInterceptor> interceptors) {
53+
for (PersistenceContextInterceptor i in interceptors) {
54+
i.init()
55+
}
56+
}
57+
58+
static void destroyPersistenceContext(ApplicationContext appCtx) {
59+
if (appCtx) {
60+
Collection<PersistenceContextInterceptor> interceptors = appCtx.getBeansOfType(PersistenceContextInterceptor).values()
61+
destroyPersistenceContextInternal(interceptors)
62+
}
63+
}
64+
65+
private static void destroyPersistenceContextInternal(Collection<PersistenceContextInterceptor> interceptors) {
66+
for (PersistenceContextInterceptor i in interceptors) {
67+
try {
68+
i.destroy()
69+
}
70+
catch (ignored) {
71+
}
72+
}
73+
}
74+
75+
}

0 commit comments

Comments
 (0)