add BinaryLengthTest
to make sure it's possible to have programs with byte[] fields work across Postgres and others
This commit is contained in:
parent
1f0a7e1760
commit
82c94ec142
|
@ -0,0 +1,32 @@
|
|||
package org.hibernate.orm.test.length;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
@SessionFactory
|
||||
@DomainModel(annotatedClasses = WithLongByteArrays.class)
|
||||
public class BinaryLengthTest {
|
||||
@Test
|
||||
public void testLength(SessionFactoryScope scope) {
|
||||
WithLongByteArrays arrays = new WithLongByteArrays();
|
||||
arrays.longish = "hello world ".repeat(2500).getBytes();
|
||||
arrays.long16 = "hello world ".repeat(2700).getBytes();
|
||||
arrays.long32 = "hello world ".repeat(20000).getBytes();
|
||||
// This is an important test that it's possible to handle
|
||||
// very long binary types in a way that's portable across
|
||||
// both Postgres (bytea) and other databases (blob)
|
||||
arrays.lob = "hello world ".repeat(40000).getBytes();
|
||||
scope.inTransaction(s -> s.persist(arrays));
|
||||
scope.inTransaction(s -> {
|
||||
WithLongByteArrays arrs = s.find(WithLongByteArrays.class, arrays.id);
|
||||
assertArrayEquals(arrs.longish, arrays.longish);
|
||||
assertArrayEquals(arrs.long16, arrays.long16);
|
||||
assertArrayEquals(arrs.long32, arrays.long32);
|
||||
assertArrayEquals(arrs.lob, arrays.lob);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -17,6 +17,36 @@ import static org.junit.Assert.assertEquals;
|
|||
public class LengthTest {
|
||||
@Test
|
||||
public void testLength(SessionFactoryScope scope) {
|
||||
WithLongStrings strings = new WithLongStrings();
|
||||
strings.longish = "hello world ".repeat(2500);
|
||||
strings.long16 = "hello world ".repeat(2700);
|
||||
strings.long32 = "hello world ".repeat(20000);
|
||||
strings.clob = "hello world ".repeat(40000);
|
||||
scope.inTransaction(s -> s.persist(strings));
|
||||
scope.inTransaction(s -> {
|
||||
WithLongStrings strs = s.find(WithLongStrings.class, strings.id);
|
||||
assertEquals(strs.longish, strings.longish);
|
||||
assertEquals(strs.long16, strings.long16);
|
||||
assertEquals(strs.long32, strings.long32);
|
||||
assertEquals(strs.clob, strings.clob);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSqlType(SessionFactoryScope scope) {
|
||||
WithLongTypeStrings strings = new WithLongTypeStrings();
|
||||
strings.longish = "hello world ".repeat(2500);
|
||||
strings.long32 = "hello world ".repeat(20000);
|
||||
scope.inTransaction(s -> s.persist(strings));
|
||||
scope.inTransaction(s -> {
|
||||
WithLongTypeStrings strs = s.find(WithLongTypeStrings.class, strings.id);
|
||||
assertEquals(strs.longish, strings.longish);
|
||||
assertEquals(strs.long32, strings.long32);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLong32(SessionFactoryScope scope) {
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
final BasicValuedMapping mapping = (BasicValuedMapping) scope.getSessionFactory()
|
||||
.getRuntimeMetamodels()
|
||||
|
@ -29,28 +59,5 @@ public class LengthTest {
|
|||
else {
|
||||
assertEquals( SqlTypes.VARCHAR, mapping.getJdbcMapping().getJdbcType().getJdbcTypeCode() );
|
||||
}
|
||||
WithLongStrings strings = new WithLongStrings();
|
||||
strings.longish = "hello world ".repeat(2500);
|
||||
strings.long16 = "hello world ".repeat(2700);
|
||||
strings.long32 = "hello world ".repeat(20000);
|
||||
scope.inTransaction(s->s.persist(strings));
|
||||
scope.inTransaction(s-> {
|
||||
WithLongStrings strs = s.find(WithLongStrings.class, strings.id);
|
||||
assertEquals(strs.longish, strings.longish);
|
||||
assertEquals(strs.long16, strings.long16);
|
||||
assertEquals(strs.long32, strings.long32);
|
||||
});
|
||||
}
|
||||
@Test
|
||||
public void testSqlType(SessionFactoryScope scope) {
|
||||
WithLongTypeStrings strings = new WithLongTypeStrings();
|
||||
strings.longish = "hello world ".repeat(2500);
|
||||
strings.long32 = "hello world ".repeat(20000);
|
||||
scope.inTransaction(s->s.persist(strings));
|
||||
scope.inTransaction(s-> {
|
||||
WithLongTypeStrings strs = s.find(WithLongTypeStrings.class, strings.id);
|
||||
assertEquals(strs.longish, strings.longish);
|
||||
assertEquals(strs.long32, strings.long32);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package org.hibernate.orm.test.length;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
import static org.hibernate.Length.LOB_DEFAULT;
|
||||
import static org.hibernate.Length.LONG;
|
||||
import static org.hibernate.Length.LONG16;
|
||||
import static org.hibernate.Length.LONG32;
|
||||
|
||||
@Entity
|
||||
public class WithLongByteArrays {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
public int id;
|
||||
|
||||
@Column(length = LONG)
|
||||
public byte[] longish;
|
||||
|
||||
@Column(length = LONG16)
|
||||
public byte[] long16;
|
||||
|
||||
@Column(length = LONG32)
|
||||
public byte[] long32;
|
||||
|
||||
@Column(length = LOB_DEFAULT+1)
|
||||
public byte[] lob;
|
||||
}
|
|
@ -21,4 +21,7 @@ public class WithLongStrings {
|
|||
|
||||
@Column(length = LONG32)
|
||||
public String long32;
|
||||
|
||||
@Column(length = LOB_DEFAULT+1)
|
||||
public String clob;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue