Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HibernateProxy and hibernate-groovy-bytebuddy lib (#624)
* HibernateProxy no longer extends SimpleHibernateProxyHandler to avoid Javassist collions. uses Hibernate helpers. Mark SimpleHibernateProxyHandler as deprecated. Add tests to show the proxy problems with groovy Add example test project for hibernate-groovy-bytebuddy Ignore BookControllerSpec for now as cant get github actions working. * move tests, use GormDatastoreSpec as base. change to new pacakge for hibernate-groovy-proxy * added test for isDirty * clean up javadocs on HibernateProxyHandler and GrailsHibernateUtil
- Loading branch information
Showing
15 changed files
with
469 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
group "examples" | ||
|
||
dependencies { | ||
implementation "org.yakworks:hibernate-groovy-proxy:$hibernateGroovyProxy" | ||
|
||
implementation "org.springframework.boot:spring-boot-starter-logging" | ||
implementation "org.springframework.boot:spring-boot-autoconfigure" | ||
// implementation "javax.servlet:javax.servlet-api:$servletApiVersion" | ||
implementation "org.grails:grails-core:$grailsVersion" | ||
implementation "org.grails:grails-dependencies:$grailsVersion", { | ||
exclude module:'grails-datastore-simple' | ||
} | ||
implementation "org.grails:grails-web-boot:$grailsVersion" | ||
implementation project(":grails-plugin") | ||
|
||
implementation "org.hibernate:hibernate-core:$hibernate5Version" | ||
|
||
// runtimeOnly "com.bertramlabs.plugins:asset-pipeline-grails:$assetPipelineVersion" | ||
runtimeOnly "com.h2database:h2" | ||
runtimeOnly "org.yaml:snakeyaml:$snakeyamlVersion" | ||
runtimeOnly "org.apache.tomcat:tomcat-jdbc:$tomcatVersion" | ||
// runtimeOnly "org.grails.plugins:fields:$fieldsVersion" | ||
// runtimeOnly "org.grails.plugins:scaffolding:$scaffoldingVersion" | ||
|
||
testImplementation "org.grails:grails-gorm-testing-support:$testingSupportVersion" | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
examples/grails-hibernate-groovy-proxy/grails-app/conf/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
grails: | ||
profile: web | ||
codegen: | ||
defaultPackage: datasources | ||
info: | ||
app: | ||
name: '@info.app.name@' | ||
version: '@info.app.version@' | ||
grailsVersion: '@info.app.grailsVersion@' | ||
spring: | ||
groovy: | ||
template: | ||
check-template-location: false | ||
main: | ||
allow-circular-references: true | ||
|
||
--- | ||
dataSource: | ||
pooled: true | ||
jmxExport: true | ||
driverClassName: org.h2.Driver | ||
dbCreate: create-drop | ||
url: jdbc:h2:mem:books;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE | ||
|
17 changes: 17 additions & 0 deletions
17
examples/grails-hibernate-groovy-proxy/grails-app/conf/logback.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
|
||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" /> | ||
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" /> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<charset>UTF-8</charset> | ||
<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> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="error"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
</configuration> |
20 changes: 20 additions & 0 deletions
20
examples/grails-hibernate-groovy-proxy/grails-app/domain/example/Customer.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package example | ||
|
||
import grails.compiler.GrailsCompileStatic | ||
import grails.persistence.Entity | ||
|
||
@Entity | ||
@GrailsCompileStatic | ||
class Customer implements Serializable { | ||
|
||
String name | ||
|
||
Customer(Long id, String name) { | ||
this.id = id | ||
this.name = name | ||
} | ||
|
||
static mapping = { | ||
id generator: 'assigned' | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
examples/grails-hibernate-groovy-proxy/grails-app/init/datasources/Application.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package datasources | ||
|
||
import grails.boot.GrailsApp | ||
import grails.boot.config.GrailsAutoConfiguration | ||
import groovy.transform.CompileStatic | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration | ||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration | ||
|
||
//@EnableAutoConfiguration(exclude = DataSourceTransactionManagerAutoConfiguration) | ||
@CompileStatic | ||
class Application extends GrailsAutoConfiguration { | ||
static void main(String[] args) { | ||
GrailsApp.run(Application) | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
examples/grails-hibernate-groovy-proxy/src/test/groovy/example/ProxySpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package example | ||
|
||
import org.hibernate.Hibernate | ||
|
||
import grails.gorm.transactions.Rollback | ||
import grails.test.hibernate.HibernateSpec | ||
|
||
/** | ||
* Tests Proxy with hibernate-groovy-proxy | ||
*/ | ||
class ProxySpec extends HibernateSpec { | ||
|
||
@Rollback | ||
void "Test Proxy"() { | ||
when: | ||
new Customer(1, "Bob").save(failOnError: true, flush: true) | ||
hibernateDatastore.currentSession.clear() | ||
|
||
def proxy | ||
Customer.withNewSession { | ||
proxy = Customer.load(1) | ||
} | ||
|
||
then: | ||
//without ByteBuddyGroovyInterceptor this would normally cause the proxy to init | ||
proxy | ||
proxy.metaClass | ||
proxy.getMetaClass() | ||
!Hibernate.isInitialized(proxy) | ||
//id calls | ||
proxy.id == 1 | ||
proxy.getId() == 1 | ||
proxy["id"] == 1 | ||
!Hibernate.isInitialized(proxy) | ||
// gorms trait implements in the class so no way to tell | ||
// proxy.toString() == "Customer : 1 (proxy)" | ||
// !Hibernate.isInitialized(proxy) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.