Hibernate SVN: r20740 - in core/trunk: core/src/main/java/org/hibernate/cfg and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-09-28 12:28:30 -0400 (Tue, 28 Sep 2010)
New Revision: 20740
Added:
core/trunk/core/src/main/java/org/hibernate/annotations/Source.java
core/trunk/core/src/main/java/org/hibernate/annotations/SourceType.java
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/DBTimestamped.java
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/TimestampTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/VMTimestamped.java
Modified:
core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/core/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java
Log:
HHH-5205 - Added @Source and emum SourceType, fixed implementation and added a test
Copied: core/trunk/core/src/main/java/org/hibernate/annotations/Source.java (from rev 20735, core/trunk/core/src/main/java/org/hibernate/annotations/AccessType.java)
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/annotations/Source.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/annotations/Source.java 2010-09-28 16:28:30 UTC (rev 20740)
@@ -0,0 +1,44 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Optional annotation in conjunction with {@link javax.persistence.Version} and timestamp version properties.
+ * The annotation value decides where the timestamp is generated.
+ *
+ * @author Hardy Ferentschik
+ */
+@Target({ METHOD, FIELD })
+@Retention(RUNTIME)
+public @interface Source {
+ SourceType value() default SourceType.VM;
+}
Property changes on: core/trunk/core/src/main/java/org/hibernate/annotations/Source.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: core/trunk/core/src/main/java/org/hibernate/annotations/SourceType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/annotations/SourceType.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/annotations/SourceType.java 2010-09-28 16:28:30 UTC (rev 20740)
@@ -0,0 +1,53 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+package org.hibernate.annotations;
+
+/**
+ * Where should Hibernate retrieve the value from? From the database, or from the current JVM?
+ *
+ * @author Hardy Ferentschik
+ */
+public enum SourceType {
+ /**
+ * Get the timestamp from the current VM.
+ * @see
+ */
+ VM("timestamp"),
+
+ /**
+ * Get the timestamp from the database.
+ */
+ DB("dbtimestamp");
+
+ private final String typeName;
+
+ SourceType(String typeName ) {
+ this.typeName = typeName;
+ }
+
+ public String typeName() {
+ return typeName;
+ }
+}
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-09-28 14:14:23 UTC (rev 20739)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-09-28 16:28:30 UTC (rev 20740)
@@ -124,6 +124,7 @@
import org.hibernate.annotations.Parent;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Sort;
+import org.hibernate.annotations.Source;
import org.hibernate.annotations.Tuplizer;
import org.hibernate.annotations.Tuplizers;
import org.hibernate.annotations.TypeDef;
@@ -372,26 +373,26 @@
idGen.setIdentifierGeneratorStrategy( org.hibernate.id.enhanced.TableGenerator.class.getName() );
idGen.addParam( org.hibernate.id.enhanced.TableGenerator.CONFIG_PREFER_SEGMENT_PER_ENTITY, "true" );
- if ( !BinderHelper.isDefault( tabGen.catalog() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( tabGen.catalog() ) ) {
idGen.addParam( org.hibernate.id.enhanced.TableGenerator.CATALOG, tabGen.catalog() );
}
- if ( !BinderHelper.isDefault( tabGen.schema() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( tabGen.schema() ) ) {
idGen.addParam( org.hibernate.id.enhanced.TableGenerator.SCHEMA, tabGen.schema() );
}
- if ( !BinderHelper.isDefault( tabGen.table() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( tabGen.table() ) ) {
idGen.addParam( org.hibernate.id.enhanced.TableGenerator.TABLE_PARAM, tabGen.table() );
}
- if ( !BinderHelper.isDefault( tabGen.pkColumnName() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( tabGen.pkColumnName() ) ) {
idGen.addParam(
org.hibernate.id.enhanced.TableGenerator.SEGMENT_COLUMN_PARAM, tabGen.pkColumnName()
);
}
- if ( !BinderHelper.isDefault( tabGen.pkColumnValue() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( tabGen.pkColumnValue() ) ) {
idGen.addParam(
org.hibernate.id.enhanced.TableGenerator.SEGMENT_VALUE_PARAM, tabGen.pkColumnValue()
);
}
- if ( !BinderHelper.isDefault( tabGen.valueColumnName() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( tabGen.valueColumnName() ) ) {
idGen.addParam(
org.hibernate.id.enhanced.TableGenerator.VALUE_COLUMN_PARAM, tabGen.valueColumnName()
);
@@ -412,13 +413,13 @@
else {
idGen.setIdentifierGeneratorStrategy( MultipleHiLoPerTableGenerator.class.getName() );
- if ( !BinderHelper.isDefault( tabGen.table() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( tabGen.table() ) ) {
idGen.addParam( MultipleHiLoPerTableGenerator.ID_TABLE, tabGen.table() );
}
- if ( !BinderHelper.isDefault( tabGen.catalog() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( tabGen.catalog() ) ) {
idGen.addParam( MultipleHiLoPerTableGenerator.CATALOG, tabGen.catalog() );
}
- if ( !BinderHelper.isDefault( tabGen.schema() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( tabGen.schema() ) ) {
idGen.addParam( MultipleHiLoPerTableGenerator.SCHEMA, tabGen.schema() );
}
//FIXME implement uniqueconstrains
@@ -426,13 +427,13 @@
log.warn( "Ignoring unique constraints specified on table generator [{}]", tabGen.name() );
}
- if ( !BinderHelper.isDefault( tabGen.pkColumnName() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( tabGen.pkColumnName() ) ) {
idGen.addParam( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, tabGen.pkColumnName() );
}
- if ( !BinderHelper.isDefault( tabGen.valueColumnName() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( tabGen.valueColumnName() ) ) {
idGen.addParam( MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, tabGen.valueColumnName() );
}
- if ( !BinderHelper.isDefault( tabGen.pkColumnValue() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( tabGen.pkColumnValue() ) ) {
idGen.addParam( MultipleHiLoPerTableGenerator.PK_VALUE_NAME, tabGen.pkColumnValue() );
}
idGen.addParam( TableHiLoGenerator.MAX_LO, String.valueOf( tabGen.allocationSize() - 1 ) );
@@ -445,13 +446,13 @@
if ( useNewGeneratorMappings ) {
idGen.setIdentifierGeneratorStrategy( SequenceStyleGenerator.class.getName() );
- if ( !BinderHelper.isDefault( seqGen.catalog() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( seqGen.catalog() ) ) {
idGen.addParam( SequenceStyleGenerator.CATALOG, seqGen.catalog() );
}
- if ( !BinderHelper.isDefault( seqGen.schema() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( seqGen.schema() ) ) {
idGen.addParam( SequenceStyleGenerator.SCHEMA, seqGen.schema() );
}
- if ( !BinderHelper.isDefault( seqGen.sequenceName() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( seqGen.sequenceName() ) ) {
idGen.addParam( SequenceStyleGenerator.SEQUENCE_PARAM, seqGen.sequenceName() );
}
idGen.addParam( SequenceStyleGenerator.INCREMENT_PARAM, String.valueOf( seqGen.allocationSize() ) );
@@ -460,7 +461,7 @@
else {
idGen.setIdentifierGeneratorStrategy( "seqhilo" );
- if ( !BinderHelper.isDefault( seqGen.sequenceName() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( seqGen.sequenceName() ) ) {
idGen.addParam( org.hibernate.id.SequenceGenerator.SEQUENCE, seqGen.sequenceName() );
}
//FIXME: work on initialValue() through SequenceGenerator.PARAMETERS
@@ -658,7 +659,7 @@
SimpleValue key = new DependantValue( mappings, jsc.getTable(), jsc.getIdentifier() );
jsc.setKey( key );
ForeignKey fk = clazzToProcess.getAnnotation( ForeignKey.class );
- if ( fk != null && !BinderHelper.isDefault( fk.name() ) ) {
+ if ( fk != null && !BinderHelper.isEmptyAnnotationValue( fk.name() ) ) {
key.setForeignKeyName( fk.name() );
}
if ( onDeleteAnn != null ) {
@@ -1302,14 +1303,14 @@
params.setProperty( param.name(), param.value() );
}
- if ( BinderHelper.isDefault( defAnn.name() ) && defAnn.defaultForType().equals( void.class ) ) {
+ if ( BinderHelper.isEmptyAnnotationValue( defAnn.name() ) && defAnn.defaultForType().equals( void.class ) ) {
throw new AnnotationException(
"Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass " +
defAnn.typeClass().getName()
);
}
- if ( !BinderHelper.isDefault( defAnn.name() ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( defAnn.name() ) ) {
log.info( "Binding type definition: {}", defAnn.name() );
mappings.addTypeDef( defAnn.name(), defAnn.typeClass().getName(), params );
}
@@ -1501,7 +1502,7 @@
RootClass rootClass = ( RootClass ) propertyHolder.getPersistentClass();
propertyBinder.setColumns( columns );
Property prop = propertyBinder.makePropertyValueAndBind();
- propertyBinder.getSimpleValueBinder().setVersion( true );
+ setVersionInformation( property, propertyBinder );
rootClass.setVersion( prop );
//If version is on a mapped superclass, update the mapping
@@ -2088,6 +2089,14 @@
}
}
+ private static void setVersionInformation(XProperty property, PropertyBinder propertyBinder) {
+ propertyBinder.getSimpleValueBinder().setVersion( true );
+ if(property.isAnnotationPresent( Source.class )) {
+ Source source = property.getAnnotation( Source.class );
+ propertyBinder.getSimpleValueBinder().setTimestampVersionType( source.value().typeName() );
+ }
+ }
+
private static void processId(
PropertyHolder propertyHolder,
PropertyData inferredData,
@@ -2174,13 +2183,13 @@
collectionBinder.setExplicitAssociationTable( true );
- if ( !BinderHelper.isDefault( schema ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( schema ) ) {
associationTableBinder.setSchema( schema );
}
- if ( !BinderHelper.isDefault( catalog ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( catalog ) ) {
associationTableBinder.setCatalog( catalog );
}
- if ( !BinderHelper.isDefault( tableName ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( tableName ) ) {
associationTableBinder.setName( tableName );
}
associationTableBinder.setUniqueConstraints( uniqueConstraints );
@@ -2605,7 +2614,7 @@
String fkName = fk != null ?
fk.name() :
"";
- if ( !BinderHelper.isDefault( fkName ) ) {
+ if ( !BinderHelper.isEmptyAnnotationValue( fkName ) ) {
value.setForeignKeyName( fkName );
}
@@ -2739,7 +2748,7 @@
}
}
}
- if ( trueOneToOne || mapToPK || !BinderHelper.isDefault( mappedBy ) ) {
+ if ( trueOneToOne || mapToPK || !BinderHelper.isEmptyAnnotationValue( mappedBy ) ) {
//is a true one-to-one
//FIXME referencedColumnName ignored => ordering may fail.
OneToOneSecondPass secondPass = new OneToOneSecondPass(
@@ -2754,7 +2763,7 @@
}
else {
mappings.addSecondPass(
- secondPass, BinderHelper.isDefault( mappedBy )
+ secondPass, BinderHelper.isEmptyAnnotationValue( mappedBy )
);
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java 2010-09-28 14:14:23 UTC (rev 20739)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java 2010-09-28 16:28:30 UTC (rev 20740)
@@ -76,6 +76,7 @@
private Table table;
private SimpleValue simpleValue;
private boolean isVersion;
+ private String timeStampVersionType;
//is a Map key
private boolean key;
private String referencedEntityName;
@@ -92,6 +93,10 @@
this.isVersion = isVersion;
}
+ public void setTimestampVersionType(String versionType) {
+ this.timeStampVersionType = versionType;
+ }
+
public void setPropertyName(String propertyName) {
this.propertyName = propertyName;
}
@@ -114,8 +119,11 @@
}
//TODO execute it lazily to be order safe
+
public void setType(XProperty property, XClass returnedClass) {
- if ( returnedClass == null ) return; //we cannot guess anything
+ if ( returnedClass == null ) {
+ return;
+ } //we cannot guess anything
XClass returnedClassOrElement = returnedClass;
boolean isArray = false;
if ( property.isArray() ) {
@@ -125,8 +133,8 @@
Properties typeParameters = this.typeParameters;
typeParameters.clear();
String type = BinderHelper.ANNOTATION_STRING_DEFAULT;
- if ( (!key && property.isAnnotationPresent( Temporal.class ) )
- || (key && property.isAnnotationPresent( MapKeyTemporal.class ) )) {
+ if ( ( !key && property.isAnnotationPresent( Temporal.class ) )
+ || ( key && property.isAnnotationPresent( MapKeyTemporal.class ) ) ) {
boolean isDate;
if ( mappings.getReflectionManager().equals( returnedClassOrElement, Date.class ) ) {
@@ -154,7 +162,8 @@
+ StringHelper.qualify( persistentClassName, propertyName )
);
}
- break; case TIMESTAMP:
+ break;
+ case TIMESTAMP:
type = isDate ? "timestamp" : "calendar";
break;
default:
@@ -237,7 +246,7 @@
private javax.persistence.EnumType getEnumType(XProperty property) {
javax.persistence.EnumType enumType = null;
- if (key) {
+ if ( key ) {
MapKeyEnumerated enumAnn = property.getAnnotation( MapKeyEnumerated.class );
if ( enumAnn != null ) {
enumType = enumAnn.value();
@@ -253,7 +262,7 @@
}
private TemporalType getTemporalType(XProperty property) {
- if (key) {
+ if ( key ) {
MapKeyTemporal ann = property.getAnnotation( MapKeyTemporal.class );
return ann.value();
}
@@ -266,13 +275,14 @@
public void setExplicitType(String explicitType) {
this.explicitType = explicitType;
}
-
+
//FIXME raise an assertion failure if setExplicitType(String) and setExplicitType(Type) are use at the same time
+
public void setExplicitType(Type typeAnn) {
if ( typeAnn != null ) {
explicitType = typeAnn.type();
typeParameters.clear();
- for (Parameter param : typeAnn.parameters()) {
+ for ( Parameter param : typeAnn.parameters() ) {
typeParameters.setProperty( param.name(), param.value() );
}
}
@@ -288,7 +298,7 @@
}
public SimpleValue make() {
-
+
validate();
log.debug( "building SimpleValue for {}", propertyName );
if ( table == null ) {
@@ -299,10 +309,10 @@
linkWithValue();
boolean isInSecondPass = mappings.isInSecondPass();
- SetSimpleValueTypeSecondPass secondPass = new SetSimpleValueTypeSecondPass(this);
- if (!isInSecondPass) {
+ SetSimpleValueTypeSecondPass secondPass = new SetSimpleValueTypeSecondPass( this );
+ if ( !isInSecondPass ) {
//Defer this to the second pass
- mappings.addSecondPass(secondPass);
+ mappings.addSecondPass( secondPass );
}
else {
//We are already in second pass
@@ -312,23 +322,25 @@
}
public void linkWithValue() {
- if ( columns[0].isNameDeferred() && ! mappings.isInSecondPass() && referencedEntityName != null) {
+ if ( columns[0].isNameDeferred() && !mappings.isInSecondPass() && referencedEntityName != null ) {
mappings.addSecondPass(
- new PkDrivenByDefaultMapsIdSecondPass( referencedEntityName, ( Ejb3JoinColumn[]) columns, simpleValue)
+ new PkDrivenByDefaultMapsIdSecondPass(
+ referencedEntityName, ( Ejb3JoinColumn[] ) columns, simpleValue
+ )
);
}
else {
- for ( Ejb3Column column : columns) {
+ for ( Ejb3Column column : columns ) {
column.linkWithValue( simpleValue );
}
}
}
public void fillSimpleValue() {
-
- log.debug( "setting SimpleValue typeName for {}", propertyName );
-
- String type = BinderHelper.isDefault( explicitType ) ? returnedClassName : explicitType;
+
+ log.debug( "Setting SimpleValue typeName for {}", propertyName );
+
+ String type = BinderHelper.isEmptyAnnotationValue( explicitType ) ? returnedClassName : explicitType;
org.hibernate.mapping.TypeDef typeDef = mappings.getTypeDef( type );
if ( typeDef != null ) {
type = typeDef.getTypeClass();
@@ -342,11 +354,15 @@
if ( persistentClassName != null ) {
simpleValue.setTypeUsingReflection( persistentClassName, propertyName );
}
-
- if ( !simpleValue.isTypeSpecified() && isVersion()) {
+
+ if ( !simpleValue.isTypeSpecified() && isVersion() ) {
simpleValue.setTypeName( "integer" );
}
-
+
+ // HHH-5205
+ if ( timeStampVersionType != null ) {
+ simpleValue.setTypeName( timeStampVersionType );
+ }
}
public void setKey(boolean key) {
Property changes on: core/trunk/core/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java
___________________________________________________________________
Name: svn:keywords
- Date Revision Author Id
+ Id
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/DBTimestamped.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/DBTimestamped.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/DBTimestamped.java 2010-09-28 16:28:30 UTC (rev 20740)
@@ -0,0 +1,67 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+// $Id:$
+package org.hibernate.test.annotations.various;
+
+import java.util.Date;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+import org.hibernate.annotations.Source;
+import org.hibernate.annotations.SourceType;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class DBTimestamped {
+ @Id
+ @GeneratedValue
+ private int id;
+
+ @Version
+ @Source(SourceType.DB)
+ private Date lastUpdate;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public Date getLastUpdate() {
+ return lastUpdate;
+ }
+
+ public void setLastUpdate(Date lastUpdate) {
+ this.lastUpdate = lastUpdate;
+ }
+}
+
+
Property changes on: core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/DBTimestamped.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/TimestampTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/TimestampTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/TimestampTest.java 2010-09-28 16:28:30 UTC (rev 20740)
@@ -0,0 +1,67 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+//$Id$
+package org.hibernate.test.annotations.various;
+
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Property;
+import org.hibernate.metadata.ClassMetadata;
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.type.DbTimestampType;
+import org.hibernate.type.TimestampType;
+
+/**
+ * Test for the @Timestamp annotation.
+ *
+ * @author Hardy Ferentschik
+ */
+public class TimestampTest extends TestCase {
+
+ public void testTimestampSourceIsVM() throws Exception {
+ assertTimestampSource( VMTimestamped.class, TimestampType.class );
+ }
+
+ public void testTimestampSourceIsDB() throws Exception {
+ assertTimestampSource( DBTimestamped.class, DbTimestampType.class );
+ }
+
+ private void assertTimestampSource(Class<?> clazz, Class<?> expectedTypeClass) throws Exception {
+ buildConfiguration();
+ ClassMetadata meta = sessions.getClassMetadata( clazz );
+ assertTrue( "Entity is annotated with @Timestamp and should hence be versioned", meta.isVersioned() );
+
+ PersistentClass persistentClass = cfg.getClassMapping( clazz.getName() );
+ assertNotNull( persistentClass );
+ Property versionProperty = persistentClass.getVersion();
+ assertNotNull( versionProperty );
+ assertEquals( "Wrong timestamp type", expectedTypeClass, versionProperty.getType().getClass() );
+ }
+
+ protected Class[] getAnnotatedClasses() {
+ return new Class[] {
+ VMTimestamped.class, DBTimestamped.class
+ };
+ }
+}
Property changes on: core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/TimestampTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/VMTimestamped.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/VMTimestamped.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/VMTimestamped.java 2010-09-28 16:28:30 UTC (rev 20740)
@@ -0,0 +1,66 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+
+// $Id:$
+package org.hibernate.test.annotations.various;
+
+import java.util.Date;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+import org.hibernate.annotations.Source;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class VMTimestamped {
+ @Id
+ @GeneratedValue
+ private int id;
+
+ @Version
+ @Source
+ private Date lastUpdate;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public Date getLastUpdate() {
+ return lastUpdate;
+ }
+
+ public void setLastUpdate(Date lastUpdate) {
+ this.lastUpdate = lastUpdate;
+ }
+}
+
+
Property changes on: core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/VMTimestamped.java
___________________________________________________________________
Name: svn:keywords
+ Id
14 years, 2 months
Hibernate SVN: r20739 - search/branches/v3_1_1_GA_CP/src/main/java/org/hibernate/search/impl.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-09-28 10:14:23 -0400 (Tue, 28 Sep 2010)
New Revision: 20739
Modified:
search/branches/v3_1_1_GA_CP/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java
Log:
JBPAPP-4895 HHH-5490 dirty data be inserted into 2L cache
Modified: search/branches/v3_1_1_GA_CP/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- search/branches/v3_1_1_GA_CP/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java 2010-09-28 10:59:36 UTC (rev 20738)
+++ search/branches/v3_1_1_GA_CP/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java 2010-09-28 14:14:23 UTC (rev 20739)
@@ -706,4 +706,13 @@
public void update(Object object) throws HibernateException {
session.update( object );
}
+
+ public void registerInsertedKey(EntityPersister persister, Serializable id) {
+ //do nothing
+ }
+
+ public boolean wasInsertedDuringTransaction(EntityPersister persister,
+ Serializable id) {
+ return false;
+ }
}
14 years, 2 months
Hibernate SVN: r20738 - in core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153: src/org/hibernate/action and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-09-28 06:59:36 -0400 (Tue, 28 Sep 2010)
New Revision: 20738
Added:
core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.hbm.xml
core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.java
core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/InsertedDataTest.java
Modified:
core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/
core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityIdentityInsertAction.java
core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityInsertAction.java
core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/SessionImplementor.java
core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/TwoPhaseLoad.java
core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/SessionImpl.java
core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/StatelessSessionImpl.java
core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
Log:
JBPAPP-5153 HHH-5490 dirty data be inserted into 2L cache
Property changes on: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153
___________________________________________________________________
Name: svn:ignore
+ .settings
build
.classpath
.project
Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityIdentityInsertAction.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityIdentityInsertAction.java 2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityIdentityInsertAction.java 2010-09-28 10:59:36 UTC (rev 20738)
@@ -52,6 +52,7 @@
//need to do that here rather than in the save event listener to let
//the post insert events to have a id-filled entity when IDENTITY is used (EJB3)
persister.setIdentifier( instance, generatedId, session.getEntityMode() );
+ getSession().registerInsertedKey( getPersister(), generatedId );
}
Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityInsertAction.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityInsertAction.java 2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityInsertAction.java 2010-09-28 10:59:36 UTC (rev 20738)
@@ -70,6 +70,8 @@
entry.postUpdate(instance, state, version);
}
+ getSession().registerInsertedKey( getPersister(), getId() );
+
}
final SessionFactoryImplementor factory = getSession().getFactory();
Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/SessionImplementor.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/SessionImplementor.java 2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/SessionImplementor.java 2010-09-28 10:59:36 UTC (rev 20738)
@@ -299,4 +299,23 @@
* @return True if the session is closed; false otherwise.
*/
public boolean isClosed();
+
+ /**
+ * Register keys inserted during the current transaction
+ *
+ * @param persister The entity persister
+ * @param id The id
+ */
+ public void registerInsertedKey(EntityPersister persister, Serializable id);
+
+ /**
+ * Allows callers to check to see if the identified entity was inserted during the current transaction.
+ *
+ * @param persister The entity persister
+ * @param id The id
+ *
+ * @return True if inserted during this transaction, false otherwise.
+ */
+ public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id);
+
}
Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/TwoPhaseLoad.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/TwoPhaseLoad.java 2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/TwoPhaseLoad.java 2010-09-28 10:59:36 UTC (rev 20738)
@@ -153,19 +153,27 @@
session.getEntityMode(),
session.getFactory()
);
- boolean put = persister.getCache().put(
- cacheKey,
- persister.getCacheEntryStructure().structure(entry),
- session.getTimestamp(),
- version,
- persister.isVersioned() ?
- persister.getVersionType().getComparator() :
- null,
- useMinimalPuts(session, entityEntry)
- ); //we could use persister.hasLazyProperties() instead of true
-
- if ( put && factory.getStatistics().isStatisticsEnabled() ) {
- factory.getStatisticsImplementor().secondLevelCachePut( persister.getCache().getRegionName() );
+ if (session.wasInsertedDuringTransaction(persister, id)) {
+ persister.getCache().update(cacheKey,
+ persister.getCacheEntryStructure().structure(entry),
+ version, version);
+ } else {
+ boolean put = persister.getCache().put(
+ cacheKey,
+ persister.getCacheEntryStructure().structure(entry),
+ session.getTimestamp(),
+ version,
+ persister.isVersioned() ? persister.getVersionType()
+ .getComparator() : null,
+ useMinimalPuts(session, entityEntry)); // we could use
+ // persister.hasLazyProperties()
+ // instead of
+ // true
+
+ if (put && factory.getStatistics().isStatisticsEnabled()) {
+ factory.getStatisticsImplementor().secondLevelCachePut(
+ persister.getCache().getRegionName());
+ }
}
}
Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/SessionImpl.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/SessionImpl.java 2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/SessionImpl.java 2010-09-28 10:59:36 UTC (rev 20738)
@@ -6,6 +6,7 @@
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.sql.Connection;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -420,6 +421,7 @@
public void afterTransactionCompletion(boolean success, Transaction tx) {
log.trace( "after transaction completion" );
+ cleanUpInsertedKeysAfterTransaction();
persistenceContext.afterTransactionCompletion();
actionQueue.afterTransactionCompletion(success);
if ( rootSession == null && tx != null ) {
@@ -1020,7 +1022,48 @@
flush();
}
+ private HashMap insertedKeysMap;
+ /**
+ * {@inheritDoc}
+ */
+ public void registerInsertedKey(EntityPersister persister, Serializable id) {
+ // we only are about registering these if the persister defines caching
+ if ( persister.hasCache() ) {
+ if ( insertedKeysMap == null ) {
+ insertedKeysMap = new HashMap();
+ }
+ final String rootEntityName = persister.getRootEntityName();
+ List insertedEntityIds = (List)insertedKeysMap.get( rootEntityName );
+ if ( insertedEntityIds == null ) {
+ insertedEntityIds = new ArrayList();
+ insertedKeysMap.put( rootEntityName, insertedEntityIds );
+ }
+ insertedEntityIds.add( id );
+ }
+ }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id) {
+ // again, we only really care if the entity is cached
+ if ( persister.hasCache() ) {
+ if ( insertedKeysMap != null ) {
+ List insertedEntityIds = (List)insertedKeysMap.get( persister.getRootEntityName() );
+ if ( insertedEntityIds != null ) {
+ return insertedEntityIds.contains( id );
+ }
+ }
+ }
+ return false;
+ }
+
+ private void cleanUpInsertedKeysAfterTransaction() {
+ if ( insertedKeysMap != null ) {
+ insertedKeysMap.clear();
+ }
+ }
+
public Filter getEnabledFilter(String filterName) {
checkTransactionSynchStatus();
return (Filter) enabledFilters.get(filterName);
Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/StatelessSessionImpl.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/StatelessSessionImpl.java 2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/StatelessSessionImpl.java 2010-09-28 10:59:36 UTC (rev 20738)
@@ -627,4 +627,17 @@
return result;
}
+
+ public void registerInsertedKey(EntityPersister persister, Serializable id) {
+ // nothing to do
+
+ }
+
+
+ public boolean wasInsertedDuringTransaction(EntityPersister persister,
+ Serializable id) {
+ // not in any meaning we need to worry about here.
+ return false;
+ }
+
}
Added: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.hbm.xml
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.hbm.xml (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.hbm.xml 2010-09-28 10:59:36 UTC (rev 20738)
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Inc.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.cache">
+
+ <class name="CacheableItem">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" type="string" />
+ </class>
+
+</hibernate-mapping>
Added: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.java 2010-09-28 10:59:36 UTC (rev 20738)
@@ -0,0 +1,57 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class CacheableItem {
+ private Long id;
+ private String name;
+
+ public CacheableItem() {
+ }
+
+ public CacheableItem(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/InsertedDataTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/InsertedDataTest.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/InsertedDataTest.java 2010-09-28 10:59:36 UTC (rev 20738)
@@ -0,0 +1,240 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache;
+
+import java.util.Map;
+
+import org.hibernate.Session;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.junit.functional.FunctionalTestCase;
+
+/**
+ * Tests for handling of data just inserted during a transaction being read from the database
+ * and placed into cache. Initially these cases went through putFromRead which causes problems because it
+ * loses the context of that data having just been read.
+ *
+ * @author Steve Ebersole
+ */
+public class InsertedDataTest extends FunctionalTestCase {
+ private static final String REGION_NAME = CacheableItem.class.getName();
+
+ public InsertedDataTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "cache/CacheableItem.hbm.xml" };
+ }
+
+ public String getCacheConcurrencyStrategy() {
+ return "read-write";
+ }
+
+ public void configure(Configuration cfg) {
+ super.configure( cfg );
+ cfg.setProperty( Environment.CACHE_REGION_PREFIX, "" );
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
+ }
+
+ public void testInsert() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.getTransaction().commit();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 1, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertWithRollback() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.getTransaction().rollback();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 0, cacheMap.size() );
+ }
+
+ public void testInsertThenUpdate() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ item.setName( "new data" );
+ s.getTransaction().commit();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 1, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertThenUpdateThenRollback() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ item.setName( "new data" );
+ s.getTransaction().rollback();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 0, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertWithRefresh() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.refresh( item );
+ s.getTransaction().commit();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 1, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertWithRefreshThenRollback() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.refresh( item );
+ s.getTransaction().rollback();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 0, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ item = (CacheableItem) s.get( CacheableItem.class, item.getId() );
+ s.getTransaction().commit();
+ s.close();
+
+ assertNull( "it should be null", item );
+ }
+
+ public void testInsertWithClear() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.clear();
+ s.getTransaction().commit();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 1, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertWithClearThenRollback() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.clear();
+ item = (CacheableItem) s.get( CacheableItem.class, item.getId() );
+ s.getTransaction().rollback();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 0, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ item = (CacheableItem) s.get( CacheableItem.class, item.getId() );
+ s.getTransaction().commit();
+ s.close();
+
+ assertNull( "it should be null", item );
+ }
+}
Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java 2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java 2010-09-28 10:59:36 UTC (rev 20738)
@@ -26,6 +26,8 @@
}
public void testComponentPropertyRef() {
+ Session s = openSession();
+ s.beginTransaction();
Person p = new Person();
p.setIdentity( new Identity() );
Account a = new Account();
@@ -33,13 +35,13 @@
a.setOwner(p);
p.getIdentity().setName("Gavin");
p.getIdentity().setSsn("123-12-1234");
- Session s = openSession();
- Transaction tx = s.beginTransaction();
s.persist(p);
s.persist(a);
- s.flush();
- s.clear();
-
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();
assertTrue( Hibernate.isInitialized( a.getOwner() ) );
assertNotNull( a.getOwner() );
@@ -65,7 +67,7 @@
s.delete( a );
s.delete( a.getOwner() );
- tx.commit();
+ s.getTransaction().commit();
s.close();
}
}
Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java 2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java 2010-09-28 10:59:36 UTC (rev 20738)
@@ -27,6 +27,8 @@
}
public void testComponentPropertyRef() {
+ Session s = openSession();
+ s.beginTransaction();
Person p = new Person();
p.setIdentity( new Identity() );
Account a = new Account();
@@ -34,13 +36,13 @@
a.setOwner(p);
p.getIdentity().setName("Gavin");
p.getIdentity().setSsn("123-12-1234");
- Session s = openSession();
- Transaction tx = s.beginTransaction();
s.persist(p);
s.persist(a);
- s.flush();
- s.clear();
+ s.getTransaction().commit();
+ s.close();
+ s = openSession();
+ s.beginTransaction();
a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();
assertTrue( Hibernate.isInitialized( a.getOwner() ) );
assertNotNull( a.getOwner() );
@@ -66,7 +68,7 @@
s.delete( a );
s.delete( a.getOwner() );
- tx.commit();
+ s.getTransaction().commit();
s.close();
}
}
14 years, 2 months
Hibernate SVN: r20737 - in core/branches/Branch_3_3_2_GA_CP: core/src/main/java/org/hibernate/engine and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-09-28 06:55:32 -0400 (Tue, 28 Sep 2010)
New Revision: 20737
Added:
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/cache/
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.hbm.xml
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/cache/InsertedDataTest.java
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/action/EntityInsertAction.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/SessionImplementor.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionImpl.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
Log:
JBPAPP-4895 HHH-5490 dirty data be inserted into 2L cache
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java 2010-09-28 10:52:55 UTC (rev 20736)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java 2010-09-28 10:55:32 UTC (rev 20737)
@@ -75,6 +75,7 @@
//need to do that here rather than in the save event listener to let
//the post insert events to have a id-filled entity when IDENTITY is used (EJB3)
persister.setIdentifier( instance, generatedId, session.getEntityMode() );
+ getSession().registerInsertedKey( getPersister(), generatedId );
}
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/action/EntityInsertAction.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/action/EntityInsertAction.java 2010-09-28 10:52:55 UTC (rev 20736)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/action/EntityInsertAction.java 2010-09-28 10:55:32 UTC (rev 20737)
@@ -92,7 +92,7 @@
}
entry.postUpdate(instance, state, version);
}
-
+ getSession().registerInsertedKey( getPersister(), getId() );
}
final SessionFactoryImplementor factory = getSession().getFactory();
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/SessionImplementor.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/SessionImplementor.java 2010-09-28 10:52:55 UTC (rev 20736)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/SessionImplementor.java 2010-09-28 10:55:32 UTC (rev 20737)
@@ -314,7 +314,7 @@
public JDBCContext getJDBCContext();
/**
- * Determine whether the session is closed. Provided seperately from
+ * Determine whether the session is closed. Provided separately from
* {@link #isOpen()} as this method does not attempt any JTA synch
* registration, where as {@link #isOpen()} does; which makes this one
* nicer to use for most internal purposes.
@@ -322,4 +322,21 @@
* @return True if the session is closed; false otherwise.
*/
public boolean isClosed();
+
+ /**
+ * Register keys inserted during the current transaction
+ *
+ * @param persister The entity persister
+ * @param id The id
+ */
+ public void registerInsertedKey(EntityPersister persister, Serializable id);
+
+ /**
+ * Allows callers to check to see if the identified entity was inserted during the current transaction.
+ *
+ * @param persister The entity persister
+ * @param id The id
+ * @return True if inserted during this transaction, false otherwise.
+ */
+ public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id);
}
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java 2010-09-28 10:52:55 UTC (rev 20736)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java 2010-09-28 10:55:32 UTC (rev 20737)
@@ -176,17 +176,22 @@
session.getEntityMode(),
session.getFactory()
);
- boolean put = persister.getCacheAccessStrategy().putFromLoad(
- cacheKey,
- persister.getCacheEntryStructure().structure( entry ),
- session.getTimestamp(),
- version,
- useMinimalPuts( session, entityEntry )
- );
+ if ( session.wasInsertedDuringTransaction( persister, id ) ) {
+ persister.getCacheAccessStrategy().update(cacheKey, persister.getCacheEntryStructure().structure(entry),version,version);
+ } else{
+ boolean put = persister.getCacheAccessStrategy().putFromLoad(
+ cacheKey,
+ persister.getCacheEntryStructure().structure( entry ),
+ session.getTimestamp(),
+ version,
+ useMinimalPuts( session, entityEntry )
+ );
- if ( put && factory.getStatistics().isStatisticsEnabled() ) {
- factory.getStatisticsImplementor().secondLevelCachePut( persister.getCacheAccessStrategy().getRegion().getName() );
+ if ( put && factory.getStatistics().isStatisticsEnabled() ) {
+ factory.getStatisticsImplementor().secondLevelCachePut( persister.getCacheAccessStrategy().getRegion().getName() );
+ }
}
+
}
if ( readOnly || !persister.isMutable() ) {
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionImpl.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionImpl.java 2010-09-28 10:52:55 UTC (rev 20736)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionImpl.java 2010-09-28 10:55:32 UTC (rev 20737)
@@ -30,6 +30,7 @@
import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -448,6 +449,7 @@
public void afterTransactionCompletion(boolean success, Transaction tx) {
log.trace( "after transaction completion" );
+ cleanUpInsertedKeysAfterTransaction();
persistenceContext.afterTransactionCompletion();
actionQueue.afterTransactionCompletion(success);
if ( rootSession == null && tx != null ) {
@@ -1048,7 +1050,48 @@
flush();
}
+ private HashMap insertedKeysMap;
+ /**
+ * {@inheritDoc}
+ */
+ public void registerInsertedKey(EntityPersister persister, Serializable id) {
+ // we only are about registering these if the persister defines caching
+ if ( persister.hasCache() ) {
+ if ( insertedKeysMap == null ) {
+ insertedKeysMap = new HashMap();
+ }
+ final String rootEntityName = persister.getRootEntityName();
+ List insertedEntityIds = (List)insertedKeysMap.get( rootEntityName );
+ if ( insertedEntityIds == null ) {
+ insertedEntityIds = new ArrayList();
+ insertedKeysMap.put( rootEntityName, insertedEntityIds );
+ }
+ insertedEntityIds.add( id );
+ }
+ }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id) {
+ // again, we only really care if the entity is cached
+ if ( persister.hasCache() ) {
+ if ( insertedKeysMap != null ) {
+ List insertedEntityIds = (List)insertedKeysMap.get( persister.getRootEntityName() );
+ if ( insertedEntityIds != null ) {
+ return insertedEntityIds.contains( id );
+ }
+ }
+ }
+ return false;
+ }
+
+ private void cleanUpInsertedKeysAfterTransaction() {
+ if ( insertedKeysMap != null ) {
+ insertedKeysMap.clear();
+ }
+ }
+
public Filter getEnabledFilter(String filterName) {
checkTransactionSynchStatus();
return (Filter) enabledFilters.get(filterName);
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java 2010-09-28 10:52:55 UTC (rev 20736)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java 2010-09-28 10:55:32 UTC (rev 20737)
@@ -659,4 +659,17 @@
return result;
}
+
+ public void registerInsertedKey(EntityPersister persister, Serializable id) {
+ // nothing to do
+
+ }
+
+
+ public boolean wasInsertedDuringTransaction(EntityPersister persister,
+ Serializable id) {
+ // not in any meaning we need to worry about here.
+ return false;
+ }
+
}
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.hbm.xml
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.hbm.xml (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.hbm.xml 2010-09-28 10:55:32 UTC (rev 20737)
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Inc.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.cache">
+
+ <class name="CacheableItem">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" type="string" />
+ </class>
+
+</hibernate-mapping>
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.java 2010-09-28 10:55:32 UTC (rev 20737)
@@ -0,0 +1,57 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class CacheableItem {
+ private Long id;
+ private String name;
+
+ public CacheableItem() {
+ }
+
+ public CacheableItem(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/cache/InsertedDataTest.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/cache/InsertedDataTest.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/cache/InsertedDataTest.java 2010-09-28 10:55:32 UTC (rev 20737)
@@ -0,0 +1,240 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache;
+
+import java.util.Map;
+
+import org.hibernate.Session;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.junit.functional.FunctionalTestCase;
+
+/**
+ * Tests for handling of data just inserted during a transaction being read from the database
+ * and placed into cache. Initially these cases went through putFromRead which causes problems because it
+ * loses the context of that data having just been read.
+ *
+ * @author Steve Ebersole
+ */
+public class InsertedDataTest extends FunctionalTestCase {
+ private static final String REGION_NAME = CacheableItem.class.getName();
+
+ public InsertedDataTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "cache/CacheableItem.hbm.xml" };
+ }
+
+ public String getCacheConcurrencyStrategy() {
+ return "read-write";
+ }
+
+ public void configure(Configuration cfg) {
+ super.configure( cfg );
+ cfg.setProperty( Environment.CACHE_REGION_PREFIX, "" );
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
+ }
+
+ public void testInsert() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.getTransaction().commit();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 1, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertWithRollback() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.getTransaction().rollback();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 0, cacheMap.size() );
+ }
+
+ public void testInsertThenUpdate() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ item.setName( "new data" );
+ s.getTransaction().commit();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 1, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertThenUpdateThenRollback() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ item.setName( "new data" );
+ s.getTransaction().rollback();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 0, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertWithRefresh() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.refresh( item );
+ s.getTransaction().commit();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 1, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertWithRefreshThenRollback() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.refresh( item );
+ s.getTransaction().rollback();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 0, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ item = (CacheableItem) s.get( CacheableItem.class, item.getId() );
+ s.getTransaction().commit();
+ s.close();
+
+ assertNull( "it should be null", item );
+ }
+
+ public void testInsertWithClear() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.clear();
+ s.getTransaction().commit();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 1, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertWithClearThenRollback() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.clear();
+ item = (CacheableItem) s.get( CacheableItem.class, item.getId() );
+ s.getTransaction().rollback();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 0, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ item = (CacheableItem) s.get( CacheableItem.class, item.getId() );
+ s.getTransaction().commit();
+ s.close();
+
+ assertNull( "it should be null", item );
+ }
+}
Modified: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java 2010-09-28 10:52:55 UTC (rev 20736)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java 2010-09-28 10:55:32 UTC (rev 20737)
@@ -26,6 +26,8 @@
}
public void testComponentPropertyRef() {
+ Session s = openSession();
+ s.beginTransaction();
Person p = new Person();
p.setIdentity( new Identity() );
Account a = new Account();
@@ -33,13 +35,14 @@
a.setOwner(p);
p.getIdentity().setName("Gavin");
p.getIdentity().setSsn("123-12-1234");
- Session s = openSession();
- Transaction tx = s.beginTransaction();
+
s.persist(p);
s.persist(a);
- s.flush();
- s.clear();
-
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();
assertTrue( Hibernate.isInitialized( a.getOwner() ) );
assertNotNull( a.getOwner() );
@@ -65,7 +68,7 @@
s.delete( a );
s.delete( a.getOwner() );
- tx.commit();
+ s.getTransaction().commit();
s.close();
}
}
Modified: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java 2010-09-28 10:52:55 UTC (rev 20736)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java 2010-09-28 10:55:32 UTC (rev 20737)
@@ -27,6 +27,8 @@
}
public void testComponentPropertyRef() {
+ Session s = openSession();
+ s.beginTransaction();
Person p = new Person();
p.setIdentity( new Identity() );
Account a = new Account();
@@ -34,13 +36,14 @@
a.setOwner(p);
p.getIdentity().setName("Gavin");
p.getIdentity().setSsn("123-12-1234");
- Session s = openSession();
- Transaction tx = s.beginTransaction();
+
s.persist(p);
s.persist(a);
- s.flush();
- s.clear();
+ s.getTransaction().commit();
+ s.close();
+ s = openSession();
+ s.beginTransaction();
a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();
assertTrue( Hibernate.isInitialized( a.getOwner() ) );
assertNotNull( a.getOwner() );
@@ -66,7 +69,7 @@
s.delete( a );
s.delete( a.getOwner() );
- tx.commit();
+ s.getTransaction().commit();
s.close();
}
}
14 years, 2 months
Hibernate SVN: r20736 - core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/cache.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-09-28 06:52:55 -0400 (Tue, 28 Sep 2010)
New Revision: 20736
Added:
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/cache/CacheableItem.hbm.xml
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/cache/CacheableItem.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/cache/InsertedDataTest.java
Log:
JBPAPP-5152 HHH-5490 dirty data be inserted into 2L cache
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/cache/CacheableItem.hbm.xml
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/cache/CacheableItem.hbm.xml (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/cache/CacheableItem.hbm.xml 2010-09-28 10:52:55 UTC (rev 20736)
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Inc.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.cache">
+
+ <class name="CacheableItem">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" type="string" />
+ </class>
+
+</hibernate-mapping>
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/cache/CacheableItem.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/cache/CacheableItem.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/cache/CacheableItem.java 2010-09-28 10:52:55 UTC (rev 20736)
@@ -0,0 +1,57 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class CacheableItem {
+ private Long id;
+ private String name;
+
+ public CacheableItem() {
+ }
+
+ public CacheableItem(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/cache/InsertedDataTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/cache/InsertedDataTest.java (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/cache/InsertedDataTest.java 2010-09-28 10:52:55 UTC (rev 20736)
@@ -0,0 +1,240 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.cache;
+
+import java.util.Map;
+
+import org.hibernate.Session;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.junit.functional.FunctionalTestCase;
+
+/**
+ * Tests for handling of data just inserted during a transaction being read from the database
+ * and placed into cache. Initially these cases went through putFromRead which causes problems because it
+ * loses the context of that data having just been read.
+ *
+ * @author Steve Ebersole
+ */
+public class InsertedDataTest extends FunctionalTestCase {
+ private static final String REGION_NAME = CacheableItem.class.getName();
+
+ public InsertedDataTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "cache/CacheableItem.hbm.xml" };
+ }
+
+ public String getCacheConcurrencyStrategy() {
+ return "read-write";
+ }
+
+ public void configure(Configuration cfg) {
+ super.configure( cfg );
+ cfg.setProperty( Environment.CACHE_REGION_PREFIX, "" );
+ cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
+ }
+
+ public void testInsert() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.getTransaction().commit();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 1, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertWithRollback() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.getTransaction().rollback();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 0, cacheMap.size() );
+ }
+
+ public void testInsertThenUpdate() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ item.setName( "new data" );
+ s.getTransaction().commit();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 1, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertThenUpdateThenRollback() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ item.setName( "new data" );
+ s.getTransaction().rollback();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 0, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertWithRefresh() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.refresh( item );
+ s.getTransaction().commit();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 1, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertWithRefreshThenRollback() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.refresh( item );
+ s.getTransaction().rollback();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 0, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ item = (CacheableItem) s.get( CacheableItem.class, item.getId() );
+ s.getTransaction().commit();
+ s.close();
+
+ assertNull( "it should be null", item );
+ }
+
+ public void testInsertWithClear() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.clear();
+ s.getTransaction().commit();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 1, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ s.createQuery( "delete CacheableItem" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testInsertWithClearThenRollback() {
+ getSessions().evict(CacheableItem.class);
+ getSessions().getStatistics().clear();
+
+ Session s = openSession();
+ s.beginTransaction();
+ CacheableItem item = new CacheableItem( "data" );
+ s.save( item );
+ s.flush();
+ s.clear();
+ item = (CacheableItem) s.get( CacheableItem.class, item.getId() );
+ s.getTransaction().rollback();
+ s.close();
+
+ Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+ assertEquals( 0, cacheMap.size() );
+
+ s = openSession();
+ s.beginTransaction();
+ item = (CacheableItem) s.get( CacheableItem.class, item.getId() );
+ s.getTransaction().commit();
+ s.close();
+
+ assertNull( "it should be null", item );
+ }
+}
14 years, 2 months
Hibernate SVN: r20735 - core/branches.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-09-28 04:04:48 -0400 (Tue, 28 Sep 2010)
New Revision: 20735
Added:
core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/
Log:
JBPAPP-5153 create one-off branch
Copied: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153 (from rev 20734, core/tags/Branch_3_2_4_SP1_CP02)
14 years, 2 months
Hibernate SVN: r20734 - search/branches/Branch_3_0_1_GA_CP/src/java/org/hibernate/search/impl.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-09-28 03:14:45 -0400 (Tue, 28 Sep 2010)
New Revision: 20734
Modified:
search/branches/Branch_3_0_1_GA_CP/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
Log:
JBPAPP-5152 HHH-5490 dirty data be inserted into 2L cache
Modified: search/branches/Branch_3_0_1_GA_CP/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- search/branches/Branch_3_0_1_GA_CP/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2010-09-28 06:57:56 UTC (rev 20733)
+++ search/branches/Branch_3_0_1_GA_CP/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2010-09-28 07:14:45 UTC (rev 20734)
@@ -688,4 +688,15 @@
public void update(Object object) throws HibernateException {
session.update( object );
}
+
+ public void registerInsertedKey(EntityPersister persister, Serializable id) {
+ // nothing to do
+
+ }
+
+ public boolean wasInsertedDuringTransaction(EntityPersister persister,
+ Serializable id) {
+ // not in any meaning we need to worry about here.
+ return false;
+ }
}
14 years, 2 months
Hibernate SVN: r20733 - jpa-api/tags/entitymanager_v3_2_1_GA.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-09-28 02:57:56 -0400 (Tue, 28 Sep 2010)
New Revision: 20733
Modified:
jpa-api/tags/entitymanager_v3_2_1_GA/
Log:
ignore eclipse metadata files
Property changes on: jpa-api/tags/entitymanager_v3_2_1_GA
___________________________________________________________________
Name: svn:ignore
+ .settings
build
.classpath
.project
bin
14 years, 2 months
Hibernate SVN: r20732 - commons-annotations/tags/v3_0_0_GA.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-09-28 02:54:48 -0400 (Tue, 28 Sep 2010)
New Revision: 20732
Modified:
commons-annotations/tags/v3_0_0_GA/
Log:
ignore eclipse metadata files
Property changes on: commons-annotations/tags/v3_0_0_GA
___________________________________________________________________
Name: svn:ignore
+ .settings
.classpath
.project
bin
14 years, 2 months
Hibernate SVN: r20731 - in core/branches/Branch_3_2_4_SP1_CP: src/org/hibernate/action and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-09-28 02:47:19 -0400 (Tue, 28 Sep 2010)
New Revision: 20731
Modified:
core/branches/Branch_3_2_4_SP1_CP/build.xml
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/action/EntityIdentityInsertAction.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/action/EntityInsertAction.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/SessionImplementor.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/TwoPhaseLoad.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/impl/SessionImpl.java
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/impl/StatelessSessionImpl.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
Log:
JBPAPP-4895 HHH-5490 dirty data be inserted into 2L cache
Modified: core/branches/Branch_3_2_4_SP1_CP/build.xml
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/build.xml 2010-09-28 06:15:52 UTC (rev 20730)
+++ core/branches/Branch_3_2_4_SP1_CP/build.xml 2010-09-28 06:47:19 UTC (rev 20731)
@@ -60,7 +60,7 @@
<property name="javac.debug" value="on"/>
<property name="javac.optimize" value="off"/>
<property name="javac.target" value="1.5"/>
- <property name="javac.source" value="1.4"/>
+ <property name="javac.source" value="1.5"/>
<property name="jar.driver" value="${dir.jdbc}/hsqldb.jar"/>
<!-- JAR and dist file names -->
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/action/EntityIdentityInsertAction.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/action/EntityIdentityInsertAction.java 2010-09-28 06:15:52 UTC (rev 20730)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/action/EntityIdentityInsertAction.java 2010-09-28 06:47:19 UTC (rev 20731)
@@ -52,6 +52,7 @@
//need to do that here rather than in the save event listener to let
//the post insert events to have a id-filled entity when IDENTITY is used (EJB3)
persister.setIdentifier( instance, generatedId, session.getEntityMode() );
+ getSession().registerInsertedKey( getPersister(), generatedId );
}
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/action/EntityInsertAction.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/action/EntityInsertAction.java 2010-09-28 06:15:52 UTC (rev 20730)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/action/EntityInsertAction.java 2010-09-28 06:47:19 UTC (rev 20731)
@@ -70,6 +70,8 @@
entry.postUpdate(instance, state, version);
}
+ getSession().registerInsertedKey( getPersister(), getId() );
+
}
final SessionFactoryImplementor factory = getSession().getFactory();
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/SessionImplementor.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/SessionImplementor.java 2010-09-28 06:15:52 UTC (rev 20730)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/SessionImplementor.java 2010-09-28 06:47:19 UTC (rev 20731)
@@ -299,4 +299,23 @@
* @return True if the session is closed; false otherwise.
*/
public boolean isClosed();
+
+ /**
+ * Register keys inserted during the current transaction
+ *
+ * @param persister The entity persister
+ * @param id The id
+ */
+ public void registerInsertedKey(EntityPersister persister, Serializable id);
+
+ /**
+ * Allows callers to check to see if the identified entity was inserted during the current transaction.
+ *
+ * @param persister The entity persister
+ * @param id The id
+ *
+ * @return True if inserted during this transaction, false otherwise.
+ */
+ public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id);
+
}
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/TwoPhaseLoad.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/TwoPhaseLoad.java 2010-09-28 06:15:52 UTC (rev 20730)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/engine/TwoPhaseLoad.java 2010-09-28 06:47:19 UTC (rev 20731)
@@ -153,19 +153,27 @@
session.getEntityMode(),
session.getFactory()
);
- boolean put = persister.getCache().put(
- cacheKey,
- persister.getCacheEntryStructure().structure(entry),
- session.getTimestamp(),
- version,
- persister.isVersioned() ?
- persister.getVersionType().getComparator() :
- null,
- useMinimalPuts(session, entityEntry)
- ); //we could use persister.hasLazyProperties() instead of true
-
- if ( put && factory.getStatistics().isStatisticsEnabled() ) {
- factory.getStatisticsImplementor().secondLevelCachePut( persister.getCache().getRegionName() );
+ if (session.wasInsertedDuringTransaction(persister, id)) {
+ persister.getCache().update(cacheKey,
+ persister.getCacheEntryStructure().structure(entry),
+ version, version);
+ } else {
+ boolean put = persister.getCache().put(
+ cacheKey,
+ persister.getCacheEntryStructure().structure(entry),
+ session.getTimestamp(),
+ version,
+ persister.isVersioned() ? persister.getVersionType()
+ .getComparator() : null,
+ useMinimalPuts(session, entityEntry)); // we could use
+ // persister.hasLazyProperties()
+ // instead of
+ // true
+
+ if (put && factory.getStatistics().isStatisticsEnabled()) {
+ factory.getStatisticsImplementor().secondLevelCachePut(
+ persister.getCache().getRegionName());
+ }
}
}
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/impl/SessionImpl.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/impl/SessionImpl.java 2010-09-28 06:15:52 UTC (rev 20730)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/impl/SessionImpl.java 2010-09-28 06:47:19 UTC (rev 20731)
@@ -6,6 +6,7 @@
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.sql.Connection;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -147,7 +148,6 @@
private transient Session rootSession;
private transient Map childSessionsByEntityMode;
-
/**
* Constructor used in building "child sessions".
*
@@ -420,6 +420,7 @@
public void afterTransactionCompletion(boolean success, Transaction tx) {
log.trace( "after transaction completion" );
+ cleanUpInsertedKeysAfterTransaction();
persistenceContext.afterTransactionCompletion();
actionQueue.afterTransactionCompletion(success);
if ( rootSession == null && tx != null ) {
@@ -1020,7 +1021,48 @@
flush();
}
+ private HashMap<String,List<Serializable>> insertedKeysMap;
+ /**
+ * {@inheritDoc}
+ */
+ public void registerInsertedKey(EntityPersister persister, Serializable id) {
+ // we only are about registering these if the persister defines caching
+ if ( persister.hasCache() ) {
+ if ( insertedKeysMap == null ) {
+ insertedKeysMap = new HashMap<String, List<Serializable>>();
+ }
+ final String rootEntityName = persister.getRootEntityName();
+ List<Serializable> insertedEntityIds = insertedKeysMap.get( rootEntityName );
+ if ( insertedEntityIds == null ) {
+ insertedEntityIds = new ArrayList<Serializable>();
+ insertedKeysMap.put( rootEntityName, insertedEntityIds );
+ }
+ insertedEntityIds.add( id );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id) {
+ // again, we only really care if the entity is cached
+ if ( persister.hasCache() ) {
+ if ( insertedKeysMap != null ) {
+ List<Serializable> insertedEntityIds = insertedKeysMap.get( persister.getRootEntityName() );
+ if ( insertedEntityIds != null ) {
+ return insertedEntityIds.contains( id );
+ }
+ }
+ }
+ return false;
+ }
+
+ private void cleanUpInsertedKeysAfterTransaction() {
+ if ( insertedKeysMap != null ) {
+ insertedKeysMap.clear();
+ }
+ }
public Filter getEnabledFilter(String filterName) {
checkTransactionSynchStatus();
return (Filter) enabledFilters.get(filterName);
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/impl/StatelessSessionImpl.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/impl/StatelessSessionImpl.java 2010-09-28 06:15:52 UTC (rev 20730)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/impl/StatelessSessionImpl.java 2010-09-28 06:47:19 UTC (rev 20731)
@@ -627,4 +627,17 @@
return result;
}
+
+ public void registerInsertedKey(EntityPersister persister, Serializable id) {
+ // nothing to do
+
+ }
+
+
+ public boolean wasInsertedDuringTransaction(EntityPersister persister,
+ Serializable id) {
+ // not in any meaning we need to worry about here.
+ return false;
+ }
+
}
Modified: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java 2010-09-28 06:15:52 UTC (rev 20730)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java 2010-09-28 06:47:19 UTC (rev 20731)
@@ -26,6 +26,8 @@
}
public void testComponentPropertyRef() {
+ Session s = openSession();
+ s.beginTransaction();
Person p = new Person();
p.setIdentity( new Identity() );
Account a = new Account();
@@ -33,13 +35,14 @@
a.setOwner(p);
p.getIdentity().setName("Gavin");
p.getIdentity().setSsn("123-12-1234");
- Session s = openSession();
- Transaction tx = s.beginTransaction();
+
s.persist(p);
s.persist(a);
- s.flush();
- s.clear();
-
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();
assertTrue( Hibernate.isInitialized( a.getOwner() ) );
assertNotNull( a.getOwner() );
@@ -65,7 +68,7 @@
s.delete( a );
s.delete( a.getOwner() );
- tx.commit();
+ s.getTransaction().commit();
s.close();
}
}
Modified: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java 2010-09-28 06:15:52 UTC (rev 20730)
+++ core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java 2010-09-28 06:47:19 UTC (rev 20731)
@@ -27,6 +27,8 @@
}
public void testComponentPropertyRef() {
+ Session s = openSession();
+ s.beginTransaction();
Person p = new Person();
p.setIdentity( new Identity() );
Account a = new Account();
@@ -34,13 +36,15 @@
a.setOwner(p);
p.getIdentity().setName("Gavin");
p.getIdentity().setSsn("123-12-1234");
- Session s = openSession();
- Transaction tx = s.beginTransaction();
+
s.persist(p);
s.persist(a);
- s.flush();
- s.clear();
+ s.getTransaction().commit();
+ s.close();
+ s = openSession();
+ s.beginTransaction();
+
a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();
assertTrue( Hibernate.isInitialized( a.getOwner() ) );
assertNotNull( a.getOwner() );
@@ -66,7 +70,7 @@
s.delete( a );
s.delete( a.getOwner() );
- tx.commit();
+ s.getTransaction().commit();
s.close();
}
}
14 years, 2 months