Merge pull request #2793 from ebean-orm/feature/2782-mariaDb-driver-update

#2782 - Support MariaDB jdbc driver update - Batched JDBC SQLException translation, SqlRow BLOB reading
This commit is contained in:
Rob Bygrave
2022-08-17 17:27:07 +12:00
committed by GitHub
8 changed files with 28 additions and 21 deletions
@@ -32,7 +32,12 @@ public class SqlCodeTranslator implements SqlExceptionTranslator {
}
private DataErrorType getErrorType(SQLException e) {
DataErrorType errorType = map.get(e.getSQLState());
String sqlState = e.getSQLState();
while (sqlState == null && e.getCause() instanceof SQLException) {
e = (SQLException)e.getCause();
sqlState = e.getSQLState();
}
DataErrorType errorType = map.get(sqlState);
if (errorType == null) {
// fall back to error code
errorType = map.get(String.valueOf(e.getErrorCode()));
@@ -58,6 +58,7 @@ public final class DRawSqlService implements SpiRawSqlService {
ret.put(name, resultSet.getString(i));
break;
case Types.LONGVARBINARY:
case Types.BLOB:
ret.put(name, resultSet.getBytes(i));
break;
@@ -298,7 +298,7 @@ public class TestRawSqlBuilder extends BaseTestCase {
}
@Test
public void testBLobClosedConnection() throws Exception {
void testBLobClosedConnection() throws Exception {
final PersistentFileContent pfc = new PersistentFileContent();
final byte[] bytes = "This is the blob as String".getBytes(StandardCharsets.UTF_8);
pfc.setContent(bytes);
@@ -5,11 +5,12 @@ import io.ebean.test.containers.MariaDBContainer;
public class StartMariaDb {
public static void main(String[] args) {
MariaDBContainer.builder("10.5")
MariaDBContainer.builder("10.6")
.dbName("unit")
.user("unit")
.password("unit")
.port(5306)
.build()
.startWithDropCreate();
.start();
}
}
@@ -15,19 +15,23 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class TestHistoryInsert extends BaseTestCase {
class TestHistoryInsert extends BaseTestCase {
private final Logger logger = LoggerFactory.getLogger(TestHistoryInsert.class);
private Timestamp currentDbSystemTime() {
return DB.sqlQuery("select current_timestamp(6)").mapToScalar(Timestamp.class).findOne();
}
/**
* Looks like we MUST use useLegacyDatetimeCode=false ... in order for
* the correct server timezone to be honored by the MariaDB JDBC driver.
*/
@Test
@ForPlatform({Platform.MARIADB})
public void mariadb_simple_history() {
void mariadb_simple_history() {
Timestamp t0 = new Timestamp(System.currentTimeMillis());
Timestamp t0 = currentDbSystemTime();
littleSleep(50);
User user = new User();
@@ -35,19 +39,19 @@ public class TestHistoryInsert extends BaseTestCase {
user.setEmail("one@email.com");
user.setPasswordHash("someHash");
DB.save(user);
Timestamp t1 = new Timestamp(System.currentTimeMillis());
Timestamp t1 = currentDbSystemTime();
littleSleep(100);
user.setName("NotJim");
user.save();
Timestamp t2 = new Timestamp(System.currentTimeMillis());
Timestamp t2 = currentDbSystemTime();
littleSleep(100);
user.setName("NotJimV2");
user.setEmail("two@email.com");
user.save();
littleSleep(50);
Timestamp t3 = new Timestamp(System.currentTimeMillis());
Timestamp t3 = currentDbSystemTime();
List<Version<User>> versions = DB.find(User.class).setId(user.getId()).findVersionsBetween(t0, t3);
assertThat(versions).hasSize(3);
@@ -59,7 +59,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
*
* @author Roland Praml, FOCONIS AG
*/
public class SqlQueryCancelTest extends BaseTestCase {
class SqlQueryCancelTest extends BaseTestCase {
private final int timing = 20;
@@ -191,17 +191,13 @@ public class SqlQueryCancelTest extends BaseTestCase {
}
@Test
public void cancelOrmDtoDuringIterate() {
void cancelOrmDtoDuringIterate() {
DtoQuery<EBasicDto> query = DB.find(EBasic.class).select("id,status").asDto(EBasicDto.class);
QueryIterator<EBasicDto> iter = query.findIterate();
assertThat(iter.hasNext()).isTrue();
query.cancel();
if (isMariaDB()) {
assertThrows(PersistenceException.class, iter::next);
} else {
assertThat(iter.next()).isNotNull();
}
assertThat(iter.next()).isNotNull();
// We might have 100 entities in a buffer. So we must iterate through all.
assertThatThrownBy(() -> {
@@ -9,7 +9,7 @@ import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestSqlUpdateExceptions extends BaseTestCase {
class TestSqlUpdateExceptions extends BaseTestCase {
private String sql = "insert into uuone (id, name, version) values (?,?,?)";
@@ -63,7 +63,7 @@ public class TestSqlUpdateExceptions extends BaseTestCase {
}
@Test
public void duplicateKey_inBatch() {
void duplicateKey_inBatch() {
UUID id = UUID.randomUUID();
assertThrows(DuplicateKeyException.class, () -> {
try (Transaction transaction = DB.beginTransaction()) {
@@ -85,7 +85,7 @@ public class TestSqlUpdateExceptions extends BaseTestCase {
}
@Test
public void duplicateKey_executeBatch() {
void duplicateKey_executeBatch() {
UUID id = UUID.randomUUID();
assertThrows(DuplicateKeyException.class, () -> {
try (Transaction transaction = DB.beginTransaction()) {
@@ -138,7 +138,7 @@ datasource.mysql.url=jdbc:mysql://127.0.0.1:4306/unit
datasource.mariadb.username=unit
datasource.mariadb.password=unit
datasource.mariadb.url=jdbc:mariadb://localhost:4306/unit?useLegacyDatetimeCode=false
datasource.mariadb.url=jdbc:mariadb://localhost:5306/unit?useLegacyDatetimeCode=false
datasource.cockroach.username=root
datasource.cockroach.password=