add select generator test for Postgres, MySQL, EDB

This commit is contained in:
Gavin 2022-12-18 03:32:32 +01:00 committed by Gavin King
parent d8bf649998
commit 679ed3bbee
5 changed files with 84 additions and 3 deletions

View File

@ -19,7 +19,6 @@ import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator;
import org.hibernate.sql.ast.spi.SqlSelection;
import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.ast.tree.cte.CteContainer;
import org.hibernate.sql.ast.tree.cte.CteStatement;
import org.hibernate.sql.ast.tree.cte.CteTableGroup;
import org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression;
import org.hibernate.sql.ast.tree.expression.ColumnReference;

View File

@ -21,6 +21,43 @@
</natural-id>
</class>
<database-object>
<create>
<![CDATA[
CREATE OR REPLACE FUNCTION gen_id_my_entity() RETURNS TRIGGER AS $$
BEGIN
select coalesce( max(id), 0 ) + 1
into new.id
from my_entity;
RETURN new;
END $$ LANGUAGE plpgsql;
CREATE OR REPLACE TRIGGER t_i_my_entity
BEFORE INSERT ON my_entity
FOR EACH ROW
EXECUTE PROCEDURE gen_id_my_entity();
]]>
</create>
<drop>
<![CDATA[DROP TRIGGER t_i_my_entity ON my_entity; DROP FUNCTION gen_id_my_entity;]]>
</drop>
<dialect-scope name="org.hibernate.dialect.PostgreSQLDialect"/>
<dialect-scope name="org.hibernate.dialect.PostgresPlusDialect"/>
</database-object>
<database-object>
<create>
<![CDATA[CREATE TRIGGER t_i_my_entity
BEFORE INSERT ON my_entity
FOR EACH ROW
SET new.id = (select coalesce( max(id), 0 ) + 1 from my_entity);]]>
</create>
<drop>
<![CDATA[DROP TRIGGER t_i_my_entity]]>
</drop>
<dialect-scope name="org.hibernate.dialect.MySQLDialect"/>
<dialect-scope name="org.hibernate.dialect.MariaDBDialect"/>
</database-object>
<database-object>
<create>
<![CDATA[CREATE OR REPLACE TRIGGER t_i_my_entity

View File

@ -11,7 +11,9 @@ import java.io.IOException;
import java.nio.file.Files;
import java.util.EnumSet;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;
@ -33,7 +35,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
xmlMappings = "org/hibernate/orm/test/generatedkeys/select/MyEntity.hbm.xml"
)
@SessionFactory
@RequiresDialect(value = OracleDialect.class)
@RequiresDialect(OracleDialect.class)
@RequiresDialect(PostgreSQLDialect.class)
@RequiresDialect(MySQLDialect.class)
public class SelectGeneratorTest {
@Test

View File

@ -11,6 +11,43 @@
<hibernate-mapping package="org.hibernate.orm.test.generatedkeys.select" default-access="field">
<database-object>
<create>
<![CDATA[
CREATE OR REPLACE FUNCTION gen_id_my_entity() RETURNS TRIGGER AS $$
BEGIN
select coalesce( max(id), 0 ) + 1
into new.id
from my_entity;
RETURN new;
END $$ LANGUAGE plpgsql;
CREATE OR REPLACE TRIGGER t_i_my_entity
BEFORE INSERT ON my_entity
FOR EACH ROW
EXECUTE PROCEDURE gen_id_my_entity();
]]>
</create>
<drop>
<![CDATA[DROP TRIGGER t_i_my_entity ON my_entity; DROP FUNCTION gen_id_my_entity;]]>
</drop>
<dialect-scope name="org.hibernate.dialect.PostgreSQLDialect"/>
<dialect-scope name="org.hibernate.dialect.PostgresPlusDialect"/>
</database-object>
<database-object>
<create>
<![CDATA[CREATE TRIGGER t_i_my_entity
BEFORE INSERT ON my_entity
FOR EACH ROW
SET new.id = (select coalesce( max(id), 0 ) + 1 from my_entity);]]>
</create>
<drop>
<![CDATA[DROP TRIGGER t_i_my_entity]]>
</drop>
<dialect-scope name="org.hibernate.dialect.MySQLDialect"/>
<dialect-scope name="org.hibernate.dialect.MariaDBDialect"/>
</database-object>
<database-object>
<create>
<![CDATA[CREATE OR REPLACE TRIGGER t_i_my_entity

View File

@ -6,7 +6,9 @@
*/
package org.hibernate.orm.test.generatedkeys.selectannotated;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.RequiresDialect;
@ -33,7 +35,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
xmlMappings = "org/hibernate/orm/test/generatedkeys/selectannotated/MyEntity.hbm.xml"
)
@SessionFactory
@RequiresDialect(value = OracleDialect.class)
@RequiresDialect(OracleDialect.class)
@RequiresDialect(PostgreSQLDialect.class)
@RequiresDialect(MySQLDialect.class)
public class SelectGeneratorTest {
@Test