Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
79dcb2f
Various code cleanup
sebersole Jan 16, 2025
2a4a447
Various code cleanup
sebersole Jan 16, 2025
f02f461
Various code cleanup
sebersole Jan 16, 2025
56c0372
Various code cleanup
sebersole Feb 20, 2025
b6154f3
Various code cleanup
sebersole Jan 17, 2025
45f2a59
Various code cleanup
sebersole Feb 4, 2025
a0f982c
Various code cleanup
sebersole Feb 4, 2025
eeb10d5
Various code cleanup
sebersole Feb 4, 2025
cee9470
Various code cleanup
sebersole Feb 4, 2025
7497c2b
Various code cleanup
sebersole Feb 4, 2025
dca1a97
Various code cleanup
sebersole Feb 4, 2025
a329bf6
Various code cleanup
sebersole Feb 4, 2025
13b447d
Various code cleanup
sebersole Feb 4, 2025
9281a48
Various code cleanup
sebersole Feb 5, 2025
2d42f3f
Various code cleanup
sebersole Feb 5, 2025
53dda34
Various code cleanup
sebersole Feb 5, 2025
022d85d
Various code cleanup
sebersole Feb 5, 2025
f6d98a7
Various code cleanup
sebersole Feb 6, 2025
fde950f
Various code cleanup
sebersole Feb 7, 2025
5445b17
Various code cleanup
sebersole Feb 7, 2025
e6dad59
Various code cleanup
sebersole Feb 7, 2025
8a9a80d
Various code cleanup
sebersole Feb 7, 2025
04f1b83
Various code cleanup
sebersole Feb 7, 2025
9194625
Various code cleanup
sebersole Feb 7, 2025
415a7b7
Various code cleanup
sebersole Feb 7, 2025
d47f0cb
Various code cleanup
sebersole Feb 7, 2025
5d82744
Various code cleanup
sebersole Feb 7, 2025
3f61c65
Various code cleanup
sebersole Feb 7, 2025
0c4c641
Various code cleanup
sebersole Feb 7, 2025
96faa42
Various code cleanup
sebersole Feb 12, 2025
b4dd2c8
Various code cleanup
sebersole Feb 12, 2025
9b96e6a
Various code cleanup
sebersole Feb 12, 2025
846c648
Various code cleanup
sebersole Feb 12, 2025
0f85112
Various code cleanup
sebersole Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.bytecode.internal.bytebuddy;

import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;

@MappedSuperclass
public abstract class BaseMappedSuperclass {
@Id
protected Long id;
protected String value;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,11 @@
*/
package org.hibernate.bytecode.internal.bytebuddy;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import java.util.LinkedHashMap;
import java.util.Map;
import org.hibernate.bytecode.enhance.internal.bytebuddy.EnhancerImpl;
import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext;
import org.hibernate.bytecode.enhance.spi.EnhancementException;
import org.hibernate.bytecode.enhance.spi.Enhancer;
import org.hibernate.bytecode.spi.ByteCodeHelper;
import org.hibernate.bytecode.spi.ReflectionOptimizer;
import org.hibernate.property.access.internal.PropertyAccessStrategyFieldImpl;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyHelper;
import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test;

public class GenerateProxiesTest {
Expand All @@ -41,45 +28,4 @@ public void generateProxy() throws InstantiationException, IllegalAccessExceptio
assertNotNull( proxyClass );
assertNotNull( proxyClass.getConstructor().newInstance() );
}

@Test
public void generateFastClassAndReflectionOptimizer() {
BytecodeProviderImpl bytecodeProvider = new BytecodeProviderImpl();
ReflectionOptimizer reflectionOptimizer = bytecodeProvider.getReflectionOptimizer( SimpleEntity.class,
new String[]{ "getId", "getName" }, new String[]{ "setId", "setName" },
new Class<?>[]{ Long.class, String.class } );
assertEquals( 2, reflectionOptimizer.getAccessOptimizer().getPropertyNames().length );
assertNotNull( reflectionOptimizer.getInstantiationOptimizer().newInstance() );
}

@Test
@JiraKey("HHH-16772")
public void generateFastMappedSuperclassAndReflectionOptimizer() {
BytecodeProviderImpl bytecodeProvider = new BytecodeProviderImpl();
final Map<String, PropertyAccess> propertyAccessMap = new LinkedHashMap<>();

final PropertyAccessStrategyFieldImpl propertyAccessStrategy = new PropertyAccessStrategyFieldImpl();

propertyAccessMap.put(
"timestamp",
propertyAccessStrategy.buildPropertyAccess(MappedSuperclassEntity.class, "value", true )
);

ReflectionOptimizer reflectionOptimizer = bytecodeProvider.getReflectionOptimizer(
MappedSuperclassEntity.class,
propertyAccessMap
);

assertNotNull(reflectionOptimizer);
assertEquals( 1, reflectionOptimizer.getAccessOptimizer().getPropertyNames().length );
assertNotNull( reflectionOptimizer.getInstantiationOptimizer().newInstance() );
}

@Test
public void generateEnhancedClass() throws EnhancementException, IOException {
Enhancer enhancer = new EnhancerImpl( new DefaultEnhancementContext(), new ByteBuddyState() );
enhancer.enhance( SimpleEntity.class.getName(),
ByteCodeHelper.readByteCode( SimpleEntity.class.getClassLoader()
.getResourceAsStream( SimpleEntity.class.getName().replace( '.', '/' ) + ".class" ) ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package org.hibernate.bytecode.internal.bytebuddy;

import jakarta.persistence.Entity;
import org.hibernate.bytecode.internal.bytebuddy.mappedsuperclass.BaseMappedSuperclass;

@Entity
public class MappedSuperclassEntity extends BaseMappedSuperclass {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.bytecode.internal.bytebuddy;

import org.hibernate.bytecode.spi.ReflectionOptimizer;
import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;

/**
* @author Steve Ebersole
*/
public class ReflectionOptimizerTests {

@Test
public void generateFastClassAndReflectionOptimizer() {
BytecodeProviderImpl bytecodeProvider = new BytecodeProviderImpl();
ReflectionOptimizer reflectionOptimizer = bytecodeProvider.getReflectionOptimizer( SimpleEntity.class,
new String[]{ "getId", "getName" }, new String[]{ "setId", "setName" },
new Class<?>[]{ Long.class, String.class } );
assertThat( reflectionOptimizer ).isNotNull();

final ReflectionOptimizer.AccessOptimizer accessOptimizer = reflectionOptimizer.getAccessOptimizer();
assertThat( accessOptimizer.getPropertyNames() ).hasSize( 2 );

final Object instance = reflectionOptimizer.getInstantiationOptimizer().newInstance();
assertNotNull( instance );

final Object[] initialValues = accessOptimizer.getPropertyValues( instance );
assertThat( initialValues ).containsExactly( null, null );

accessOptimizer.setPropertyValues( instance, new Object[] { 1L, "a name" } );

final Object[] injectedValues = accessOptimizer.getPropertyValues( instance );
assertThat( injectedValues ).containsExactly( 1L, "a name" );
}

@Test
@JiraKey("HHH-16772")
public void generateFastMappedSuperclassAndReflectionOptimizer() {
BytecodeProviderImpl bytecodeProvider = new BytecodeProviderImpl();
ReflectionOptimizer reflectionOptimizer = bytecodeProvider.getReflectionOptimizer(
MappedSuperclassEntity.class,
new String[]{ "getId", "getValue" }, new String[]{ "setId", "setValue" },
new Class<?>[]{ Long.class, String.class }
);
assertThat( reflectionOptimizer ).isNotNull();

final ReflectionOptimizer.AccessOptimizer accessOptimizer = reflectionOptimizer.getAccessOptimizer();
assertThat( accessOptimizer.getPropertyNames() ).hasSize( 2 );

final Object instance = reflectionOptimizer.getInstantiationOptimizer().newInstance();
assertNotNull( instance );

final Object[] initialValues = accessOptimizer.getPropertyValues( instance );
assertThat( initialValues ).containsExactly( null, null );

accessOptimizer.setPropertyValues( instance, new Object[] { 1L, "a value" } );

final Object[] injectedValues = accessOptimizer.getPropertyValues( instance );
assertThat( injectedValues ).containsExactly( 1L, "a value" );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.bytecode.internal.bytebuddy;

import org.hibernate.bytecode.enhance.internal.bytebuddy.EnhancerImpl;
import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext;
import org.hibernate.bytecode.enhance.spi.EnhancementException;
import org.hibernate.bytecode.enhance.spi.Enhancer;
import org.hibernate.bytecode.spi.ByteCodeHelper;
import org.junit.Test;

import java.io.IOException;

/**
* @author Steve Ebersole
*/
public class SimpleEnhancerTests {
@Test
public void generateEnhancedClass() throws EnhancementException, IOException {
Enhancer enhancer = new EnhancerImpl( new DefaultEnhancementContext(), new ByteBuddyState() );
enhancer.enhance( SimpleEntity.class.getName(),
ByteCodeHelper.readByteCode( SimpleEntity.class.getClassLoader()
.getResourceAsStream( SimpleEntity.class.getName().replace( '.', '/' ) + ".class" ) ) );
}
}

This file was deleted.

This file was deleted.

Loading
Loading