Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15822 from Sanne/Ban
Avoid class initializations more aggressively in the Hibernate ORM extension
- Loading branch information
Showing
20 changed files
with
248 additions
and
180 deletions.
There are no files selected for viewing
14 changes: 11 additions & 3 deletions
14
...ment/src/main/java/io/quarkus/deployment/builditem/AdditionalIndexedClassesBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@defaultMessage Don't use the pattern MyClass.class.getName() or DotName.createSimple("org.mycompany.MyClass"). Instead, create constants using createConstant("org.mycompany.MyClass") in io.quarkus.hibernate.orm.deployment.ClassNames. That way, all class names will get checked against the classpath in ConstantsTest. | ||
java.lang.Class#getName() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ClassNames.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.quarkus.hibernate.orm.deployment; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.jboss.jandex.DotName; | ||
|
||
public class ClassNames { | ||
|
||
static final Set<DotName> CREATED_CONSTANTS = new HashSet<>(); | ||
|
||
private ClassNames() { | ||
} | ||
|
||
private static DotName createConstant(String fqcn) { | ||
DotName result = DotName.createSimple(fqcn); | ||
CREATED_CONSTANTS.add(result); | ||
return result; | ||
} | ||
|
||
public static final DotName ENUM = createConstant("java.lang.Enum"); | ||
|
||
public static final DotName TENANT_CONNECTION_RESOLVER = createConstant( | ||
"io.quarkus.hibernate.orm.runtime.tenant.TenantConnectionResolver"); | ||
public static final DotName TENANT_RESOLVER = createConstant("io.quarkus.hibernate.orm.runtime.tenant.TenantResolver"); | ||
|
||
public static final DotName STATIC_METAMODEL = createConstant("javax.persistence.metamodel.StaticMetamodel"); | ||
|
||
public static final DotName QUARKUS_PERSISTENCE_UNIT = createConstant("io.quarkus.hibernate.orm.PersistenceUnit"); | ||
public static final DotName QUARKUS_PERSISTENCE_UNIT_REPEATABLE_CONTAINER = createConstant( | ||
"io.quarkus.hibernate.orm.PersistenceUnit$List"); | ||
public static final DotName JPA_PERSISTENCE_UNIT = createConstant("javax.persistence.PersistenceUnit"); | ||
public static final DotName JPA_PERSISTENCE_CONTEXT = createConstant("javax.persistence.PersistenceContext"); | ||
|
||
public static final DotName JPA_ENTITY = createConstant("javax.persistence.Entity"); | ||
public static final DotName MAPPED_SUPERCLASS = createConstant("javax.persistence.MappedSuperclass"); | ||
public static final DotName EMBEDDABLE = createConstant("javax.persistence.Embeddable"); | ||
public static final DotName EMBEDDED = createConstant("javax.persistence.Embedded"); | ||
public static final DotName ELEMENT_COLLECTION = createConstant("javax.persistence.ElementCollection"); | ||
public static final DotName PROXY = createConstant("org.hibernate.annotations.Proxy"); | ||
public static final DotName HIBERNATE_PROXY = createConstant("org.hibernate.proxy.HibernateProxy"); | ||
public static final DotName TYPE = createConstant("org.hibernate.annotations.Type"); | ||
public static final DotName TYPE_DEFINITION = createConstant("org.hibernate.annotations.TypeDef"); | ||
public static final DotName TYPE_DEFINITIONS = createConstant("org.hibernate.annotations.TypeDefs"); | ||
|
||
public static final DotName ENTITY_MANAGER_FACTORY = createConstant("javax.persistence.EntityManagerFactory"); | ||
public static final DotName SESSION_FACTORY = createConstant("org.hibernate.SessionFactory"); | ||
public static final DotName ENTITY_MANAGER = createConstant("javax.persistence.EntityManager"); | ||
public static final DotName SESSION = createConstant("org.hibernate.Session"); | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
.../hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/Dialects.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.quarkus.hibernate.orm.deployment; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.datasource.common.runtime.DatabaseKind; | ||
import io.quarkus.deployment.configuration.ConfigurationError; | ||
|
||
public final class Dialects { | ||
|
||
private Dialects() { | ||
//utility | ||
} | ||
|
||
public static Optional<String> guessDialect(String resolvedDbKind) { | ||
// For now select the latest dialect from the driver | ||
// later, we can keep doing that but also avoid DCE | ||
// of all the dialects we want in so that people can override them | ||
if (DatabaseKind.isDB2(resolvedDbKind)) { | ||
return Optional.of("org.hibernate.dialect.DB297Dialect"); | ||
} | ||
if (DatabaseKind.isPostgreSQL(resolvedDbKind)) { | ||
return Optional.of("io.quarkus.hibernate.orm.runtime.dialect.QuarkusPostgreSQL10Dialect"); | ||
} | ||
if (DatabaseKind.isH2(resolvedDbKind)) { | ||
return Optional.of("io.quarkus.hibernate.orm.runtime.dialect.QuarkusH2Dialect"); | ||
} | ||
if (DatabaseKind.isMariaDB(resolvedDbKind)) { | ||
return Optional.of("org.hibernate.dialect.MariaDB103Dialect"); | ||
} | ||
if (DatabaseKind.isMySQL(resolvedDbKind)) { | ||
return Optional.of("org.hibernate.dialect.MySQL8Dialect"); | ||
} | ||
if (DatabaseKind.isOracle(resolvedDbKind)) { | ||
return Optional.of("org.hibernate.dialect.Oracle12cDialect"); | ||
} | ||
if (DatabaseKind.isDerby(resolvedDbKind)) { | ||
return Optional.of("org.hibernate.dialect.DerbyTenSevenDialect"); | ||
} | ||
if (DatabaseKind.isMsSQL(resolvedDbKind)) { | ||
return Optional.of("org.hibernate.dialect.SQLServer2012Dialect"); | ||
} | ||
|
||
String error = "Hibernate extension could not guess the dialect from the database kind '" + resolvedDbKind | ||
+ "'. Add an explicit '" + HibernateOrmProcessor.HIBERNATE_ORM_CONFIG_PREFIX + "dialect' property."; | ||
throw new ConfigurationError(error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.