Skip to content

Commit

Permalink
Update H2 to 1.4.200. Replace LockMode in Fetch and DomainResult with…
Browse files Browse the repository at this point in the history
… the source alias to resolve lock mode during initializer creation. Introduce notion of aggregate function with an optional filter clause. Implement support for rendering locks into SQL. Move locking tests to orm package
  • Loading branch information
beikov committed Jun 8, 2021
1 parent 6ced2f0 commit 5f4b097
Show file tree
Hide file tree
Showing 259 changed files with 3,581 additions and 1,122 deletions.
2 changes: 1 addition & 1 deletion gradle/libraries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ext {
junitVintageVersion = '5.7.1'
junit5Version = '5.7.1'

h2Version = '1.4.199'
h2Version = '1.4.200'
bytemanVersion = '4.0.13' //Compatible with JDK16
jnpVersion = '5.0.6.CR1'

Expand Down
30 changes: 24 additions & 6 deletions hibernate-core/src/main/java/org/hibernate/LockOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ public LockOptions setAliasSpecificLockMode(String alias, LockMode lockMode) {
if ( aliasSpecificLockModes == null ) {
aliasSpecificLockModes = new LinkedHashMap<>();
}
aliasSpecificLockModes.put( alias, lockMode );
if ( lockMode == null ) {
aliasSpecificLockModes.remove( alias );
}
else {
aliasSpecificLockModes.put( alias, lockMode );
}
return this;
}

Expand Down Expand Up @@ -338,13 +343,16 @@ public static LockOptions copy(LockOptions source, LockOptions destination) {
return destination;
}

public boolean isCompatible(LockOptions that) {
if ( that == null ) {
return isEmpty();
}
else if ( this == that ) {
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( o == null || getClass() != o.getClass() ) {
return false;
}

LockOptions that = (LockOptions) o;

if ( timeout != that.timeout ) {
return false;
Expand All @@ -363,4 +371,14 @@ else if ( this == that ) {
return followOnLocking != null ? followOnLocking.equals( that.followOnLocking ) : that.followOnLocking == null;
}

@Override
public int hashCode() {
int result = lockMode != null ? lockMode.hashCode() : 0;
result = 31 * result + timeout;
result = 31 * result + ( aliasSpecificLockModes != null ? aliasSpecificLockModes.hashCode() : 0 );
result = 31 * result + ( followOnLocking != null ? followOnLocking.hashCode() : 0 );
result = 31 * result + ( scope ? 1 : 0 );
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Iterator;
import java.util.function.Consumer;

import org.hibernate.LockMode;
import org.hibernate.collection.spi.BagSemantics;
import org.hibernate.collection.spi.CollectionInitializerProducer;
import org.hibernate.engine.FetchTiming;
Expand Down Expand Up @@ -68,7 +67,6 @@ public CollectionInitializerProducer createInitializerProducer(
FetchParent fetchParent,
boolean selected,
String resultVariable,
LockMode lockMode,
DomainResultCreationState creationState) {
return new BagInitializerProducer(
attributeMapping,
Expand All @@ -77,7 +75,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.ID.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
),
Expand All @@ -86,7 +83,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
)
Expand All @@ -100,7 +96,6 @@ public CollectionInitializerProducer createInitializerProducer(
FetchParent fetchParent,
boolean selected,
String resultVariable,
LockMode lockMode,
Fetch indexFetch,
Fetch elementFetch,
DomainResultCreationState creationState){
Expand All @@ -110,7 +105,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.ID.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
);
Expand All @@ -121,7 +115,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.function.BiConsumer;
import java.util.function.Consumer;

import org.hibernate.LockMode;
import org.hibernate.collection.spi.CollectionInitializerProducer;
import org.hibernate.collection.spi.MapSemantics;
import org.hibernate.engine.FetchTiming;
Expand Down Expand Up @@ -80,7 +79,6 @@ public CollectionInitializerProducer createInitializerProducer(
FetchParent fetchParent,
boolean selected,
String resultVariable,
LockMode lockMode,
DomainResultCreationState creationState) {
return new MapInitializerProducer(
attributeMapping,
Expand All @@ -89,7 +87,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.INDEX.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
),
Expand All @@ -98,7 +95,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
)
Expand All @@ -112,7 +108,6 @@ public CollectionInitializerProducer createInitializerProducer(
FetchParent fetchParent,
boolean selected,
String resultVariable,
LockMode lockMode,
Fetch indexFetch,
Fetch elementFetch,
DomainResultCreationState creationState){
Expand All @@ -122,7 +117,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.INDEX.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
);
Expand All @@ -133,7 +127,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Set;
import java.util.function.Consumer;

import org.hibernate.LockMode;
import org.hibernate.collection.spi.CollectionInitializerProducer;
import org.hibernate.collection.spi.CollectionSemantics;
import org.hibernate.engine.FetchTiming;
Expand Down Expand Up @@ -53,7 +52,6 @@ public CollectionInitializerProducer createInitializerProducer(
FetchParent fetchParent,
boolean selected,
String resultVariable,
LockMode lockMode,
DomainResultCreationState creationState) {
return new SetInitializerProducer(
attributeMapping,
Expand All @@ -62,7 +60,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
)
Expand All @@ -76,7 +73,6 @@ public CollectionInitializerProducer createInitializerProducer(
FetchParent fetchParent,
boolean selected,
String resultVariable,
LockMode lockMode,
Fetch indexFetch,
Fetch elementFetch,
DomainResultCreationState creationState){
Expand All @@ -87,7 +83,6 @@ public CollectionInitializerProducer createInitializerProducer(
fetchParent,
selected,
resultVariable,
lockMode,
creationState
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Iterator;
import java.util.function.Consumer;

import org.hibernate.LockMode;
import org.hibernate.collection.spi.CollectionInitializerProducer;
import org.hibernate.collection.spi.CollectionSemantics;
import org.hibernate.collection.spi.PersistentCollection;
Expand Down Expand Up @@ -101,7 +100,6 @@ public CollectionInitializerProducer createInitializerProducer(
FetchParent fetchParent,
boolean selected,
String resultVariable,
LockMode lockMode,
DomainResultCreationState creationState) {
return new ArrayInitializerProducer(
attributeMapping,
Expand All @@ -110,7 +108,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.INDEX.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
),
Expand All @@ -119,7 +116,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
)
Expand All @@ -133,7 +129,6 @@ public CollectionInitializerProducer createInitializerProducer(
FetchParent fetchParent,
boolean selected,
String resultVariable,
LockMode lockMode,
Fetch indexFetch,
Fetch elementFetch,
DomainResultCreationState creationState){
Expand All @@ -143,7 +138,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.INDEX.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
);
Expand All @@ -154,7 +148,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.List;
import java.util.function.Consumer;

import org.hibernate.LockMode;
import org.hibernate.collection.spi.CollectionInitializerProducer;
import org.hibernate.collection.spi.CollectionSemantics;
import org.hibernate.collection.spi.PersistentCollection;
Expand Down Expand Up @@ -75,7 +74,6 @@ public CollectionInitializerProducer createInitializerProducer(
FetchParent fetchParent,
boolean selected,
String resultVariable,
LockMode lockMode,
DomainResultCreationState creationState) {
return new ListInitializerProducer(
attributeMapping,
Expand All @@ -84,7 +82,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.INDEX.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
),
Expand All @@ -93,7 +90,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
)
Expand All @@ -107,7 +103,6 @@ public CollectionInitializerProducer createInitializerProducer(
FetchParent fetchParent,
boolean selected,
String resultVariable,
LockMode lockMode,
Fetch indexFetch,
Fetch elementFetch,
DomainResultCreationState creationState) {
Expand All @@ -117,7 +112,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.INDEX.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
);
Expand All @@ -128,7 +122,6 @@ public CollectionInitializerProducer createInitializerProducer(
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
FetchTiming.IMMEDIATE,
selected,
lockMode,
null,
creationState
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ CollectionInitializerProducer createInitializerProducer(
FetchParent fetchParent,
boolean selected,
String resultVariable,
LockMode lockMode,
DomainResultCreationState creationState);

CollectionInitializerProducer createInitializerProducer(
Expand All @@ -74,7 +73,6 @@ CollectionInitializerProducer createInitializerProducer(
FetchParent fetchParent,
boolean selected,
String resultVariable,
LockMode lockMode,
Fetch indexFetch,
Fetch elementFetch,
DomainResultCreationState creationState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,11 @@ public boolean forUpdateOfColumns() {
return true;
}

@Override
public RowLockStrategy getWriteRowLockStrategy() {
return RowLockStrategy.COLUMN;
}

@Override
public String getAddColumnString() {
return "add (";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ public String getForUpdateString() {
return "";
}

@Override
public RowLockStrategy getWriteRowLockStrategy() {
return RowLockStrategy.TABLE;
}

@Override
public String appendLockHint(LockOptions lockOptions, String tableName) {
return lockOptions.getLockMode().greaterThan( LockMode.READ ) ? tableName + " holdlock" : tableName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ public CacheSqlAstTranslator(SessionFactoryImplementor sessionFactory, Statement
super( sessionFactory, statement );
}

@Override
protected LockStrategy determineLockingStrategy(
QuerySpec querySpec,
ForUpdateClause forUpdateClause,
Boolean followOnLocking) {
return LockStrategy.NONE;
}

@Override
protected void renderForUpdateClause(QuerySpec querySpec, ForUpdateClause forUpdateClause) {
// Cache does not support the FOR UPDATE clause
}

@Override
protected boolean needsRowsToSkip() {
return true;
Expand Down
Loading

0 comments on commit 5f4b097

Please sign in to comment.