Skip to content

Commit

Permalink
Merge pull request #3694 from OpenLiberty/staging
Browse files Browse the repository at this point in the history
Publish 24.0.0.4-beta post
  • Loading branch information
dmuelle authored Apr 9, 2024
2 parents 0354bb7 + 749c205 commit 244eade
Show file tree
Hide file tree
Showing 2 changed files with 297 additions and 6 deletions.
16 changes: 10 additions & 6 deletions blog_tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"blog_tags": [
{
"name": "announcements",
"posts": ["24.0.0.3", "24.0.0.2",
"posts": ["24.0.0.4-beta",
"24.0.0.3", "24.0.0.2",
"24.0.0.2-beta", "24.0.0.1",
"24.0.0.1-beta", "liberty-certification",
"23.0.0.12", "23.0.0.12-beta",
Expand Down Expand Up @@ -139,7 +140,7 @@
},
{
"name": "java-se",
"posts": ["24.0.0.3",
"posts": ["24.0.0.4-beta", "24.0.0.3",
"24.0.0.1", "Java21-Images",
"23.0.0.10", "23.0.0.10-beta",
"23.0.0.3", "23.0.0.3-beta",
Expand All @@ -155,7 +156,8 @@
},
{
"name": "release",
"posts": ["24.0.0.3", "24.0.0.2",
"posts": ["24.0.0.4-beta",
"24.0.0.3", "24.0.0.2",
"24.0.0.2-beta", "24.0.0.1",
"24.0.0.1-beta", "23.0.0.12",
"23.0.0.12-beta","23.0.0.11",
Expand Down Expand Up @@ -211,7 +213,7 @@
},
{
"name": "beta",
"posts": ["24.0.0.2-beta",
"posts": ["24.0.0.4-beta", "24.0.0.2-beta",
"24.0.0.1-beta", "23.0.0.12-beta",
"23.0.0.11-beta", "23.0.0.10-beta",
"23.0.0.9-beta", "23.0.0.8-beta",
Expand Down Expand Up @@ -336,7 +338,8 @@
},
{
"name": "jakarta-ee",
"posts": ["open-liberty-with-langchain4j-example", "DevNexus24",
"posts": ["24.0.0.4-beta",
"open-liberty-with-langchain4j-example", "DevNexus24",
"24.0.0.1-beta", "23.0.0.12-beta",
"IvarJakartaData", "23.0.0.10-beta",
"23.0.0.9-beta", "23.0.0.8-beta",
Expand Down Expand Up @@ -522,7 +525,8 @@
},
{
"name": "data-sources",
"posts": ["24.0.0.1-beta", "23.0.0.12-beta",
"posts": ["24.0.0.4-beta",
"24.0.0.1-beta", "23.0.0.12-beta",
"IvarJakartaData", "23.0.0.10-beta",
"23.0.0.5-beta", "23.0.0.4-beta",
"23.0.0.3", "23.0.0.2",
Expand Down
287 changes: 287 additions & 0 deletions posts/2024-04-09-24.0.0.4-beta.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
---
layout: post
title: "Support for Java 22 and an updated preview of Jakarta Data in 24.0.0.4-beta"
# Do NOT change the categories section
categories: blog
author_picture: https://avatars3.githubusercontent.com/dmuelle
author_github: https://github.com/dmuelle
seo-title: Support for Java 22 and an updated preview of Jakarta Data in 24.0.0.4-beta - OpenLiberty.io
seo-description: The 24.0.0.4-beta release introduces support for Java SE 22 and updates for the Jakarta Data 1.0 preview, including improvements for type safety and a new annotation to define repository find methods.
blog_description: The 24.0.0.4-beta release introduces support for Java SE 22 and updates for the Jakarta Data 1.0 preview, including improvements for type safety and a new annotation to define repository find methods.
open-graph-image: https://openliberty.io/img/twitter_card.jpg
open-graph-image-alt: Open Liberty Logo
---
= Support for Java 22 and an updated preview of Jakarta Data in 24.0.0.4-beta
David Mueller <https://github.com/dmuelle>
:imagesdir: /
:url-prefix:
:url-about: /

The 24.0.0.4-beta release introduces support for Java SE 22 and updates for the Jakarta Data 1.0 preview, including improvements for type safety and a new `@Find` annotation to define repository find methods.

The link:{url-about}[Open Liberty] 24.0.0.4-beta includes the following beta features (along with link:{url-prefix}/docs/latest/reference/feature/feature-overview.html[all GA features]):

* <<java_22, Run your Open Liberty apps with Java 22>>
* <<jakarta_data, Try out new functions for Jakarta Data 1.0 at milestone 3>>

See also link:{url-prefix}/blog/?search=beta&key=tag[previous Open Liberty beta blog posts].

// // // // DO NOT MODIFY THIS COMMENT BLOCK <GHA-BLOG-TOPIC> // // // //
// Blog issue: https://github.com/OpenLiberty/open-liberty/issues/27856
// Contact/Reviewer: gjwatts
// // // // // // // //
[#java_22]
== Run your Open Liberty apps with Java 22

Java 22 is the latest release of Java, released in March 2024. It contains new features and enhancements over previous versions of Java. However, Java 22 is not a long-term support (LTS) release and support for it will be dropped when the next version of Java is supported. It offers some new functions and changes that you are going to want to check out for yourself.

Check out the following link:https://openjdk.org/projects/jdk/22/[feature changes in Java 22]:

* 423: link:https://openjdk.org/jeps/423[Region Pinning for G1]
* 447: link:https://openjdk.org/jeps/447[Statements before super(...) (Preview)]
* 454: link:https://openjdk.org/jeps/454[Foreign Function & Memory API]
* 456: link:https://openjdk.org/jeps/456[Unnamed Variables & Patterns]
* 457: link:https://openjdk.org/jeps/457[Class-File API (Preview)]
* 458: link:https://openjdk.org/jeps/458[Launch Multi-File Source-Code Programs]
* 459: link:https://openjdk.org/jeps/459[String Templates (Second Preview)]
* 460: link:https://openjdk.org/jeps/460[Vector API (Seventh Incubator)]
* 461: link:https://openjdk.org/jeps/461[Stream Gatherers (Preview)]
* 462: link:https://openjdk.org/jeps/462[Structured Concurrency (Second Preview)]
* 463: link:https://openjdk.org/jeps/463[Implicitly Declared Classes and Instance Main Methods (Second Preview)]
* 464: link:https://openjdk.org/jeps/464[Scoped Values (Second Preview)]



Take advantage of the new changes in Java 22 in Open Liberty now and get more time to review your applications, microservices, and runtime environments on your favorite server runtime!

To use Java 22 with Open Liberty, just link:https://adoptium.net/temurin/releases/?version=22[download the latest release of Java 22] and install the link:{url-prefix}/downloads/#runtime_betas[24.0.0.4-beta] version of Open Liberty. Then, edit your Liberty link:{url-prefix}/docs/latest/reference/config/server-configuration-overview.html#server-env[server.env file] to point the `JAVA_HOME` environment variable to your Java 22 installation and start testing today. The 24.0.0.4-beta release introduces beta support for Java 22. As we work toward full Java 22 support, please bear with any of our implementations of these functions that might not be ready yet.

For more information about Java 22, see the following resources:

* link:https://jdk.java.net/22/release-notes[Release notes]
* link:https://docs.oracle.com/en/java/javase/22/docs/api/index.html[Javadocs]
* link:https://docs.oracle.com/en/java/javase/22/migrate/index.html[Migration guide]
* link:https://adoptium.net/temurin/releases/?version=22[Download page]

// DO NOT MODIFY THIS LINE. </GHA-BLOG-TOPIC>

// // // // DO NOT MODIFY THIS COMMENT BLOCK <GHA-BLOG-TOPIC> // // // //
// Blog issue: https://github.com/OpenLiberty/open-liberty/issues/27808
// Contact/Reviewer: njr-11
// // // // // // // //
[#jakarta_data]
== Try out new functions for Jakarta Data 1.0 at milestone 3

Jakarta Data is a new Jakarta EE open source specification that standardizes the popular Data Repository pattern across various providers. Open Liberty 24.0.0.4-beta includes the Jakarta Data 1.0 Milestone 3 release, which introduces the static metamodel and the ability to annotatively compose `Find` methods.

The Open Liberty beta includes a test implementation of Jakarta Data that we are using to experiment with proposed specification features. You can try out these features and provide feedback to influence the Jakarta Data 1.0 specification as it continues to be developed. The test implementation currently works with relational databases and operates by redirecting repository operations to the built-in Jakarta Persistence provider.

Jakarta Data 1.0 milestone 3 introduces the concept of a static metamodel, which allows for more type-safe usage, and the ability to define repository find methods with the `@Find` annotation. To use these capabilities, you need an Entity and a Repository.

Start by defining an entity class that corresponds to your data. With relational databases, the entity class corresponds to a database table and the entity properties (public methods and fields of the entity class) generally correspond to the columns of the table. An entity class can be:

- annotated with `jakarta.persistence.Entity` and related annotations from Jakarta Persistence.
- a Java class without entity annotations, in which case the primary key is inferred from an entity property that is named `id` or ending with `Id` and an entity property that is named `version` designates an automatically incremented version column.

You define one or more repository interfaces for an entity, annotate those interfaces as `@Repository`, and inject them into components by using `@Inject`. The Jakarta Data provider supplies the implementation of the repository interface for you.

The following example shows a simple entity:

[source,java]
----
@Entity
public class Product {
@Id
public long id;
public boolean isDiscounted;
public String name;
public float price;
@Version
public long version;
}
----

The following example shows a repository that defines operations that relate to the entity. Your repository interface can inherit from built-in interfaces such as `BasicRepository` and `CrudRepository` to gain various general-purpose repository methods for inserting, updating, deleting, and querying for entities. However, in this case, we define all of the methods ourselves by using the new life-cycle annotations.

[source,java]
----
@Repository(dataStore = "java:app/jdbc/my-example-data")
public interface Products extends BasicRepository<Product, Long> {
@Insert
Product add(Product newProduct);
// parameter based query that requires compilation with -parameters to preserve parameter names
@Find
Optional<Product> find(long id);
// parameter based query that does not require -parameters because it explicitly specifies the name
@Find
Page<Product> find(@By("isDiscounted") boolean onSale,
PageRequest<Product> pageRequest);
// query-by-method name pattern:
List<Product> findByNameIgnoreCaseContains(String searchFor, Order<Product> orderBy);
// query via JPQL:
@Query("UPDATE Product o SET o.price = o.price - (?2 * o.price), o.isDiscounted = true WHERE o.id = ?1")
boolean discount(long productId, float discountRate);
}
----

Observe that the repository interface includes type parameters in `PageRequest<Product>` and `Order<Product>`. These parameters help ensure that the page request and sort criteria are for a `Product` entity, rather than some other entity. To enable this function, you can optionally define a static metamodel class for the entity (or various IDEs might generate one for you after the 1.0 specification is released). The following example shows that you can use with the `Product` entity,

[source,java]
----
@StaticMetamodel(Product.class)
public class _Product {
public static volatile SortableAttribute<Product> id;
public static volatile SortableAttribute<Product> isDiscounted;
public static volatile TextAttribute<Product> name;
public static volatile SortableAttribute<Product> price;
public static volatile SortableAttribute<Product> version;
// The static metamodel can also have String constants for attribute names,
// but those are omitted from this example
}
----

The following example shows the repository and static metamodel being used:

[source,java]
----
@DataSourceDefinition(name = "java:app/jdbc/my-example-data",
className = "org.postgresql.xa.PGXADataSource",
databaseName = "ExampleDB",
serverName = "localhost",
portNumber = 5432,
user = "${example.database.user}",
password = "${example.database.password}")
public class MyServlet extends HttpServlet {
@Inject
Products products;
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// Insert:
Product prod = ...
prod = products.add(prod);
// Find one entity:
prod = products.find(productId).orElseThrow();
// Find all, sorted:
List<Product> all = products.findByNameIgnoreCaseContains(searchFor, Order.by(
_Product.price.desc(),
_Product.name.asc(),
_Product.id.asc()));
// Find the first 20 most expensive products on sale:
Page<Product> page1 = products.find(onSale, Order.by(_Product.price.desc(),
_Product.name.asc(),
_Product.id.asc())
.pageSize(20));
...
}
}
----


// DO NOT MODIFY THIS LINE. </GHA-BLOG-TOPIC>



To enable the new beta feature in your app, add it to your `server.xml` file:

[source, xml]
----
<server>
<featureManager>
<feature>data-1.0</feature>
...
</featureManager>
...
<server>
----

[#run]
=== Try it now

To try out these features, update your build tools to pull the Open Liberty All Beta Features package instead of the main release. The beta works with Java SE 22, Java SE 21, Java SE 17, Java SE 11, and Java SE 8.

If you're using link:{url-prefix}/guides/maven-intro.html[Maven], you can install the All Beta Features package by using:

[source,xml]
----
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.10.2</version>
<configuration>
<runtimeArtifact>
<groupId>io.openliberty.beta</groupId>
<artifactId>openliberty-runtime</artifactId>
<version>24.0.0.4-beta</version>
<type>zip</type>
</runtimeArtifact>
</configuration>
</plugin>
----

You must also add dependencies to your pom.xml file for the beta version of the APIs that are associated with the beta features that you want to try. For example, the following block adds dependencies for two example beta APIs:

[source,xml]
----
<dependency>
<groupId>org.example.spec</groupId>
<artifactId>exampleApi</artifactId>
<version>7.0</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>example.platform</groupId>
<artifactId>example.example-api</artifactId>
<version>11.0.0</version>
<scope>provided</scope>
</dependency>
----

Or for link:{url-prefix}/guides/gradle-intro.html[Gradle]:

[source,gradle]
----
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'io.openliberty.tools:liberty-gradle-plugin:3.8.2'
}
}
apply plugin: 'liberty'
dependencies {
libertyRuntime group: 'io.openliberty.beta', name: 'openliberty-runtime', version: '[24.0.0.4-beta,)'
}
----

Or if you're using link:{url-prefix}/docs/latest/container-images.html[container images]:

[source]
----
FROM icr.io/appcafe/open-liberty:beta
----

Or take a look at our link:{url-prefix}/downloads/#runtime_betas[Downloads page].

If you're using link:https://plugins.jetbrains.com/plugin/14856-liberty-tools[IntelliJ IDEA], link:https://marketplace.visualstudio.com/items?itemName=Open-Liberty.liberty-dev-vscode-ext[Visual Studio Code] or link:https://marketplace.eclipse.org/content/liberty-tools[Eclipse IDE], you can also take advantage of our open source link:{url-prefix}/docs/latest/develop-liberty-tools.html[Liberty developer tools] to enable effective development, testing, debugging, and application management all from within your IDE.

For more information on using a beta release, refer to the link:{url-prefix}docs/latest/installing-open-liberty-betas.html[Installing Open Liberty beta releases] documentation.

[#feedback]
== We welcome your feedback

Let us know what you think on link:https://groups.io/g/openliberty[our mailing list]. If you hit a problem, link:https://stackoverflow.com/questions/tagged/open-liberty[post a question on StackOverflow]. If you hit a bug, link:https://github.com/OpenLiberty/open-liberty/issues[please raise an issue].

0 comments on commit 244eade

Please sign in to comment.