diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000000..2bd7143061 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,17 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" + groups: + workflow-actions: + patterns: + - "*" + allow: + - dependency-name: "actions/*" diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 109aede3b3..e8ca8fe816 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -9,20 +9,18 @@ jobs: steps: - name: Checkout PR Branch - uses: actions/checkout@v2 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: ref: ${{ github.event.pull_request.head.sha }} fetch-depth: 0 - name: Setup Java 11 - uses: actions/setup-java@v1 + uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0 with: java-version: 11 - java-package: jdk - architecture: x64 + distribution: temurin - name: Build and Test - uses: GabrielBB/xvfb-action@v1 - with: - run: mvn clean install - + uses: GabrielBB/xvfb-action@b706e4e27b14669b486812790492dc50ca16b465 # v1.7 + with: + run: mvn clean install diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000000..7967f30dd1 Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000..f5b763a229 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=bin +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar diff --git a/.release/.gitignore b/.release/.gitignore new file mode 100644 index 0000000000..cdd9a17d6b --- /dev/null +++ b/.release/.gitignore @@ -0,0 +1,3 @@ +# The folder into which we checkout our release scripts into +* +!.gitignore \ No newline at end of file diff --git a/ant/pom.xml b/ant/pom.xml index 1fed055dc8..b0b6c48f88 100644 --- a/ant/pom.xml +++ b/ant/pom.xml @@ -21,7 +21,7 @@ org.hibernate.tool hibernate-tools-parent - 6.2.7-SNAPSHOT + 6.2.42-SNAPSHOT hibernate-tools-ant @@ -30,6 +30,11 @@ Hibernate Tools Ant Tasks jar + + + false + + org.apache.ant diff --git a/ci/release/Jenkinsfile b/ci/release/Jenkinsfile new file mode 100644 index 0000000000..b2f169b3c8 --- /dev/null +++ b/ci/release/Jenkinsfile @@ -0,0 +1,119 @@ +/* + * Hibernate Tools, Tooling for your Hibernate Projects + * + * Copyright 2016-2024 Red Hat, Inc. + * + * Licensed under the GNU Lesser General Public License (LGPL), + * version 2.1 or later (the "License"). + * You may not use this file except in compliance with the License. + * You may read the licence in the 'lgpl.txt' file in the root folder of + * project or obtain a copy at + * + * http://www.gnu.org/licenses/lgpl-2.1.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@Library('hibernate-jenkins-pipeline-helpers') _ + +import org.hibernate.jenkins.pipeline.helpers.version.Version + +pipeline { + agent { + label 'Release' + } + tools { + maven 'Apache Maven 3.9' + jdk 'OpenJDK 11 Latest' + } + options { + buildDiscarder logRotator(daysToKeepStr: '30', numToKeepStr: '10') + disableConcurrentBuilds(abortPrevious: false) + } + parameters { + string( + name: 'RELEASE_VERSION', + defaultValue: '6.2.42.Final', + description: 'The version to be released, e.g. 6.2.42.Final.', + trim: true + ) + string( + name: 'DEVELOPMENT_VERSION', + defaultValue: '6.2.43-SNAPSHOT', + description: 'The next version to be used after the release, e.g. 6.2.43-SNAPSHOT.', + trim: true + ) + booleanParam( + name: 'RELEASE_DRY_RUN', + defaultValue: true, + description: 'If true, just simulate the release, without pushing any commits or tags, and without uploading any artifacts or documentation.' + ) + booleanParam( + name: 'RELEASE_PUBLISH_AUTOMATICALLY', + defaultValue: false, + description: 'If true, staging repository will get closed and published automatically, otherwise the artifacts will only be uploaded and the publishing (releasing the staging repository) has to be performed manually at Maven Central portal.' + ) + } + stages { + stage('Release') { + when { + beforeAgent true + // Releases must be triggered explicitly + // This is just for safety; normally the Jenkins job for this pipeline + // should be configured to "Suppress automatic SCM triggering" + // See https://stackoverflow.com/questions/58259326/prevent-jenkins-multibranch-pipeline-from-triggering-builds-for-new-branches + triggeredBy cause: "UserIdCause" + } + steps { + script { + // Check that all the necessary parameters are set + if (!params.RELEASE_VERSION) { + throw new IllegalArgumentException("Missing value for parameter RELEASE_VERSION.") + } + if (!params.DEVELOPMENT_VERSION) { + throw new IllegalArgumentException("Missing value for parameter DEVELOPMENT_VERSION.") + } + + def releaseVersion = Version.parseReleaseVersion(params.RELEASE_VERSION) + def developmentVersion = Version.parseDevelopmentVersion(params.DEVELOPMENT_VERSION) + env.JRELEASER_DRY_RUN = params.RELEASE_DRY_RUN + if (!params.RELEASE_PUBLISH_AUTOMATICALLY) { + env.JRELEASER_DEPLOY_MAVEN_MAVENCENTRAL_STAGE='UPLOAD' + } + echo "Performing full release for version ${releaseVersion.toString()}" + + withMaven(mavenSettingsConfig: params.RELEASE_DRY_RUN ? null : 'ci-hibernate.deploy.settings.maven', + mavenLocalRepo: env.WORKSPACE_TMP + '/.m2repository') { + configFileProvider([configFile(fileId: 'release.config.ssh', targetLocation: env.HOME + '/.ssh/config'), + configFile(fileId: 'release.config.ssh.knownhosts', targetLocation: env.HOME + '/.ssh/known_hosts')]) { + // using MAVEN_GPG_PASSPHRASE (the default env variable name for passphrase in maven gpg plugin) + withCredentials([file(credentialsId: 'release.gpg.private-key', variable: 'RELEASE_GPG_PRIVATE_KEY_PATH'), + string(credentialsId: 'release.gpg.passphrase', variable: 'JRELEASER_GPG_PASSPHRASE'), + usernamePassword(credentialsId: 'central.sonatype.com', passwordVariable: 'JRELEASER_MAVENCENTRAL_TOKEN', usernameVariable: 'JRELEASER_MAVENCENTRAL_USERNAME'), + string(credentialsId: 'Hibernate-CI.github.com', variable: 'JRELEASER_GITHUB_TOKEN')]) { + sshagent(['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net']) { + sh 'cat $HOME/.ssh/config' + dir('.release/scripts') { + sh 'git clone https://github.com/hibernate/hibernate-release-scripts.git .' + } + sh """ + bash -xe .release/scripts/release.sh -j ${params.RELEASE_DRY_RUN ? '-d' : ''} \ + tools ${releaseVersion.toString()} ${developmentVersion.toString()} + """ + } + } + } + } + } + } + } + } + post { + always { + notifyBuildResult notifySuccessAfterSuccess: true, maintainers: 'koen@hibernate.org' + } + } +} diff --git a/jbt/pom.xml b/jbt/pom.xml index 6227632cf0..d06215fdd4 100644 --- a/jbt/pom.xml +++ b/jbt/pom.xml @@ -25,7 +25,7 @@ org.hibernate.tool hibernate-tools-parent - 6.2.7-SNAPSHOT + 6.2.42-SNAPSHOT hibernate-tools-orm-jbt @@ -35,6 +35,11 @@ Hibernate Tools ORM - JBoss Tools Adapter Hibernate Tools ORM - JBoss Tools Adapter + + + false + + com.h2database diff --git a/jbt/src/main/java/org/hibernate/tool/hbm2x/DAOExporter.java b/jbt/src/main/java/org/hibernate/tool/hbm2x/DAOExporter.java new file mode 100644 index 0000000000..263e564e9a --- /dev/null +++ b/jbt/src/main/java/org/hibernate/tool/hbm2x/DAOExporter.java @@ -0,0 +1,5 @@ +package org.hibernate.tool.hbm2x; + +import org.hibernate.tool.internal.export.dao.DaoExporter; + +public class DAOExporter extends DaoExporter {} diff --git a/jbt/src/main/java/org/hibernate/tool/hbm2x/DocExporter.java b/jbt/src/main/java/org/hibernate/tool/hbm2x/DocExporter.java new file mode 100644 index 0000000000..01ea56276e --- /dev/null +++ b/jbt/src/main/java/org/hibernate/tool/hbm2x/DocExporter.java @@ -0,0 +1,3 @@ +package org.hibernate.tool.hbm2x; + +public class DocExporter extends org.hibernate.tool.internal.export.doc.DocExporter {} diff --git a/jbt/src/main/java/org/hibernate/tool/hbm2x/GenericExporter.java b/jbt/src/main/java/org/hibernate/tool/hbm2x/GenericExporter.java new file mode 100644 index 0000000000..3ae36af92d --- /dev/null +++ b/jbt/src/main/java/org/hibernate/tool/hbm2x/GenericExporter.java @@ -0,0 +1,3 @@ +package org.hibernate.tool.hbm2x; + +public class GenericExporter extends org.hibernate.tool.internal.export.common.GenericExporter {} diff --git a/jbt/src/main/java/org/hibernate/tool/hbm2x/Hbm2DDLExporter.java b/jbt/src/main/java/org/hibernate/tool/hbm2x/Hbm2DDLExporter.java new file mode 100644 index 0000000000..ce5334e854 --- /dev/null +++ b/jbt/src/main/java/org/hibernate/tool/hbm2x/Hbm2DDLExporter.java @@ -0,0 +1,5 @@ +package org.hibernate.tool.hbm2x; + +import org.hibernate.tool.internal.export.ddl.DdlExporter; + +public class Hbm2DDLExporter extends DdlExporter {} diff --git a/jbt/src/main/java/org/hibernate/tool/hbm2x/HibernateConfigurationExporter.java b/jbt/src/main/java/org/hibernate/tool/hbm2x/HibernateConfigurationExporter.java new file mode 100644 index 0000000000..104afd6bcf --- /dev/null +++ b/jbt/src/main/java/org/hibernate/tool/hbm2x/HibernateConfigurationExporter.java @@ -0,0 +1,5 @@ +package org.hibernate.tool.hbm2x; + +import org.hibernate.tool.internal.export.cfg.CfgExporter; + +public class HibernateConfigurationExporter extends CfgExporter {} diff --git a/jbt/src/main/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java b/jbt/src/main/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java new file mode 100644 index 0000000000..d537be13d1 --- /dev/null +++ b/jbt/src/main/java/org/hibernate/tool/hbm2x/HibernateMappingExporter.java @@ -0,0 +1,7 @@ +package org.hibernate.tool.hbm2x; + +import org.hibernate.tool.internal.export.hbm.HbmExporter; + +public class HibernateMappingExporter extends HbmExporter { + +} diff --git a/jbt/src/main/java/org/hibernate/tool/hbm2x/POJOExporter.java b/jbt/src/main/java/org/hibernate/tool/hbm2x/POJOExporter.java new file mode 100644 index 0000000000..7f7801634d --- /dev/null +++ b/jbt/src/main/java/org/hibernate/tool/hbm2x/POJOExporter.java @@ -0,0 +1,7 @@ +package org.hibernate.tool.hbm2x; + +import org.hibernate.tool.internal.export.java.JavaExporter; + +public class POJOExporter extends JavaExporter { + +} diff --git a/jbt/src/main/java/org/hibernate/tool/hbm2x/QueryExporter.java b/jbt/src/main/java/org/hibernate/tool/hbm2x/QueryExporter.java new file mode 100644 index 0000000000..cb199780c0 --- /dev/null +++ b/jbt/src/main/java/org/hibernate/tool/hbm2x/QueryExporter.java @@ -0,0 +1,3 @@ +package org.hibernate.tool.hbm2x; + +public class QueryExporter extends org.hibernate.tool.internal.export.query.QueryExporter {} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/BigIntegerType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/BigIntegerType.java deleted file mode 100644 index 93a92a2216..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/BigIntegerType.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import java.math.BigInteger; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.BigIntegerJavaType; -import org.hibernate.type.descriptor.jdbc.NumericJdbcType; - -public class BigIntegerType extends AbstractSingleColumnStandardBasicType { - - public static final BigIntegerType INSTANCE = new BigIntegerType(); - - public BigIntegerType() { - super(NumericJdbcType.INSTANCE, BigIntegerJavaType.INSTANCE); - } - - @Override - public String getName() { - return "big_integer"; - } - - @Override - protected boolean registerUnderJavaType() { - return true; - } - -} \ No newline at end of file diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/BooleanType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/BooleanType.java deleted file mode 100644 index 80fef7b6c4..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/BooleanType.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.AdjustableBasicType; -import org.hibernate.type.descriptor.java.BooleanJavaType; -import org.hibernate.type.descriptor.jdbc.BooleanJdbcType; - -public class BooleanType extends AbstractSingleColumnStandardBasicType - implements AdjustableBasicType { - - public static final BooleanType INSTANCE = new BooleanType(); - - public BooleanType() { - super(BooleanJdbcType.INSTANCE, BooleanJavaType.INSTANCE); - } - - @Override - public String getName() { - return "boolean"; - } - - @Override - public String[] getRegistrationKeys() { - return new String[] { getName(), boolean.class.getName(), Boolean.class.getName() }; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/ByteType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/ByteType.java deleted file mode 100644 index 4ea2ef80b0..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/ByteType.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.ByteJavaType; -import org.hibernate.type.descriptor.jdbc.TinyIntJdbcType; - -public class ByteType extends AbstractSingleColumnStandardBasicType { - - public static final ByteType INSTANCE = new ByteType(); - - public ByteType() { - super(TinyIntJdbcType.INSTANCE, ByteJavaType.INSTANCE); - } - - @Override - public String getName() { - return "byte"; - } - - @Override - public String[] getRegistrationKeys() { - return new String[] { getName(), byte.class.getName(), Byte.class.getName() }; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/CalendarDateType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/CalendarDateType.java deleted file mode 100644 index d2fa3d0263..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/CalendarDateType.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import java.util.Calendar; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.CalendarDateJavaType; -import org.hibernate.type.descriptor.jdbc.DateJdbcType; - -public class CalendarDateType extends AbstractSingleColumnStandardBasicType { - public static final CalendarDateType INSTANCE = new CalendarDateType(); - - public CalendarDateType() { - super(DateJdbcType.INSTANCE, CalendarDateJavaType.INSTANCE); - } - - - public String getName() { - return "calendar_date"; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/CalendarType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/CalendarType.java deleted file mode 100644 index 5753749e89..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/CalendarType.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import java.util.Calendar; -import java.util.GregorianCalendar; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.CalendarJavaType; -import org.hibernate.type.descriptor.jdbc.TimestampJdbcType; - -public class CalendarType extends AbstractSingleColumnStandardBasicType { - - public static final CalendarType INSTANCE = new CalendarType(); - - public CalendarType() { - super(TimestampJdbcType.INSTANCE, CalendarJavaType.INSTANCE); - } - - @Override - public String getName() { - return "calendar"; - } - - @Override - public String[] getRegistrationKeys() { - return new String[] { getName(), Calendar.class.getName(), GregorianCalendar.class.getName() }; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/CharacterType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/CharacterType.java deleted file mode 100644 index d8e2019af3..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/CharacterType.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.AdjustableBasicType; -import org.hibernate.type.descriptor.java.CharacterJavaType; -import org.hibernate.type.descriptor.jdbc.CharJdbcType; - -public class CharacterType extends AbstractSingleColumnStandardBasicType - implements AdjustableBasicType { - - public static final CharacterType INSTANCE = new CharacterType(); - - public CharacterType() { - super(CharJdbcType.INSTANCE, CharacterJavaType.INSTANCE); - } - - public String getName() { - return "character"; - } - - @Override - public String[] getRegistrationKeys() { - return new String[] { getName(), char.class.getName(), Character.class.getName() }; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/ClassType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/ClassType.java deleted file mode 100644 index d3647d5837..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/ClassType.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.ClassJavaType; -import org.hibernate.type.descriptor.jdbc.VarcharJdbcType; - -public class ClassType extends AbstractSingleColumnStandardBasicType { - public static final ClassType INSTANCE = new ClassType(); - - public ClassType() { - super(VarcharJdbcType.INSTANCE, ClassJavaType.INSTANCE); - } - - public String getName() { - return "class"; - } - - @Override - protected boolean registerUnderJavaType() { - return true; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/CurrencyType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/CurrencyType.java deleted file mode 100644 index 18b862c70a..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/CurrencyType.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import java.util.Currency; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.CurrencyJavaType; -import org.hibernate.type.descriptor.jdbc.VarcharJdbcType; - -public class CurrencyType extends AbstractSingleColumnStandardBasicType { - - public static final CurrencyType INSTANCE = new CurrencyType(); - - public CurrencyType() { - super(VarcharJdbcType.INSTANCE, CurrencyJavaType.INSTANCE); - } - - public String getName() { - return "currency"; - } - - @Override - protected boolean registerUnderJavaType() { - return true; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/DateType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/DateType.java deleted file mode 100644 index 8b6c429fd9..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/DateType.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import java.util.Date; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.JdbcDateJavaType; -import org.hibernate.type.descriptor.jdbc.DateJdbcType; - -public class DateType extends AbstractSingleColumnStandardBasicType { - - public static final DateType INSTANCE = new DateType(); - - public DateType() { - super(DateJdbcType.INSTANCE, JdbcDateJavaType.INSTANCE); - } - - public String getName() { - return "date"; - } - - @Override - public String[] getRegistrationKeys() { - return new String[] { getName(), java.sql.Date.class.getName() }; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/DoubleType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/DoubleType.java deleted file mode 100644 index e754e0b88a..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/DoubleType.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.DoubleJavaType; -import org.hibernate.type.descriptor.jdbc.DoubleJdbcType; - -public class DoubleType extends AbstractSingleColumnStandardBasicType { - - public static final DoubleType INSTANCE = new DoubleType(); - - public DoubleType() { - super(DoubleJdbcType.INSTANCE, DoubleJavaType.INSTANCE); - } - - @Override - public String getName() { - return "double"; - } - - @Override - public String[] getRegistrationKeys() { - return new String[] { getName(), double.class.getName(), Double.class.getName() }; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/FloatType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/FloatType.java deleted file mode 100644 index 6bbc91c9e8..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/FloatType.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.FloatJavaType; -import org.hibernate.type.descriptor.jdbc.FloatJdbcType; - -public class FloatType extends AbstractSingleColumnStandardBasicType { - - public static final FloatType INSTANCE = new FloatType(); - - public FloatType() { - super( FloatJdbcType.INSTANCE, FloatJavaType.INSTANCE ); - } - - @Override - public String getName() { - return "float"; - } - - @Override - public String[] getRegistrationKeys() { - return new String[] { getName(), float.class.getName(), Float.class.getName() }; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/IntegerType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/IntegerType.java deleted file mode 100644 index 2346e8e3db..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/IntegerType.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.IntegerJavaType; -import org.hibernate.type.descriptor.jdbc.IntegerJdbcType; - -public class IntegerType extends AbstractSingleColumnStandardBasicType { - - public static final IntegerType INSTANCE = new IntegerType(); - - public IntegerType() { - super( IntegerJdbcType.INSTANCE, IntegerJavaType.INSTANCE ); - } - - @Override - public String getName() { - return "integer"; - } - - @Override - public String[] getRegistrationKeys() { - return new String[] {getName(), int.class.getName(), Integer.class.getName()}; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/LocaleType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/LocaleType.java deleted file mode 100644 index 7eec0df927..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/LocaleType.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import java.util.Locale; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.LocaleJavaType; -import org.hibernate.type.descriptor.jdbc.VarcharJdbcType; - -public class LocaleType extends AbstractSingleColumnStandardBasicType { - - public static final LocaleType INSTANCE = new LocaleType(); - - public LocaleType() { - super( VarcharJdbcType.INSTANCE, LocaleJavaType.INSTANCE ); - } - - @Override - public String getName() { - return "locale"; - } - - @Override - protected boolean registerUnderJavaType() { - return true; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/LongType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/LongType.java deleted file mode 100644 index 2d46732f29..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/LongType.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.LongJavaType; -import org.hibernate.type.descriptor.jdbc.BigIntJdbcType; - -public class LongType extends AbstractSingleColumnStandardBasicType { - - public static final LongType INSTANCE = new LongType(); - - public LongType() { - super(BigIntJdbcType.INSTANCE, LongJavaType.INSTANCE); - } - - @Override - public String getName() { - return "long"; - } - - @Override - public String[] getRegistrationKeys() { - return new String[] { getName(), long.class.getName(), Long.class.getName() }; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/ShortType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/ShortType.java deleted file mode 100644 index 7dad7cfe94..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/ShortType.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.ShortJavaType; -import org.hibernate.type.descriptor.jdbc.SmallIntJdbcType; - -public class ShortType extends AbstractSingleColumnStandardBasicType { - - public static final ShortType INSTANCE = new ShortType(); - - public ShortType() { - super(SmallIntJdbcType.INSTANCE, ShortJavaType.INSTANCE); - } - - @Override - public String getName() { - return "short"; - } - - @Override - public String[] getRegistrationKeys() { - return new String[] { getName(), short.class.getName(), Short.class.getName() }; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/StringType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/StringType.java deleted file mode 100644 index 732a98872b..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/StringType.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.AdjustableBasicType; -import org.hibernate.type.descriptor.java.StringJavaType; -import org.hibernate.type.descriptor.jdbc.VarcharJdbcType; - -public class StringType extends AbstractSingleColumnStandardBasicType implements AdjustableBasicType { - - public static final StringType INSTANCE = new StringType(); - - public StringType() { - super(VarcharJdbcType.INSTANCE, StringJavaType.INSTANCE); - } - - @Override - public String getName() { - return "string"; - } - - @Override - protected boolean registerUnderJavaType() { - return true; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TextType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TextType.java deleted file mode 100644 index ae6de3561d..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TextType.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.AdjustableBasicType; -import org.hibernate.type.descriptor.java.StringJavaType; -import org.hibernate.type.descriptor.jdbc.LongVarcharJdbcType; - -public class TextType extends AbstractSingleColumnStandardBasicType implements AdjustableBasicType { - - public static final TextType INSTANCE = new TextType(); - - public TextType() { - super(LongVarcharJdbcType.INSTANCE, StringJavaType.INSTANCE); - } - - @Override - public String getName() { - return "text"; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TimeType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TimeType.java deleted file mode 100644 index a5f9d472f6..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TimeType.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import java.sql.Time; -import java.util.Date; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.JdbcTimeJavaType; -import org.hibernate.type.descriptor.jdbc.TimeJdbcType; - -public class TimeType extends AbstractSingleColumnStandardBasicType { - - public static final TimeType INSTANCE = new TimeType(); - - public TimeType() { - super(TimeJdbcType.INSTANCE, JdbcTimeJavaType.INSTANCE); - } - - @Override - public String getName() { - return "time"; - } - - @Override - public String[] getRegistrationKeys() { - return new String[] { getName(), Time.class.getName() }; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TimeZoneType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TimeZoneType.java deleted file mode 100644 index 9819734b8f..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TimeZoneType.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import java.util.TimeZone; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.TimeZoneJavaType; -import org.hibernate.type.descriptor.jdbc.VarcharJdbcType; - -public class TimeZoneType extends AbstractSingleColumnStandardBasicType { - - public static final TimeZoneType INSTANCE = new TimeZoneType(); - - public TimeZoneType() { - super(VarcharJdbcType.INSTANCE, TimeZoneJavaType.INSTANCE); - } - - @Override - public String getName() { - return "timezone"; - } - - @Override - protected boolean registerUnderJavaType() { - return true; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TimestampType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TimestampType.java deleted file mode 100644 index 74a2a37744..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TimestampType.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import java.sql.Timestamp; -import java.util.Date; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.descriptor.java.JdbcTimestampJavaType; -import org.hibernate.type.descriptor.jdbc.TimestampJdbcType; - -public class TimestampType extends AbstractSingleColumnStandardBasicType { - - public static final TimestampType INSTANCE = new TimestampType(); - - public TimestampType() { - super(TimestampJdbcType.INSTANCE, JdbcTimestampJavaType.INSTANCE); - } - - @Override - public String getName() { - return "timestamp"; - } - - @Override - public String[] getRegistrationKeys() { - return new String[] { getName(), Timestamp.class.getName(), Date.class.getName() }; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TrueFalseType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TrueFalseType.java deleted file mode 100644 index ce43c31318..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/TrueFalseType.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.ConvertedBasicType; -import org.hibernate.type.TrueFalseConverter; -import org.hibernate.type.descriptor.converter.spi.BasicValueConverter; -import org.hibernate.type.descriptor.java.BooleanJavaType; -import org.hibernate.type.descriptor.jdbc.CharJdbcType; - -public class TrueFalseType extends AbstractSingleColumnStandardBasicType - implements ConvertedBasicType { - - public static final TrueFalseType INSTANCE = new TrueFalseType(); - - public TrueFalseType() { - super(CharJdbcType.INSTANCE, new BooleanJavaType('T', 'F')); - } - - @Override - public String getName() { - return "true_false"; - } - - @Override - public BasicValueConverter getValueConverter() { - return TrueFalseConverter.INSTANCE; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/YesNoType.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/YesNoType.java deleted file mode 100644 index a1946f80af..0000000000 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/type/YesNoType.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.ConvertedBasicType; -import org.hibernate.type.YesNoConverter; -import org.hibernate.type.descriptor.converter.spi.BasicValueConverter; -import org.hibernate.type.descriptor.java.BooleanJavaType; -import org.hibernate.type.descriptor.jdbc.CharJdbcType; - -public class YesNoType extends AbstractSingleColumnStandardBasicType implements ConvertedBasicType { - - public static final YesNoType INSTANCE = new YesNoType(); - - public YesNoType() { - super(CharJdbcType.INSTANCE, BooleanJavaType.INSTANCE); - } - - @Override - public String getName() { - return "yes_no"; - } - - @Override - public BasicValueConverter getValueConverter() { - return YesNoConverter.INSTANCE; - } - -} diff --git a/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/TypeWrapperFactory.java b/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/TypeWrapperFactory.java index c5b403b9c3..a105f48670 100644 --- a/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/TypeWrapperFactory.java +++ b/jbt/src/main/java/org/hibernate/tool/orm/jbt/wrp/TypeWrapperFactory.java @@ -8,7 +8,6 @@ import java.util.Calendar; import java.util.Map; -import org.hibernate.tool.orm.jbt.type.IntegerType; import org.hibernate.type.BasicType; import org.hibernate.type.CollectionType; import org.hibernate.type.Type; @@ -65,7 +64,7 @@ default String getAssociatedEntityName() { return null; } default boolean isIntegerType() { - return IntegerType.class.isAssignableFrom(getWrappedObject().getClass()); + return Integer.class.isAssignableFrom(((Type)getWrappedObject()).getReturnedClass()); } default boolean isArrayType() { if (CollectionType.class.isAssignableFrom(getWrappedObject().getClass())) { diff --git a/jbt/src/test/java/org/hibernate/tool/hbm2x/ExportersPresenceTest.java b/jbt/src/test/java/org/hibernate/tool/hbm2x/ExportersPresenceTest.java new file mode 100644 index 0000000000..8da80187da --- /dev/null +++ b/jbt/src/test/java/org/hibernate/tool/hbm2x/ExportersPresenceTest.java @@ -0,0 +1,98 @@ +package org.hibernate.tool.hbm2x; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; + +import org.junit.jupiter.api.Test; + +public class ExportersPresenceTest { + + @Test + public void testHbm2DDLExporter() { + try { + ClassLoader cl = getClass().getClassLoader(); + Class ddlExporterClass = cl.loadClass("org.hibernate.tool.hbm2x.Hbm2DDLExporter"); + assertNotNull(ddlExporterClass); + } catch (Throwable t) { + fail(t); + } + } + + @Test + public void testPOJOExporter() { + try { + ClassLoader cl = getClass().getClassLoader(); + Class pojoExporterClass = cl.loadClass("org.hibernate.tool.hbm2x.POJOExporter"); + assertNotNull(pojoExporterClass); + } catch (Throwable t) { + fail(t); + } + } + + @Test + public void testHibernateMappingExporter() { + try { + ClassLoader cl = getClass().getClassLoader(); + Class hibernateMappingExporterClass = cl.loadClass("org.hibernate.tool.hbm2x.HibernateMappingExporter"); + assertNotNull(hibernateMappingExporterClass); + } catch (Throwable t) { + fail(t); + } + } + + @Test + public void testDAOExporter() { + try { + ClassLoader cl = getClass().getClassLoader(); + Class daoExporterClass = cl.loadClass("org.hibernate.tool.hbm2x.DAOExporter"); + assertNotNull(daoExporterClass); + } catch (Throwable t) { + fail(t); + } + } + + @Test + public void testGenericExporter() { + try { + ClassLoader cl = getClass().getClassLoader(); + Class genericExporterClass = cl.loadClass("org.hibernate.tool.hbm2x.GenericExporter"); + assertNotNull(genericExporterClass); + } catch (Throwable t) { + fail(t); + } + } + + @Test + public void testHibernateConfigurationExporter() { + try { + ClassLoader cl = getClass().getClassLoader(); + Class hibernateConfigurationExporterClass = cl.loadClass("org.hibernate.tool.hbm2x.HibernateConfigurationExporter"); + assertNotNull(hibernateConfigurationExporterClass); + } catch (Throwable t) { + fail(t); + } + } + + @Test + public void testQueryExporter() { + try { + ClassLoader cl = getClass().getClassLoader(); + Class hibernateConfigurationExporterClass = cl.loadClass("org.hibernate.tool.hbm2x.QueryExporter"); + assertNotNull(hibernateConfigurationExporterClass); + } catch (Throwable t) { + fail(t); + } + } + + @Test + public void testDocExporter() { + try { + ClassLoader cl = getClass().getClassLoader(); + Class docExporterClass = cl.loadClass("org.hibernate.tool.hbm2x.DocExporter"); + assertNotNull(docExporterClass); + } catch (Throwable t) { + fail(t); + } + } + +} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/BigIntegerTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/BigIntegerTypeTest.java deleted file mode 100644 index ac9f8c62bb..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/BigIntegerTypeTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - -public class BigIntegerTypeTest { - - @Test - public void testInstance() { - assertNotNull(BigIntegerType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("big_integer", BigIntegerType.INSTANCE.getName()); - } - - @Test - public void testRegisterUnderJavaType() { - assertTrue(BigIntegerType.INSTANCE.registerUnderJavaType()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/BooleanTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/BooleanTypeTest.java deleted file mode 100644 index 1dc9ef4413..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/BooleanTypeTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -public class BooleanTypeTest { - - @Test - public void testInstance() { - assertNotNull(BooleanType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("boolean", BooleanType.INSTANCE.getName()); - } - - @Test - public void testGetRegistrationKeys() { - assertArrayEquals( - new String[] { - "boolean", - "boolean", - "java.lang.Boolean" - }, - BooleanType.INSTANCE.getRegistrationKeys()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/ByteTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/ByteTypeTest.java deleted file mode 100644 index 5160c5837f..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/ByteTypeTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -public class ByteTypeTest { - - @Test - public void testInstance() { - assertNotNull(ByteType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("byte", ByteType.INSTANCE.getName()); - } - - @Test - public void testGetRegistrationKeys() { - assertArrayEquals( - new String[] { - "byte", - "byte", - "java.lang.Byte" - }, - ByteType.INSTANCE.getRegistrationKeys()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/CalendarDateTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/CalendarDateTypeTest.java deleted file mode 100644 index 5b60c17249..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/CalendarDateTypeTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -public class CalendarDateTypeTest { - - @Test - public void testInstance() { - assertNotNull(CalendarDateType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("calendar_date", CalendarDateType.INSTANCE.getName()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/CalendarTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/CalendarTypeTest.java deleted file mode 100644 index b493614c62..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/CalendarTypeTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -public class CalendarTypeTest { - - @Test - public void testInstance() { - assertNotNull(CalendarType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("calendar", CalendarType.INSTANCE.getName()); - } - - @Test - public void testGetRegistrationKeys() { - assertArrayEquals( - new String[] { - "calendar", - "java.util.Calendar", - "java.util.GregorianCalendar" - }, - CalendarType.INSTANCE.getRegistrationKeys()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/CharacterTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/CharacterTypeTest.java deleted file mode 100644 index e6ccff03e2..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/CharacterTypeTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -public class CharacterTypeTest { - - @Test - public void testInstance() { - assertNotNull(CharacterType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("character", CharacterType.INSTANCE.getName()); - } - - @Test - public void testGetRegistrationKeys() { - assertArrayEquals( - new String[] { - "character", - "char", - "java.lang.Character" - }, - CharacterType.INSTANCE.getRegistrationKeys()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/ClassTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/ClassTypeTest.java deleted file mode 100644 index fe7ffd7ef9..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/ClassTypeTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - -public class ClassTypeTest { - - @Test - public void testInstance() { - assertNotNull(ClassType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("class", ClassType.INSTANCE.getName()); - } - - @Test - public void testRegisterUnderJavaType() { - assertTrue(ClassType.INSTANCE.registerUnderJavaType()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/CurrencyTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/CurrencyTypeTest.java deleted file mode 100644 index 01c995a39f..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/CurrencyTypeTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - -public class CurrencyTypeTest { - - @Test - public void testInstance() { - assertNotNull(CurrencyType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("currency", CurrencyType.INSTANCE.getName()); - } - - @Test - public void testRegisterUnderJavaType() { - assertTrue(CurrencyType.INSTANCE.registerUnderJavaType()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/DateTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/DateTypeTest.java deleted file mode 100644 index 40feee0c4e..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/DateTypeTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -public class DateTypeTest { - - @Test - public void testInstance() { - assertNotNull(DateType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("date", DateType.INSTANCE.getName()); - } - - @Test - public void testGetRegistrationKeys() { - assertArrayEquals( - new String[] { - "date", - "java.sql.Date" - }, - DateType.INSTANCE.getRegistrationKeys()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/DoubleTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/DoubleTypeTest.java deleted file mode 100644 index 1a8899deaf..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/DoubleTypeTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -public class DoubleTypeTest { - - @Test - public void testInstance() { - assertNotNull(DoubleType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("double", DoubleType.INSTANCE.getName()); - } - - @Test - public void testGetRegistrationKeys() { - assertArrayEquals( - new String[] { - "double", - "double", - "java.lang.Double" - }, - DoubleType.INSTANCE.getRegistrationKeys()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/FloatTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/FloatTypeTest.java deleted file mode 100644 index 2c363efc42..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/FloatTypeTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -public class FloatTypeTest { - - @Test - public void testInstance() { - assertNotNull(FloatType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("float", FloatType.INSTANCE.getName()); - } - - @Test - public void testGetRegistrationKeys() { - assertArrayEquals( - new String[] { - "float", - "float", - "java.lang.Float" - }, - FloatType.INSTANCE.getRegistrationKeys()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/IntegerTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/IntegerTypeTest.java deleted file mode 100644 index 4f2b1e7088..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/IntegerTypeTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -public class IntegerTypeTest { - - @Test - public void testInstance() { - assertNotNull(IntegerType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("integer", IntegerType.INSTANCE.getName()); - } - - @Test - public void testGetRegistrationKeys() { - assertArrayEquals( - new String[] { - "integer", - "int", - "java.lang.Integer" - }, - IntegerType.INSTANCE.getRegistrationKeys()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/LocaleTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/LocaleTypeTest.java deleted file mode 100644 index e5d841f40d..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/LocaleTypeTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - -public class LocaleTypeTest { - - @Test - public void testInstance() { - assertNotNull(LocaleType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("locale", LocaleType.INSTANCE.getName()); - } - - @Test - public void testRegisterUnderJavaType() { - assertTrue(LocaleType.INSTANCE.registerUnderJavaType()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/LongTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/LongTypeTest.java deleted file mode 100644 index d62b99c5c4..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/LongTypeTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -public class LongTypeTest { - - @Test - public void testInstance() { - assertNotNull(LongType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("long", LongType.INSTANCE.getName()); - } - - @Test - public void testGetRegistrationKeys() { - assertArrayEquals( - new String[] { - "long", - "long", - "java.lang.Long" - }, - LongType.INSTANCE.getRegistrationKeys()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/ShortTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/ShortTypeTest.java deleted file mode 100644 index 8cfed17f1b..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/ShortTypeTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -public class ShortTypeTest { - - @Test - public void testInstance() { - assertNotNull(ShortType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("short", ShortType.INSTANCE.getName()); - } - - @Test - public void testGetRegistrationKeys() { - assertArrayEquals( - new String[] { - "short", - "short", - "java.lang.Short" - }, - ShortType.INSTANCE.getRegistrationKeys()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/StringTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/StringTypeTest.java deleted file mode 100644 index 541adde9c7..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/StringTypeTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - -public class StringTypeTest { - - @Test - public void testInstance() { - assertNotNull(StringType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("string", StringType.INSTANCE.getName()); - } - - @Test - public void testRegisterUnderJavaType() { - assertTrue(StringType.INSTANCE.registerUnderJavaType()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TextTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TextTypeTest.java deleted file mode 100644 index 8a6a865a9d..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TextTypeTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -public class TextTypeTest { - - @Test - public void testInstance() { - assertNotNull(TextType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("text", TextType.INSTANCE.getName()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TimeTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TimeTypeTest.java deleted file mode 100644 index 00bbff71bc..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TimeTypeTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -public class TimeTypeTest { - - @Test - public void testInstance() { - assertNotNull(TimeType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("time", TimeType.INSTANCE.getName()); - } - - @Test - public void testGetRegistrationKeys() { - assertArrayEquals( - new String[] { - "time", - "java.sql.Time" - }, - TimeType.INSTANCE.getRegistrationKeys()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TimeZoneTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TimeZoneTypeTest.java deleted file mode 100644 index 745738ce05..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TimeZoneTypeTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - -public class TimeZoneTypeTest { - - @Test - public void testInstance() { - assertNotNull(TimeZoneType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("timezone", TimeZoneType.INSTANCE.getName()); - } - - @Test - public void testRegisterUnderJavaType() { - assertTrue(TimeZoneType.INSTANCE.registerUnderJavaType()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TimestampTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TimestampTypeTest.java deleted file mode 100644 index 065d5d6f3d..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TimestampTypeTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -public class TimestampTypeTest { - - @Test - public void testInstance() { - assertNotNull(TimestampType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("timestamp", TimestampType.INSTANCE.getName()); - } - - @Test - public void testGetRegistrationKeys() { - assertArrayEquals( - new String[] { - "timestamp", - "java.sql.Timestamp", - "java.util.Date" - }, - TimestampType.INSTANCE.getRegistrationKeys()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TrueFalseTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TrueFalseTypeTest.java deleted file mode 100644 index d8e54728bd..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/TrueFalseTypeTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertSame; - -import org.hibernate.type.TrueFalseConverter; -import org.junit.jupiter.api.Test; - -public class TrueFalseTypeTest { - - @Test - public void testInstance() { - assertNotNull(TrueFalseType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("true_false", TrueFalseType.INSTANCE.getName()); - } - - @Test - public void testGetValueConverter() { - assertSame(TrueFalseConverter.INSTANCE, TrueFalseType.INSTANCE.getValueConverter()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/YesNoTypeTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/YesNoTypeTest.java deleted file mode 100644 index 501560567e..0000000000 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/type/YesNoTypeTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.hibernate.tool.orm.jbt.type; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertSame; - -import org.hibernate.type.YesNoConverter; -import org.junit.jupiter.api.Test; - -public class YesNoTypeTest { - - @Test - public void testInstance() { - assertNotNull(YesNoType.INSTANCE); - } - - @Test - public void testGetName() { - assertEquals("yes_no", YesNoType.INSTANCE.getName()); - } - - @Test - public void testGetValueConverter() { - assertSame(YesNoConverter.INSTANCE, YesNoType.INSTANCE.getValueConverter()); - } - -} diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/util/MetadataHelperTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/util/MetadataHelperTest.java index b5c8c30f74..8ce2ab03ea 100644 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/util/MetadataHelperTest.java +++ b/jbt/src/test/java/org/hibernate/tool/orm/jbt/util/MetadataHelperTest.java @@ -88,7 +88,7 @@ private static class Foo { private static final String TEST_HBM_XML_STRING = "" + + " 'https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd'>" + "" + " " + " " + diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/DelegatingColumnWrapperImplTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/DelegatingColumnWrapperImplTest.java index dac1b0ea92..b03c0b5a61 100644 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/DelegatingColumnWrapperImplTest.java +++ b/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/DelegatingColumnWrapperImplTest.java @@ -15,10 +15,10 @@ import org.hibernate.cfg.Configuration; import org.hibernate.mapping.Column; import org.hibernate.mapping.Value; -import org.hibernate.tool.orm.jbt.type.IntegerType; import org.hibernate.tool.orm.jbt.util.MockConnectionProvider; import org.hibernate.tool.orm.jbt.util.MockDialect; import org.hibernate.tool.orm.jbt.wrp.ValueWrapperFactory.ValueWrapper; +import org.hibernate.type.spi.TypeConfiguration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -106,7 +106,7 @@ private Value createValue() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().equals("getType")) { - return IntegerType.INSTANCE; + return new TypeConfiguration().getBasicTypeForJavaType(Integer.class); } return null; } diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/TypeFactoryWrapperTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/TypeFactoryWrapperTest.java index fb2a6d3bc1..774962526a 100644 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/TypeFactoryWrapperTest.java +++ b/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/TypeFactoryWrapperTest.java @@ -4,6 +4,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import java.text.SimpleDateFormat; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.util.Currency; import java.util.Date; import java.util.Locale; @@ -221,8 +223,10 @@ public void testGetTypeFormats() { assertEquals("a string", typeFormats.get(TypeFactoryWrapper.INSTANCE.getStringType())); assertEquals("a text", typeFormats.get(TypeFactoryWrapper.INSTANCE.getTextType())); assertEquals(':', typeFormats.get(TypeFactoryWrapper.INSTANCE.getTimeType()).charAt(2)); - assertEquals( - new SimpleDateFormat("yyyy-MM-dd").format(new Date()), + //JdbcTimestampJavaType uses timezone UTC+0 for the string format vs the system default tz for JdbcDateJavaType. + SimpleDateFormat utcDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + utcDateFormat.setTimeZone(TimeZone.getTimeZone(ZoneId.from( ZoneOffset.UTC ))); + assertEquals(utcDateFormat.format(new Date()).substring(0, 10), typeFormats.get(TypeFactoryWrapper.INSTANCE.getTimestampType()).substring(0, 10)); assertEquals( TimeZone.getDefault().getID(), diff --git a/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/TypeWrapperTest.java b/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/TypeWrapperTest.java index 041023eba6..7c80b108c6 100644 --- a/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/TypeWrapperTest.java +++ b/jbt/src/test/java/org/hibernate/tool/orm/jbt/wrp/TypeWrapperTest.java @@ -10,9 +10,6 @@ import org.hibernate.mapping.Component; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.RootClass; -import org.hibernate.tool.orm.jbt.type.ClassType; -import org.hibernate.tool.orm.jbt.type.IntegerType; -import org.hibernate.tool.orm.jbt.type.StringType; import org.hibernate.tool.orm.jbt.util.DummyMetadataBuildingContext; import org.hibernate.tool.orm.jbt.wrp.TypeWrapperFactory.TypeWrapper; import org.hibernate.type.AnyType; @@ -22,14 +19,23 @@ import org.hibernate.type.ManyToOneType; import org.hibernate.type.OneToOneType; import org.hibernate.type.spi.TypeConfiguration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class TypeWrapperTest { + + private TypeConfiguration typeConfiguration = null; + + @BeforeEach + public void beforeEach() { + typeConfiguration = new TypeConfiguration(); + } @Test public void testToString() { // first try type that is string representable - TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); assertEquals( TypeWrapperTest.class.getName(), classTypeWrapper.toString(TypeWrapperTest.class)); @@ -47,7 +53,8 @@ public void testToString() { @Test public void testGetName() { // first try a class type - TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); assertEquals("class", classTypeWrapper.getName()); // next try a array type TypeWrapper arrayTypeWrapper = @@ -57,7 +64,8 @@ public void testGetName() { @Test public void testFromStringValue() { - TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); assertEquals( TypeWrapperTest.class, classTypeWrapper.fromStringValue(TypeWrapperTest.class.getName())); @@ -75,7 +83,8 @@ public void testFromStringValue() { @Test public void testIsEntityType() { // first try type that is not an entity type - TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); assertFalse(classTypeWrapper.isEntityType()); // next try type that is an entity type TypeWrapper entityTypeWrapper = TypeWrapperFactory.createTypeWrapper( @@ -87,7 +96,8 @@ public void testIsEntityType() { public void testIsOneToOne() { // first try type that is not a one to one type try { - TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); classTypeWrapper.isOneToOne(); fail(); } catch (UnsupportedOperationException e) { @@ -107,7 +117,8 @@ public void testIsOneToOne() { @Test public void testIsAnyType() { // first try type that is not a any type - TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); assertFalse(classTypeWrapper.isAnyType()); // next try a any type TypeWrapper anyTypeWrapper = @@ -118,7 +129,8 @@ public void testIsAnyType() { @Test public void testIsComponentType() { // first try type that is not a component type - TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); assertFalse(classTypeWrapper.isComponentType()); // next try a component type Component component = new Component( @@ -135,7 +147,8 @@ public void testIsComponentType() { public void testIsCollectionType() { // first try type that is not a collection type TypeWrapper classTypeWrapper = - TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); assertFalse(classTypeWrapper.isCollectionType()); // next try a collection type TypeWrapper arrayTypeWrapper = @@ -146,7 +159,8 @@ public void testIsCollectionType() { @Test public void testGetReturnedClassName() { // first try a class type - TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); assertEquals(Class.class.getName(), classTypeWrapper.getReturnedClassName()); // next try an array type of string values TypeWrapper arrayTypeWrapper = TypeWrapperFactory.createTypeWrapper( @@ -170,7 +184,8 @@ public void testGetReturnedClassName() { @Test public void testGetAssociatedEntityName() { // first try a class type - TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); assertNull(classTypeWrapper.getAssociatedEntityName()); // next try a many to one type TypeWrapper manyToOneTypeWrapper = TypeWrapperFactory.createTypeWrapper( @@ -181,17 +196,20 @@ public void testGetAssociatedEntityName() { @Test public void testIsIntegerType() { // first try a class type - TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); assertFalse(classTypeWrapper.isIntegerType()); // next try a integer type - TypeWrapper integerTypeWrapper = TypeWrapperFactory.createTypeWrapper(new IntegerType()); + TypeWrapper integerTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Integer.class)); assertTrue(integerTypeWrapper.isIntegerType()); } @Test public void testIsArrayType() { // first try a class type - TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); assertFalse(classTypeWrapper.isArrayType()); // next try a bag type TypeWrapper bagTypeWrapper = TypeWrapperFactory.createTypeWrapper(new BagType(null, null)); @@ -205,13 +223,16 @@ public void testIsArrayType() { @Test public void testIsInstanceOfPrimitiveType() { // first try a class type - TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); assertFalse(classTypeWrapper.isInstanceOfPrimitiveType()); // next try a string type - TypeWrapper stringTypeWrapper = TypeWrapperFactory.createTypeWrapper(new StringType()); + TypeWrapper stringTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(String.class)); assertFalse(stringTypeWrapper.isInstanceOfPrimitiveType()); // finally try a integer type - TypeWrapper integerTypeWrapper = TypeWrapperFactory.createTypeWrapper(new IntegerType()); + TypeWrapper integerTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Integer.class)); assertTrue(integerTypeWrapper.isInstanceOfPrimitiveType()); } @@ -219,13 +240,15 @@ public void testIsInstanceOfPrimitiveType() { public void testGetPrimitiveClass() { // first try a class type try { - TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); classTypeWrapper.getPrimitiveClass(); } catch (UnsupportedOperationException e) { assertTrue(e.getMessage().contains("does not support 'getPrimitiveClass()'")); } // next try a integer type - TypeWrapper integerTypeWrapper = TypeWrapperFactory.createTypeWrapper(new IntegerType()); + TypeWrapper integerTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Integer.class)); assertEquals(int.class, integerTypeWrapper.getPrimitiveClass()); } @@ -233,7 +256,8 @@ public void testGetPrimitiveClass() { public void testGetRole() { // first try a class type try { - TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper(new ClassType()); + TypeWrapper classTypeWrapper = TypeWrapperFactory.createTypeWrapper( + typeConfiguration.getBasicTypeForJavaType(Class.class)); classTypeWrapper.getRole(); } catch (UnsupportedOperationException e) { assertTrue(e.getMessage().contains("does not support 'getRole()'")); diff --git a/maven/pom.xml b/maven/pom.xml index 6d554eed19..7db70632a4 100644 --- a/maven/pom.xml +++ b/maven/pom.xml @@ -21,7 +21,7 @@ org.hibernate.tool hibernate-tools-parent - 6.2.7-SNAPSHOT + 6.2.42-SNAPSHOT hibernate-tools-maven @@ -68,11 +68,13 @@ - false + + false false 3.5 3.5.2 + 3.9.9 2.9 @@ -92,6 +94,11 @@ maven-plugin-api ${maven-plugin-api.version} + + org.apache.maven + maven-core + ${maven-core.version} + org.apache.maven.plugin-tools maven-plugin-annotations @@ -124,12 +131,18 @@ default-descriptor process-classes + + hibernate-tools + help-goal helpmojo + + hibernate-tools + diff --git a/maven/src/main/java/org/hibernate/tool/maven/AbstractGenerationMojo.java b/maven/src/main/java/org/hibernate/tool/maven/AbstractGenerationMojo.java index 56d8433674..ea76fa0f74 100644 --- a/maven/src/main/java/org/hibernate/tool/maven/AbstractGenerationMojo.java +++ b/maven/src/main/java/org/hibernate/tool/maven/AbstractGenerationMojo.java @@ -23,10 +23,18 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; import java.util.Properties; +import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; import org.apache.tools.ant.BuildException; import org.hibernate.tool.api.metadata.MetadataDescriptor; import org.hibernate.tool.api.metadata.MetadataDescriptorFactory; @@ -83,15 +91,24 @@ public abstract class AbstractGenerationMojo extends AbstractMojo { // Not exposed for now private boolean preferBasicCompositeIds = true; + @Parameter(defaultValue = "${project}", readonly = true, required = true) + private MavenProject project; + public void execute() { - getLog().info("Starting " + this.getClass().getSimpleName() + "..."); - RevengStrategy strategy = setupReverseEngineeringStrategy(); - if (propertyFile.exists()) { - executeExporter(createJdbcDescriptor(strategy, loadPropertiesFile())); - } else { - getLog().info("Property file '" + propertyFile + "' cannot be found, aborting..."); - } - getLog().info("Finished " + this.getClass().getSimpleName() + "!"); + ClassLoader original = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(createExporterClassLoader(original)); + getLog().info("Starting " + this.getClass().getSimpleName() + "..."); + RevengStrategy strategy = setupReverseEngineeringStrategy(); + if (propertyFile.exists()) { + executeExporter(createJdbcDescriptor(strategy, loadPropertiesFile())); + } else { + getLog().info("Property file '" + propertyFile + "' cannot be found, aborting..."); + } + getLog().info("Finished " + this.getClass().getSimpleName() + "!"); + } finally { + Thread.currentThread().setContextClassLoader(original); + } } private RevengStrategy setupReverseEngineeringStrategy() { @@ -134,6 +151,18 @@ private MetadataDescriptor createJdbcDescriptor(RevengStrategy strategy, Propert strategy, properties); } + + private ClassLoader createExporterClassLoader(ClassLoader parent) { + ArrayList urls = new ArrayList(); + try { + for (String cpe : project.getRuntimeClasspathElements()) { + urls.add(new File(cpe).toURI().toURL()); + } + } catch (DependencyResolutionRequiredException | MalformedURLException e) { + throw new RuntimeException("Problem while constructing project classloader", e); + } + return new URLClassLoader(urls.toArray(new URL[0]), parent); + } protected abstract void executeExporter(MetadataDescriptor metadataDescriptor); } diff --git a/maven/src/main/java/org/hibernate/tool/maven/GenerateDaoMojo.java b/maven/src/main/java/org/hibernate/tool/maven/GenerateDaoMojo.java index afbe350dec..98554cf7e5 100644 --- a/maven/src/main/java/org/hibernate/tool/maven/GenerateDaoMojo.java +++ b/maven/src/main/java/org/hibernate/tool/maven/GenerateDaoMojo.java @@ -21,6 +21,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; import org.hibernate.tool.api.export.Exporter; import org.hibernate.tool.api.export.ExporterConstants; import org.hibernate.tool.api.export.ExporterFactory; @@ -36,7 +37,10 @@ *

* See: https://docs.jboss.org/tools/latest/en/hibernatetools/html_single/#d0e4821 */ -@Mojo(name = "hbm2dao", defaultPhase = GENERATE_SOURCES) +@Mojo( + name = "hbm2dao", + defaultPhase = GENERATE_SOURCES, + requiresDependencyResolution = ResolutionScope.RUNTIME) public class GenerateDaoMojo extends AbstractGenerationMojo { /** The directory into which the DAOs will be generated. */ diff --git a/maven/src/main/java/org/hibernate/tool/maven/GenerateDdlMojo.java b/maven/src/main/java/org/hibernate/tool/maven/GenerateDdlMojo.java index a60958f51b..8ade339a4e 100644 --- a/maven/src/main/java/org/hibernate/tool/maven/GenerateDdlMojo.java +++ b/maven/src/main/java/org/hibernate/tool/maven/GenerateDdlMojo.java @@ -21,6 +21,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; import org.hibernate.boot.Metadata; import org.hibernate.tool.api.metadata.MetadataDescriptor; import org.hibernate.tool.hbm2ddl.SchemaExport; @@ -37,7 +38,10 @@ *

* See https://docs.jboss.org/tools/latest/en/hibernatetools/html_single/#d0e4651 */ -@Mojo(name = "hbm2ddl", defaultPhase = GENERATE_RESOURCES) +@Mojo( + name = "hbm2ddl", + defaultPhase = GENERATE_RESOURCES, + requiresDependencyResolution = ResolutionScope.RUNTIME) public class GenerateDdlMojo extends AbstractGenerationMojo { /** The directory into which the DDLs will be generated. */ diff --git a/maven/src/main/java/org/hibernate/tool/maven/GenerateHbmMojo.java b/maven/src/main/java/org/hibernate/tool/maven/GenerateHbmMojo.java new file mode 100644 index 0000000000..80aa790a4f --- /dev/null +++ b/maven/src/main/java/org/hibernate/tool/maven/GenerateHbmMojo.java @@ -0,0 +1,70 @@ +/* + * Hibernate Tools, Tooling for your Hibernate Projects + * + * Copyright 2016-2020 Red Hat, Inc. + * + * Licensed under the GNU Lesser General Public License (LGPL), + * version 2.1 or later (the "License"). + * You may not use this file except in compliance with the License. + * You may read the licence in the 'lgpl.txt' file in the root folder of + * project or obtain a copy at + * + * http://www.gnu.org/licenses/lgpl-2.1.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hibernate.tool.maven; + +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.hibernate.tool.api.export.Exporter; +import org.hibernate.tool.api.export.ExporterConstants; +import org.hibernate.tool.api.export.ExporterFactory; +import org.hibernate.tool.api.export.ExporterType; +import org.hibernate.tool.api.metadata.MetadataDescriptor; + +import java.io.File; + +import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES; + +/** + * Mojo to generate hbm.xml files from an existing database. + *

+ * See: https://docs.jboss.org/tools/latest/en/hibernatetools/html_single/#d0e4821 + */ +@Mojo( + name = "generateHbm", + defaultPhase = GENERATE_SOURCES, + requiresDependencyResolution = ResolutionScope.RUNTIME) +public class GenerateHbmMojo extends AbstractGenerationMojo { + + /** The directory into which the DAOs will be generated. */ + @Parameter(defaultValue = "${project.basedir}/src/main/resources") + private File outputDirectory; + + @Parameter + private String templatePath; + + protected void executeExporter(MetadataDescriptor metadataDescriptor) { + try { + Exporter hbmExporter = ExporterFactory.createExporter(ExporterType.HBM); + hbmExporter.getProperties().put(ExporterConstants.METADATA_DESCRIPTOR, metadataDescriptor); + hbmExporter.getProperties().put(ExporterConstants.DESTINATION_FOLDER, outputDirectory); + if (templatePath != null) { + getLog().info("Setting template path to: " + templatePath); + hbmExporter.getProperties().put(ExporterConstants.TEMPLATE_PATH, new String[] {templatePath}); + } + getLog().info("Starting HBM export to directory: " + outputDirectory + "..."); + hbmExporter.start(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + +} diff --git a/maven/src/main/java/org/hibernate/tool/maven/GenerateJavaMojo.java b/maven/src/main/java/org/hibernate/tool/maven/GenerateJavaMojo.java index 3ec6709185..faf6ae588e 100644 --- a/maven/src/main/java/org/hibernate/tool/maven/GenerateJavaMojo.java +++ b/maven/src/main/java/org/hibernate/tool/maven/GenerateJavaMojo.java @@ -25,6 +25,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; import org.hibernate.tool.api.export.Exporter; import org.hibernate.tool.api.export.ExporterConstants; import org.hibernate.tool.api.export.ExporterFactory; @@ -36,7 +37,10 @@ *

* See: https://docs.jboss.org/tools/latest/en/hibernatetools/html_single/#d0e4821 */ -@Mojo(name = "hbm2java", defaultPhase = GENERATE_SOURCES) +@Mojo( + name = "hbm2java", + defaultPhase = GENERATE_SOURCES, + requiresDependencyResolution = ResolutionScope.RUNTIME) public class GenerateJavaMojo extends AbstractGenerationMojo { /** The directory into which the JPA entities will be generated. */ @@ -69,6 +73,8 @@ protected void executeExporter(MetadataDescriptor metadataDescriptor) { getLog().info("Starting POJO export to directory: " + outputDirectory + "..."); pojoExporter.start(); } + + } diff --git a/orm/pom.xml b/orm/pom.xml index 826b990f23..c93444b4fd 100644 --- a/orm/pom.xml +++ b/orm/pom.xml @@ -25,7 +25,7 @@ org.hibernate.tool hibernate-tools-parent - 6.2.7-SNAPSHOT + 6.2.42-SNAPSHOT hibernate-tools-orm @@ -35,6 +35,11 @@ Hibernate Tools ORM Hibernate Tools ORM + + + false + + com.google.googlejavaformat @@ -82,4 +87,26 @@ + + + + org.jboss.maven.plugins + maven-injection-plugin + + + + ${project.version} + + + org.hibernate.tool.api.version.Version + versionString + + + + + + + + + diff --git a/orm/src/main/java/org/hibernate/tool/api/version/Version.java b/orm/src/main/java/org/hibernate/tool/api/version/Version.java index d4997b6dd9..4447b9615e 100644 --- a/orm/src/main/java/org/hibernate/tool/api/version/Version.java +++ b/orm/src/main/java/org/hibernate/tool/api/version/Version.java @@ -1,7 +1,16 @@ package org.hibernate.tool.api.version; public interface Version { - - final static String CURRENT_VERSION = "6.2.7-SNAPSHOT"; + + /** + * @deprecated Use {@link #versionString()} instead. + */ + @Deprecated + final static String CURRENT_VERSION = versionString(); + + static String versionString() { + // This implementation is replaced during the build with another one that returns the correct value. + return "UNKNOWN"; + } } diff --git a/orm/src/main/java/org/hibernate/tool/internal/export/java/BasicPOJOClass.java b/orm/src/main/java/org/hibernate/tool/internal/export/java/BasicPOJOClass.java index 1130f58ded..501652fb4d 100644 --- a/orm/src/main/java/org/hibernate/tool/internal/export/java/BasicPOJOClass.java +++ b/orm/src/main/java/org/hibernate/tool/internal/export/java/BasicPOJOClass.java @@ -817,7 +817,7 @@ protected boolean isRequiredInConstructor(Property field) { return false; } if(field.getValue()!=null) { - if (!field.isOptional() && (field.getValueGeneratorCreator() == null )) { + if (!(field.isOptional() || field.getValue().isNullable()) && (field.getValueGeneratorCreator() == null )) { return true; } else if (field.getValue() instanceof Component) { Component c = (Component) field.getValue(); diff --git a/orm/src/main/java/org/hibernate/tool/internal/reveng/reader/BasicColumnProcessor.java b/orm/src/main/java/org/hibernate/tool/internal/reveng/reader/BasicColumnProcessor.java index 6536ce30ae..2947d871e7 100644 --- a/orm/src/main/java/org/hibernate/tool/internal/reveng/reader/BasicColumnProcessor.java +++ b/orm/src/main/java/org/hibernate/tool/internal/reveng/reader/BasicColumnProcessor.java @@ -85,12 +85,12 @@ public static void processBasicColumns( if(JdbcToHibernateTypeHelper.typeHasLength(sqlType) ) { column.setLength(size); } - if(JdbcToHibernateTypeHelper.typeHasScaleAndPrecision(sqlType) ) { + if(JdbcToHibernateTypeHelper.typeHasPrecision(sqlType) ) { column.setPrecision(size); } } if(intBounds(decimalDigits) ) { - if(JdbcToHibernateTypeHelper.typeHasScaleAndPrecision(sqlType) ) { + if(JdbcToHibernateTypeHelper.typeHasScale(sqlType) ) { column.setScale(decimalDigits); } } diff --git a/orm/src/main/java/org/hibernate/tool/internal/reveng/reader/ForeignKeyProcessor.java b/orm/src/main/java/org/hibernate/tool/internal/reveng/reader/ForeignKeyProcessor.java index 445e3317c1..55548f45fc 100644 --- a/orm/src/main/java/org/hibernate/tool/internal/reveng/reader/ForeignKeyProcessor.java +++ b/orm/src/main/java/org/hibernate/tool/internal/reveng/reader/ForeignKeyProcessor.java @@ -244,10 +244,9 @@ private void processUserForeignKey( " references unknown or filtered table " + TableIdentifier.create(element.getTable()) ); } else { - dependentTables.put(element.getName(), deptable); - List refColumns = getReferencedColums(referencedTable, element); - referencedColumns.put(element.getName(), refColumns ); - dependentColumns.put(element.getName(), getDependendColumns(refColumns, deptable) ); + dependentTables.put(element.getName(), deptable); + referencedColumns.put(element.getName(), getReferencedColums(referencedTable, element) ); + dependentColumns.put(element.getName(), getDependendColumns(deptable, element) ); } } @@ -264,7 +263,8 @@ private Table determineDependentTable(Map dependentTables, Foreig userfkTable.getName()); } - private List getDependendColumns(List userColumns, Table deptable) { + private List getDependendColumns(Table deptable, ForeignKey element) { + List userColumns = element.getColumns(); List depColumns = new ArrayList(userColumns.size() ); Iterator colIterator = userColumns.iterator(); while(colIterator.hasNext() ) { diff --git a/orm/src/main/java/org/hibernate/tool/internal/reveng/strategy/OverrideRepository.java b/orm/src/main/java/org/hibernate/tool/internal/reveng/strategy/OverrideRepository.java index ecd9777a4f..4f36a7dbb7 100644 --- a/orm/src/main/java/org/hibernate/tool/internal/reveng/strategy/OverrideRepository.java +++ b/orm/src/main/java/org/hibernate/tool/internal/reveng/strategy/OverrideRepository.java @@ -60,7 +60,7 @@ public class OverrideRepository { final private Set excludedColumns; - final private Map tableToClassName; + final private TableToClassName tableToClassName; final private List schemaSelections; @@ -99,7 +99,7 @@ public OverrideRepository() { identifierPropertiesForTable = new HashMap(); primaryKeyColumnsForTable = new HashMap>(); propertyNameForPrimaryKey = new HashMap(); - tableToClassName = new HashMap(); + tableToClassName = new TableToClassName(); excludedColumns = new HashSet(); schemaSelections = new ArrayList(); compositeIdNameForTable = new HashMap(); @@ -600,12 +600,23 @@ public void addTable(Table table, String wantedClassName) { existing.add( fk ); } - tables.add(table); - if(StringHelper.isNotEmpty(wantedClassName)) { - tableToClassName.put(TableIdentifier.create(table), wantedClassName); + TableIdentifier tableIdentifier = TableIdentifier.create(table); + String className = wantedClassName; + /* If wantedClassName specifies a package, it is given by + config so do no more. */ + if(!wantedClassName.contains(".")) { + /* Now look for the package name specified by + config. */ + String packageName = getPackageName(tableIdentifier); + if (packageName != null && !packageName.isBlank()) { + className = packageName + "." + wantedClassName; + } + } + tableToClassName.put(tableIdentifier, className); } - } + tables.add(table); + } static class TableColumnKey { private TableIdentifier query; @@ -739,7 +750,60 @@ public void addMetaAttributeInfo( } - - - + /*It is not possible to match a table on TableMapper alone because RootClassBinder.bind() + calls nullifyDefaultCatalogAndSchema(table) before doing this TableToClassName lookup. + So only use the table name for initial matching, and catalog or schema names when they + are not null. + */ + + private class TableToClassName { + Map map = new HashMap(); + + private String get(TableIdentifier tableIdentifier) { + TableMapper mapper = map.get(tableIdentifier.getName()); + if (mapper != null) { + if (mapper.catalog == null || tableIdentifier.getCatalog() == null || + mapper.catalog.equals(tableIdentifier.getCatalog())){ + if (mapper.schema == null || tableIdentifier.getSchema() == null || + mapper.schema.equals(tableIdentifier.getSchema())){ + if (mapper.packageName.length() == 0) { + return mapper.className; + } else { + return mapper.packageName + "." + mapper.className; + } + } + } + } + return null; + } + + private void put(TableIdentifier tableIdentifier, String wantedClassName) { + TableMapper tableMapper = new TableMapper( + tableIdentifier.getCatalog(), + tableIdentifier.getSchema(), + tableIdentifier.getName(), + wantedClassName); + map.put(tableIdentifier.getName(), tableMapper); + } + } + + private class TableMapper { + String catalog; + String schema; + String className; + String packageName; + + private TableMapper(String catalog, String schema, String name, String wantedClassName) { + this.catalog = catalog; + this.schema = schema; + if (wantedClassName.contains(".")) { + int nameStartPos = wantedClassName.lastIndexOf("."); + this.className = wantedClassName.substring(nameStartPos+1); + this.packageName = wantedClassName.substring(0, nameStartPos); + } else { + this.className = wantedClassName; + this.packageName = ""; + } + } + } } diff --git a/orm/src/main/java/org/hibernate/tool/internal/util/JdbcToHibernateTypeHelper.java b/orm/src/main/java/org/hibernate/tool/internal/util/JdbcToHibernateTypeHelper.java index 8fc41f0941..c6cb354907 100644 --- a/orm/src/main/java/org/hibernate/tool/internal/util/JdbcToHibernateTypeHelper.java +++ b/orm/src/main/java/org/hibernate/tool/internal/util/JdbcToHibernateTypeHelper.java @@ -183,17 +183,25 @@ public static String getJDBCTypeName(int value) { * @throws SQLException */ - // scale and precision have numeric column - public static boolean typeHasScaleAndPrecision(int sqlType) { - return (sqlType == Types.DECIMAL || sqlType == Types.NUMERIC - || sqlType == Types.REAL || sqlType == Types.FLOAT || sqlType == Types.DOUBLE); - } - - // length is for string column - public static boolean typeHasLength(int sqlType) { - return (sqlType == Types.CHAR || sqlType == Types.DATE - || sqlType == Types.LONGVARCHAR || sqlType == Types.TIME || sqlType == Types.TIMESTAMP - || sqlType == Types.VARCHAR ); - } -} + // scale is for non floating point numeric columns + public static boolean typeHasScale(int sqlType) { + return (sqlType == Types.DECIMAL || sqlType == Types.NUMERIC); + } + + // precision is for numeric columns + public static boolean typeHasPrecision(int sqlType) { + return (sqlType == Types.DECIMAL || sqlType == Types.NUMERIC + || sqlType == Types.REAL || sqlType == Types.FLOAT || sqlType == Types.DOUBLE); + } + public static boolean typeHasScaleAndPrecision(int sqlType) { + return typeHasScale(sqlType) && typeHasPrecision(sqlType); + } + + // length is for string columns + public static boolean typeHasLength(int sqlType) { + return (sqlType == Types.CHAR || sqlType == Types.DATE + || sqlType == Types.LONGVARCHAR || sqlType == Types.TIME || sqlType == Types.TIMESTAMP + || sqlType == Types.VARCHAR ); + } +} diff --git a/orm/src/main/resources/hbm/generalhbm.hbm.ftl b/orm/src/main/resources/hbm/generalhbm.hbm.ftl index bf73afd337..5d9d8e982c 100644 --- a/orm/src/main/resources/hbm/generalhbm.hbm.ftl +++ b/orm/src/main/resources/hbm/generalhbm.hbm.ftl @@ -1,7 +1,7 @@ + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <#if hmgs?exists && hmgs.hasNonDefaultSettings()> diff --git a/orm/src/main/resources/pojo/PojoPropertyAccessors.ftl b/orm/src/main/resources/pojo/PojoPropertyAccessors.ftl index 74f66a35f7..167e8515fb 100644 --- a/orm/src/main/resources/pojo/PojoPropertyAccessors.ftl +++ b/orm/src/main/resources/pojo/PojoPropertyAccessors.ftl @@ -3,7 +3,7 @@ <#if pojo.getMetaAttribAsBool(property, "gen-property", true)> <#if pojo.hasFieldJavaDoc(property)> /** - * ${pojo.getFieldJavaDoc(property, 4)} + ${pojo.getFieldJavaDoc(property, 4)} */ <#include "GetPropertyAnnotation.ftl"/> diff --git a/pom.xml b/pom.xml index dc22b75a3b..726720d6ca 100644 --- a/pom.xml +++ b/pom.xml @@ -23,15 +23,15 @@ org.jboss jboss-parent - 39 + 48 - + org.hibernate.tool hibernate-tools-parent - 6.2.7-SNAPSHOT + 6.2.42-SNAPSHOT pom - + Hibernate Tools Parent Project http://hibernate.org/tools/ @@ -85,27 +85,53 @@ - 1.10.12 - 4.10.1 + 1.10.15 + 4.13.2 4.4 - 2.3.31 - 1.15.0 - 2.1.214 - 6.0.5.Final - 6.2.6.Final + 2.3.34 + + 1.24.0 + 2.3.232 + 7.0.3.Final + 6.2.41.Final 2.6.1 8.0.1 - 3.5.0.Final - 5.9.1 + 3.6.1.Final + 5.13.2 8.0.22 19.3.0.0 9.2.1.jre8 + + 3.3.2 + 1.7.0 + + + true + + + + + staging-deploy + Local Staging Directory Releases Repository + file:${maven.multiModuleProjectDirectory}/target/staging-deploy/maven + central-releases + Maven Central Releases Repository + https://central.sonatype.com/api/v1/publisher/ + central-snapshots + Maven Central Snapshots Repository + https://central.sonatype.com/repository/maven-snapshots/ + + 11 11 + 3.9.7 - + @@ -224,16 +250,116 @@ - - ossrh-releases-repository - Sonatype OSSRH Releases - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - ossrh-snapshots-repository - Sonatype OSSRH Snapshots - https://oss.sonatype.org/content/repositories/snapshots/ - + + ${central.releases.repo.id} + ${central.releases.repo.name} + ${central.releases.repo.url} + + + ${central.snapshots.repo.id} + ${central.snapshots.repo.name} + ${central.snapshots.repo.url} + + + + + + + org.apache.maven.plugins + maven-wrapper-plugin + ${maven-wrapper-plugin.version} + + ${maven.min.version} + bin + + + + org.codehaus.mojo + flatten-maven-plugin + ${flatten-maven-plugin.version} + + ${project.build.directory} + + ossrh + + true + + + + flatten-pom + process-resources + + flatten + + + + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + ${deploy.skip} + + + + org.codehaus.mojo + flatten-maven-plugin + + + org.apache.maven.plugins + maven-enforcer-plugin + + + enforce-java-version + + enforce + + + + + + To build this project JDK ${jdk.min.version} (or greater) is required. Please install it. + ${jdk.min.version} + + + + + + + + + + + + release + + + performRelease + true + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + ${local.staging.releases.repo.id}::${local.staging.releases.repo.url} + + + + + + + diff --git a/test/common/pom.xml b/test/common/pom.xml index 108abd9927..148d3091cf 100644 --- a/test/common/pom.xml +++ b/test/common/pom.xml @@ -28,7 +28,7 @@ org.hibernate.tool hibernate-tools-tests-parent - 6.2.7-SNAPSHOT + 6.2.42-SNAPSHOT hibernate-tools-tests-common diff --git a/test/common/src/main/resources/org/hibernate/tool/ant/AntHibernateTool/TopDown.hbm.xml b/test/common/src/main/resources/org/hibernate/tool/ant/AntHibernateTool/TopDown.hbm.xml index 7423324ed5..767bd5de29 100644 --- a/test/common/src/main/resources/org/hibernate/tool/ant/AntHibernateTool/TopDown.hbm.xml +++ b/test/common/src/main/resources/org/hibernate/tool/ant/AntHibernateTool/TopDown.hbm.xml @@ -1,7 +1,7 @@ + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/common/src/main/resources/org/hibernate/tool/ant/GenericExport/TopDown.hbm.xml b/test/common/src/main/resources/org/hibernate/tool/ant/GenericExport/TopDown.hbm.xml index 7423324ed5..767bd5de29 100644 --- a/test/common/src/main/resources/org/hibernate/tool/ant/GenericExport/TopDown.hbm.xml +++ b/test/common/src/main/resources/org/hibernate/tool/ant/GenericExport/TopDown.hbm.xml @@ -1,7 +1,7 @@ + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/common/src/main/resources/org/hibernate/tool/ant/Hbm2JavaConfiguration/SomeClass.hbm.xml b/test/common/src/main/resources/org/hibernate/tool/ant/Hbm2JavaConfiguration/SomeClass.hbm.xml index 6f660da374..a18a73271f 100644 --- a/test/common/src/main/resources/org/hibernate/tool/ant/Hbm2JavaConfiguration/SomeClass.hbm.xml +++ b/test/common/src/main/resources/org/hibernate/tool/ant/Hbm2JavaConfiguration/SomeClass.hbm.xml @@ -1,7 +1,7 @@ + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/common/src/main/resources/org/hibernate/tool/ant/Hbm2JavaEJB3Configuration/SomeClass.hbm.xml b/test/common/src/main/resources/org/hibernate/tool/ant/Hbm2JavaEJB3Configuration/SomeClass.hbm.xml index 6f660da374..a18a73271f 100644 --- a/test/common/src/main/resources/org/hibernate/tool/ant/Hbm2JavaEJB3Configuration/SomeClass.hbm.xml +++ b/test/common/src/main/resources/org/hibernate/tool/ant/Hbm2JavaEJB3Configuration/SomeClass.hbm.xml @@ -1,7 +1,7 @@ + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/common/src/main/resources/org/hibernate/tool/ant/HbmLint/Column.hbm.xml b/test/common/src/main/resources/org/hibernate/tool/ant/HbmLint/Column.hbm.xml index 658bef462f..54b5df61c2 100644 --- a/test/common/src/main/resources/org/hibernate/tool/ant/HbmLint/Column.hbm.xml +++ b/test/common/src/main/resources/org/hibernate/tool/ant/HbmLint/Column.hbm.xml @@ -1,7 +1,7 @@ + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + com.h2database + h2 + ${h2.version} + + + + + + + \ No newline at end of file diff --git a/test/maven/src/it/generateHbm/src/main/resources/hibernate.properties b/test/maven/src/it/generateHbm/src/main/resources/hibernate.properties new file mode 100644 index 0000000000..71496b3adc --- /dev/null +++ b/test/maven/src/it/generateHbm/src/main/resources/hibernate.properties @@ -0,0 +1,7 @@ +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:./test;DB_CLOSE_ON_EXIT=FALSE +hibernate.connection.username=sa +hibernate.connection.password= +hibernate.connection.pool_size=1 +hibernate.show_sql=true \ No newline at end of file diff --git a/test/maven/src/it/generateHbm/src/main/resources/hibernate.reveng.xml b/test/maven/src/it/generateHbm/src/main/resources/hibernate.reveng.xml new file mode 100644 index 0000000000..7ac52fd2cf --- /dev/null +++ b/test/maven/src/it/generateHbm/src/main/resources/hibernate.reveng.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/test/maven/src/it/generateHbm/src/main/resources/templates/pojo/Pojo.ftl b/test/maven/src/it/generateHbm/src/main/resources/templates/pojo/Pojo.ftl new file mode 100644 index 0000000000..84ff76a5b2 --- /dev/null +++ b/test/maven/src/it/generateHbm/src/main/resources/templates/pojo/Pojo.ftl @@ -0,0 +1,29 @@ +${pojo.getPackageDeclaration()} +// Generated ${date} by Hibernate Tools ${version} + +<#assign classbody> +<#include "PojoTypeDeclaration.ftl"/> { + +<#if !pojo.isInterface()> +<#include "PojoFields.ftl"/> + +<#include "PojoConstructors.ftl"/> + +<#include "PojoPropertyAccessors.ftl"/> + +<#include "PojoToString.ftl"/> + +<#include "PojoEqualsHashcode.ftl"/> + +<#else> +<#include "PojoInterfacePropertyAccessors.ftl"/> + + +<#include "PojoExtraClassCode.ftl"/> + +} + + +${pojo.generateImports()} +${classbody} + diff --git a/test/maven/src/it/generateHbm/src/main/resources/templates/pojo/PojoFields.ftl b/test/maven/src/it/generateHbm/src/main/resources/templates/pojo/PojoFields.ftl new file mode 100644 index 0000000000..18cf396cc6 --- /dev/null +++ b/test/maven/src/it/generateHbm/src/main/resources/templates/pojo/PojoFields.ftl @@ -0,0 +1,7 @@ +<#-- // Fields --> +<#list pojo.getAllPropertiesIterator() as field><#if pojo.getMetaAttribAsBool(field, "gen-property", true)><#if pojo.hasMetaAttribute(field, "field-description")> /** + ${pojo.getFieldJavaDoc(field, 0)} + */ + ${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)} ${c2j.keyWordCheck(field.name)}<#if pojo.hasFieldInitializor(field, jdk5)> = ${pojo.getFieldInitialization(field, jdk5)}; + + diff --git a/test/maven/src/it/generateHbm/test.mv.db b/test/maven/src/it/generateHbm/test.mv.db new file mode 100644 index 0000000000..72d79270f8 Binary files /dev/null and b/test/maven/src/it/generateHbm/test.mv.db differ diff --git a/test/maven/src/it/generateHbm/verify.groovy b/test/maven/src/it/generateHbm/verify.groovy new file mode 100644 index 0000000000..586fe51dc5 --- /dev/null +++ b/test/maven/src/it/generateHbm/verify.groovy @@ -0,0 +1,6 @@ +import java.io.*; + +File file = new File(basedir, "target/generated-sources/Person.hbm.xml"); +if (!file.isFile()) { + throw new FileNotFoundException("Could not find generated HBM file: " + file); +} diff --git a/test/mssql/pom.xml b/test/mssql/pom.xml index 06f4957061..9c7156818b 100644 --- a/test/mssql/pom.xml +++ b/test/mssql/pom.xml @@ -28,7 +28,7 @@ org.hibernate.tool hibernate-tools-tests-parent - 6.2.7-SNAPSHOT + 6.2.42-SNAPSHOT hibernate-tools-tests-mssql diff --git a/test/mysql/pom.xml b/test/mysql/pom.xml index e50f186685..23abd5e4a8 100644 --- a/test/mysql/pom.xml +++ b/test/mysql/pom.xml @@ -28,7 +28,7 @@ org.hibernate.tool hibernate-tools-tests-parent - 6.2.7-SNAPSHOT + 6.2.42-SNAPSHOT hibernate-tools-tests-mysql diff --git a/test/mysql/src/test/resources/org/hibernate/tool/hbmlint/SchemaAnalyzer/SchemaIssues.hbm.xml b/test/mysql/src/test/resources/org/hibernate/tool/hbmlint/SchemaAnalyzer/SchemaIssues.hbm.xml index 67c8779e6e..66c5b1f035 100644 --- a/test/mysql/src/test/resources/org/hibernate/tool/hbmlint/SchemaAnalyzer/SchemaIssues.hbm.xml +++ b/test/mysql/src/test/resources/org/hibernate/tool/hbmlint/SchemaAnalyzer/SchemaIssues.hbm.xml @@ -1,7 +1,7 @@ + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/pom.xml b/test/nodb/pom.xml index 54574deced..10a9df36c0 100644 --- a/test/nodb/pom.xml +++ b/test/nodb/pom.xml @@ -27,7 +27,7 @@ org.hibernate.tool hibernate-tools-tests-parent - 6.2.7-SNAPSHOT + 6.2.42-SNAPSHOT hibernate-tools-tests-nodb diff --git a/test/nodb/src/test/java/org/hibernate/tool/hbm2x/Hbm2CfgTest/TestCase.java b/test/nodb/src/test/java/org/hibernate/tool/hbm2x/Hbm2CfgTest/TestCase.java index ea7067d9e5..dd2339d2f7 100644 --- a/test/nodb/src/test/java/org/hibernate/tool/hbm2x/Hbm2CfgTest/TestCase.java +++ b/test/nodb/src/test/java/org/hibernate/tool/hbm2x/Hbm2CfgTest/TestCase.java @@ -29,6 +29,10 @@ import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Environment; +import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; +import org.hibernate.resource.transaction.spi.TransactionCoordinator; +import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; +import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner; import org.hibernate.tool.api.export.ArtifactCollector; import org.hibernate.tool.api.export.Exporter; import org.hibernate.tool.api.export.ExporterConstants; @@ -49,6 +53,22 @@ */ public class TestCase { + @SuppressWarnings("serial") + public static class FakeTransactionManagerLookup implements TransactionCoordinatorBuilder { + @Override + public TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner, Options options) { + return null; + } + @Override + public boolean isJta() { + return false; + } + @Override + public PhysicalConnectionHandlingMode getDefaultConnectionHandlingMode() { + return PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT; + } + } + private static final String[] HBM_XML_FILES = new String[] { "HelloWorld.hbm.xml" }; @@ -114,7 +134,7 @@ public void testMagicPropertyHandling() { FileUtil.findFirstString( Environment.HBM2DDL_AUTO, file )); exporter = ExporterFactory.createExporter(ExporterType.CFG); properties = exporter.getProperties(); - properties.put( AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, "org.hibernate.console.FakeTransactionManagerLookup"); // Hack for seam-gen console configurations + properties.put( AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, FakeTransactionManagerLookup.class.getName()); // Hack for seam-gen console configurations properties.put(AvailableSettings.DIALECT, HibernateUtil.Dialect.class.getName()); properties.put(AvailableSettings.CONNECTION_PROVIDER, HibernateUtil.ConnectionProvider.class.getName()); exporter.getProperties().put( @@ -122,7 +142,7 @@ public void testMagicPropertyHandling() { MetadataDescriptorFactory.createNativeDescriptor(null, null, properties)); exporter.getProperties().put(ExporterConstants.DESTINATION_FOLDER, srcDir); exporter.start(); - assertNull( + assertNotNull( FileUtil.findFirstString( AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, file )); } diff --git a/test/nodb/src/test/java/org/hibernate/tool/hbm2x/hbm2hbmxml/TypeParamsTest/TestCase.java b/test/nodb/src/test/java/org/hibernate/tool/hbm2x/hbm2hbmxml/TypeParamsTest/TestCase.java index 743ea72b8a..d9de8fa42a 100644 --- a/test/nodb/src/test/java/org/hibernate/tool/hbm2x/hbm2hbmxml/TypeParamsTest/TestCase.java +++ b/test/nodb/src/test/java/org/hibernate/tool/hbm2x/hbm2hbmxml/TypeParamsTest/TestCase.java @@ -45,7 +45,6 @@ import org.hibernate.tools.test.util.HibernateUtil; import org.hibernate.tools.test.util.JUnitUtil; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.w3c.dom.Document; @@ -82,8 +81,6 @@ public void setUp() throws Exception { hbmexporter.start(); } - // TODO HBX-2062: Investigate and reenable - @Disabled @Test public void testAllFilesExistence() { JUnitUtil.assertIsNonEmptyFile( @@ -92,8 +89,6 @@ public void testAllFilesExistence() { "org/hibernate/tool/hbm2x/hbm2hbmxml/TypeParamsTest/Order.hbm.xml")); } - // TODO HBX-2062: Investigate and reenable - @Disabled @Test public void testReadable() { File orderHbmXml = @@ -102,14 +97,13 @@ public void testReadable() { "org/hibernate/tool/hbm2x/hbm2hbmxml/TypeParamsTest/Order.hbm.xml"); Properties properties = new Properties(); properties.setProperty(AvailableSettings.DIALECT, HibernateUtil.Dialect.class.getName()); + properties.setProperty(AvailableSettings.CONNECTION_PROVIDER, HibernateUtil.ConnectionProvider.class.getName()); File[] files = new File[] { orderHbmXml }; MetadataDescriptor metadataDescriptor = MetadataDescriptorFactory .createNativeDescriptor(null, files, properties); assertNotNull(metadataDescriptor.createMetadata()); } - // TODO HBX-2062: Investigate and reenable - @Disabled @Test public void testTypeParamsElements() throws Exception { File outputXml = new File( @@ -163,10 +157,14 @@ public void testTypeParamsElements() throws Exception { set.contains("enumClass"), "Can't find 'enumClass' param"); assertEquals( - "org.hibernate.tool.hbm2x.hbm2hbmxml.Order$Status", + Status.class.getName(), params.get("enumClass")); assertTrue(nameElement.getElementsByTagName("type").getLength() == 0, "property name should not have any type element"); assertEquals(nameElement.getAttribute("type"), "string"); } + + enum Status { + ON, OFF + } } diff --git a/test/nodb/src/test/resources/org/hibernate/tool/ant/Exception/TopDown.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/ant/Exception/TopDown.hbm.xml index df2640ea90..768dd54b2e 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/ant/Exception/TopDown.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/ant/Exception/TopDown.hbm.xml @@ -1,7 +1,7 @@ + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/ant/NoConnInfoExport/TopDown.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/ant/NoConnInfoExport/TopDown.hbm.xml index df2640ea90..768dd54b2e 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/ant/NoConnInfoExport/TopDown.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/ant/NoConnInfoExport/TopDown.hbm.xml @@ -1,7 +1,7 @@ + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/DocExporterTest/Customer.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/DocExporterTest/Customer.hbm.xml index b91a4145b9..91bb6ea031 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/DocExporterTest/Customer.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/DocExporterTest/Customer.hbm.xml @@ -1,7 +1,7 @@ + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/DocExporterTest/HelloWorld.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/DocExporterTest/HelloWorld.hbm.xml index 8c4356fb7e..1154536904 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/DocExporterTest/HelloWorld.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/DocExporterTest/HelloWorld.hbm.xml @@ -1,7 +1,7 @@ + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test/Article.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test/Article.hbm.xml index d8e7735f38..0a482aab98 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test/Article.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test/Article.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test/Train.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test/Train.hbm.xml index 952b427a73..0c3bde51aa 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test/Train.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test/Train.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaInitializationTest/Article.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaInitializationTest/Article.hbm.xml index 9a68082f9a..e9ebd5b664 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaInitializationTest/Article.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaInitializationTest/Article.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaInitializationTest/Train.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaInitializationTest/Train.hbm.xml index dc0a988503..8d96f024cc 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaInitializationTest/Train.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaInitializationTest/Train.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaTest/Customer.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaTest/Customer.hbm.xml index a0b4ec90bc..2f7b495534 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaTest/Customer.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaTest/Customer.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaTest/Product.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaTest/Product.hbm.xml index 85a13d7fd7..e77ea2f095 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaTest/Product.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaTest/Product.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaTest/Train.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaTest/Train.hbm.xml index 55f2cbc135..1b3b7fd96a 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaTest/Train.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/Hbm2JavaTest/Train.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/OtherCfg2HbmTest/Customer.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/OtherCfg2HbmTest/Customer.hbm.xml index 38653807d2..a62e6a4cff 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/OtherCfg2HbmTest/Customer.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/OtherCfg2HbmTest/Customer.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/PropertiesTest/Properties.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/PropertiesTest/Properties.hbm.xml index e920773905..5c64f5ed02 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/PropertiesTest/Properties.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/PropertiesTest/Properties.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> @@ -24,24 +24,24 @@ next_hi_value - - description - + - + - + - anotherone + anotherone - + diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/Hbm2HbmXmlTest/BasicCompositeId.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/Hbm2HbmXmlTest/BasicCompositeId.hbm.xml index a84fb49183..61302ff3d6 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/Hbm2HbmXmlTest/BasicCompositeId.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/Hbm2HbmXmlTest/BasicCompositeId.hbm.xml @@ -1,7 +1,7 @@ + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/ManyToManyTest/UserGroup.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/ManyToManyTest/UserGroup.hbm.xml index 9e6bae762d..c17fcaa406 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/ManyToManyTest/UserGroup.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/ManyToManyTest/UserGroup.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/MapAndAnyTest/Properties.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/MapAndAnyTest/Properties.hbm.xml index 93589770aa..4a3c2ee60f 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/MapAndAnyTest/Properties.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/MapAndAnyTest/Properties.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/OneToOneTest/PersonAddressOneToOnePrimaryKey.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/OneToOneTest/PersonAddressOneToOnePrimaryKey.hbm.xml index a9f8cf2b97..1d9dd0fbdd 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/OneToOneTest/PersonAddressOneToOnePrimaryKey.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/OneToOneTest/PersonAddressOneToOnePrimaryKey.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/SetElementTest/Search.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/SetElementTest/Search.hbm.xml index c1e9209050..0053e91228 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/SetElementTest/Search.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/hbm2x/hbm2hbmxml/SetElementTest/Search.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> @@ -34,7 +34,7 @@ STATUS ORDERS - org.hibernate.tool.hbm2x.hbm2hbmxml.Order$Status + org.hibernate.tool.hbm2x.hbm2hbmxml.TypeParamsTest.TestCase$Status diff --git a/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/City.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/City.hbm.xml index 856c645c75..912a538be2 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/City.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/City.hbm.xml @@ -19,7 +19,7 @@ ~ limitations under the License. --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/Product.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/Product.hbm.xml index 15fa04a68a..a2870a0c40 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/Product.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/Product.hbm.xml @@ -19,7 +19,7 @@ ~ limitations under the License. --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/ProductOwnerAddress.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/ProductOwnerAddress.hbm.xml index 2153e46bf9..d92284e914 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/ProductOwnerAddress.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/ProductOwnerAddress.hbm.xml @@ -19,7 +19,7 @@ ~ limitations under the License. --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/Store.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/Store.hbm.xml index 57ef3c7d89..338c7bdd06 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/Store.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/Store.hbm.xml @@ -19,7 +19,7 @@ ~ limitations under the License. --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/StoreCity.hbm.xml b/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/StoreCity.hbm.xml index e21ffe69e4..10e6c75fa2 100644 --- a/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/StoreCity.hbm.xml +++ b/test/nodb/src/test/resources/org/hibernate/tool/ide/completion/ModelCompletion/StoreCity.hbm.xml @@ -19,7 +19,7 @@ ~ limitations under the License. --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/oracle/pom.xml b/test/oracle/pom.xml index dd9a8bec78..bea0131e60 100644 --- a/test/oracle/pom.xml +++ b/test/oracle/pom.xml @@ -28,7 +28,7 @@ org.hibernate.tool hibernate-tools-tests-parent - 6.2.7-SNAPSHOT + 6.2.42-SNAPSHOT hibernate-tools-tests-oracle diff --git a/test/oracle/src/test/resources/org/hibernate/tool/hbmlint/SchemaAnalyzer/SchemaIssues.hbm.xml b/test/oracle/src/test/resources/org/hibernate/tool/hbmlint/SchemaAnalyzer/SchemaIssues.hbm.xml index 84d9e8289c..a31c8dcc3e 100644 --- a/test/oracle/src/test/resources/org/hibernate/tool/hbmlint/SchemaAnalyzer/SchemaIssues.hbm.xml +++ b/test/oracle/src/test/resources/org/hibernate/tool/hbmlint/SchemaAnalyzer/SchemaIssues.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/pom.xml b/test/pom.xml index f40fcfa2ca..6c0e7b0c02 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -28,7 +28,7 @@ org.hibernate.tool hibernate-tools-parent - 6.2.7-SNAPSHOT + 6.2.42-SNAPSHOT hibernate-tools-tests-parent diff --git a/test/utils/pom.xml b/test/utils/pom.xml index bbf77cdea0..e69d36ae68 100644 --- a/test/utils/pom.xml +++ b/test/utils/pom.xml @@ -27,7 +27,7 @@ org.hibernate.tool hibernate-tools-tests-parent - 6.2.7-SNAPSHOT + 6.2.42-SNAPSHOT hibernate-tools-tests-utils diff --git a/test/utils/src/main/java/org/hibernate/tools/test/util/JdbcUtil.java b/test/utils/src/main/java/org/hibernate/tools/test/util/JdbcUtil.java index 622ddaa1d6..39fa6cd130 100644 --- a/test/utils/src/main/java/org/hibernate/tools/test/util/JdbcUtil.java +++ b/test/utils/src/main/java/org/hibernate/tools/test/util/JdbcUtil.java @@ -35,13 +35,25 @@ public class JdbcUtil { static HashMap CONNECTION_TABLE = new HashMap<>(); - - public static Properties getConnectionProperties() { + + /** + * Obtain the database connection properties. + * @param test object residing in the package of an optional alternate hibernate.properties. + * Set null for the default hibernate.properties. + * @return + */ + public static Properties getConnectionProperties(Object test) { Properties properties = new Properties(); - InputStream inputStream = Thread + InputStream inputStream = null; + if (test != null) { + inputStream = getAlternateHibernateProperties(test); + } + if (inputStream == null) { + inputStream = Thread .currentThread() .getContextClassLoader() .getResourceAsStream("hibernate.properties"); + } try { properties.load(inputStream); } catch (IOException e) { @@ -59,10 +71,21 @@ public static Properties getConnectionProperties() { properties.getProperty("hibernate.connection.password")); return connectionProperties; } - + + public static InputStream getAlternateHibernateProperties(Object test) { + InputStream inputStream = ResourceUtil.resolveResourceLocation( + test.getClass(), "hibernate.properties"); + return inputStream; + } + + /** + * Create a database connection associated with a test object. + * @param test object as key to stored connection. Test object package may also contain + * an optional hibernate.properties. + */ public static void establishJdbcConnection(Object test) { try { - CONNECTION_TABLE.put(test, createJdbcConnection()); + CONNECTION_TABLE.put(test, createJdbcConnection(test)); } catch (SQLException e) { throw new RuntimeException(e); } @@ -102,10 +125,10 @@ public static String toIdentifier(Object test, String string) { } } - public static boolean isDatabaseOnline() { + public static boolean isDatabaseOnline(Object test) { boolean result = false; try { - Connection connection = createJdbcConnection(); + Connection connection = createJdbcConnection(test); result = connection.isValid(1); connection.commit(); connection.close(); @@ -115,15 +138,30 @@ public static boolean isDatabaseOnline() { return result; } + /** + * Establish a connection and execute create.sql. + * + * @param Object residing in the package of create.sql and optional alternate hibernate.properties. + */ public static void createDatabase(Object test) { establishJdbcConnection(test); executeSql(test, getSqls(test, "create.sql")); } + /** + * Using an established connection, execute data.sql. + * + * @param Object residing in the package of data.sql resource. + */ public static void populateDatabase(Object test) { executeSql(test, getSqls(test, "data.sql")); } - + + /** + * Using an established connection, execute drop.sql. + * + * @param Object residing in the package of drop.sql resource. + */ public static void dropDatabase(Object test) { executeSql(test, getSqls(test, "drop.sql")); releaseJdbcConnection(test); @@ -149,9 +187,14 @@ private static String[] getSqls(Object test, String scriptName) { return result; } - private static Connection createJdbcConnection() + /** + * Obtain a connection to a database. + * @param test object as key to stored connection. Test object package may also contain + * an optional hibernate.properties. + */ + private static Connection createJdbcConnection(Object test) throws SQLException { - Properties connectionProperties = getConnectionProperties(); + Properties connectionProperties = getConnectionProperties(test); String connectionUrl = (String)connectionProperties.remove("url"); return DriverManager .getDriver(connectionUrl) diff --git a/test/utils/src/main/java/org/hibernate/tools/test/util/ResourceUtil.java b/test/utils/src/main/java/org/hibernate/tools/test/util/ResourceUtil.java index 6e5ff068e8..5d3ffefbe3 100644 --- a/test/utils/src/main/java/org/hibernate/tools/test/util/ResourceUtil.java +++ b/test/utils/src/main/java/org/hibernate/tools/test/util/ResourceUtil.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.nio.file.Files; public class ResourceUtil { @@ -51,6 +52,14 @@ public static InputStream resolveResourceLocation(Class testClass, String res } return result; } + + public static File resolveResourceFile(Class testClass, String resourceName) { + String path = testClass.getPackage().getName().replace('.', File.separatorChar); + URL resourceUrl = testClass.getClassLoader().getResource(path + File.separatorChar + + resourceName); + File resourceFile = new File(resourceUrl.getFile()); + return resourceFile; + } private static String getRelativeResourcesRoot(Class testClass) { return '/' + testClass.getPackage().getName().replace('.', '/') + '/'; diff --git a/test/utils/src/test/java/org/hibernate/tools/test/util/JdbcUtilTest.java b/test/utils/src/test/java/org/hibernate/tools/test/util/JdbcUtilTest.java index 4acf7162ee..26d794577c 100644 --- a/test/utils/src/test/java/org/hibernate/tools/test/util/JdbcUtilTest.java +++ b/test/utils/src/test/java/org/hibernate/tools/test/util/JdbcUtilTest.java @@ -60,10 +60,10 @@ public void tearDown() throws Exception { clearConnectionTable(); restoreClassLoader(); } - + @Test - public void testGetConnectionProperties() throws Exception { - Properties properties = JdbcUtil.getConnectionProperties(); + public void testGetConnectionPropertiesForTest() throws Exception { + Properties properties = JdbcUtil.getConnectionProperties(null); assertEquals("jdbc:h2:mem:test", properties.get("url")); assertEquals("sa", properties.get("user")); assertEquals("", properties.get("password")); @@ -128,10 +128,10 @@ public void testToIdentifier() throws Exception { @Test public void testIsDatabaseOnline() throws Exception { - assertTrue(JdbcUtil.isDatabaseOnline()); + assertTrue(JdbcUtil.isDatabaseOnline(null)); new File(outputFolder, "hibernate.properties").delete(); createHibernateProperties("foo", "bar", "jdbc:sqlserver://org.foo.bar:1433"); - assertFalse(JdbcUtil.isDatabaseOnline()); + assertFalse(JdbcUtil.isDatabaseOnline(null)); } private void clearConnectionTable() throws Exception { diff --git a/test/utils/src/test/java/org/hibernate/tools/test/util/ResourceUtilTest.java b/test/utils/src/test/java/org/hibernate/tools/test/util/ResourceUtilTest.java index 5a72c059f3..12248671f8 100644 --- a/test/utils/src/test/java/org/hibernate/tools/test/util/ResourceUtilTest.java +++ b/test/utils/src/test/java/org/hibernate/tools/test/util/ResourceUtilTest.java @@ -58,4 +58,9 @@ public void testCreateResources() { .contains("HelloWorld")); } + @Test + public void testFindResourceFile() { + File resourceFile = ResourceUtil.resolveResourceFile(this.getClass(), "FileUtilTest.resource"); + assertTrue(resourceFile.exists()); + } } diff --git a/test/utils/src/test/java/org/hibernate/tools/test/util/hprops/AlternateHibernatePropsTest.java b/test/utils/src/test/java/org/hibernate/tools/test/util/hprops/AlternateHibernatePropsTest.java new file mode 100644 index 0000000000..ad2050fa33 --- /dev/null +++ b/test/utils/src/test/java/org/hibernate/tools/test/util/hprops/AlternateHibernatePropsTest.java @@ -0,0 +1,43 @@ +/* + * Hibernate Tools, Tooling for your Hibernate Projects + * + * Copyright 2017-2020 Red Hat, Inc. + * + * Licensed under the GNU Lesser General Public License (LGPL), + * version 2.1 or later (the "License"). + * You may not use this file except in compliance with the License. + * You may read the licence in the 'lgpl.txt' file in the root folder of + * project or obtain a copy at + * + * http://www.gnu.org/licenses/lgpl-2.1.html + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hibernate.tools.test.util.hprops; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.hibernate.tools.test.util.JdbcUtil; +import org.junit.jupiter.api.Test; + +import java.util.Properties; + +public class AlternateHibernatePropsTest { + private static final String connectString = "jdbc:h2:mem:test1;"; + + @Test + public void testExecuteDDL() throws Exception { + + Properties properties = JdbcUtil.getConnectionProperties(this); + assertEquals(connectString, properties.get("url")); + assertEquals("sa", properties.get("user")); + assertEquals("123", properties.get("password")); + + JdbcUtil.createDatabase(this); + JdbcUtil.dropDatabase(this); + } +} \ No newline at end of file diff --git a/test/utils/src/test/resources/org/hibernate/tools/test/util/HelloWorld.hbm.xml b/test/utils/src/test/resources/org/hibernate/tools/test/util/HelloWorld.hbm.xml index aae3f88b47..27917869c7 100644 --- a/test/utils/src/test/resources/org/hibernate/tools/test/util/HelloWorld.hbm.xml +++ b/test/utils/src/test/resources/org/hibernate/tools/test/util/HelloWorld.hbm.xml @@ -20,7 +20,7 @@ --> + "https://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> diff --git a/test/utils/src/test/resources/org/hibernate/tools/test/util/hprops/create.sql b/test/utils/src/test/resources/org/hibernate/tools/test/util/hprops/create.sql new file mode 100644 index 0000000000..3ae830f859 --- /dev/null +++ b/test/utils/src/test/resources/org/hibernate/tools/test/util/hprops/create.sql @@ -0,0 +1 @@ +CREATE TABLE DUMMY (ID INT, NAME VARCHAR(10)) diff --git a/test/utils/src/test/resources/org/hibernate/tools/test/util/hprops/drop.sql b/test/utils/src/test/resources/org/hibernate/tools/test/util/hprops/drop.sql new file mode 100644 index 0000000000..fd18ea0a11 --- /dev/null +++ b/test/utils/src/test/resources/org/hibernate/tools/test/util/hprops/drop.sql @@ -0,0 +1 @@ +DROP TABLE DUMMY \ No newline at end of file diff --git a/test/utils/src/test/resources/org/hibernate/tools/test/util/hprops/hibernate.properties b/test/utils/src/test/resources/org/hibernate/tools/test/util/hprops/hibernate.properties new file mode 100644 index 0000000000..c9c293a49b --- /dev/null +++ b/test/utils/src/test/resources/org/hibernate/tools/test/util/hprops/hibernate.properties @@ -0,0 +1,6 @@ +hibernate.connection.username sa +hibernate.connection.password 123 +hibernate.connection.url jdbc:h2:mem:test1; +hibernate.dialect org.hibernate.dialect.H2Dialect +hibernate.connection.driver_class org.h2.Driver +hibernate.default_schema PUBLIC diff --git a/utils/pom.xml b/utils/pom.xml index 5f8e090153..0bb8d8f2a6 100644 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -21,7 +21,7 @@ org.hibernate.tool hibernate-tools-parent - 6.2.7-SNAPSHOT + 6.2.42-SNAPSHOT hibernate-tools-utils @@ -30,6 +30,11 @@ Hibernate Tools Common Utilities jar + + + false + + org.junit.jupiter