HHH-4894 - Process composite-id sub-generators PersistentIdentifierGenerator contract(s)
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18748 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
f0cdfa3ac8
commit
81fd208898
|
@ -27,8 +27,10 @@ import java.io.Serializable;
|
|||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
|
||||
|
@ -48,8 +50,8 @@ public class Multiple implements Serializable
|
|||
private Long id1;
|
||||
|
||||
@Id
|
||||
@GenericGenerator(name = "increment2", strategy = "increment")
|
||||
@GeneratedValue(generator = "increment2")
|
||||
@GeneratedValue(generator = "MULTIPLE_SEQ", strategy = GenerationType.SEQUENCE)
|
||||
@SequenceGenerator( name = "MULTIPLE_SEQ", sequenceName = "MULTIPLE_SEQ")
|
||||
private Long id2;
|
||||
|
||||
@Id
|
||||
|
|
|
@ -67,6 +67,7 @@ import org.hibernate.MappingNotFoundException;
|
|||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.SessionFactoryObserver;
|
||||
import org.hibernate.DuplicateMappingException;
|
||||
import org.hibernate.id.IdentifierGeneratorAggregator;
|
||||
import org.hibernate.tuple.entity.EntityTuplizerFactory;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.MySQLDialect;
|
||||
|
@ -800,6 +801,9 @@ public class Configuration implements Serializable {
|
|||
if ( ig instanceof PersistentIdentifierGenerator ) {
|
||||
generators.put( ( (PersistentIdentifierGenerator) ig ).generatorKey(), ig );
|
||||
}
|
||||
else if ( ig instanceof IdentifierGeneratorAggregator ) {
|
||||
( (IdentifierGeneratorAggregator) ig ).registerPersistentGenerators( generators );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.io.Serializable;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.SessionImplementor;
|
||||
|
@ -61,7 +62,7 @@ import org.hibernate.engine.SessionImplementor;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class CompositeNestedGeneratedValueGenerator implements IdentifierGenerator, Serializable {
|
||||
public class CompositeNestedGeneratedValueGenerator implements IdentifierGenerator, Serializable, IdentifierGeneratorAggregator {
|
||||
/**
|
||||
* Contract for declaring how to locate the context for sub-value injection.
|
||||
*/
|
||||
|
@ -91,6 +92,14 @@ public class CompositeNestedGeneratedValueGenerator implements IdentifierGenerat
|
|||
* @param injectionContext The context into which the generated value can be injected
|
||||
*/
|
||||
public void execute(SessionImplementor session, Object incomingObject, Object injectionContext);
|
||||
|
||||
/**
|
||||
* Register any sub generators which implement {@link PersistentIdentifierGenerator} by their
|
||||
* {@link PersistentIdentifierGenerator#generatorKey generatorKey}.
|
||||
*
|
||||
* @param generatorMap The map of generators.
|
||||
*/
|
||||
public void registerPersistentGenerators(Map generatorMap);
|
||||
}
|
||||
|
||||
private final GenerationContextLocator generationContextLocator;
|
||||
|
@ -116,4 +125,14 @@ public class CompositeNestedGeneratedValueGenerator implements IdentifierGenerat
|
|||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void registerPersistentGenerators(Map generatorMap) {
|
||||
final Iterator itr = generationPlans.iterator();
|
||||
while ( itr.hasNext() ) {
|
||||
final GenerationPlan plan = (GenerationPlan) itr.next();
|
||||
plan.registerPersistentGenerators( generatorMap );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Inc.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.id;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Identifies {@link IdentifierGenerator generators} which potentially aggregate other
|
||||
* {@link PersistentIdentifierGenerator} generators.
|
||||
* <p/>
|
||||
* Initially this is limited to {@link CompositeNestedGeneratedValueGenerator}
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface IdentifierGeneratorAggregator {
|
||||
/**
|
||||
* Register any sub generators which implement {@link PersistentIdentifierGenerator} by their
|
||||
* {@link PersistentIdentifierGenerator#generatorKey generatorKey}.
|
||||
*
|
||||
* @param generatorMap The map of generators.
|
||||
*/
|
||||
public void registerPersistentGenerators(Map generatorMap);
|
||||
}
|
|
@ -24,26 +24,19 @@
|
|||
package org.hibernate.mapping;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.EntityEntry;
|
||||
import org.hibernate.engine.SessionImplementor;
|
||||
import org.hibernate.id.CompositeNestedGeneratedValueGenerator;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.PersistentIdentifierGenerator;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.property.Getter;
|
||||
import org.hibernate.property.PropertyAccessor;
|
||||
import org.hibernate.property.Setter;
|
||||
import org.hibernate.tuple.component.ComponentMetamodel;
|
||||
import org.hibernate.type.ComponentType;
|
||||
|
@ -444,6 +437,12 @@ public class Component extends SimpleValue implements MetaAttributable {
|
|||
final Object generatedValue = subGenerator.generate( session, incomingObject );
|
||||
injector.set( injectionContext, generatedValue, session.getFactory() );
|
||||
}
|
||||
|
||||
public void registerPersistentGenerators(Map generatorMap) {
|
||||
if ( PersistentIdentifierGenerator.class.isInstance( subGenerator ) ) {
|
||||
generatorMap.put( ( (PersistentIdentifierGenerator) subGenerator ).generatorKey(), subGenerator );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue