From 25191b7d247e8d191537e4b4053a1b3e33a7d780 Mon Sep 17 00:00:00 2001 From: Adrien Kantcheff <5028967+akantcheff@users.noreply.github.com> Date: Wed, 25 Sep 2024 11:12:56 +0200 Subject: [PATCH] feat(community-back): move hibernate interceptors and dialects to SP (#3168) * feat(hibernate): move hibernate properties to SP * feat(hibernate): move hibernate interceptors to SP * feat(hibernate): move custom data types registration to SP * test(business-data): execute community database IT from SP * feat(persistence): move SQLServerExtendedDialect to SP * feat(persistence): move SQLServerOrderByBuilder to SP * add bonita-persistence testRuntimeOnly dep * fix(persistence): throw exception if unknown vendor * fix(persistence): call super in default switch case --- .../TestLocalSessionFactoryBuilder.java | 8 +- .../engine/home/BonitaHomeServer.java | 1 - ...nita-platform-private-community.properties | 9 -- ...bonita-tenant-private-community.properties | 6 - .../bonita-business-data-impl/build.gradle | 6 - .../datasource-dependency-mysql.xml | 32 ------ .../datasource-dependency-oracle.xml | 32 ------ .../datasource-dependency-sqlserver.xml | 32 ------ services/bonita-persistence/build.gradle | 17 +-- .../CustomDataTypesRegistration.java | 7 +- .../HibernateConfigurationProviderImpl.java | 108 ++++++++++-------- .../HibernatePersistenceService.java | 4 - .../engine/persistence/OracleInterceptor.java | 56 --------- .../persistence/SQLServerExtendedDialect.java | 34 ------ .../persistence/SQLServerInterceptor.java | 30 ----- .../persistence/SQLServerOrderByBuilder.java | 46 -------- .../persistence/OracleInterceptorTest.java | 83 -------------- .../SQLServerOrderByBuilderTest.java | 89 --------------- 18 files changed, 75 insertions(+), 525 deletions(-) delete mode 100644 bpm/bonita-core/bonita-process-engine/src/main/resources/bonita-tenant-private-community.properties delete mode 100644 services/bonita-business-data/bonita-business-data-impl/src/test/resources/datasource/datasource-dependency-mysql.xml delete mode 100644 services/bonita-business-data/bonita-business-data-impl/src/test/resources/datasource/datasource-dependency-oracle.xml delete mode 100644 services/bonita-business-data/bonita-business-data-impl/src/test/resources/datasource/datasource-dependency-sqlserver.xml delete mode 100644 services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/OracleInterceptor.java delete mode 100644 services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/SQLServerExtendedDialect.java delete mode 100644 services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/SQLServerInterceptor.java delete mode 100644 services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/SQLServerOrderByBuilder.java delete mode 100644 services/bonita-persistence/src/test/java/org/bonitasoft/engine/persistence/OracleInterceptorTest.java delete mode 100644 services/bonita-persistence/src/test/java/org/bonitasoft/engine/persistence/SQLServerOrderByBuilderTest.java diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/TestLocalSessionFactoryBuilder.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/TestLocalSessionFactoryBuilder.java index 8162abeef96..36b890b6991 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/TestLocalSessionFactoryBuilder.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/TestLocalSessionFactoryBuilder.java @@ -27,14 +27,16 @@ protected SessionFactory buildSessionFactory(LocalSessionFactoryBuilder sfb) { //register type before loading mappings/entities, type should be present before loading JPA entities switch (vendor) { case ORACLE: - sfb.setInterceptor(new OracleInterceptor()); + // FIXME set following interceptor when this module is configured to run on all DB + // sfb.setInterceptor(new OracleInterceptor()); break; case MYSQL: case OTHER: sfb.registerTypeOverride(XMLType.INSTANCE); break; case SQLSERVER: - sfb.setInterceptor(new SQLServerInterceptor()); + // FIXME set following interceptor when this module is configured to run on all DB + // sfb.setInterceptor(new SQLServerInterceptor()); sfb.registerTypeOverride(XMLType.INSTANCE); break; case POSTGRES: @@ -43,7 +45,7 @@ protected SessionFactory buildSessionFactory(LocalSessionFactoryBuilder sfb) { sfb.registerTypeOverride(new PostgresMaterializedClobType()); sfb.registerTypeOverride(PostgresXMLType.INSTANCE); break; - }; + } return super.buildSessionFactory(sfb); } } diff --git a/bpm/bonita-core/bonita-home-server/src/main/java/org/bonitasoft/engine/home/BonitaHomeServer.java b/bpm/bonita-core/bonita-home-server/src/main/java/org/bonitasoft/engine/home/BonitaHomeServer.java index 55bab6bd13b..bf2b1b1e153 100644 --- a/bpm/bonita-core/bonita-home-server/src/main/java/org/bonitasoft/engine/home/BonitaHomeServer.java +++ b/bpm/bonita-core/bonita-home-server/src/main/java/org/bonitasoft/engine/home/BonitaHomeServer.java @@ -107,7 +107,6 @@ public Properties getTenantProperties(long tenantId) throws IOException { Properties allProperties = getPlatformProperties(); Properties tenantProperties = mergeProperties(getPropertiesFromClassPath( "bonita-tenant-community.properties", - "bonita-tenant-private-community.properties", "bonita-tenant-sp.properties", "bonita-tenant-sp-cluster.properties"), getConfigurationService().getTenantEngineConf(tenantId)); allProperties.putAll(tenantProperties); diff --git a/bpm/bonita-core/bonita-process-engine/src/main/resources/bonita-platform-private-community.properties b/bpm/bonita-core/bonita-process-engine/src/main/resources/bonita-platform-private-community.properties index 48f713a7b43..b0df05e3c1b 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/resources/bonita-platform-private-community.properties +++ b/bpm/bonita-core/bonita-process-engine/src/main/resources/bonita-platform-private-community.properties @@ -7,21 +7,12 @@ serverApi=org.bonitasoft.engine.api.impl.ServerAPIImpl # Hibernate Dialects h2.hibernate.dialect=org.hibernate.dialect.H2Dialect -mysql.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect -oracle.hibernate.dialect=org.hibernate.dialect.Oracle12cDialect postgres.hibernate.dialect=org.hibernate.dialect.PostgreSQL10Dialect -sqlserver.hibernate.dialect=org.bonitasoft.engine.persistence.SQLServerExtendedDialect # Hibernate Interceptors for journal (runtime database) h2.hibernate.journal.interceptor= -mysql.hibernate.journal.interceptor= -oracle.hibernate.journal.interceptor=org.bonitasoft.engine.persistence.OracleInterceptor postgres.hibernate.journal.interceptor=org.bonitasoft.engine.persistence.PostgresInterceptor -sqlserver.hibernate.journal.interceptor=org.bonitasoft.engine.persistence.SQLServerInterceptor # Quartz properties h2.quartz.connection.jobstoredriver=org.quartz.impl.jdbcjobstore.StdJDBCDelegate -mysql.quartz.connection.jobstoredriver=org.quartz.impl.jdbcjobstore.StdJDBCDelegate -oracle.quartz.connection.jobstoredriver=org.quartz.impl.jdbcjobstore.StdJDBCDelegate postgres.quartz.connection.jobstoredriver=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate -sqlserver.quartz.connection.jobstoredriver=org.quartz.impl.jdbcjobstore.MSSQLDelegate diff --git a/bpm/bonita-core/bonita-process-engine/src/main/resources/bonita-tenant-private-community.properties b/bpm/bonita-core/bonita-process-engine/src/main/resources/bonita-tenant-private-community.properties deleted file mode 100644 index 9729b4a6206..00000000000 --- a/bpm/bonita-core/bonita-process-engine/src/main/resources/bonita-tenant-private-community.properties +++ /dev/null @@ -1,6 +0,0 @@ -# Hibernate Dialects -h2.hibernate.dialect=org.hibernate.dialect.H2Dialect -mysql.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect -oracle.hibernate.dialect=org.hibernate.dialect.Oracle12cDialect -postgres.hibernate.dialect=org.hibernate.dialect.PostgreSQL10Dialect -sqlserver.hibernate.dialect=org.bonitasoft.engine.persistence.SQLServerExtendedDialect \ No newline at end of file diff --git a/services/bonita-business-data/bonita-business-data-impl/build.gradle b/services/bonita-business-data/bonita-business-data-impl/build.gradle index 68f28ac41ab..4323a45b26c 100644 --- a/services/bonita-business-data/bonita-business-data-impl/build.gradle +++ b/services/bonita-business-data/bonita-business-data-impl/build.gradle @@ -33,10 +33,4 @@ dependencies { testImplementation("com.pholser:junit-quickcheck-generators:${Deps.junitQuickCheck}") } -// run: -// ./gradlew mysqlDatabaseTest -// ./gradlew oracleDatabaseTest -// ./gradlew sqlserverDatabaseTest -// ./gradlew postgresDatabaseTest -// to run tests on specific docker DB: databaseIntegrationTest { includes '**/*Test.class' } diff --git a/services/bonita-business-data/bonita-business-data-impl/src/test/resources/datasource/datasource-dependency-mysql.xml b/services/bonita-business-data/bonita-business-data-impl/src/test/resources/datasource/datasource-dependency-mysql.xml deleted file mode 100644 index 3b0e51a6444..00000000000 --- a/services/bonita-business-data/bonita-business-data-impl/src/test/resources/datasource/datasource-dependency-mysql.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - org.hibernate.dialect.MySQL8Dialect - com.mysql.cj.jdbc.MysqlXADataSource - localhost - 3306 - bonita - root - root - jdbc:mysql://${db.server.name}:${db.server.port}/${db.database.name}?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true - - - - - - - - ${db.user} - ${db.password} - ${db.url} - - - - - diff --git a/services/bonita-business-data/bonita-business-data-impl/src/test/resources/datasource/datasource-dependency-oracle.xml b/services/bonita-business-data/bonita-business-data-impl/src/test/resources/datasource/datasource-dependency-oracle.xml deleted file mode 100644 index 16f356b3df2..00000000000 --- a/services/bonita-business-data/bonita-business-data-impl/src/test/resources/datasource/datasource-dependency-oracle.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - org.hibernate.dialect.Oracle12cDialect - oracle.jdbc.xa.client.OracleXADataSource - localhost - 1521 - ${db.database.name:ORCLPDB1.localdomain} - bonita - bpm - jdbc:oracle:thin:@//${db.server.name}:${db.server.port}/${db.instance.name}?oracle.net.disableOob=true - - - - - - - - ${db.user} - ${db.password} - jdbc:oracle:thin:@//${db.server.name}:${db.server.port}/${db.instance.name}?oracle.net.disableOob=true - - - - - diff --git a/services/bonita-business-data/bonita-business-data-impl/src/test/resources/datasource/datasource-dependency-sqlserver.xml b/services/bonita-business-data/bonita-business-data-impl/src/test/resources/datasource/datasource-dependency-sqlserver.xml deleted file mode 100644 index e048197594e..00000000000 --- a/services/bonita-business-data/bonita-business-data-impl/src/test/resources/datasource/datasource-dependency-sqlserver.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - org.bonitasoft.engine.persistence.SQLServerExtendedDialect - com.microsoft.sqlserver.jdbc.SQLServerXADataSource - localhost - 1533 - bonita_engine - sa - Bonita12 - jdbc:sqlserver://${db.server.name}:${db.server.port};database=${db.database.name} - - - - - - - - ${db.user} - ${db.password} - ${db.url} - - - - - \ No newline at end of file diff --git a/services/bonita-persistence/build.gradle b/services/bonita-persistence/build.gradle index 5f1ac3ae559..8d179cb4a74 100644 --- a/services/bonita-persistence/build.gradle +++ b/services/bonita-persistence/build.gradle @@ -1,7 +1,3 @@ -plugins { - id('bonita-tests') -} - dependencies { api libs.commonsLang api project(':services:bonita-events') @@ -14,16 +10,21 @@ dependencies { api project(':services:bonita-commons') api project(':services:bonita-lock') api libs.slf4jApi + implementation(libs.javaxAnnotations) - testImplementation "junit:junit:${Deps.junit4Version}" - testImplementation "org.mockito:mockito-core:${Deps.mockitoVersion}" - testImplementation "org.assertj:assertj-core:${Deps.assertjVersion}" + compileOnly libs.jakartaTransactionApi annotationProcessor libs.lombok compileOnly libs.lombok - testRuntimeOnly libs.logback + + testImplementation "junit:junit:${Deps.junit4Version}" + testImplementation "org.mockito:mockito-core:${Deps.mockitoVersion}" + testImplementation "org.assertj:assertj-core:${Deps.assertjVersion}" testImplementation "com.github.stefanbirkner:system-rules:${Deps.systemRulesVersion}" + testAnnotationProcessor libs.lombok testImplementation libs.lombok + + testRuntimeOnly libs.logback } diff --git a/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/CustomDataTypesRegistration.java b/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/CustomDataTypesRegistration.java index 748f1047355..4ca8b54df58 100644 --- a/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/CustomDataTypesRegistration.java +++ b/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/CustomDataTypesRegistration.java @@ -16,6 +16,7 @@ import java.util.HashSet; import java.util.Set; +import lombok.Getter; import org.hibernate.boot.SessionFactoryBuilder; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.SessionFactoryBuilderFactory; @@ -27,6 +28,7 @@ public class CustomDataTypesRegistration implements SessionFactoryBuilderFactory private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CustomDataTypesRegistration.class); + @Getter private static Set typeOverrides = new HashSet<>(); @Override @@ -39,11 +41,8 @@ public SessionFactoryBuilder getSessionFactoryBuilder(final MetadataImplementor return defaultBuilder; } - static void addTypeOverride(BasicType type) { + public static void addTypeOverride(BasicType type) { typeOverrides.add(type); } - public static Set getTypeOverrides() { - return typeOverrides; - } } diff --git a/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/HibernateConfigurationProviderImpl.java b/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/HibernateConfigurationProviderImpl.java index 031990fc526..8e43fe9be5a 100644 --- a/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/HibernateConfigurationProviderImpl.java +++ b/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/HibernateConfigurationProviderImpl.java @@ -13,7 +13,7 @@ **/ package org.bonitasoft.engine.persistence; -import static org.bonitasoft.engine.services.Vendor.*; +import static org.bonitasoft.engine.services.Vendor.POSTGRES; import java.util.ArrayList; import java.util.Collections; @@ -23,6 +23,7 @@ import javax.persistence.SharedCacheMode; +import lombok.Getter; import org.bonitasoft.engine.services.Vendor; import org.hibernate.Interceptor; import org.hibernate.SessionFactory; @@ -30,11 +31,11 @@ import org.hibernate.boot.MetadataBuilder; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.SessionFactoryBuilder; -import org.hibernate.boot.registry.BootstrapServiceRegistry; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.mapping.PersistentClass; +import org.hibernate.service.ServiceRegistry; import org.hibernate.type.BasicType; /** @@ -47,9 +48,12 @@ public class HibernateConfigurationProviderImpl implements HibernateConfiguratio private final HibernateResourcesConfigurationProvider hibernateResourcesConfigurationProvider; protected final Properties properties; private final List mappingExclusions; - private Vendor vendor; + @Getter + protected Vendor vendor; + @Getter private SessionFactory sessionFactory; - private List> mappedClasses = new ArrayList<>(); + @Getter + private final List> mappedClasses = new ArrayList<>(); public HibernateConfigurationProviderImpl(final Properties properties, final HibernateResourcesConfigurationProvider hibernateResourcesConfigurationProvider, @@ -76,27 +80,45 @@ public Map getCacheQueries() { @Override public void bootstrap(Properties extraHibernateProperties) { - BootstrapServiceRegistryBuilder bootstrapRegistryBuilder = new BootstrapServiceRegistryBuilder(); - BootstrapServiceRegistry bootstrapRegistry = bootstrapRegistryBuilder.build(); - StandardServiceRegistryBuilder standardRegistryBuilder = new StandardServiceRegistryBuilder(bootstrapRegistry); + StandardServiceRegistryBuilder standardRegistryBuilder = new StandardServiceRegistryBuilder( + new BootstrapServiceRegistryBuilder().build()); Properties allProps = gatherAllProperties(extraHibernateProperties, standardRegistryBuilder); - this.vendor = Vendor.fromHibernateDialectProperty(allProps.getProperty("hibernate.dialect")); StandardServiceRegistry standardRegistry = standardRegistryBuilder.build(); + + this.vendor = Vendor.fromHibernateDialectProperty(allProps.getProperty("hibernate.dialect")); + setCustomHibernateDataTypesAndProperties(); + + Metadata metadata = buildHibernateMetadata(standardRegistry); + + this.sessionFactory = applyInterceptors(metadata, allProps).build(); + + for (PersistentClass entityBinding : metadata.getEntityBindings()) { + mappedClasses.add(entityBinding.getMappedClass()); + } + } + + /** + * Set custom Hibernate data types using {@link CustomDataTypesRegistration} and set Hibernate system properties. + */ + protected void setCustomHibernateDataTypesAndProperties() { switch (vendor) { - case ORACLE: - case SQLSERVER: - case MYSQL: - System.setProperty("hibernate.dialect.storage_engine", "innodb"); - case OTHER: - CustomDataTypesRegistration.addTypeOverride(new XMLType()); - break; - case POSTGRES: + case POSTGRES -> { CustomDataTypesRegistration.addTypeOverride(new PostgresMaterializedBlobType()); CustomDataTypesRegistration.addTypeOverride(new PostgresMaterializedClobType()); CustomDataTypesRegistration.addTypeOverride(new PostgresXMLType()); - break; + } + case OTHER -> CustomDataTypesRegistration.addTypeOverride(new XMLType()); + default -> throw new IllegalStateException("Unsupported vendor: " + vendor); } + } + /** + * Build the hibernate metadata from the provided resources and entities. + * + * @param standardRegistry the standard registry of services needed to create metadata sources + * @return the hibernate metadata + */ + private Metadata buildHibernateMetadata(ServiceRegistry standardRegistry) { MetadataSources metadataSources = new MetadataSources(standardRegistry) { @Override @@ -116,31 +138,33 @@ public MetadataBuilder getMetadataBuilder() { for (Class entity : hibernateResourcesConfigurationProvider.getEntities()) { metadataSources.addAnnotatedClass(entity); } + return metadataSources.buildMetadata(); + } - Metadata metadata = metadataSources.buildMetadata(); + /** + * Apply interceptors to a new session factory. + * + * @param metadata the hibernate metadata + * @param allProps the hibernate properties + * @return a new session factory builder + * @throws IllegalStateException if an interceptor class is unknown or cannot be instantiated + */ + protected SessionFactoryBuilder applyInterceptors(Metadata metadata, Properties allProps) + throws IllegalStateException { SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder(); final String className = allProps.getProperty("hibernate.interceptor"); if (className != null && !className.isEmpty()) { try { - final Interceptor interceptor = (Interceptor) Class.forName(className).newInstance(); - sessionFactoryBuilder.applyInterceptor(interceptor); - } catch (final ClassNotFoundException | IllegalAccessException | InstantiationException cnfe) { - throw new IllegalStateException("Unknown interceptor class " + className, cnfe); + sessionFactoryBuilder.applyInterceptor( + (Interceptor) Class.forName(className).getDeclaredConstructor().newInstance()); + } catch (final ReflectiveOperationException e) { + throw new IllegalStateException("Unknown interceptor class " + className, e); } } if (vendor == POSTGRES) { sessionFactoryBuilder.applyInterceptor(new PostgresInterceptor()); } - if (vendor == SQLSERVER) { - sessionFactoryBuilder.applyInterceptor(new SQLServerInterceptor()); - } - if (vendor == ORACLE) { - sessionFactoryBuilder.applyInterceptor(new OracleInterceptor()); - } - this.sessionFactory = sessionFactoryBuilder.build(); - for (PersistentClass entityBinding : metadata.getEntityBindings()) { - mappedClasses.add(entityBinding.getMappedClass()); - } + return sessionFactoryBuilder; } protected void applyCacheMode(MetadataBuilder metadataBuilder) { @@ -150,12 +174,8 @@ protected void applyCacheMode(MetadataBuilder metadataBuilder) { protected Properties gatherAllProperties(Properties extraHibernateProperties, StandardServiceRegistryBuilder standardRegistryBuilder) { Properties allProps = new Properties(); - for (Map.Entry extraProp : properties.entrySet()) { - allProps.put(extraProp.getKey(), extraProp.getValue()); - } - for (Map.Entry extraProp : extraHibernateProperties.entrySet()) { - allProps.put(extraProp.getKey(), extraProp.getValue()); - } + allProps.putAll(properties); + allProps.putAll(extraHibernateProperties); for (Map.Entry prop : allProps.entrySet()) { standardRegistryBuilder.applySetting(prop.getKey().toString(), prop.getValue()); @@ -163,16 +183,4 @@ protected Properties gatherAllProperties(Properties extraHibernateProperties, return allProps; } - public Vendor getVendor() { - return vendor; - } - - public SessionFactory getSessionFactory() { - return sessionFactory; - } - - public List> getMappedClasses() { - return mappedClasses; - } - } diff --git a/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/HibernatePersistenceService.java b/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/HibernatePersistenceService.java index b862634b51e..f1394ef8b85 100644 --- a/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/HibernatePersistenceService.java +++ b/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/HibernatePersistenceService.java @@ -35,7 +35,6 @@ import org.bonitasoft.engine.services.PersistenceService; import org.bonitasoft.engine.services.SPersistenceException; import org.bonitasoft.engine.services.UpdateDescriptor; -import org.bonitasoft.engine.services.Vendor; import org.bonitasoft.engine.sessionaccessor.ReadSessionAccessor; import org.bonitasoft.engine.sessionaccessor.STenantIdNotSetException; import org.hibernate.AssertionFailure; @@ -90,9 +89,6 @@ public HibernatePersistenceService(final ReadSessionAccessor sessionAccessor, sessionFactory = hbmConfigurationProvider.getSessionFactory(); this.queryBuilderFactory = queryBuilderFactory; - if (hbmConfigurationProvider.getVendor() == Vendor.SQLSERVER) { - this.queryBuilderFactory.setOrderByBuilder(new SQLServerOrderByBuilder()); - } statistics = sessionFactory.getStatistics(); classMapping = hbmConfigurationProvider.getMappedClasses(); classAliasMappings = hbmConfigurationProvider.getClassAliasMappings(); diff --git a/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/OracleInterceptor.java b/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/OracleInterceptor.java deleted file mode 100644 index 3157d2fc7ad..00000000000 --- a/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/OracleInterceptor.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (C) 2023 Bonitasoft S.A. - * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This library is free software; you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Foundation - * version 2.1 of the License. - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth - * Floor, Boston, MA 02110-1301, USA. - **/ -package org.bonitasoft.engine.persistence; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.hibernate.EmptyInterceptor; - -/** - * Make search case insensitive in oracle by using upper() function - */ -public class OracleInterceptor extends EmptyInterceptor { - - /* - * Pattern to find like clauses in sql query : - * (?<= WHERE | OR | AND ) : preceded by WHERE, OR or AND - * (?:[ \(]*) : followed by 0 or more spaces or ( (non-capturing group) - * ((?:(?! WHERE | OR | AND |\\)).)*) : followed by anything except WHERE, OR, AND or ) 0 or more times (capturing - * group) - * (\\)?) : followed by 0 or 1 ) (capturing group) - * ( +LIKE +) : followed by 1 or more spaces, LIKE and 1 or more spaces (capturing group) - * ((?:[^ ]+(?: *\|\| *[^ ]*)*)) : followed by any character except space 1 or more times - * and 0 or more times (space, ||, space and 0 or more times any character except space) (capturing group) - */ - public static final Pattern LIKE_PATTERN = Pattern.compile( - "(?<= WHERE | OR | AND )(?:[ \\(]*)((?:(?! WHERE | OR | AND |\\)).)*)(\\)?)( +LIKE +)((?:[^ ]+(?: *\\|\\| *[^ ]*)*))", - Pattern.CASE_INSENSITIVE); - - @Override - public String onPrepareStatement(final String sql) { - if (sql.contains("like '") || sql.contains("LIKE '") || sql.contains("like ?") || sql.contains("LIKE ?")) { - Matcher matcher = LIKE_PATTERN.matcher(sql); - String newSQL = sql; - while (matcher.find()) { - newSQL = newSQL.replace(matcher.group(1) + matcher.group(2) + matcher.group(3) + matcher.group(4), - "UPPER(" + matcher.group(1) + ")" - + matcher.group(2) + matcher.group(3) - + "UPPER(" + matcher.group(4) + ")"); - } - return newSQL; - } - return sql; - } -} diff --git a/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/SQLServerExtendedDialect.java b/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/SQLServerExtendedDialect.java deleted file mode 100644 index 6d682ef78a1..00000000000 --- a/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/SQLServerExtendedDialect.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (C) 2017 Bonitasoft S.A. - * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This library is free software; you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Foundation - * version 2.1 of the License. - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth - * Floor, Boston, MA 02110-1301, USA. - **/ -package org.bonitasoft.engine.persistence; - -import java.sql.Types; - -import org.hibernate.dialect.SQLServer2012Dialect; - -/** - * @author Emmanuel Duchastenier - */ -public class SQLServerExtendedDialect extends SQLServer2012Dialect { - - public SQLServerExtendedDialect() { - super(); - registerColumnType(Types.CHAR, "nchar(1)"); - registerColumnType(Types.VARCHAR, "nvarchar($l)"); - registerColumnType(Types.VARCHAR, 8000, "nvarchar($l)"); - registerColumnType(Types.LONGVARCHAR, "nvarchar($l)"); - registerColumnType(Types.CLOB, "ntext"); - } - -} diff --git a/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/SQLServerInterceptor.java b/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/SQLServerInterceptor.java deleted file mode 100644 index 7a8cd5c7d93..00000000000 --- a/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/SQLServerInterceptor.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (C) 2019 Bonitasoft S.A. - * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This library is free software; you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Foundation - * version 2.1 of the License. - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth - * Floor, Boston, MA 02110-1301, USA. - **/ -package org.bonitasoft.engine.persistence; - -import org.hibernate.EmptyInterceptor; - -/** - * @author Matthieu Chaffotte - */ -public class SQLServerInterceptor extends EmptyInterceptor { - - private static final long serialVersionUID = -6720122264417020259L; - - @Override - public String onPrepareStatement(final String sql) { - // this replace does not work with prepared statements - return sql.replace("like '", "like N'").replace("LIKE '", "like N'"); - } -} diff --git a/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/SQLServerOrderByBuilder.java b/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/SQLServerOrderByBuilder.java deleted file mode 100644 index 9a5dfe99cff..00000000000 --- a/services/bonita-persistence/src/main/java/org/bonitasoft/engine/persistence/SQLServerOrderByBuilder.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright (C) 2019 Bonitasoft S.A. - * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This library is free software; you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Foundation - * version 2.1 of the License. - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth - * Floor, Boston, MA 02110-1301, USA. - **/ -package org.bonitasoft.engine.persistence; - -/** - * @author Baptiste Mesta - */ -public class SQLServerOrderByBuilder implements OrderByBuilder { - - @Override - public void appendOrderBy(StringBuilder builder, String fieldName, OrderByType orderByType) { - switch (orderByType) { - case ASC: - case DESC: - builder.append(fieldName).append(" ").append(orderByType.getSqlKeyword()); - break; - case ASC_NULLS_FIRST: - builder.append("CASE WHEN ").append(fieldName).append(" IS NULL THEN 0 ELSE 1 END ASC, ") - .append(fieldName).append(" ASC"); - break; - case ASC_NULLS_LAST: - builder.append("CASE WHEN ").append(fieldName).append(" IS NULL THEN 0 ELSE 1 END DESC, ") - .append(fieldName).append(" ASC"); - break; - case DESC_NULLS_FIRST: - builder.append("CASE WHEN ").append(fieldName).append(" IS NULL THEN 0 ELSE 1 END ASC, ") - .append(fieldName).append(" DESC"); - break; - case DESC_NULLS_LAST: - builder.append("CASE WHEN ").append(fieldName).append(" IS NULL THEN 0 ELSE 1 END DESC, ") - .append(fieldName).append(" DESC"); - break; - } - } -} diff --git a/services/bonita-persistence/src/test/java/org/bonitasoft/engine/persistence/OracleInterceptorTest.java b/services/bonita-persistence/src/test/java/org/bonitasoft/engine/persistence/OracleInterceptorTest.java deleted file mode 100644 index e5552125919..00000000000 --- a/services/bonita-persistence/src/test/java/org/bonitasoft/engine/persistence/OracleInterceptorTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright (C) 2024 Bonitasoft S.A. - * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This library is free software; you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Foundation - * version 2.1 of the License. - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth - * Floor, Boston, MA 02110-1301, USA. - **/ -package org.bonitasoft.engine.persistence; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; - -import org.junit.Test; - -public class OracleInterceptorTest { - - private String sql = "select * from ( select sgatewayin0_.id as col_0_0_ from flownode_instance sgatewayin0_ " - + "where sgatewayin0_.kind='gate' and sgatewayin0_.stateId<>3 " - + "and (sgatewayin0_.stateId<>61 or sgatewayin0_.hitBys like 'FINISH:%' " - + "or sgatewayin0_.stateCategory='ABORTING' or sgatewayin0_.stateCategory='CANCELLING') " - + "and sgatewayin0_.lastUpdateDate<:1 order by sgatewayin0_.id ) where rownum <= :2"; - - private String preparedStatement = "select * from ( select sgatewayin0_.id as col_0_0_ from flownode_instance sgatewayin0_ " - + "where sgatewayin0_.kind='gate' and sgatewayin0_.stateId<>3 " - + "and (sgatewayin0_.stateId<>61 or sgatewayin0_.hitBys like ? " - + "or sgatewayin0_.stateCategory='ABORTING' or sgatewayin0_.stateCategory='CANCELLING') " - + "and sgatewayin0_.lastUpdateDate<:1 order by sgatewayin0_.id ) where rownum <= ?"; - - private String preparedStatementWithConcat = "select * from ( select distinct sprocessde2_.id as id1_47_, " - + "sprocessde2_.version as version14_47_ from actor sactor0_ cross join actormember sactormemb1_ " - + "cross join process_definition sprocessde2_ where sactor0_.scopeId=sprocessde2_.processId and " - + "sactor0_.id=sactormemb1_.actorId and (sactormemb1_.groupId in (select sgroup3_.id from group_ " - + "sgroup3_ cross join group_ sgroup4_ where ((sgroup3_.parentPath||'/'||sgroup3_.name||'/') " - + "like '/' || sgroup4_.name || '/' || '%' or sgroup3_.id=?) and sgroup4_.id=?)) and " - + "(sactormemb1_.actorId not in (select sactormemb5_.actorId from actormember sactormemb5_ " - + "where sactormemb5_.groupId<>sactormemb1_.groupId and (sactormemb5_.groupId not in " - + "(select sgroup6_.id from group_ sgroup6_ cross join group_ sgroup7_ where " - + "(sgroup6_.parentPath||'/'||sgroup6_.name||'/' like sgroup7_.name||'/'||'%' or sgroup6_.id=?) " - + "and sgroup7_.id=?)))) order by sprocessde2_.name ASC, sprocessde2_.id ASC ) where rownum <= ?"; - private OracleInterceptor oracleInterceptor = new OracleInterceptor(); - - @Test - public void should_uppercase_like_on_sql() { - assertThat(oracleInterceptor.onPrepareStatement(sql)).isEqualTo( - "select * from ( select sgatewayin0_.id as col_0_0_ from flownode_instance sgatewayin0_ " - + "where sgatewayin0_.kind='gate' and sgatewayin0_.stateId<>3 " - + "and (sgatewayin0_.stateId<>61 or UPPER(sgatewayin0_.hitBys) like UPPER('FINISH:%') " - + "or sgatewayin0_.stateCategory='ABORTING' or sgatewayin0_.stateCategory='CANCELLING') " - + "and sgatewayin0_.lastUpdateDate<:1 order by sgatewayin0_.id ) where rownum <= :2"); - } - - @Test - public void should_uppercase_like_on_prepared_statement() { - assertThat(oracleInterceptor.onPrepareStatement(preparedStatement)).isEqualTo( - "select * from ( select sgatewayin0_.id as col_0_0_ from flownode_instance sgatewayin0_ " - + "where sgatewayin0_.kind='gate' and sgatewayin0_.stateId<>3 " - + "and (sgatewayin0_.stateId<>61 or UPPER(sgatewayin0_.hitBys) like UPPER(?) " - + "or sgatewayin0_.stateCategory='ABORTING' or sgatewayin0_.stateCategory='CANCELLING') " - + "and sgatewayin0_.lastUpdateDate<:1 order by sgatewayin0_.id ) where rownum <= ?"); - } - - @Test - public void should_uppercase_like_on_prepared_statement_with_concat() { - assertThat(oracleInterceptor.onPrepareStatement(preparedStatementWithConcat)).isEqualTo( - "select * from ( select distinct sprocessde2_.id as id1_47_, " - + "sprocessde2_.version as version14_47_ from actor sactor0_ cross join actormember sactormemb1_ " - + "cross join process_definition sprocessde2_ where sactor0_.scopeId=sprocessde2_.processId and " - + "sactor0_.id=sactormemb1_.actorId and (sactormemb1_.groupId in (select sgroup3_.id from group_ " - + "sgroup3_ cross join group_ sgroup4_ where ((UPPER(sgroup3_.parentPath||'/'||sgroup3_.name||'/')) " - + "like UPPER('/' || sgroup4_.name || '/' || '%') or sgroup3_.id=?) and sgroup4_.id=?)) and " - + "(sactormemb1_.actorId not in (select sactormemb5_.actorId from actormember sactormemb5_ " - + "where sactormemb5_.groupId<>sactormemb1_.groupId and (sactormemb5_.groupId not in " - + "(select sgroup6_.id from group_ sgroup6_ cross join group_ sgroup7_ where " - + "(UPPER(sgroup6_.parentPath||'/'||sgroup6_.name||'/') like UPPER(sgroup7_.name||'/'||'%') or sgroup6_.id=?) " - + "and sgroup7_.id=?)))) order by sprocessde2_.name ASC, sprocessde2_.id ASC ) where rownum <= ?"); - } -} diff --git a/services/bonita-persistence/src/test/java/org/bonitasoft/engine/persistence/SQLServerOrderByBuilderTest.java b/services/bonita-persistence/src/test/java/org/bonitasoft/engine/persistence/SQLServerOrderByBuilderTest.java deleted file mode 100644 index 58c6b99703f..00000000000 --- a/services/bonita-persistence/src/test/java/org/bonitasoft/engine/persistence/SQLServerOrderByBuilderTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Copyright (C) 2019 Bonitasoft S.A. - * Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble - * This library is free software; you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Foundation - * version 2.1 of the License. - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth - * Floor, Boston, MA 02110-1301, USA. - **/ -package org.bonitasoft.engine.persistence; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Before; -import org.junit.Test; - -/** - * @author Laurent Leseigneur - */ -public class SQLServerOrderByBuilderTest { - - private StringBuilder builder; - - private SQLServerOrderByBuilder sqlServerInterceptor; - - @Before - public void before() { - builder = new StringBuilder(); - sqlServerInterceptor = new SQLServerOrderByBuilder(); - } - - @Test - public void should_sort_asc() { - //when - sqlServerInterceptor.appendOrderBy(builder, "field", OrderByType.ASC); - - //then - assertThat(builder.toString()).isEqualTo("field ASC"); - } - - @Test - public void should_sort_asc_with_nulls_first() { - //when - sqlServerInterceptor.appendOrderBy(builder, "field", OrderByType.ASC_NULLS_FIRST); - - //then - assertThat(builder.toString()).isEqualTo("CASE WHEN field IS NULL THEN 0 ELSE 1 END ASC, field ASC"); - } - - @Test - public void should_sort_asc_with_nulls_last() { - //when - sqlServerInterceptor.appendOrderBy(builder, "field", OrderByType.ASC_NULLS_LAST); - - //then - assertThat(builder.toString()).isEqualTo("CASE WHEN field IS NULL THEN 0 ELSE 1 END DESC, field ASC"); - } - - @Test - public void should_sort_desc() { - //when - sqlServerInterceptor.appendOrderBy(builder, "field", OrderByType.DESC); - - //then - assertThat(builder.toString()).isEqualTo("field DESC"); - } - - @Test - public void should_sort_desc_with_nulls_first() { - //when - sqlServerInterceptor.appendOrderBy(builder, "field", OrderByType.DESC_NULLS_FIRST); - - //then - assertThat(builder.toString()).isEqualTo("CASE WHEN field IS NULL THEN 0 ELSE 1 END ASC, field DESC"); - } - - @Test - public void should_sort_desc_with_nulls_last() { - //when - sqlServerInterceptor.appendOrderBy(builder, "field", OrderByType.DESC_NULLS_LAST); - - //then - assertThat(builder.toString()).isEqualTo("CASE WHEN field IS NULL THEN 0 ELSE 1 END DESC, field DESC"); - } -}