-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speedup Hibernate ORM's enhancement of large models
- Loading branch information
Showing
3 changed files
with
104 additions
and
34 deletions.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
...rc/main/java/io/quarkus/hibernate/orm/deployment/integration/QuarkusClassFileLocator.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,37 @@ | ||
package io.quarkus.hibernate.orm.deployment.integration; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import net.bytebuddy.dynamic.ClassFileLocator; | ||
import net.bytebuddy.utility.StreamDrainer; | ||
|
||
public final class QuarkusClassFileLocator implements ClassFileLocator { | ||
|
||
public static final QuarkusClassFileLocator INSTANCE = new QuarkusClassFileLocator(); | ||
|
||
private QuarkusClassFileLocator() { | ||
//do not invoke, use INSTANCE | ||
} | ||
|
||
@Override | ||
public Resolution locate(final String name) throws IOException { | ||
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
InputStream inputStream = classLoader.getResourceAsStream(name.replace('.', '/') + CLASS_FILE_EXTENSION); | ||
if (inputStream != null) { | ||
try { | ||
return new Resolution.Explicit(StreamDrainer.DEFAULT.drain(inputStream)); | ||
} finally { | ||
inputStream.close(); | ||
} | ||
} else { | ||
return new Resolution.Illegal(name); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
//nothing to do | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
.../main/java/io/quarkus/hibernate/orm/deployment/integration/QuarkusEnhancementContext.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,28 @@ | ||
package io.quarkus.hibernate.orm.deployment.integration; | ||
|
||
import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext; | ||
import org.hibernate.bytecode.enhance.spi.UnloadedField; | ||
|
||
public final class QuarkusEnhancementContext extends DefaultEnhancementContext { | ||
|
||
public static final QuarkusEnhancementContext INSTANCE = new QuarkusEnhancementContext(); | ||
|
||
private QuarkusEnhancementContext() { | ||
//do not invoke, use INSTANCE | ||
} | ||
|
||
@Override | ||
public boolean doBiDirectionalAssociationManagement(final UnloadedField field) { | ||
//Don't enable automatic association management as it's often too surprising. | ||
//Also, there's several cases in which its semantics are of unspecified, | ||
//such as what should happen when dealing with ordered collections. | ||
return false; | ||
} | ||
|
||
@Override | ||
public ClassLoader getLoadingClassLoader() { | ||
//This shouldn't matter, see: QuarkusClassFileLocator | ||
return Thread.currentThread().getContextClassLoader(); | ||
} | ||
|
||
} |