Skip to content

Commit

Permalink
fixup! --wip-- test to use more generic delegates for identity
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel committed Dec 21, 2023
1 parent 25c974d commit f408626
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.hibernate.boot.model.FunctionContributions;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.dialect.identity.MariaDBIdentityColumnSupport;
import org.hibernate.dialect.sequence.MariaDBSequenceSupport;
import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
Expand Down Expand Up @@ -253,6 +255,11 @@ public boolean supportsUpdateReturning() {
return false;
}

@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return MariaDBIdentityColumnSupport.INSTANCE;
}

@Override
public FunctionalDependencyAnalysisSupport getFunctionalDependencyAnalysisSupport() {
return FunctionalDependencyAnalysisSupportImpl.TABLE_GROUP_AND_CONSTANTS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ public interface IdentityColumnSupport {
*
* @return The insert command with any necessary identity select
* clause attached.
*
* @deprecated Use {@link #appendIdentitySelectToInsert(String, String)} instead.
*/
@Deprecated( forRemoval = true, since = "6.5" )
String appendIdentitySelectToInsert(String insertString);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.dialect.identity;

/**
* @author Marco Belladelli
*/
public class MariaDBIdentityColumnSupport extends MySQLIdentityColumnSupport {
public static final MariaDBIdentityColumnSupport INSTANCE = new MariaDBIdentityColumnSupport();

@Override
public String appendIdentitySelectToInsert(String identityColumnName, String insertString) {
return insertString + " returning " + identityColumnName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.hibernate.generator.values.GeneratedValuesMutationDelegate;
import org.hibernate.generator.values.TableUpdateReturningBuilder;
import org.hibernate.jdbc.Expectation;
import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.sql.ast.tree.expression.ColumnReference;
import org.hibernate.sql.model.ast.MutatingTableReference;
Expand Down Expand Up @@ -112,7 +113,10 @@ public JdbcValuesMappingProducer getGeneratedValuesMappingProducer() {

@Override
public String prepareIdentifierGeneratingInsert(String insertSQL) {
return dialect.getIdentityColumnSupport().appendIdentitySelectToInsert( insertSQL );
return dialect.getIdentityColumnSupport().appendIdentitySelectToInsert(
( (BasicEntityIdentifierMapping) persister.getRootEntityDescriptor().getIdentifierMapping() ).getSelectionExpression(),
insertSQL
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.EventType;
import org.hibernate.generator.values.GeneratedValues;
import org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping;
import org.hibernate.persister.entity.EntityPersister;

import static org.hibernate.generator.values.GeneratedValuesHelper.getGeneratedValues;
Expand All @@ -37,7 +38,10 @@ public SybaseJConnGetGeneratedKeysDelegate(EntityPersister persister, Dialect di

@Override
public String prepareIdentifierGeneratingInsert(String insertSQL) {
return dialect.getIdentityColumnSupport().appendIdentitySelectToInsert( insertSQL );
return dialect.getIdentityColumnSupport().appendIdentitySelectToInsert(
( (BasicEntityIdentifierMapping) persister.getRootEntityDescriptor().getIdentifierMapping() ).getSelectionExpression(),
insertSQL
);
}

@Override
Expand Down

0 comments on commit f408626

Please sign in to comment.