HHH-10280 - Remove legacy bytecode enhancement artifacts

This commit is contained in:
Steve Ebersole 2015-11-12 20:33:38 -06:00
parent 472f4ab9ef
commit 63b4f69deb
6 changed files with 173 additions and 229 deletions

View File

@ -27,6 +27,7 @@ import org.hibernate.test.bytecode.enhancement.lazy.LazyLoadingIntegrationTestTa
import org.hibernate.test.bytecode.enhancement.lazy.LazyLoadingTestTask;
import org.hibernate.test.bytecode.enhancement.lazy.basic.LazyBasicFieldAccessTestTask;
import org.hibernate.test.bytecode.enhancement.lazy.basic.LazyBasicPropertyAccessTestTask;
import org.hibernate.test.bytecode.enhancement.lazyCache.InitFromCacheTestTask;
import org.hibernate.test.bytecode.enhancement.merge.CompositeMergeTestTask;
import org.hibernate.test.bytecode.enhancement.pk.EmbeddedPKTestTask;
import org.hibernate.test.bytecode.enhancement.ondemandload.LazyCollectionWithClearedSessionTestTask;
@ -123,4 +124,9 @@ public class EnhancerTest extends BaseUnitTestCase {
public void testLazyBasicFieldNotInitialized() {
EnhancerTestUtils.runEnhancerTestTask( LazyBasicFieldNotInitializedTestTask.class );
}
@Test
public void testInitFromCache() {
EnhancerTestUtils.runEnhancerTestTask( InitFromCacheTestTask.class );
}
}

View File

@ -0,0 +1,54 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.bytecode.enhancement.lazyCache;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.testing.bytecode.enhancement.EnhancerTestTask;
/**
* @author Steve Ebersole
*/
public abstract class AbstractCachingTestTask implements EnhancerTestTask {
private SessionFactoryImplementor sessionFactory;
protected SessionFactoryImplementor sessionFactory() {
return sessionFactory;
}
@Override
public Class<?>[] getAnnotatedClasses() {
return new Class[] { Document.class };
}
@Override
public void prepare() {
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
registryBuilder.applySetting( AvailableSettings.GENERATE_STATISTICS, "true" );
registryBuilder.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
registryBuilder.addService( ClassLoaderService.class, new ClassLoaderServiceImpl( Thread.currentThread().getContextClassLoader() ) );
StandardServiceRegistry registry = registryBuilder.build();
MetadataSources metadataSources = new MetadataSources( registry );
metadataSources.addAnnotatedClass( Document.class );
sessionFactory = (SessionFactoryImplementor) metadataSources.buildMetadata().buildSessionFactory();
}
@Override
public void complete() {
if ( sessionFactory != null ) {
sessionFactory.close();
}
}
}

View File

@ -4,104 +4,102 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.bytecode.enhancement.lazyCache;
//$Id: Document.java 7772 2005-08-05 23:03:46Z oneovthafew $
package org.hibernate.test.lazycache;
import java.util.Date;
import java.util.Locale;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Formula;
/**
* @author Gavin King
*/
@Entity
@Cacheable
@Cache( usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, include = "non-lazy", region = "foo" )
public class Document {
@Id
@GeneratedValue
private Long id;
private String name;
@Basic( fetch = FetchType.LAZY )
@Formula( "upper(name)" )
private String upperCaseName;
@Basic( fetch = FetchType.LAZY )
private String summary;
@Basic( fetch = FetchType.LAZY )
private String text;
@Basic( fetch = FetchType.LAZY )
private Date lastTextModification;
Document() {
}
public Document(String name, String summary, String text) {
lastTextModification = new Date();
this.lastTextModification = new Date();
this.name = name;
upperCaseName = name.toUpperCase(Locale.ROOT);
this.upperCaseName = name.toUpperCase( Locale.ROOT );
this.summary = summary;
this.text = text;
}
Document() {}
public Date getLastTextModification() {
return lastTextModification;
}
/**
* @return Returns the id.
*/
public Long getId() {
return id;
}
/**
* @param id The id to set.
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return Returns the name.
*/
public String getName() {
return name;
}
/**
* @param name The name to set.
*/
public void setName(String name) {
this.name = name;
}
/**
* @return Returns the summary.
*/
public String getSummary() {
return summary;
}
/**
* @param summary The summary to set.
*/
public void setSummary(String summary) {
this.summary = summary;
}
/**
* @return Returns the text.
*/
public String getText() {
return text;
}
/**
* @param text The text to set.
*/
private void setText(String text) {
this.text = text;
}
/**
* @return Returns the upperCaseName.
*/
public String getUpperCaseName() {
return upperCaseName;
}
/**
* @param upperCaseName The upperCaseName to set.
*/
public void setUpperCaseName(String upperCaseName) {
this.upperCaseName = upperCaseName;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getText() {
return text;
}
private void setText(String text) {
this.text = text;
}
public void updateText(String newText) {
if ( !newText.equals(text) ) {
this.text = newText;
lastTextModification = new Date();
}
}
public Date getLastTextModification() {
return lastTextModification;
}
}

View File

@ -0,0 +1,61 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.bytecode.enhancement.lazyCache;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Steve Ebersole
*/
public class InitFromCacheTestTask extends AbstractCachingTestTask {
@Override
public void execute() {
Session s;
Transaction tx;
s = sessionFactory().openSession();
tx = s.beginTransaction();
s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );
tx.commit();
s.close();
s = sessionFactory().openSession();
tx = s.beginTransaction();
s.createQuery("from Document fetch all properties").uniqueResult();
tx.commit();
s.close();
sessionFactory().getStatistics().clear();
s = sessionFactory().openSession();
tx = s.beginTransaction();
Document d = (Document) s.createCriteria(Document.class).uniqueResult();
assertFalse( Hibernate.isPropertyInitialized( d, "text") );
assertFalse( Hibernate.isPropertyInitialized(d, "summary") );
assertEquals( "Hibernate is....", d.getText() );
assertTrue( Hibernate.isPropertyInitialized(d, "text") );
assertTrue( Hibernate.isPropertyInitialized(d, "summary") );
tx.commit();
s.close();
assertEquals( 2, sessionFactory().getStatistics().getPrepareStatementCount() );
s = sessionFactory().openSession();
tx = s.beginTransaction();
d = s.get(Document.class, d.getId());
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
assertFalse( Hibernate.isPropertyInitialized(d, "summary") );
tx.commit();
s.close();
}
}

View File

@ -1,43 +0,0 @@
<?xml version="1.0"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!--
This mapping demonstrates
(1) use of lazy properties - this feature requires buildtime
bytecode instrumentation; we don't think this is a very
necessary feature, but provide it for completeleness; if
Hibernate encounters uninstrumented classes, lazy property
fetching will be silently disabled, to enable testing
(2) use of a formula to define a "derived property"
-->
<hibernate-mapping
package="org.hibernate.test.lazycache"
default-access="field">
<class name="Document" table="documents">
<cache usage="nonstrict-read-write" include="non-lazy" region="foo"/>
<id name="id">
<generator class="native"/>
</id>
<property name="name" not-null="true" length="50"/>
<property name="upperCaseName" formula="upper(name)" lazy="true"/>
<property name="summary" not-null="true" length="200" lazy="true"/>
<property name="text" not-null="true" length="2000" lazy="true"/>
<property name="lastTextModification" not-null="true" lazy="true" access="field"/>
</class>
</hibernate-mapping>

View File

@ -1,132 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.lazycache;
import org.junit.Test;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.testing.Skip;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Gavin King
*/
@Skip( condition = InstrumentCacheTest.SkipMatcher.class, message = "Test domain classes not instrumented" )
public class InstrumentCacheTest extends BaseCoreFunctionalTestCase {
public static class SkipMatcher implements Skip.Matcher {
@Override
public boolean isMatch() {
return ! PersistentAttributeInterceptable.class.isAssignableFrom( Document.class );
}
}
public String[] getMappings() {
return new String[] { "lazycache/Documents.hbm.xml" };
}
public void configure(Configuration cfg) {
cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
}
public boolean overrideCacheStrategy() {
return false;
}
@Test
public void testInitFromCache() {
Session s;
Transaction tx;
s = sessionFactory().openSession();
tx = s.beginTransaction();
s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );
tx.commit();
s.close();
s = sessionFactory().openSession();
tx = s.beginTransaction();
s.createQuery("from Document fetch all properties").uniqueResult();
tx.commit();
s.close();
sessionFactory().getStatistics().clear();
s = sessionFactory().openSession();
tx = s.beginTransaction();
Document d = (Document) s.createCriteria(Document.class).uniqueResult();
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
assertFalse( Hibernate.isPropertyInitialized(d, "summary") );
assertEquals( "Hibernate is....", d.getText() );
assertTrue( Hibernate.isPropertyInitialized(d, "text") );
assertTrue( Hibernate.isPropertyInitialized(d, "summary") );
tx.commit();
s.close();
assertEquals( 2, sessionFactory().getStatistics().getPrepareStatementCount() );
s = sessionFactory().openSession();
tx = s.beginTransaction();
d = (Document) s.get(Document.class, d.getId());
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
assertFalse( Hibernate.isPropertyInitialized(d, "summary") );
tx.commit();
s.close();
}
@Test
public void testInitFromCache2() {
Session s;
Transaction tx;
s = sessionFactory().openSession();
tx = s.beginTransaction();
s.persist( new Document("HiA", "Hibernate book", "Hibernate is....") );
tx.commit();
s.close();
s = sessionFactory().openSession();
tx = s.beginTransaction();
s.createQuery("from Document fetch all properties").uniqueResult();
tx.commit();
s.close();
sessionFactory().getStatistics().clear();
s = sessionFactory().openSession();
tx = s.beginTransaction();
Document d = (Document) s.createCriteria(Document.class).uniqueResult();
assertFalse( Hibernate.isPropertyInitialized(d, "text") );
assertFalse( Hibernate.isPropertyInitialized(d, "summary") );
assertEquals( "Hibernate is....", d.getText() );
assertTrue( Hibernate.isPropertyInitialized(d, "text") );
assertTrue( Hibernate.isPropertyInitialized(d, "summary") );
tx.commit();
s.close();
assertEquals( 1, sessionFactory().getStatistics().getPrepareStatementCount() );
s = sessionFactory().openSession();
tx = s.beginTransaction();
d = (Document) s.get(Document.class, d.getId());
assertTrue( Hibernate.isPropertyInitialized(d, "text") );
assertTrue( Hibernate.isPropertyInitialized(d, "summary") );
tx.commit();
s.close();
}
}