Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: YDB Hibernate Dialect CI with Maven
name: YDB Hibernate Dialect CI v6 with Maven

on:
push:
paths:
- 'hibernate-dialect/**'
- 'hibernate-dialect-v6/**'
branches:
- main
pull_request:
paths:
- 'hibernate-dialect/**'
- 'hibernate-dialect-v6/**'

env:
MAVEN_ARGS: --batch-mode --update-snapshots -Dstyle.color=always
Expand All @@ -33,17 +33,17 @@ jobs:
cache: maven

- name: Extract Hibernate Dialect version
working-directory: ./hibernate-dialect
working-directory: ./hibernate-dialect-v6
run: |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "HIBERNATE_DIALECT_VERSION=$VERSION" >> "$GITHUB_ENV"

- name: Download Hibernate Dialect dependencies
working-directory: ./hibernate-dialect
working-directory: ./hibernate-dialect-v6
run: mvn $MAVEN_ARGS dependency:go-offline

- name: Build Hibernate Dialect
working-directory: ./hibernate-dialect
working-directory: ./hibernate-dialect-v6
run: mvn $MAVEN_ARGS install

- uses: actions/checkout@v4
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/ci-hibernate-dialect-v7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: YDB Hibernate Dialect v7 CI with Maven

on:
push:
paths:
- 'hibernate-dialect-v7/**'
branches:
- main
pull_request:
paths:
- 'hibernate-dialect-v7/**'

env:
MAVEN_ARGS: --batch-mode --update-snapshots -Dstyle.color=always

jobs:
build:
name: YDB Java Hibernate Dialect
runs-on: ubuntu-latest

strategy:
matrix:
java: [ '17', '21' ]

steps:
- uses: actions/checkout@v4

- name: Set up JDK ${{matrix.java}}
uses: actions/setup-java@v4
with:
java-version: ${{matrix.java}}
distribution: 'temurin'
cache: maven

- name: Extract Hibernate Dialect version
working-directory: ./hibernate-dialect-v7
run: |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "HIBERNATE_DIALECT_VERSION=$VERSION" >> "$GITHUB_ENV"

- name: Download Hibernate Dialect dependencies
working-directory: ./hibernate-dialect-v7
run: mvn $MAVEN_ARGS dependency:go-offline

- name: Build Hibernate Dialect
working-directory: ./hibernate-dialect-v7
run: mvn $MAVEN_ARGS install

- uses: actions/checkout@v4
with:
repository: ydb-platform/ydb-java-examples
ref: master
path: examples

- name: Download dependencies
working-directory: ./examples/jdbc/spring-data-jpa
run: mvn $MAVEN_ARGS -Dhibernate.ydb.dialect.version=$HIBERNATE_DIALECT_VERSION dependency:go-offline

- name: Test examples with Maven
working-directory: ./examples/jdbc/spring-data-jpa
run: mvn $MAVEN_ARGS -Dhibernate.ydb.dialect.version=$HIBERNATE_DIALECT_VERSION test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish YDB Hibernate Dialect
name: Publish YDB Hibernate Dialect v6

on:
push:
Expand All @@ -18,7 +18,7 @@ jobs:

- name: Extract hibernate dialect version
run: |
cd hibernate-dialect
cd hibernate-dialect-v6
HIBERNATE_DIALECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "HIBERNATE_DIALECT_VERSION=$HIBERNATE_DIALECT_VERSION" >> "$GITHUB_ENV"

Expand All @@ -43,12 +43,12 @@ jobs:

- name: Download dependencies
run: |
cd hibernate-dialect
cd hibernate-dialect-v6
mvn $MAVEN_ARGS dependency:go-offline

- name: Build with Maven
run: |
cd hibernate-dialect
cd hibernate-dialect-v6
mvn $MAVEN_ARGS package

publish:
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:

- name: Publish package
run: |
cd hibernate-dialect
cd hibernate-dialect-v6
mvn $MAVEN_ARGS -Possrh-s01 -Dgpg.passphrase=${{ secrets.MAVEN_OSSRH_GPG_PASSWORD }} clean deploy
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_OSSRH_USERNAME }}
Expand Down
85 changes: 85 additions & 0 deletions .github/workflows/publish-hibernate-dialect-v7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Publish YDB Hibernate Dialect v7

on:
push:
tags:
- 'hibernate-ydb/v[0-9]+.[0-9]+.[0-9]+'

env:
MAVEN_ARGS: --batch-mode --no-transfer-progress -Dstyle.color=always

jobs:
validate:
name: Validate YDB Hibernate Dialect
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Extract hibernate dialect version
run: |
cd hibernate-dialect-v7
HIBERNATE_DIALECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "HIBERNATE_DIALECT_VERSION=$HIBERNATE_DIALECT_VERSION" >> "$GITHUB_ENV"

- name: Fail workflow if version is snapshot
if: endsWith(env.HIBERNATE_DIALECT_VERSION, 'SNAPSHOT')
uses: actions/github-script@v6
with:
script: core.setFailed('SNAPSHOT version cannot be published')

- name: Fail workflow if version is not equal to tag name
if: format('hibernate-ydb/v{0}', env.HIBERNATE_DIALECT_VERSION) != github.ref_name
uses: actions/github-script@v6
with:
script: core.setFailed('Release name must be equal to project version')

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: 'maven'

- name: Download dependencies
run: |
cd hibernate-dialect-v7
mvn $MAVEN_ARGS dependency:go-offline

- name: Build with Maven
run: |
cd hibernate-dialect-v7
mvn $MAVEN_ARGS package

publish:
name: Publish YDB Hibernate Dialect
runs-on: ubuntu-latest
needs: validate

steps:
- name: Install gpg secret key
run: |
# Install gpg secret key
cat <(echo -e "${{ secrets.MAVEN_OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import
# Verify gpg secret key
gpg --list-secret-keys --keyid-format LONG

- uses: actions/checkout@v4

- name: Set up Maven Central Repository
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: 'maven'
server-id: ossrh-s01
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD

- name: Publish package
run: |
cd hibernate-dialect-v7
mvn $MAVEN_ARGS -Possrh-s01 -Dgpg.passphrase=${{ secrets.MAVEN_OSSRH_GPG_PASSWORD }} clean deploy
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_OSSRH_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.5.3 ##

- Support `lower` and `upper` functions

## 1.5.2 ##

- Set LIMIT Long.MAX_VALUE in case, when there is offset without limit. Workaround on this issue https://github.com/ydb-platform/ydb/issues/33136
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Maven metadata URL](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Ftech%2Fydb%2Fdialects%2Fhibernate-ydb-dialect%2Fmaven-metadata.xml)](https://mvnrepository.com/artifact/tech.ydb.dialects/hibernate-ydb-dialect)
[![CI](https://img.shields.io/github/actions/workflow/status/ydb-platform/ydb-java-dialects/ci-hibernate-dialect.yaml?branch=main&label=CI)](https://github.com/ydb-platform/ydb-java-dialects/actions/workflows/ci-hibernate-dialect.yaml)

# YDB Dialect for Hibernate 6+
# YDB Dialect for Hibernate 6.*

## Overview

Expand All @@ -21,10 +21,10 @@ features while using YDB as your underlying database.

### Requirements

To use this Hibernate YDB Dialect, you'll need:
To use this Hibernate V6 YDB Dialect, you'll need:

- Java 17 or above.
- Hibernate version 6+
- Hibernate version 6.*
- [YDB JDBC Driver](https://github.com/ydb-platform/ydb-jdbc-driver)
- Access to a YDB Database instance

Expand Down
6 changes: 3 additions & 3 deletions hibernate-dialect/pom.xml → hibernate-dialect-v6/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

<groupId>tech.ydb.dialects</groupId>
<artifactId>hibernate-ydb-dialect</artifactId>
<version>1.5.2</version>
<version>1.5.3</version>

<packaging>jar</packaging>

<name>Hibernate YDB Dialect</name>
<description>Support Hibernate YDB (YQL) Dialect</description>
<name>Hibernate V6 YDB Dialect</name>
<description>Support Hibernate version 6 YDB (YQL) Dialect</description>
<url>https://github.com/ydb-platform/ydb-java-dialects</url>

<developers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.hibernate.mapping.ForeignKey;
import org.hibernate.mapping.Index;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.spi.SqlAppender;
Expand Down Expand Up @@ -239,15 +240,26 @@ public int getDefaultDecimalPrecision() {
public void initializeFunctionRegistry(FunctionContributions functionContributions) {
super.initializeFunctionRegistry(functionContributions);

final SqmFunctionRegistry functionRegistry = functionContributions.getFunctionRegistry();
final BasicType<LocalDateTime> localDateTimeType = functionContributions
.getTypeConfiguration()
.getBasicTypeRegistry()
.resolve(StandardBasicTypes.LOCAL_DATE_TIME);

functionContributions.getFunctionRegistry().register(
functionRegistry.register(
"current_time",
new CurrentFunction("current_time", currentTime(), localDateTimeType)
);

functionRegistry.registerPattern(
"lower",
"Unicode::ToLower(?1)"
);

functionRegistry.registerPattern(
"upper",
"Unicode::ToUpper(?1)"
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package tech.ydb.hibernate.casing;

import org.hibernate.cfg.AvailableSettings;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import tech.ydb.hibernate.TestUtils;
import tech.ydb.test.junit5.YdbHelperExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static tech.ydb.hibernate.TestUtils.*;

/**
* @author Ainur Mukhtarov
*/
public class StringCasingTest {

@RegisterExtension
private static final YdbHelperExtension ydb = new YdbHelperExtension();

@BeforeAll
static void beforeAll() {
TestUtils.SESSION_FACTORY = basedConfiguration()
.setProperty(AvailableSettings.URL, jdbcUrl(ydb))
.buildSessionFactory();
}

@Test
void lowerFunctionTest() {
inTransaction(session -> assertEquals("lower text 123", session
.createQuery("select lower('LoWer Text 123')")
.getSingleResult()));
}

@Test
void upperFunctionTest() {
inTransaction(session -> assertEquals("LOWER TEXT 123", session
.createQuery("select upper('LoWer Text 123')")
.getSingleResult()));
}
}
9 changes: 9 additions & 0 deletions hibernate-dialect-v7/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## 0.9.1 ##

- Full CRUD operations
- Support LIKE / ILIKE statement with ESCAPE
- Support LIMIT ? OFFSET ? statement
- Support ORDER BY ? statement
- @OneToOne, @ManyToMany, @OneToMany, @ManyToOne
- Generate table schema
- Support `lower` and `upper` functions
Loading