Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hibernate 5.4 extension updates #36

Open
wants to merge 153 commits into
base: 5.4
Choose a base branch
from

Conversation

michaelborn
Copy link
Collaborator

@michaelborn michaelborn commented Feb 13, 2023

Hibernate 5.4 Extension Updates

Thanks to a client project, we (Ortus Solutions) have had the opportunity to assist with closing some of the open ORM / Hibernate extension issues, as well as bring the extension up to modern standards in a few areas. Notably, this PR:

  1. resolves a number of bugs in the current Hibernate extension
  2. adds new features,
  3. cuts the ORM reload time in half via refactoring the initialization process,
  4. adds documentation via the readme and javadocs,
  5. adds or improves the existing test suite,
  6. and does some general code cleanup and housekeeping

Explanation of changes:

Bug Fixes

New Features

Initialization Rework

See commits 41f0d86, e8d0dd0, and e31782f

  • Don't reinit ORM except 1. on first run or 2. if ORMReload() is fired
    • This fixes a bug where INIT_CFCS and INIT_ALL were mapped to the same int, so each page load would re-inspect all ORM entities.
    • Avoids re-hashing the ORM config on every request
    • Reduces unnecessary config hashing and component scans on every request
  • Use hasTempCFCs() boolean method for clarity when looking for ORM entities in the list of pre-inspected entities
  • Don't attempt to reinit when instantiating an entity

This refactor alone reduces the time to reinit 1,000 entities from ~14s to ~4s - a ~70% improvement!

See performance data collected via Hibernate Playground against the 3.5 extension, 5.4 extension, and 5.4 with modifications:

Pivot table showing execution time for various actions on three different extension versions

Documentation

Tests

  • Imported tests for LDEV-4150 (20a0005)
  • Imported tests for LDEV-3907 (4271c5f)
  • Added test for this.ormSettings.ormConfig XML file (c0fdc92)
  • Added test for this.ormSettings.cacheconfig XML file (2e1455e)
  • Added test for datasource annotation on individual entity components (6cac457)
  • Setup Junit tests (d3266be, 73a9939, 70482ce, a5f4b89, b525356)
  • Added test.sh for easily running Lucee test cases (c997777)

Housekeeping

  • Moved all ORM*(), entity*() methods such as ORMReload(), entitySave() to extension (e116049, c0879cd, 00681de)
  • Drop support for Lucee dialect / .lucee components (aa4aa49), (ac5abbf)
  • Drop unused methods and classes cluttering the source code (c00e275, 96eb530, 461e423, )
  • Moved all *Util.java classes to .util package (24c4115)
  • Use Hibernate setting key names if they exist (4c51369, d342d21, 0edede7)
  • Refactored configuration to use a Builder pattern for clarity (c7d74a4, 929fff4)
  • Added automatic java source formatting via formatter-maven-plugin (c43c60e, c4c3ad9, 65f44cf)
  • Updated copyright notice to use "Lucee Association Switzerland" instead of Railo. (882ea9a)

GitHub Actions Secrets

The new javadocs CI build auto-uploads generated java documentation to S3 using the configured secrets.

You'll need to add these secrets to the Github Secrets admin:

  • AWS_APIDOCS_BUCKET Bucket name to upload to - for example, apidocs.lucee.org
  • AWS_ACCESS_KEY S3 access key ID
  • AWS_ACCESS_SECRET S3 access key secret

In addition, the maven java formatter requires read/write permissions in order to commit file changes to the repository. This can be accomplished using a GH_TOKEN secret containing a personal access token with read and write permissions to the extension-hibernate repository.

Useful for tests or simply acquiring the internal Hibernate transaction
1. Drop the old EVComponent and InterceptorImpl. We only need event handling in a single place (for now).
2. Rename variables, method names, and class properties to make it obvious when we're invoking an EventHandler method, and when we're invoking a method on a standard entity CFC.
3. More java docs
4. A basic unit test - ya know, for science.
Using `ant dist && ./test.sh`, we can easily build the extension to a .lex file and immediately run CFML tests against a specific version of Lucee.
These function definitions belong in the ORM extension. Copied verbatim from Lucee core.
@@ -0,0 +1,37 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

@@ -0,0 +1,76 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

@@ -0,0 +1,34 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

@@ -0,0 +1,38 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

@@ -0,0 +1,39 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

@@ -0,0 +1,40 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

*
* You should have received a copy of the GNU Lesser General Public
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what is going on here, but print and aprint are classes present in the lucee core and every extension, they are used to make printout while developing and should NOT be removed.

  • print can be used like the dump function and can better show complex structures than System.out
  • you can simply remove the "extends aprint" from the print class to see where the class is used, helpful to clean up

please do not simply remove stuff you don't completely understand the need for

@@ -0,0 +1,40 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

@@ -0,0 +1,42 @@
/**
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

@@ -0,0 +1,41 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

@@ -0,0 +1,39 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

@@ -0,0 +1,108 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

@@ -0,0 +1,39 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

@@ -0,0 +1,47 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

@@ -0,0 +1,47 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

@@ -0,0 +1,44 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment for EntityDelete

@@ -0,0 +1,1068 @@
package org.lucee.extension.orm.hibernate.util;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hard to see the change, when the function not got moved but deleted and created. did you just chnage the package name or also code inside the class. best do not move stuff around at all,this can be done is a separate "clean up PR".
In short move the class back to it's old package

@@ -0,0 +1,299 @@
package org.lucee.extension.orm.hibernate.util;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as CommonUtil i guess

@@ -1,432 +0,0 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert that change, add it again

@@ -0,0 +1,21 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this tld has no use, why did you add it?

@@ -0,0 +1,28 @@
package org.lucee.extension.orm.hibernate;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we make all our test cases on CFML level, for one simple reason. we wanna have the test as close to real world as possible, so no java based test cases, please remove

@michaeloffner
Copy link
Contributor

I have reviewed part of the PR, not everything because we have some issue repeating itself over and over again.
We have 125 files changed but in my opinion the changes that matter are only in 2 or 3 files. Other changes are just noise hard to filter out.

"Noise problems"
you have moved all the orm functions from the Lucee core to the extension, this adds a lot of functions , but it is not clear if you have simply copy/paste them or also made some changes, we need that info. In addition all this functions are useless because they are not registered. In addition they do not implement the BIF class and because of that create a lot of overhead. Also i'm not sure if they load the session in the correct way. But biggest question is why did you do it? I think i know why, we did similar with the S3 extension.

You have changed couple of package names of classes and not moved them. so they appear as new classes and the old one got deleted, so like with the functions it is unclear if you simply changed the package name or also modified the classes, best revert that change and do it in a separate clean up PR.

Please do not remove code like print/aprint, that is used in every Lucee project and do not indroduce new stuff like junit that is not used in any Lucee project, let's just stick to the necessary changes with that PR.

@michaelborn
Copy link
Collaborator Author

The ORM*() and entity*() methods were moved into the extension to resolve several main issues:

  • The ORM methods can be updated and improved without requiring a Lucee core update.
  • The ORM functionality is only utilized within the Hibernate extension, so it makes sense to encapsulate those methods therein.
  • Experimental ORM methods can be added to (and removed from!) the Hibernate extension without requiring "buy-in" from the Lucee core.

Besides these concerns, having ORM functionality encapsulated within the Lucee ORM extension makes practical and organizational sense.

With that said, the ormFunctions.fld file was supposed to point to the ported ORM functions - that is my fault! I will update this.

Other feedback items:

  • The source/java/.project changes were made automatically by VS Code. That file only pertains to the Hibernate extension project - I am not sure why we should care if it is incompatible with another Lucee project. The IDE shouldn't care, as it should simply pick up the file and move forward with the project configuration. That is the entire reason the .project file exists.
  • Having all ORM and Entity functions extend BIF will require us to implement the invoke() method for each class for switching between call() methods based on the number and type of arguments. I am not opposed to this, but it will take some time to update the function definitions.
  • Since the print.java and aprint.java classes are unused in production and provide no production value, I would prefer we not ship them with the Hibernate extension. If dump debugging is to be used in 2023, I would recommend using the aprint.java class in the Lucee core.
  • The EXTENSION.MF is used in the Maven build, which uses the echo-maven-plugin to append manifest entries into a Lucee-compatible extension manifest. Since Lucee's extension manifest does not adhere to the Jar File Specification, this is the only way to build a manifest in Maven that will parse successfully in Lucee.
  • I strongly disagree with removing junit tests. YES, we need CFML functionality and syntax to be tested in CFML, but it is a huge benefit to have java-based unit tests which are going to run much faster and have much better integration with the IDE. In addition, it allows us to catch bugs in situations which are very hard or verbose to replicate from CFML.
  • Finally, moving the Util classes to a .util package makes structural sense. There were several changes to those util classes apart from the package move, though, mostly related to removing reflection when possible and/or reworking the configuration process as part of the ORM reload performance improvements.

Our only aim here is to improve the quality and maintenance overhead of the Hibernate extension. As long as the changes improve maintainability and do not adversely affect the CFML developer, I don't see why these changes should be backed out of the PR.

@michaelborn
Copy link
Collaborator Author

With that said, the ormFunctions.fld file was supposed to point to the ported ORM functions - that is my fault! I will update this.

Actually, this file is already committed and does point to the moved functions:

<function>
<name>EntityDelete</name>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.orm.functions.EntityDelete</class>
<description>Deletes the record from the database for the specified entity.
EntityDelete(entity)</description>
<argument>
<name>name</name>
<type>object</type>
<required>Yes</required>
<description>Name of the entity being deleted.</description>
</argument>
<return>
<type>void</type>
</return>
</function>

@michaelborn
Copy link
Collaborator Author

@michaeloffner I updated the built-ins (ORM*() and entity*()) to extends BIF as you suggested.
I also dropped the .tld XML config file for configuring built-in tags, since, as you mentioned, it is unused.

Can we get another review on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants