Skip to content

Commit 63b4f69

Browse files
committed
HHH-10280 - Remove legacy bytecode enhancement artifacts
1 parent 472f4ab commit 63b4f69

File tree

6 files changed

+167
-223
lines changed

6 files changed

+167
-223
lines changed

hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/EnhancerTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.hibernate.test.bytecode.enhancement.lazy.LazyLoadingTestTask;
2828
import org.hibernate.test.bytecode.enhancement.lazy.basic.LazyBasicFieldAccessTestTask;
2929
import org.hibernate.test.bytecode.enhancement.lazy.basic.LazyBasicPropertyAccessTestTask;
30+
import org.hibernate.test.bytecode.enhancement.lazyCache.InitFromCacheTestTask;
3031
import org.hibernate.test.bytecode.enhancement.merge.CompositeMergeTestTask;
3132
import org.hibernate.test.bytecode.enhancement.pk.EmbeddedPKTestTask;
3233
import org.hibernate.test.bytecode.enhancement.ondemandload.LazyCollectionWithClearedSessionTestTask;
@@ -123,4 +124,9 @@ public void testHHH3949() {
123124
public void testLazyBasicFieldNotInitialized() {
124125
EnhancerTestUtils.runEnhancerTestTask( LazyBasicFieldNotInitializedTestTask.class );
125126
}
127+
128+
@Test
129+
public void testInitFromCache() {
130+
EnhancerTestUtils.runEnhancerTestTask( InitFromCacheTestTask.class );
131+
}
126132
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.bytecode.enhancement.lazyCache;
8+
9+
import org.hibernate.boot.MetadataSources;
10+
import org.hibernate.boot.registry.StandardServiceRegistry;
11+
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
12+
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
13+
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
14+
import org.hibernate.cfg.AvailableSettings;
15+
import org.hibernate.engine.spi.SessionFactoryImplementor;
16+
17+
import org.hibernate.testing.bytecode.enhancement.EnhancerTestTask;
18+
19+
/**
20+
* @author Steve Ebersole
21+
*/
22+
public abstract class AbstractCachingTestTask implements EnhancerTestTask {
23+
private SessionFactoryImplementor sessionFactory;
24+
25+
protected SessionFactoryImplementor sessionFactory() {
26+
return sessionFactory;
27+
}
28+
29+
@Override
30+
public Class<?>[] getAnnotatedClasses() {
31+
return new Class[] { Document.class };
32+
}
33+
34+
@Override
35+
public void prepare() {
36+
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
37+
registryBuilder.applySetting( AvailableSettings.GENERATE_STATISTICS, "true" );
38+
registryBuilder.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
39+
registryBuilder.addService( ClassLoaderService.class, new ClassLoaderServiceImpl( Thread.currentThread().getContextClassLoader() ) );
40+
StandardServiceRegistry registry = registryBuilder.build();
41+
42+
MetadataSources metadataSources = new MetadataSources( registry );
43+
metadataSources.addAnnotatedClass( Document.class );
44+
45+
sessionFactory = (SessionFactoryImplementor) metadataSources.buildMetadata().buildSessionFactory();
46+
}
47+
48+
@Override
49+
public void complete() {
50+
if ( sessionFactory != null ) {
51+
sessionFactory.close();
52+
}
53+
}
54+
}

hibernate-core/src/test/java/org/hibernate/test/lazycache/Document.java renamed to hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazyCache/Document.java

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,104 +4,102 @@
44
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
55
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
66
*/
7+
package org.hibernate.test.bytecode.enhancement.lazyCache;
78

8-
//$Id: Document.java 7772 2005-08-05 23:03:46Z oneovthafew $
9-
package org.hibernate.test.lazycache;
109
import java.util.Date;
1110
import java.util.Locale;
11+
import javax.persistence.Basic;
12+
import javax.persistence.Cacheable;
13+
import javax.persistence.Entity;
14+
import javax.persistence.FetchType;
15+
import javax.persistence.GeneratedValue;
16+
import javax.persistence.Id;
17+
18+
import org.hibernate.annotations.Cache;
19+
import org.hibernate.annotations.CacheConcurrencyStrategy;
20+
import org.hibernate.annotations.Formula;
1221

1322
/**
1423
* @author Gavin King
1524
*/
25+
@Entity
26+
@Cacheable
27+
@Cache( usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, include = "non-lazy", region = "foo" )
1628
public class Document {
17-
29+
@Id
30+
@GeneratedValue
1831
private Long id;
1932
private String name;
33+
@Basic( fetch = FetchType.LAZY )
34+
@Formula( "upper(name)" )
2035
private String upperCaseName;
36+
@Basic( fetch = FetchType.LAZY )
2137
private String summary;
38+
@Basic( fetch = FetchType.LAZY )
2239
private String text;
40+
@Basic( fetch = FetchType.LAZY )
2341
private Date lastTextModification;
42+
43+
Document() {
44+
}
2445

2546
public Document(String name, String summary, String text) {
26-
lastTextModification = new Date();
47+
this.lastTextModification = new Date();
2748
this.name = name;
28-
upperCaseName = name.toUpperCase(Locale.ROOT);
49+
this.upperCaseName = name.toUpperCase( Locale.ROOT );
2950
this.summary = summary;
3051
this.text = text;
3152
}
32-
33-
Document() {}
34-
35-
public Date getLastTextModification() {
36-
return lastTextModification;
37-
}
3853

39-
/**
40-
* @return Returns the id.
41-
*/
4254
public Long getId() {
4355
return id;
4456
}
45-
/**
46-
* @param id The id to set.
47-
*/
57+
4858
public void setId(Long id) {
4959
this.id = id;
5060
}
51-
/**
52-
* @return Returns the name.
53-
*/
61+
5462
public String getName() {
5563
return name;
5664
}
57-
/**
58-
* @param name The name to set.
59-
*/
65+
6066
public void setName(String name) {
6167
this.name = name;
6268
}
63-
/**
64-
* @return Returns the summary.
65-
*/
69+
70+
public String getUpperCaseName() {
71+
return upperCaseName;
72+
}
73+
74+
public void setUpperCaseName(String upperCaseName) {
75+
this.upperCaseName = upperCaseName;
76+
}
77+
6678
public String getSummary() {
6779
return summary;
6880
}
69-
/**
70-
* @param summary The summary to set.
71-
*/
81+
7282
public void setSummary(String summary) {
7383
this.summary = summary;
7484
}
75-
/**
76-
* @return Returns the text.
77-
*/
85+
7886
public String getText() {
7987
return text;
8088
}
81-
/**
82-
* @param text The text to set.
83-
*/
89+
8490
private void setText(String text) {
8591
this.text = text;
8692
}
87-
/**
88-
* @return Returns the upperCaseName.
89-
*/
90-
public String getUpperCaseName() {
91-
return upperCaseName;
92-
}
93-
/**
94-
* @param upperCaseName The upperCaseName to set.
95-
*/
96-
public void setUpperCaseName(String upperCaseName) {
97-
this.upperCaseName = upperCaseName;
98-
}
99-
93+
10094
public void updateText(String newText) {
10195
if ( !newText.equals(text) ) {
10296
this.text = newText;
10397
lastTextModification = new Date();
10498
}
10599
}
100+
101+
public Date getLastTextModification() {
102+
return lastTextModification;
103+
}
106104

107105
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.bytecode.enhancement.lazyCache;
8+
9+
import org.hibernate.Hibernate;
10+
import org.hibernate.Session;
11+
import org.hibernate.Transaction;
12+
13+
import static org.junit.Assert.assertEquals;
14+
import static org.junit.Assert.assertFalse;
15+
import static org.junit.Assert.assertTrue;
16+
17+
/**
18+
* @author Steve Ebersole
19+
*/
20+
public class InitFromCacheTestTask extends AbstractCachingTestTask {
21+
@Override
22+
public void execute() {
23+
Session s;
24+
Transaction tx;
25+
26+
s = sessionFactory().openSession();
27+
tx = s.beginTransaction();
28+
s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );
29+
tx.commit();
30+
s.close();
31+
32+
s = sessionFactory().openSession();
33+
tx = s.beginTransaction();
34+
s.createQuery("from Document fetch all properties").uniqueResult();
35+
tx.commit();
36+
s.close();
37+
38+
sessionFactory().getStatistics().clear();
39+
40+
s = sessionFactory().openSession();
41+
tx = s.beginTransaction();
42+
Document d = (Document) s.createCriteria(Document.class).uniqueResult();
43+
assertFalse( Hibernate.isPropertyInitialized( d, "text") );
44+
assertFalse( Hibernate.isPropertyInitialized(d, "summary") );
45+
assertEquals( "Hibernate is....", d.getText() );
46+
assertTrue( Hibernate.isPropertyInitialized(d, "text") );
47+
assertTrue( Hibernate.isPropertyInitialized(d, "summary") );
48+
tx.commit();
49+
s.close();
50+
51+
assertEquals( 2, sessionFactory().getStatistics().getPrepareStatementCount() );
52+
53+
s = sessionFactory().openSession();
54+
tx = s.beginTransaction();
55+
d = s.get(Document.class, d.getId());
56+
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
57+
assertFalse( Hibernate.isPropertyInitialized(d, "summary") );
58+
tx.commit();
59+
s.close();
60+
}
61+
}

hibernate-core/src/test/java/org/hibernate/test/lazycache/Documents.hbm.xml

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)