diff --git a/.github/workflows/main-5.4.yml b/.github/workflows/main-5.4.yml deleted file mode 100644 index c2809f3b..00000000 --- a/.github/workflows/main-5.4.yml +++ /dev/null @@ -1,74 +0,0 @@ -# This workflow will build a Java project with Ant -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-ant - -name: Java CI - Lucee 5.4 - -on: [push, pull_request,workflow_dispatch] - -jobs: - build: - - runs-on: ubuntu-latest - env: - luceeVersion: light-5.4.0.79-SNAPSHOT - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'adopt' - - name: Set up MySQL (local) - run: | - sudo systemctl start mysql - mysql -e 'CREATE DATABASE lucee' -uroot -proot - mysql -e 'CREATE USER "lucee"@"localhost" IDENTIFIED WITH mysql_native_password BY "lucee";' -uroot -proot - mysql -e 'GRANT ALL PRIVILEGES ON lucee.* TO "lucee"@"localhost"' -uroot -proot - - name: Cache Maven packages - uses: actions/cache@v3 - with: - path: ~/.m2 - key: lucee-script-runner-maven-cache - - name: Cache Lucee files - uses: actions/cache@v3 - with: - path: _actions/lucee/script-runner/main/lucee-download-cache - key: lucee-downloads-${{ env.luceeVersion }} - restore-keys: | - lucee-downloads - - name: Build with Ant - run: ant -noinput -verbose -buildfile build.xml - - name: Upload Artifact - uses: actions/upload-artifact@v3 - with: - name: hibernate-lex - path: dist/*.lex - - name: Checkout Lucee - uses: actions/checkout@v3 - with: - repository: lucee/lucee - path: lucee - - name: Run Lucee Test Suite (testFilter="orm") - uses: lucee/script-runner@main - with: - webroot: ${{ github.workspace }}/lucee/test - execute: /bootstrap-tests.cfm - luceeVersion: ${{ env.luceeVersion }} - extensionDir: ${{ github.workspace }}/dist - extensions: - env: - testLabels: orm - testAdditional: ${{ github.workspace }}/tests - MYSQL_SERVER: localhost - MYSQL_USERNAME: lucee - MYSQL_PASSWORD: lucee - MYSQL_PORT: 3306 - MYSQL_DATABASE: lucee - - name: Publish Test Results - uses: EnricoMi/publish-unit-test-result-action@v1 - if: always() - with: - files: ${{ github.workspace }}/lucee/test/reports/junit-test-results.xml - check_name: "Test Results" - diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 38a56859..35bc9089 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,74 +1,156 @@ -# This workflow will build a Java project with Ant -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-ant +name: Java CI Combined -name: Java CI - Lucee 6 - -on: [push, pull_request,workflow_dispatch] +on: [push, pull_request, workflow_dispatch] jobs: - build: + setup: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.extract-version.outputs.VERSION }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '11' + - name: Set up MySQL (local) + run: | + sudo systemctl start mysql + mysql -e 'CREATE DATABASE lucee' -uroot -proot + mysql -e 'CREATE USER "lucee"@"localhost" IDENTIFIED WITH mysql_native_password BY "lucee";' -uroot -proot + mysql -e 'GRANT ALL PRIVILEGES ON lucee.* TO "lucee"@"localhost"' -uroot -proot + - name: Cache Maven packages + uses: actions/cache@v3 + with: + path: ~/.m2 + key: lucee-script-runner-maven-cache + - name: Cache Maven packages + uses: actions/cache@v4 + with: + path: ~/.m2 + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Extract version number + id: extract-version + run: | + VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) + echo "::set-output name=VERSION::$VERSION" + - name: Cache Lucee files + uses: actions/cache@v4 + with: + path: ~/work/_actions/lucee/script-runner/main/lucee-download-cache + key: lucee-downloads + + - name: Import GPG key + run: | + echo "$GPG_PRIVATE_KEY" | base64 --decode | gpg --batch --import + env: + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + + build-and-test: runs-on: ubuntu-latest + needs: setup env: - luceeVersion: light-6.0.0.462-SNAPSHOT + testLabels: orm + testAdditional: ${{ github.workspace }}/tests + MYSQL_SERVER: localhost + MYSQL_USERNAME: lucee + MYSQL_PASSWORD: lucee + MYSQL_PORT: 3306 + MYSQL_DATABASE: lucee + strategy: + matrix: + lucee: + - { version: 'light-5.4.6.9', query: '5/all/light' } + - { version: 'light-6.0.3.1', query: '6.0/all/light' } + - { version: 'light-6.1.0.206-SNAPSHOT', query: '6.1/all/light' } + services: + minio: + image: fclairamb/minio-github-actions + ports: + - 9000:9000 + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + java-version: '11' + distribution: 'adopt' + - name: Build and Install with Maven + run: | + echo "------- Maven Install -------"; + mvn -B -e -f pom.xml clean install + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: hibernate-lex-${{ matrix.lucee.version }} + path: target/*.lex + + - name: Checkout Lucee + uses: actions/checkout@v4 + with: + repository: lucee/lucee + path: lucee + + - name: Run Lucee Test Suite + uses: lucee/script-runner@main + with: + webroot: ${{ github.workspace }}/lucee/test + execute: /bootstrap-tests.cfm + luceeVersion: ${{ matrix.lucee.version }} + luceeVersionQuery: ${{ matrix.lucee.query }} + extensionDir: ${{ github.workspace }}/target + env: + testLabels: s3 + testAdditional: ${{ github.workspace }}/tests + + deploy: + runs-on: ubuntu-latest + needs: [build-and-test] + if: always() && needs.build-and-test.result == 'success' steps: - - uses: actions/checkout@v3 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'adopt' - - name: Set up MySQL (local) - run: | - sudo systemctl start mysql - mysql -e 'CREATE DATABASE lucee' -uroot -proot - mysql -e 'CREATE USER "lucee"@"localhost" IDENTIFIED WITH mysql_native_password BY "lucee";' -uroot -proot - mysql -e 'GRANT ALL PRIVILEGES ON lucee.* TO "lucee"@"localhost"' -uroot -proot - - name: Cache Maven packages - uses: actions/cache@v3 - with: - path: ~/.m2 - key: lucee-script-runner-maven-cache - - name: Cache Lucee files - uses: actions/cache@v3 - with: - path: _actions/lucee/script-runner/main/lucee-download-cache - key: lucee-downloads-${{ env.luceeVersion }} - restore-keys: | - lucee-downloads - - name: Build with Ant - run: ant -noinput -verbose -buildfile build.xml - - name: Upload Artifact - uses: actions/upload-artifact@v3 - with: - name: hibernate-lex - path: dist/*.lex - - name: Checkout Lucee - uses: actions/checkout@v3 - with: - repository: lucee/lucee - path: lucee - - name: Run Lucee Test Suite (testFilter="orm") - uses: lucee/script-runner@main - with: - webroot: ${{ github.workspace }}/lucee/test - execute: /bootstrap-tests.cfm - luceeVersion: ${{ env.luceeVersion }} - extensionDir: ${{ github.workspace }}/dist - extensions: - env: - testLabels: orm - testAdditional: ${{ github.workspace }}/tests - MYSQL_SERVER: localhost - MYSQL_USERNAME: lucee - MYSQL_PASSWORD: lucee - MYSQL_PORT: 3306 - MYSQL_DATABASE: lucee - - name: Publish Test Results - uses: EnricoMi/publish-unit-test-result-action@v1 - if: always() - with: - files: ${{ github.workspace }}/lucee/test/reports/junit-test-results.xml - check_name: "Test Results" + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '11' + + - name: Cache Maven packages + uses: actions/cache@v4 + with: + path: ~/.m2 + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Import GPG key + run: | + echo "$GPG_PRIVATE_KEY" | base64 --decode | gpg --batch --import + env: + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + - name: Build and Deploy with Maven + env: + MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + run: | + if [[ "${{ needs.setup.outputs.version }}" == *-SNAPSHOT ]]; then + echo "------- Maven Deploy snapshot on ${{ github.event_name }} -------"; + mvn -B -e -f pom.xml clean deploy --settings maven-settings.xml + else + echo "------- Maven Deploy release on ${{ github.event_name }} -------"; + mvn -B -e -f pom.xml clean deploy -DperformRelease=true --settings maven-settings.xml + fi diff --git a/build.number b/build.number deleted file mode 100644 index ed96e4c5..00000000 --- a/build.number +++ /dev/null @@ -1,3 +0,0 @@ -#Build Number for ANT. Do not edit! -#Sat Jun 17 08:58:45 CEST 2023 -build.number=28 diff --git a/build.properties b/build.properties deleted file mode 100644 index b8c07ff0..00000000 --- a/build.properties +++ /dev/null @@ -1,12 +0,0 @@ -bundlename: hibernate.extension -bundleversion:5.4.29. -versionAppendix: -BETA -id: FAD1E8CB-4F45-4184-86359145767C29DE -luceeCoreVersion: 5.3.9.73 -releaseType: server -label: Hibernate ORM Engine -description: Hibernate ORM (Hibernate in short) is an object-relational mapping library for the Java language, - providing a framework for mapping an object-oriented domain model to a traditional relational database. - Hibernate solves object-relational impedance mismatch problems by replacing direct persistence-related - database accesses with high-level object handling functions. -class: org.lucee.extension.orm.hibernate.HibernateORMEngine diff --git a/build.xml b/build.xml index 0d04fb43..de365c50 100644 --- a/build.xml +++ b/build.xml @@ -4,18 +4,15 @@ Build Hibernate Extension - - + - + - - @@ -55,13 +52,13 @@ Manifest-Version: 1.0 Built-Date: ${NOW} -version: "${bundleversion}${build.number}${versionAppendix}" +version: "${bundleversion}" id: "FAD1E8CB-4F45-4184-86359145767C29DE" name: ${label} description: ${description} start-bundles: false release-type: ${releaseType} -orm: "[{'class':'${class}','name':'${bundlename}','version':'${bundleversion}${build.number}${versionAppendix}'}]" +orm: "[{'class':'${class}','name':'${bundlename}','version':'${bundleversion}'}]" lucee-core-version: "${luceeCoreVersion}" @@ -74,7 +71,7 @@ lucee-core-version: "${luceeCoreVersion}" - + @@ -85,9 +82,9 @@ lucee-core-version: "${luceeCoreVersion}" + jarfile="${dist}/extension/jars/${bundlename}-${bundleversion}.jar" basedir="${build}" manifest="${src}/META-INF/MANIFEST.MF"> - + @@ -115,7 +112,7 @@ lucee-core-version: "${luceeCoreVersion}" - + diff --git a/maven-settings.xml b/maven-settings.xml new file mode 100755 index 00000000..36475394 --- /dev/null +++ b/maven-settings.xml @@ -0,0 +1,27 @@ + + + + + + + ossrh + ${env.MAVEN_USERNAME} + ${env.MAVEN_PASSWORD} + + + + + + ossrh + + true + + + gpg2 + ${env.GPG_PASSPHRASE} + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index da0e9a51..07225cb7 100644 --- a/pom.xml +++ b/pom.xml @@ -1,945 +1,257 @@ - - 4.0.0 - - org.lucee - extension.hibernate - 5.0.0.99-SNAPSHOT - jar - - Extension Hibernate - Lucee Extension for Hibernate ORM Engine. - http://maven.lucee.org/extension/hibernate - - - - hibernate.extension - FAD1E8CB-4F45-4184-86359145767C29DE - Hibernate ORM (Hibernate in short) is an object-relational mapping library for the Java language, + + 4.0.0 + org.lucee + hibernate-extension + 5.4.29.29-SNAPSHOT + pom + Hibernate Extension + + + UTF-8 + 11 + 11 + FAD1E8CB-4F45-4184-86359145767C29DE + org.lucee.hibernate.extension + 5.0.0.157 + server + + org.lucee.extension.orm.hibernate.HibernateORMEngine + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + https://oss.sonatype.org/content/repositories/snapshots/ + + + + https://github.com/lucee/extension-hibernate + scm:git:git://github.com/lucee/extension-hibernate.git + scm:git:git@github.com:lucee/extension-hibernate.git + ${project.version} + + + + + ossrh + ${release.url} + + + ossrh + ${snapshot.url} + + + + + + The GNU Lesser General Public License, Version 2.1 + http://www.gnu.org/licenses/lgpl-2.1.txt + repo + + + + + + micstriit + Michael Offner + michael@lucee.org + Lucee Association Switzerland + http://lucee.org + + Project-Administrator + Developer + + +1 + + + + Hibernate ORM (Hibernate in short) is an object-relational mapping library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database. Hibernate solves object-relational impedance mismatch problems by replacing direct persistence-related database accesses with high-level object handling functions. - org.lucee.extension.orm.hibernate.HibernateORMEngine - - - - - The GNU Lesser General Public License, Version 2.1 - http://www.gnu.org/licenses/lgpl-2.1.txt - repo - - - - - - micstriit - Michael Offner - michael@lucee.org - Lucee Association Switzerland - http://lucee.org - - Project-Administrator - Developer - - +1 - - - - - - - - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - true - - - - .* - - - src/main/java/META-INF/MANIFEST.MF - - ${main.class} - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.3 - - 1.7 - 1.7 - - - - - - - - - - - - - - - - junit - junit - 4.12 - - - - - - org.lucee - lucee - - - org.lucee - lucee - 3.1.0 - - - - - compile - org.apache.felix - org.apache.felix.framework - 4.2.1 - - - javax.servlet - javax.servlet-api - 3.1.0 - - - javax.servlet.jsp - jsp-api - 2.2 - - - javax.el - javax.el-api - 3.0.0 - - - - org.apache.ant - ant - 1.9.5 - - - - org.apache.tika - tika-core - 1.10 - - - - - - org.apache.sanselan - sanselan - 0.97-incubator - - - - - - org.apache.commons - codec - 1.6.0 - - - - - - - - - - org.apache.commons - commons-collections4 - 4.0 - - - - - - - - org.apache.commons - commons-compress - 1.9 - - - - - commons-discovery - commons-discovery - 0.5 - - - - - org.apache.commons - commons-email - 1.2 - - - - - org.apache.commons - fileupload - 1.2.1 - - - - - org.lucee - commons-httpclient - 3.1 - - - - - commons-io - commons-io - 2.4 - - - - - commons-lang - commons-lang - 2.6 - - - - - - - - org.apache.commons.logging - adapters - 1.1.1 - - - - - org.apache.commons.logging - api - jar - 1.1.1 - - - - - org.apache.commons - logging - jar - 1.1.1 - - - - - commons-net - commons-net - 3.3 - - - - - org.apache - oro - jar - 2.0.8 - - - - - log4j - log4j - 1.2.17 - - - - - apache.poi.ooxml - schemas - jar - 3.8.0 - - - - org.apache.poi - ooxml - jar - 3.8.0 - - - - apache.poi.tm - extractors - jar - 3.8.0 - - - - org.apache - poi - jar - 3.8.0 - - - - apache.ws.axis - ant - jar - 1.4.0 - - - - apache.ws - axis - jar - 1.4.0.L004 - - - - apache.xml - xalan - jar - 2.7.1 - - - - apache.xml - xerces - jar - 2.11.0 - - - - backport.util - concurrent - jar - 2.2.0 - - - - bcprov - jdk14 - jar - 1.36.0 - - - - - edu.oswego.cs.gee - concurrent - jar - 1.3.3 - - - - - net.sf.ehcache - ehcache - 2.10.0 - - - - - - ESAPI - ESAPI - jar - 2.1.0 - - - - - flex.messaging - common - jar - 3.3.0.22497 - - - - flex.messaging - core - jar - 3.3.0.22497 - - - - flex.messaging - opt - jar - 3.3.0.22497 - - - - flex.messaging - proxy - jar - 3.3.0.22497 - - - - flex.messaging - remoting - jar - 3.3.0.22497 - - - - fusiondebug.api - server - jar - 1.0.20 - - - - apache.http.components - client - jar - 4.5.0.0001L - - - - apache.http.components - core - jar - 4.4.1 - - - - apache.http.components - mime - jar - 4.5.0 - - - - hsqldb - hsqldb - jar - 1.8.0 - - - - icepdf - core - jar - 3.1.0.3 - - - - jacob - jacob - jar - 1.16.1 - - - - javaparser - javaparser - jar - 1.0.8 - - - - javasysmon - javasysmon - jar - 0.3.3 - - - - - org.samba - jcifs - jar - 1.3.17 - - - - jcommon - jcommon - jar - 1.0.10 - - - - jencrypt - jencrypt - jar - 1.4.2.04 - - - - jffmpeg - jffmpeg - jar - 1.4.2.09 - - - - jfreechart - patch - jar - 1.0.12 - - - - jfreechart - jfreechart - jar - 1.0.12 - - - - - org.joda - time - jar - 2.1.0 - - - - jpedal - gpl - jar - 3.51.12 - - - - - - lowagie - itext - jar - 2.1.2.1 - - - - metadata - extractor - jar - 2.6.4 - - - - - org.ow2.asm - asm-all - 4.2 - - - - - ojdbc14 - ojdbc14 - jar - 0.0.0 - - - - - openamf - astranslator - jar - 1.5.8 - - - - openamf - openamf - jar - 1.5.8 - - - - org.apache.pdfbox - pdfbox - 1.8.9 - - - - - - org.apache.pdfbox - fontbox - 1.8.9 - - - - - org.apache.pdfbox - jempbox - 1.8.9 - - - - - PDFRenderer - PDFRenderer - jar - 1.0.5 - - - - resolver - resolver - jar - 1.2.0 - - - - serializer - serializer - jar - 2.7.1 - - - - - org.slf4j - slf4j-api - 1.7.12 - - - - - org.slf4j - slf4j-nop - 1.7.12 - - - - - ss - css2 - jar - 0.9.4 - - - - stax - api - jar - 1.0.1 - - - - sun - activation - jar - 1.1.0 - - - - sun.jai - codec - jar - 1.1.2 - - - - sun.jai - core - jar - 1.2.1 - - - - sun.jndi - ldap - jar - 1.2.4 - - - - sun.jndi - ldapbp - jar - 1.2.4 - - - - sun.jndi - ldapsec - jar - 1.2.4 - - - - sun.jndi - providerutil - jar - 1.2.4 - - - - sun - mail - jar - 1.3.3.01 - - - - sun.security - jaas - jar - 1.2.4 - - - - sun.xml - jaxrpc - jar - 1.2.1 - - - - sun.xml - wsdl4j - jar - 1.5.1 - - - - sun.xml - saaj - jar - 1.2.1 - - - - tagsoup - tagsoup - jar - 1.2.1 - - - - w3c - dom - jar - 1.1.0 - - - - xdb - xdb - jar - 1.0.0 - - - - xml - apis - jar - 1.3.2 - - - - xmlbeans - xmlbeans - jar - 2.3.0.r540734 - - - - xmlparserv2 - xmlparserv2 - jar - 1.2.2 - - - - - - - - repo - https://raw.githubusercontent.com/lucee/mvn/master/releases - - - snapi - https://oss.sonatype.org/content/repositories/snapshots - - - - - https://github.com/lucee/Lucee - scm:git:git://github.com/lucee/Lucee.git - scm:git:git@github.com:lucee/Lucee.git - ${project.version} - - - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - - \ No newline at end of file + https://github.com/lucee/extension-hibernate + + + + release-sign-artifacts + + + performRelease + true + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.0.1 + + + sign-artifacts + verify + + sign + + + + ${project.build.directory}/${project.artifactId}-${project.version}.lex + + + + + + + org.apache.maven.plugins + maven-release-plugin + 3.0.0 + + true + false + release + deploy + + + + + + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.8 + + + package + + run + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.2.0 + + + attach-artifacts + package + + attach-artifact + + + + + ${project.build.directory}/${project.artifactId}-${project.version}.lex + lex + + + + + + + + + + org.apache.maven.plugins + maven-clean-plugin + 3.1.0 + + + cleanup + post-package + + clean + + + + + ${project.build.directory}/antrun + + **/* + + + + ${project.build.directory}/archive-tmp + + **/* + + + + + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + 3.0.0-M1 + + + default-deploy + deploy + + deploy-file + + + ${project.build.directory}/${project.artifactId}-${project.version}.lex + ${project.groupId} + ${project.artifactId} + ${project.version} + ossrh + ${deploy.url} + lex + + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.13 + true + + ossrh + https://oss.sonatype.org/ + true + + + + + diff --git a/source/java/src/META-INF/MANIFEST.MF b/source/java/src/META-INF/MANIFEST.MF index c3ed0f4a..2599eaa4 100644 --- a/source/java/src/META-INF/MANIFEST.MF +++ b/source/java/src/META-INF/MANIFEST.MF @@ -4,7 +4,6 @@ Import-Package: net.sf.ehcache.hibernate Require-Bundle: org.lucee.hibernate;bundle-version="[5.4.33.Final,6)", org.lucee.antlr;bundle-version="[2.7.7,3)", org.lucee.dom4j;bundle-version=2.1.4, - org.lucee.javassist;bundle-version=3.9.0.GA, org.lucee.jta;bundle-version=1.1.0, slf4j.api;bundle-version=1.7.36, org.apache.commons.commons-collections4;bundle-version=4.4.0, diff --git a/source/java/src/org/lucee/extension/orm/hibernate/ExceptionUtil.java b/source/java/src/org/lucee/extension/orm/hibernate/ExceptionUtil.java index 5bdbf493..a2ab749b 100644 --- a/source/java/src/org/lucee/extension/orm/hibernate/ExceptionUtil.java +++ b/source/java/src/org/lucee/extension/orm/hibernate/ExceptionUtil.java @@ -2,8 +2,6 @@ import java.lang.reflect.Method; -import org.lucee.extension.orm.hibernate.SessionFactoryData; - import lucee.loader.engine.CFMLEngineFactory; import lucee.runtime.Component; import lucee.runtime.db.DataSource; @@ -19,8 +17,7 @@ public class ExceptionUtil { * Create a generic PageException with the given message. Utilizes Lucee's * lucee.runtime.op.ExceptonImpl under the hood. * - * @param message - * Exception message + * @param message Exception message * * @return A PageException object */ @@ -32,10 +29,8 @@ public static PageException createException(String message) { * Create a generic PageException with the given message and detail. Utilizes Lucee's * lucee.runtime.op.ExceptonImpl under the hood. * - * @param message - * Exception message - * @param detail - * Exception detail string + * @param message Exception message + * @param detail Exception detail string * * @return A PageException object */ @@ -91,26 +86,22 @@ public static void setAdditional(PageException pe, Key name, Object value) { if (t instanceof ThreadDeath) throw (ThreadDeath) t; } } - + /** - * A java.lang.ThreadDeath must never be caught, so any catch(Throwable t) must go through this method in order to - * ensure that the throwable is not of type ThreadDeath + * A java.lang.ThreadDeath must never be caught, so any catch(Throwable t) must go through this + * method in order to ensure that the throwable is not of type ThreadDeath * - * @param t - * the thrown Throwable + * @param t the thrown Throwable */ public static void rethrowIfNecessary(Throwable t) { - if (unwrap(t) instanceof ThreadDeath) - throw (ThreadDeath) t; // never catch a ThreadDeath + if (unwrap(t) instanceof ThreadDeath) throw (ThreadDeath) t; // never catch a ThreadDeath } private static Throwable unwrap(Throwable t) { - if (t == null) - return t; + if (t == null) return t; // if (t instanceof NativeException) return unwrap(((NativeException) t).getException()); Throwable cause = t.getCause(); - if (cause != null && cause != t) - return unwrap(cause); + if (cause != null && cause != t) return unwrap(cause); return t; } } diff --git a/source/java/src/org/lucee/extension/orm/hibernate/HibernateORMEngine.java b/source/java/src/org/lucee/extension/orm/hibernate/HibernateORMEngine.java index 03f00397..8f677c65 100755 --- a/source/java/src/org/lucee/extension/orm/hibernate/HibernateORMEngine.java +++ b/source/java/src/org/lucee/extension/orm/hibernate/HibernateORMEngine.java @@ -1,6 +1,5 @@ package org.lucee.extension.orm.hibernate; -import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -8,24 +7,13 @@ import java.util.concurrent.ConcurrentHashMap; import org.hibernate.EntityMode; -import org.hibernate.SessionFactory; -import org.hibernate.cfg.Configuration; import org.hibernate.tuple.entity.EntityTuplizerFactory; import org.lucee.extension.orm.hibernate.event.EventListenerIntegrator; -import org.lucee.extension.orm.hibernate.event.InterceptorImpl; import org.lucee.extension.orm.hibernate.tuplizer.AbstractEntityTuplizerImpl; -import org.lucee.extension.orm.hibernate.util.XMLUtil; -import org.lucee.extension.orm.hibernate.ExceptionUtil; -import org.lucee.extension.orm.hibernate.HibernateUtil; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; import lucee.commons.io.log.Log; import lucee.commons.io.res.Resource; -import lucee.loader.engine.CFMLEngine; import lucee.loader.engine.CFMLEngineFactory; -import lucee.loader.util.Util; import lucee.runtime.Component; import lucee.runtime.PageContext; import lucee.runtime.db.DataSource; @@ -46,6 +34,7 @@ public class HibernateORMEngine implements ORMEngine { // reason // Class clazz = ContextFactory.class; // System.setProperty("javax.xml.bind.context.factory", "com.sun.xml.bind.v2.ContextFactory"); + System.setProperty("javax.xml.bind.context.factory", "com.sun.xml.bind.v2.ContextFactory"); } public HibernateORMEngine() { @@ -54,8 +43,7 @@ public HibernateORMEngine() { /** * Instantiate the Hibernate session and factory data. * - * @param pc - * PageContext + * @param pc PageContext */ @Override public void init(PageContext pc) throws PageException { @@ -77,10 +65,8 @@ public ORMSession createSession(PageContext pc) throws PageException { * * Will NOT reload if force is false and the given pageContext already has a session factory. * - * @param pc - * The current page context object - * @param force - * Force reload all session factory data. + * @param pc The current page context object + * @param force Force reload all session factory data. */ @Override @@ -94,22 +80,23 @@ public boolean reload(PageContext pc, boolean force) throws PageException { private boolean isInitializedForApplication(String applicationName) { return factories.containsKey(applicationName); - } + } + /** * Get the SessionFactoryData by application name. * - * @param applicationName - * Lucee application name, retrieve from {@link lucee.runtime.listener.ApplicationContext#getName()} + * @param applicationName Lucee application name, retrieve from + * {@link lucee.runtime.listener.ApplicationContext#getName()} */ private SessionFactoryData getSessionFactory(String applicationName) { return factories.get(applicationName); } /** - * Retrieve a SessionFactoryData() if configured for this application. If not, build one and retrieve that. + * Retrieve a SessionFactoryData() if configured for this application. If not, build one and + * retrieve that. * - * @param pc - * Lucee PageContext object. + * @param pc Lucee PageContext object. * * @return extension SessionFactoryData object. * @@ -126,10 +113,10 @@ private SessionFactoryData getOrBuildSessionFactoryData(PageContext pc) throws P /** * Add a new session factory specific to this application. * - * @param applicationName - * Lucee application name, retrieve from {@link lucee.runtime.listener.ApplicationContext#getName()} - * @param factory - * the SessionFactoryData object which houses the application-level Hibernate session factory + * @param applicationName Lucee application name, retrieve from + * {@link lucee.runtime.listener.ApplicationContext#getName()} + * @param factory the SessionFactoryData object which houses the application-level Hibernate session + * factory */ private void setSessionFactory(String applicationName, SessionFactoryData factory) { factories.put(applicationName, factory); @@ -138,8 +125,7 @@ private void setSessionFactory(String applicationName, SessionFactoryData factor /** * Wipe the SessionFactoryData object for this Lucee application name from memory. * - * @param applicationName - * The Lucee application name. + * @param applicationName The Lucee application name. */ private void clearSessionFactory(String applicationName) { SessionFactoryData data = getSessionFactory(applicationName); @@ -152,8 +138,7 @@ private void clearSessionFactory(String applicationName) { /** * Reload all ORM configuration and entities and reload the HIbernate ORM session factory. * - * @param pc - * Lucee PageContext + * @param pc Lucee PageContext * * @return SessionFactoryData * @@ -161,8 +146,7 @@ private void clearSessionFactory(String applicationName) { */ private SessionFactoryData buildSessionFactoryData(PageContext pc) throws PageException { ApplicationContext appContext = pc.getApplicationContext(); - if (!appContext.isORMEnabled()) - throw ExceptionUtil.createException((ORMSession) null, null, "ORM is not enabled", ""); + if (!appContext.isORMEnabled()) throw ExceptionUtil.createException((ORMSession) null, null, "ORM is not enabled", ""); String applicationName = pc.getApplicationContext().getName(); clearSessionFactory(applicationName); @@ -180,35 +164,36 @@ private SessionFactoryData buildSessionFactoryData(PageContext pc) throws PageEx data.tmpList = HibernateSessionFactory.loadComponents(pc, this, ormConf); data.clearCFCs(); - // load entities + // load entities if (data.hasTempCFCs()) { - data.getNamingStrategy();// called here to make sure, it is called in the right context the - // first one - - // creates CFCInfo objects - { - Iterator it = data.tmpList.iterator(); - while (it.hasNext()) { - createMapping(pc, it.next(), ormConf, data); - } + data.getNamingStrategy();// called here to make sure, it is called in the right context the + // first one + + // creates CFCInfo objects + { + Iterator it = data.tmpList.iterator(); + while (it.hasNext()) { + createMapping(pc, it.next(), ormConf, data); } - if (data.tmpList.size() != data.sizeCFCs()) { - Component cfc; - String name, lcName; - Map names = new HashMap(); - Iterator it = data.tmpList.iterator(); - while (it.hasNext()) { - cfc = it.next(); - name = HibernateCaster.getEntityName(cfc); - lcName = name.toLowerCase(); - if (names.containsKey(lcName)) throw ExceptionUtil.createException(data, null, "Entity Name [" + name + "] is ambigous, [" + names.get(lcName) - + "] and [" + cfc.getPageSource().getDisplayPath() + "] use the same entity name.", ""); - names.put(lcName, cfc.getPageSource().getDisplayPath()); - } + } + if (data.tmpList.size() != data.sizeCFCs()) { + Component cfc; + String name, lcName; + Map names = new HashMap(); + Iterator it = data.tmpList.iterator(); + while (it.hasNext()) { + cfc = it.next(); + name = HibernateCaster.getEntityName(cfc); + lcName = name.toLowerCase(); + if (names.containsKey(lcName)) throw ExceptionUtil.createException(data, null, "Entity Name [" + name + "] is ambigous, [" + names.get(lcName) + + "] and [" + cfc.getPageSource().getDisplayPath() + "] use the same entity name.", ""); + names.put(lcName, cfc.getPageSource().getDisplayPath()); } } + } } - } finally { + } + finally { data.tmpList = null; } @@ -221,8 +206,7 @@ private SessionFactoryData buildSessionFactoryData(PageContext pc) throws PageEx Log log = pc.getConfig().getLog("orm"); - Iterator> it = HibernateSessionFactory.assembleMappingsByDatasource(data).entrySet() - .iterator(); + Iterator> it = HibernateSessionFactory.assembleMappingsByDatasource(data).entrySet().iterator(); Entry e; while (it.hasNext()) { e = it.next(); @@ -278,11 +262,11 @@ public void createMapping(PageContext pc, Component cfc, ORMConfiguration ormCon if (ormConf.autogenmap()) { data.reset(); pc.addPageSource(cfc.getPageSource(), true); - // + // /** - * TODO: Create a map of connections per datasource. - * Then we can grab and reuse existing connections based on the component's datasource annotation. - * This should save a good bit of time from opening and releasing connections hundreds of times for a single ORM reload. + * TODO: Create a map of connections per datasource. Then we can grab and reuse existing connections + * based on the component's datasource annotation. This should save a good bit of time from opening + * and releasing connections hundreds of times for a single ORM reload. */ DatasourceConnection dc = CommonUtil.getDatasourceConnection(pc, ds, null, null, false); try { @@ -290,9 +274,11 @@ public void createMapping(PageContext pc, Component cfc, ORMConfiguration ormCon if (ormConf.saveMapping()) { HBMCreator.saveMapping(cfc, xml); } - } catch (Exception e) { + } + catch (Exception e) { throw CFMLEngineFactory.getInstance().getCastUtil().toPageException(e); - } finally { + } + finally { pc.removeLastPageSource(true); CommonUtil.releaseDatasourceConnection(pc, dc, false); } @@ -301,7 +287,8 @@ public void createMapping(PageContext pc, Component cfc, ORMConfiguration ormCon else { try { xml = HBMCreator.loadMapping(cfc); - } catch (Exception e) { + } + catch (Exception e) { throw CFMLEngineFactory.getInstance().getCastUtil().toPageException(e); } @@ -325,8 +312,7 @@ public String getLabel() { /** * Get the ORM configuration for the given PageContext * - * @param pc - * PageContext object + * @param pc PageContext object * * @return ORMConfiguration */ diff --git a/source/java/src/org/lucee/extension/orm/hibernate/ORMUtil.java b/source/java/src/org/lucee/extension/orm/hibernate/ORMUtil.java index 4857aca1..040b501a 100644 --- a/source/java/src/org/lucee/extension/orm/hibernate/ORMUtil.java +++ b/source/java/src/org/lucee/extension/orm/hibernate/ORMUtil.java @@ -20,382 +20,363 @@ import java.util.ArrayList; -import lucee.runtime.orm.ORMSession; +import lucee.loader.util.Util; import lucee.runtime.Component; import lucee.runtime.PageContext; // import lucee.runtime.PageContextImpl; import lucee.runtime.component.Property; -import lucee.runtime.orm.ORMEngine; import lucee.runtime.db.DataSource; // import lucee.runtime.engine.ThreadLocalPageContext; import lucee.runtime.exp.PageException; +import lucee.runtime.orm.ORMEngine; +import lucee.runtime.orm.ORMSession; import lucee.runtime.type.Collection.Key; import lucee.runtime.type.Struct; -import lucee.loader.util.Util; public class ORMUtil { - public static final Key PROPS_FIELDTYPE = CommonUtil.createKey("fieldtype"); - public static final Key PROPS_DATASOURCE = CommonUtil.createKey("datasource"); - - public static final String DELIMITER = new String("."); - - public static ORMSession getSession(PageContext pc) throws PageException { - return getSession(pc, true); - } - - public static ORMSession getSession(PageContext pc, boolean create) throws PageException { - return pc.getORMSession(create); - } - - // /** - // * Override's Lucee's {@link lucee.runtime.PageContext#getORMSession(boolean)} method to avoid stupidly creating a - // new session if one already exists. - // * - // * @param create Create a new session if none found. - // * @return A new or previously existing {@link lucee.runtime.orm.ORMSession} - // * @throws PageException - // */ - // public ORMSession getORMSession(boolean create) throws PageException { - // if (ormSession == null || !ormSession.isValid()) { - // if (!create) return null; - // ormSession = config.getORMEngine(this).createSession(this); - // } - // DatasourceManagerImpl manager = (DatasourceManagerImpl) getDataSourceManager(); - // manager.add(this, ormSession); - - // return ormSession; - // } - - public static ORMEngine getEngine(PageContext pc) throws PageException { - return pc.getConfig().getORMEngine(pc); - } - - /** - * - * @param pc - * @param force - * if set to false the engine is on loaded when the configuration has changed - * - * @throws PageException - */ - public static ORMEngine resetEngine(PageContext pc, boolean force) throws PageException { - ORMEngine e = getEngine(pc); - e.reload(pc, force); - return e; - } - - // public static boolean equals(Object left, Object right) { - // HashSet done = new HashSet(); - // return _equals(done, left, right); - // } - - // private static boolean _equals(HashSet done, Object left, Object right) { - - // if (left == right) return true; - // if (left == null || right == null) return false; - - // // components - // if (left instanceof Component && right instanceof Component) { - // return _equals(done, (Component) left, (Component) right); - // } - - // // arrays - // if (CommonUtil.isArray(left) && CommonUtil.isArray(right)) { - // return _equals(done, CommonUtil.toArray(left, null), CommonUtil.toArray(right, null)); - // } - - // // struct - // if (CommonUtil.isStruct(left) && CommonUtil.isStruct(right)) { - // return _equals(done, CommonUtil.toStruct(left, null), CommonUtil.toStruct(right, null)); - // } - - // try { - // return OpUtil.equals(ThreadLocalPageContext.get(), left, right, false); - // } - // catch (PageException e) { - // return false; - // } - // } - - // private static boolean _equals(HashSet done, Collection left, Collection right) { - // if (done.contains(left)) return done.contains(right); - // done.add(left); - // done.add(right); - - // if (left.size() != right.size()) return false; - // // Key[] keys = left.keys(); - // Iterator> it = left.entryIterator(); - // Entry e; - // Object l, r; - // while (it.hasNext()) { - // e = it.next(); - // l = e.getValue(); - // r = right.get(e.getKey(), null); - // if (r == null || !_equals(done, l, r)) return false; - // } - // return true; - // } - - // private static boolean _equals(HashSet done, Component left, Component right) { - // if (done.contains(left)) return done.contains(right); - // done.add(left); - // done.add(right); - - // if (left == null || right == null) return false; - // if (!left.getPageSource().equals(right.getPageSource())) return false; - // Property[] props = getProperties(left); - // Object l, r; - // props = getIds(props); - // for (int i = 0; i < props.length; i++) { - // l = left.getComponentScope().get(CommonUtil.createKey(props[i].getName()), null); - // r = right.getComponentScope().get(CommonUtil.createKey(props[i].getName()), null); - // if (!_equals(done, l, r)) return false; - // } - // return true; - // } - - public static Property[] getIds(Property[] props) { - ArrayList ids = new ArrayList(); - for (int y = 0; y < props.length; y++) { - String fieldType = CommonUtil.toString(props[y].getDynamicAttributes().get(PROPS_FIELDTYPE, null), null); - Character delimiterChar = Character.valueOf(DELIMITER.charAt(0)); - if ("id".equalsIgnoreCase(fieldType) - || CommonUtil.listFindNoCaseIgnoreEmpty(fieldType, "id", delimiterChar) != -1) - ids.add(props[y]); - } - - // no id field defined - if (ids.size() == 0) { - String fieldType; - for (int y = 0; y < props.length; y++) { - fieldType = CommonUtil.toString(props[y].getDynamicAttributes().get(PROPS_FIELDTYPE, null), null); - if (Util.isEmpty(fieldType, true) && props[y].getName().equalsIgnoreCase("id")) { - ids.add(props[y]); - props[y].getDynamicAttributes().setEL(PROPS_FIELDTYPE, "id"); - } - } - } - - // still no id field defined - if (ids.size() == 0 && props.length > 0) { - String owner = props[0].getOwnerName(); - if (!Util.isEmpty(owner)) - owner = CommonUtil.last(owner, DELIMITER).trim(); - - String fieldType; - if (!Util.isEmpty(owner)) { - String id = owner + "id"; - for (int y = 0; y < props.length; y++) { - fieldType = CommonUtil.toString(props[y].getDynamicAttributes().get(PROPS_FIELDTYPE, null), null); - if (Util.isEmpty(fieldType, true) && props[y].getName().equalsIgnoreCase(id)) { - ids.add(props[y]); - props[y].getDynamicAttributes().setEL(PROPS_FIELDTYPE, "id"); - } - } - } - } - return ids.toArray(new Property[ids.size()]); - } - - public static Object getPropertyValue(Component cfc, String name, Object defaultValue) { - Property[] props = getProperties(cfc); - - for (int i = 0; i < props.length; i++) { - if (!props[i].getName().equalsIgnoreCase(name)) - continue; - return cfc.getComponentScope().get(CommonUtil.createKey(name), null); - } - return defaultValue; - } - /* - * jira2049 public static Object getPropertyValue(ORMSession session,Component cfc, String name, Object - * defaultValue) { Property[] props=getProperties(cfc); Object raw=null; SessionImpl sess=null; if(session!=null){ - * raw=session.getRawSession(); if(raw instanceof SessionImpl) sess=(SessionImpl) raw; } Object val; for(int - * i=0;i done = new HashSet(); + // return _equals(done, left, right); + // } + + // private static boolean _equals(HashSet done, Object left, Object right) { + + // if (left == right) return true; + // if (left == null || right == null) return false; + + // // components + // if (left instanceof Component && right instanceof Component) { + // return _equals(done, (Component) left, (Component) right); + // } + + // // arrays + // if (CommonUtil.isArray(left) && CommonUtil.isArray(right)) { + // return _equals(done, CommonUtil.toArray(left, null), CommonUtil.toArray(right, null)); + // } + + // // struct + // if (CommonUtil.isStruct(left) && CommonUtil.isStruct(right)) { + // return _equals(done, CommonUtil.toStruct(left, null), CommonUtil.toStruct(right, null)); + // } + + // try { + // return OpUtil.equals(ThreadLocalPageContext.get(), left, right, false); + // } + // catch (PageException e) { + // return false; + // } + // } + + // private static boolean _equals(HashSet done, Collection left, Collection right) { + // if (done.contains(left)) return done.contains(right); + // done.add(left); + // done.add(right); + + // if (left.size() != right.size()) return false; + // // Key[] keys = left.keys(); + // Iterator> it = left.entryIterator(); + // Entry e; + // Object l, r; + // while (it.hasNext()) { + // e = it.next(); + // l = e.getValue(); + // r = right.get(e.getKey(), null); + // if (r == null || !_equals(done, l, r)) return false; + // } + // return true; + // } + + // private static boolean _equals(HashSet done, Component left, Component right) { + // if (done.contains(left)) return done.contains(right); + // done.add(left); + // done.add(right); + + // if (left == null || right == null) return false; + // if (!left.getPageSource().equals(right.getPageSource())) return false; + // Property[] props = getProperties(left); + // Object l, r; + // props = getIds(props); + // for (int i = 0; i < props.length; i++) { + // l = left.getComponentScope().get(CommonUtil.createKey(props[i].getName()), null); + // r = right.getComponentScope().get(CommonUtil.createKey(props[i].getName()), null); + // if (!_equals(done, l, r)) return false; + // } + // return true; + // } + + public static Property[] getIds(Property[] props) { + ArrayList ids = new ArrayList(); + for (int y = 0; y < props.length; y++) { + String fieldType = CommonUtil.toString(props[y].getDynamicAttributes().get(PROPS_FIELDTYPE, null), null); + Character delimiterChar = Character.valueOf(DELIMITER.charAt(0)); + if ("id".equalsIgnoreCase(fieldType) || CommonUtil.listFindNoCaseIgnoreEmpty(fieldType, "id", delimiterChar) != -1) ids.add(props[y]); + } + + // no id field defined + if (ids.size() == 0) { + String fieldType; + for (int y = 0; y < props.length; y++) { + fieldType = CommonUtil.toString(props[y].getDynamicAttributes().get(PROPS_FIELDTYPE, null), null); + if (Util.isEmpty(fieldType, true) && props[y].getName().equalsIgnoreCase("id")) { + ids.add(props[y]); + props[y].getDynamicAttributes().setEL(PROPS_FIELDTYPE, "id"); + } + } + } + + // still no id field defined + if (ids.size() == 0 && props.length > 0) { + String owner = props[0].getOwnerName(); + if (!Util.isEmpty(owner)) owner = CommonUtil.last(owner, DELIMITER).trim(); + + String fieldType; + if (!Util.isEmpty(owner)) { + String id = owner + "id"; + for (int y = 0; y < props.length; y++) { + fieldType = CommonUtil.toString(props[y].getDynamicAttributes().get(PROPS_FIELDTYPE, null), null); + if (Util.isEmpty(fieldType, true) && props[y].getName().equalsIgnoreCase(id)) { + ids.add(props[y]); + props[y].getDynamicAttributes().setEL(PROPS_FIELDTYPE, "id"); + } + } + } + } + return ids.toArray(new Property[ids.size()]); + } + + public static Object getPropertyValue(Component cfc, String name, Object defaultValue) { + Property[] props = getProperties(cfc); + + for (int i = 0; i < props.length; i++) { + if (!props[i].getName().equalsIgnoreCase(name)) continue; + return cfc.getComponentScope().get(CommonUtil.createKey(name), null); + } + return defaultValue; + } + /* + * jira2049 public static Object getPropertyValue(ORMSession session,Component cfc, String name, + * Object defaultValue) { Property[] props=getProperties(cfc); Object raw=null; SessionImpl + * sess=null; if(session!=null){ raw=session.getRawSession(); if(raw instanceof SessionImpl) + * sess=(SessionImpl) raw; } Object val; for(int i=0;i