Skip to content

Commit 5cf714f

Browse files
committed
HHH-19608 add tests for table partitioning with 'options' and @PartitionKey
1 parent f4073da commit 5cf714f

File tree

9 files changed

+263
-0
lines changed

9 files changed

+263
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.sql.partition;
6+
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.Id;
9+
import jakarta.persistence.Table;
10+
import org.hibernate.annotations.PartitionKey;
11+
import org.hibernate.dialect.DB2Dialect;
12+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
13+
import org.hibernate.testing.orm.junit.Jpa;
14+
import org.hibernate.testing.orm.junit.RequiresDialect;
15+
import org.junit.jupiter.api.Test;
16+
17+
import static org.junit.jupiter.api.Assertions.assertNotNull;
18+
19+
@RequiresDialect(DB2Dialect.class)
20+
@Jpa(annotatedClasses = Db2PartitionedTableTest.Partitioned.class)
21+
class Db2PartitionedTableTest {
22+
@Test void test(EntityManagerFactoryScope scope) {
23+
scope.inTransaction( session -> {
24+
Partitioned partitioned = new Partitioned();
25+
partitioned.id = 1L;
26+
partitioned.pid = 500L;
27+
session.persist( partitioned );
28+
} );
29+
scope.inTransaction( session -> {
30+
Partitioned partitioned = session.find( Partitioned.class, 1L );
31+
assertNotNull( partitioned );
32+
partitioned.text = "updated";
33+
} );
34+
}
35+
@Entity
36+
@Table(name = "db2parts",
37+
options =
38+
"""
39+
PARTITION BY RANGE (pid) (
40+
STARTING FROM (0) ENDING AT (1000),
41+
ENDING AT (2000)
42+
)
43+
""")
44+
static class Partitioned {
45+
@Id Long id;
46+
@PartitionKey Long pid;
47+
String text = "";
48+
}
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.sql.partition;
6+
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.Id;
9+
import jakarta.persistence.Table;
10+
import org.hibernate.annotations.PartitionKey;
11+
import org.hibernate.dialect.MySQLDialect;
12+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
13+
import org.hibernate.testing.orm.junit.Jpa;
14+
import org.hibernate.testing.orm.junit.RequiresDialect;
15+
import org.junit.jupiter.api.Test;
16+
17+
import static org.junit.jupiter.api.Assertions.assertNotNull;
18+
19+
@RequiresDialect(MySQLDialect.class)
20+
@Jpa(annotatedClasses = MySQLPartitionedTableTest.Partitioned.class)
21+
class MySQLPartitionedTableTest {
22+
@Test void test(EntityManagerFactoryScope scope) {
23+
scope.inTransaction( session -> {
24+
Partitioned partitioned = new Partitioned();
25+
partitioned.id = 1L;
26+
partitioned.pid = 500L;
27+
session.persist( partitioned );
28+
} );
29+
scope.inTransaction( session -> {
30+
Partitioned partitioned = session.find( Partitioned.class, 1L );
31+
assertNotNull( partitioned );
32+
partitioned.text = "updated";
33+
} );
34+
}
35+
@Entity
36+
@Table(name = "myparts",
37+
options =
38+
"""
39+
PARTITION BY RANGE (pid) (
40+
PARTITION p1 VALUES LESS THAN (1000),
41+
PARTITION p2 VALUES LESS THAN (2000)
42+
)
43+
""")
44+
static class Partitioned {
45+
@Id Long id;
46+
@PartitionKey Long pid;
47+
String text = "";
48+
}
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.sql.partition;
6+
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.Id;
9+
import jakarta.persistence.Table;
10+
import org.hibernate.annotations.PartitionKey;
11+
import org.hibernate.dialect.OracleDialect;
12+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
13+
import org.hibernate.testing.orm.junit.Jpa;
14+
import org.hibernate.testing.orm.junit.RequiresDialect;
15+
import org.junit.jupiter.api.Test;
16+
17+
import static org.junit.jupiter.api.Assertions.assertNotNull;
18+
19+
@RequiresDialect(OracleDialect.class)
20+
@Jpa(annotatedClasses = OraclePartitionedTableTest.Partitioned.class)
21+
class OraclePartitionedTableTest {
22+
@Test void test(EntityManagerFactoryScope scope) {
23+
scope.inTransaction( session -> {
24+
Partitioned partitioned = new Partitioned();
25+
partitioned.id = 1L;
26+
partitioned.pid = 500L;
27+
session.persist( partitioned );
28+
} );
29+
scope.inTransaction( session -> {
30+
Partitioned partitioned = session.find( Partitioned.class, 1L );
31+
assertNotNull( partitioned );
32+
partitioned.text = "updated";
33+
} );
34+
}
35+
@Entity
36+
@Table(name = "oraparts",
37+
options =
38+
"""
39+
PARTITION BY RANGE (pid) (
40+
PARTITION p1 VALUES LESS THAN (1000),
41+
PARTITION p2 VALUES LESS THAN (2000)
42+
)
43+
""")
44+
static class Partitioned {
45+
@Id Long id;
46+
@PartitionKey Long pid;
47+
String text = "";
48+
}
49+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.sql.partition;
6+
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.Id;
9+
import jakarta.persistence.Table;
10+
import org.hibernate.annotations.PartitionKey;
11+
import org.hibernate.cfg.SchemaToolingSettings;
12+
import org.hibernate.dialect.PostgreSQLDialect;
13+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
14+
import org.hibernate.testing.orm.junit.Jpa;
15+
import org.hibernate.testing.orm.junit.RequiresDialect;
16+
import org.hibernate.testing.orm.junit.Setting;
17+
import org.junit.jupiter.api.Test;
18+
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
21+
@RequiresDialect(PostgreSQLDialect.class)
22+
@Jpa(annotatedClasses = PostgresPartitionedTableTest.Partitioned.class,
23+
integrationSettings = {
24+
@Setting(name = SchemaToolingSettings.JAKARTA_HBM2DDL_CREATE_SCRIPT_SOURCE,
25+
value = "org/hibernate/orm/test/sql/partition/postgrespartitions-create.sql"),
26+
@Setting(name = SchemaToolingSettings.JAKARTA_HBM2DDL_CREATE_SOURCE,
27+
value = "metadata-then-script"),
28+
@Setting(name = SchemaToolingSettings.JAKARTA_HBM2DDL_DROP_SCRIPT_SOURCE,
29+
value = "org/hibernate/orm/test/sql/partition/postgrespartitions-drop.sql"),
30+
@Setting(name = SchemaToolingSettings.JAKARTA_HBM2DDL_DROP_SOURCE,
31+
value = "script-then-metadata")})
32+
class PostgresPartitionedTableTest {
33+
@Test void test(EntityManagerFactoryScope scope) {
34+
scope.inTransaction( session -> {
35+
Partitioned partitioned = new Partitioned();
36+
partitioned.id = 1L;
37+
partitioned.pid = 500L;
38+
session.persist( partitioned );
39+
} );
40+
scope.inTransaction( session -> {
41+
Partitioned partitioned = session.find( Partitioned.class, 1L );
42+
assertNotNull( partitioned );
43+
partitioned.text = "updated";
44+
} );
45+
}
46+
@Entity
47+
@Table(name = "pgparts",
48+
options = "partition by range (pid)")
49+
static class Partitioned {
50+
@Id Long id;
51+
@PartitionKey Long pid;
52+
String text = "";
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.sql.partition;
6+
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.Id;
9+
import jakarta.persistence.Table;
10+
import org.hibernate.annotations.PartitionKey;
11+
import org.hibernate.cfg.SchemaToolingSettings;
12+
import org.hibernate.dialect.SQLServerDialect;
13+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
14+
import org.hibernate.testing.orm.junit.Jpa;
15+
import org.hibernate.testing.orm.junit.RequiresDialect;
16+
import org.hibernate.testing.orm.junit.Setting;
17+
import org.junit.jupiter.api.Test;
18+
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
21+
@RequiresDialect(SQLServerDialect.class)
22+
@Jpa(annotatedClasses = SQLServerPartitionedTableTest.Partitioned.class,
23+
integrationSettings = {
24+
@Setting(name = SchemaToolingSettings.JAKARTA_HBM2DDL_CREATE_SCRIPT_SOURCE,
25+
value = "org/hibernate/orm/test/sql/partition/sqlserverpartitions-create.sql"),
26+
@Setting(name = SchemaToolingSettings.JAKARTA_HBM2DDL_CREATE_SOURCE,
27+
value = "script-then-metadata"),
28+
@Setting(name = SchemaToolingSettings.JAKARTA_HBM2DDL_DROP_SCRIPT_SOURCE,
29+
value = "org/hibernate/orm/test/sql/partition/sqlserverpartitions-drop.sql"),
30+
@Setting(name = SchemaToolingSettings.JAKARTA_HBM2DDL_DROP_SOURCE,
31+
value = "metadata-then-script")})
32+
class SQLServerPartitionedTableTest {
33+
@Test void test(EntityManagerFactoryScope scope) {
34+
scope.inTransaction( session -> {
35+
Partitioned partitioned = new Partitioned();
36+
partitioned.id = 1L;
37+
partitioned.pid = 500L;
38+
session.persist( partitioned );
39+
} );
40+
scope.inTransaction( session -> {
41+
Partitioned partitioned = session.find( Partitioned.class, 1L );
42+
assertNotNull( partitioned );
43+
partitioned.text = "updated";
44+
} );
45+
}
46+
@Entity
47+
@Table(name = "msparts",
48+
options = "on partScheme(pid)")
49+
static class Partitioned {
50+
@Id Long id;
51+
@PartitionKey Long pid;
52+
String text = "";
53+
}
54+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
create table p1 partition of pgparts for values from (0) to (1000);
2+
create table p2 partition of pgparts for values from (1001) to (2000);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
drop table if exists p1;
2+
drop table if exists p2;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE PARTITION FUNCTION partFun (bigint) AS RANGE LEFT FOR VALUES (1000, 2000);
2+
CREATE PARTITION SCHEME partScheme AS PARTITION partFun ALL TO ('PRIMARY');
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DROP PARTITION SCHEME partScheme;
2+
DROP PARTITION FUNCTION partFun;

0 commit comments

Comments
 (0)