HHH-16567 - Remove support for CockroachDB versions older than 22.1
Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
parent
467399437c
commit
2e97374660
|
@ -60,6 +60,7 @@ import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
|
|||
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.JdbcExceptionHelper;
|
||||
import org.hibernate.query.SemanticException;
|
||||
import org.hibernate.query.sqm.IntervalType;
|
||||
import org.hibernate.query.sqm.NullOrdering;
|
||||
import org.hibernate.query.sqm.TemporalUnit;
|
||||
|
@ -88,6 +89,7 @@ import org.jboss.logging.Logger;
|
|||
|
||||
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
|
||||
import static org.hibernate.query.sqm.TemporalUnit.DAY;
|
||||
import static org.hibernate.query.sqm.TemporalUnit.EPOCH;
|
||||
import static org.hibernate.query.sqm.TemporalUnit.NATIVE;
|
||||
import static org.hibernate.type.SqlTypes.*;
|
||||
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDate;
|
||||
|
@ -788,23 +790,53 @@ public class CockroachLegacyDialect extends Dialect {
|
|||
}
|
||||
}
|
||||
else {
|
||||
switch (unit) {
|
||||
case YEAR:
|
||||
return "extract(year from ?3-?2)";
|
||||
case QUARTER:
|
||||
return "(extract(year from ?3-?2)*4+extract(month from ?3-?2)//3)";
|
||||
case MONTH:
|
||||
return "(extract(year from ?3-?2)*12+extract(month from ?3-?2))";
|
||||
// Prior to v20, Cockroach didn't support extracting from an interval/duration,
|
||||
// so we use the extract_duration function
|
||||
case WEEK:
|
||||
return "extract_duration(hour from ?3-?2)/168";
|
||||
case DAY:
|
||||
return "extract_duration(hour from ?3-?2)/24";
|
||||
case NANOSECOND:
|
||||
return "extract_duration(microsecond from ?3-?2)*1e3";
|
||||
default:
|
||||
return "extract_duration(?1 from ?3-?2)";
|
||||
if (getVersion().isSameOrAfter( 20, 1 )) {
|
||||
switch (unit) {
|
||||
case YEAR:
|
||||
return "extract(year from ?3-?2)";
|
||||
case QUARTER:
|
||||
return "(extract(year from ?3-?2)*4+extract(month from ?3-?2)//3)";
|
||||
case MONTH:
|
||||
return "(extract(year from ?3-?2)*12+extract(month from ?3-?2))";
|
||||
case WEEK: //week is not supported by extract() when the argument is a duration
|
||||
return "(extract(day from ?3-?2)/7)";
|
||||
case DAY:
|
||||
return "extract(day from ?3-?2)";
|
||||
//in order to avoid multiple calls to extract(),
|
||||
//we use extract(epoch from x - y) * factor for
|
||||
//all the following units:
|
||||
|
||||
// Note that CockroachDB also has an extract_duration function which returns an int,
|
||||
// but we don't use that here because it is deprecated since v20
|
||||
case HOUR:
|
||||
case MINUTE:
|
||||
case SECOND:
|
||||
case NANOSECOND:
|
||||
case NATIVE:
|
||||
return "cast(extract(epoch from ?3-?2)" + EPOCH.conversionFactor( unit, this ) + " as int)";
|
||||
default:
|
||||
throw new SemanticException( "unrecognized field: " + unit );
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (unit) {
|
||||
case YEAR:
|
||||
return "extract(year from ?3-?2)";
|
||||
case QUARTER:
|
||||
return "(extract(year from ?3-?2)*4+extract(month from ?3-?2)//3)";
|
||||
case MONTH:
|
||||
return "(extract(year from ?3-?2)*12+extract(month from ?3-?2))";
|
||||
// Prior to v20, Cockroach didn't support extracting from an interval/duration,
|
||||
// so we use the extract_duration function
|
||||
case WEEK:
|
||||
return "extract_duration(hour from ?3-?2)/168";
|
||||
case DAY:
|
||||
return "extract_duration(hour from ?3-?2)/24";
|
||||
case NANOSECOND:
|
||||
return "extract_duration(microsecond from ?3-?2)*1e3";
|
||||
default:
|
||||
return "extract_duration(?1 from ?3-?2)";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ public class CockroachDialect extends Dialect {
|
|||
// Pre-compile and reuse pattern
|
||||
private static final Pattern CRDB_VERSION_PATTERN = Pattern.compile( "v[\\d]+(\\.[\\d]+)?(\\.[\\d]+)?" );
|
||||
|
||||
protected static final DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 21, 1 );
|
||||
protected static final DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 22, 1 );
|
||||
|
||||
protected final PostgreSQLDriverKind driverKind;
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ stage('Configure') {
|
|||
// new BuildEnvironment( dbName: 'sybase_16' ), // There only is a Sybase ASE 16 image, so no pint in testing that nightly
|
||||
// Long running databases
|
||||
new BuildEnvironment( dbName: 'cockroachdb', node: 'cockroachdb', longRunning: true ),
|
||||
new BuildEnvironment( dbName: 'cockroachdb_21_2', node: 'cockroachdb', longRunning: true ),
|
||||
new BuildEnvironment( dbName: 'cockroachdb_22_1', node: 'cockroachdb', longRunning: true ),
|
||||
new BuildEnvironment( dbName: 'hana_cloud', dbLockableResource: 'hana-cloud', dbLockResourceAsHost: true )
|
||||
];
|
||||
|
||||
|
@ -226,11 +226,11 @@ stage('Build') {
|
|||
sh "./docker_db.sh cockroachdb"
|
||||
state[buildEnv.tag]['containerName'] = "cockroach"
|
||||
break;
|
||||
case "cockroachdb_21_2":
|
||||
case "cockroachdb_22_1":
|
||||
docker.withRegistry('https://index.docker.io/v1/', 'hibernateci.hub.docker.com') {
|
||||
docker.image('cockroachdb/cockroach:v21.2.16').pull()
|
||||
docker.image('cockroachdb/cockroach:v22.1.13').pull()
|
||||
}
|
||||
sh "./docker_db.sh cockroachdb_21_2"
|
||||
sh "./docker_db.sh cockroachdb_22_1"
|
||||
state[buildEnv.tag]['containerName'] = "cockroach"
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue