HHH-15800 clean up GenerationTiming
This commit is contained in:
parent
b40d15e528
commit
c09664711d
|
@ -9,7 +9,6 @@ package org.hibernate.metamodel.mapping.internal;
|
|||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.metamodel.UnsupportedMappingException;
|
||||
import org.hibernate.metamodel.mapping.GeneratedValueResolver;
|
||||
import org.hibernate.tuple.GenerationTiming;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
|
|
@ -9,6 +9,8 @@ package org.hibernate.tuple;
|
|||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.annotations.GenerationTime;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Represents the timing of {@link ValueGeneration value generation} that occurs
|
||||
* in the Java program, or in the database.
|
||||
|
@ -21,107 +23,58 @@ public enum GenerationTiming {
|
|||
/**
|
||||
* Value generation that never occurs.
|
||||
*/
|
||||
NEVER {
|
||||
@Override
|
||||
public boolean includesInsert() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includesUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includes(GenerationTiming timing) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
NEVER,
|
||||
/**
|
||||
* Value generation that occurs when a row is inserted in the database.
|
||||
*/
|
||||
INSERT {
|
||||
@Override
|
||||
public boolean includesInsert() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includesUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includes(GenerationTiming timing) {
|
||||
return timing.includesInsert();
|
||||
}
|
||||
},
|
||||
INSERT,
|
||||
/**
|
||||
* Value generation that occurs when a row is updated in the database.
|
||||
*/
|
||||
UPDATE {
|
||||
@Override
|
||||
public boolean includesInsert() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includesUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includes(GenerationTiming timing) {
|
||||
return timing.includesUpdate();
|
||||
}
|
||||
},
|
||||
UPDATE,
|
||||
/**
|
||||
* Value generation that occurs when a row is inserted or updated in the database.
|
||||
*/
|
||||
ALWAYS {
|
||||
@Override
|
||||
public boolean includesInsert() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includesUpdate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includes(GenerationTiming timing) {
|
||||
return timing != NEVER;
|
||||
}
|
||||
};
|
||||
ALWAYS;
|
||||
|
||||
/**
|
||||
* Does value generation happen for SQL {@code insert} statements?
|
||||
*/
|
||||
public abstract boolean includesInsert();
|
||||
public boolean includesInsert() {
|
||||
return this == INSERT || this == ALWAYS;
|
||||
}
|
||||
/**
|
||||
* Does value generation happen for SQL {@code update} statements?
|
||||
*/
|
||||
public abstract boolean includesUpdate();
|
||||
|
||||
public boolean isAlways() {
|
||||
return this == ALWAYS;
|
||||
public boolean includesUpdate() {
|
||||
return this == UPDATE || this == ALWAYS;
|
||||
}
|
||||
|
||||
public abstract boolean includes(GenerationTiming timing);
|
||||
public boolean includes(GenerationTiming timing) {
|
||||
switch (this) {
|
||||
case NEVER:
|
||||
return timing == NEVER;
|
||||
case INSERT:
|
||||
return timing.includesInsert();
|
||||
case UPDATE:
|
||||
return timing.includesUpdate();
|
||||
case ALWAYS:
|
||||
return true;
|
||||
default:
|
||||
throw new AssertionFailure("unknown timing");
|
||||
}
|
||||
}
|
||||
|
||||
public static GenerationTiming parseFromName(String name) {
|
||||
if ( "insert".equalsIgnoreCase( name ) ) {
|
||||
return INSERT;
|
||||
}
|
||||
else if ( "update".equalsIgnoreCase( name ) ) {
|
||||
return UPDATE;
|
||||
}
|
||||
else if ( "always".equalsIgnoreCase( name ) ) {
|
||||
return ALWAYS;
|
||||
}
|
||||
else {
|
||||
return NEVER;
|
||||
switch ( name.toLowerCase(Locale.ROOT) ) {
|
||||
case "insert":
|
||||
return INSERT;
|
||||
case "update":
|
||||
return UPDATE;
|
||||
case "always":
|
||||
return ALWAYS;
|
||||
default:
|
||||
return NEVER;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue