Skip to content

Commit

Permalink
HHH-7088 - Implement secondary table support in new metamodel code
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Feb 22, 2012
1 parent f765247 commit 8afab9f
Show file tree
Hide file tree
Showing 28 changed files with 199 additions and 143 deletions.
Expand Up @@ -66,16 +66,18 @@
public abstract class AbstractEntitySourceImpl
extends AbstractHbmSourceNode
implements EntitySource, Helper.InLineViewNameInferrer {

private final EntityElement entityElement;
private final String className;
private final String entityName;

private List<SubclassEntitySource> subclassEntitySources = new ArrayList<SubclassEntitySource>();

private int inLineViewCount = 0;

// logically final, but built during 'afterInstantiation' callback
private List<AttributeSource> attributeSources;
private Set<SecondaryTableSource> secondaryTableSources;
private List<SubclassEntitySource> subclassEntitySources;

protected AbstractEntitySourceImpl(MappingDocument sourceMappingDocument, EntityElement entityElement) {
super( sourceMappingDocument );
Expand All @@ -95,8 +97,6 @@ public String inferInLineViewName() {
protected void afterInstantiation() {
this.attributeSources = buildAttributeSources();
this.secondaryTableSources = buildSecondaryTables();

this.subclassEntitySources = buildSubClassSources();
}

protected List<AttributeSource> buildAttributeSources() {
Expand Down Expand Up @@ -161,6 +161,7 @@ else if ( JaxbAnyElement.class.isInstance( attributeElement ) ) {
else if ( JaxbBagElement.class.isInstance( attributeElement ) ) {
results.add(
new BagAttributeSourceImpl(
sourceMappingDocument(),
JaxbBagElement.class.cast( attributeElement ),
this
)
Expand All @@ -172,6 +173,7 @@ else if ( JaxbIdbagElement.class.isInstance( attributeElement ) ) {
else if ( JaxbSetElement.class.isInstance( attributeElement ) ) {
results.add(
new SetAttributeSourceImpl(
sourceMappingDocument(),
JaxbSetElement.class.cast( attributeElement ),
this
)
Expand All @@ -189,11 +191,6 @@ else if ( JaxbMapElement.class.isInstance( attributeElement ) ) {
}
}

protected List<SubclassEntitySource> buildSubClassSources() {
// todo : implement subclass processing
return Collections.emptyList();
}

private Set<SecondaryTableSource> buildSecondaryTables() {
if ( ! JoinElementSource.class.isInstance( entityElement ) ) {
return Collections.emptySet();
Expand Down
Expand Up @@ -38,7 +38,6 @@
import org.hibernate.metamodel.spi.binding.CustomSQL;
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.LocalBindingContext;
import org.hibernate.metamodel.spi.source.MappingException;
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
import org.hibernate.metamodel.spi.source.PluralAttributeElementSource;
Expand All @@ -50,6 +49,7 @@
* @author Steve Ebersole
*/
public abstract class AbstractPluralAttributeSourceImpl
extends AbstractHbmSourceNode
implements PluralAttributeSource, Helper.InLineViewNameInferrer {
private final PluralAttributeElement pluralAttributeElement;
private final AttributeSourceContainer container;
Expand All @@ -60,12 +60,18 @@ public abstract class AbstractPluralAttributeSourceImpl
private final PluralAttributeElementSource elementSource;

protected AbstractPluralAttributeSourceImpl(
MappingDocument sourceMappingDocument,
final PluralAttributeElement pluralAttributeElement,
AttributeSourceContainer container) {
super( sourceMappingDocument );
this.pluralAttributeElement = pluralAttributeElement;
this.container = container;

this.keySource = new PluralAttributeKeySourceImpl( pluralAttributeElement.getKey(), container );
this.keySource = new PluralAttributeKeySourceImpl(
sourceMappingDocument(),
pluralAttributeElement.getKey(),
container
);
this.elementSource = interpretElementType();

this.typeInformation = new ExplicitHibernateTypeSource() {
Expand All @@ -84,26 +90,28 @@ public Map<String, String> getParameters() {
private PluralAttributeElementSource interpretElementType() {
if ( pluralAttributeElement.getElement() != null ) {
return new BasicPluralAttributeElementSourceImpl(
pluralAttributeElement.getElement(), container.getLocalBindingContext()
sourceMappingDocument(),
pluralAttributeElement.getElement()
);
}
else if ( pluralAttributeElement.getCompositeElement() != null ) {
return new CompositePluralAttributeElementSourceImpl(
pluralAttributeElement.getCompositeElement(), container.getLocalBindingContext()
sourceMappingDocument(),
pluralAttributeElement.getCompositeElement()
);
}
else if ( pluralAttributeElement.getOneToMany() != null ) {
return new OneToManyPluralAttributeElementSourceImpl(
sourceMappingDocument(),
pluralAttributeElement,
pluralAttributeElement.getOneToMany(),
container.getLocalBindingContext()
pluralAttributeElement.getOneToMany()
);
}
else if ( pluralAttributeElement.getManyToMany() != null ) {
return new ManyToManyPluralAttributeElementSourceImpl(
sourceMappingDocument(),
pluralAttributeElement,
pluralAttributeElement.getManyToMany(),
container.getLocalBindingContext()
pluralAttributeElement.getManyToMany()
);
}
else if ( pluralAttributeElement.getManyToAny() != null ) {
Expand All @@ -126,10 +134,6 @@ protected AttributeSourceContainer container() {
return container;
}

protected LocalBindingContext bindingContext() {
return container().getLocalBindingContext();
}

@Override
public PluralAttributeKeySource getKeySource() {
return keySource;
Expand All @@ -147,7 +151,7 @@ public String inferInLineViewName() {

@Override
public TableSpecificationSource getCollectionTableSpecificationSource() {
return Helper.createTableSource( pluralAttributeElement, this );
return Helper.createTableSource( sourceMappingDocument(), pluralAttributeElement, this );
}

@Override
Expand Down Expand Up @@ -302,7 +306,7 @@ else if ( "false".equals( lazySelection ) ) {
lazySelection,
pluralAttributeElement.getName()
),
bindingContext().getOrigin()
origin()
);
}

Expand Down
Expand Up @@ -33,8 +33,11 @@
* @author Steve Ebersole
*/
public class BagAttributeSourceImpl extends AbstractPluralAttributeSourceImpl implements Orderable {
public BagAttributeSourceImpl(JaxbBagElement bagElement, AttributeSourceContainer container) {
super( bagElement, container );
public BagAttributeSourceImpl(
MappingDocument sourceMappingDocument,
JaxbBagElement bagElement,
AttributeSourceContainer container) {
super( sourceMappingDocument, bagElement, container );
}

@Override
Expand Down
Expand Up @@ -28,22 +28,25 @@

import org.hibernate.internal.jaxb.mapping.hbm.JaxbElementElement;
import org.hibernate.metamodel.spi.source.BasicPluralAttributeElementSource;
import org.hibernate.metamodel.spi.source.LocalBindingContext;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.PluralAttributeElementNature;
import org.hibernate.metamodel.spi.source.RelationalValueSource;

/**
* @author Steve Ebersole
*/
public class BasicPluralAttributeElementSourceImpl implements BasicPluralAttributeElementSource {
public class BasicPluralAttributeElementSourceImpl
extends AbstractHbmSourceNode
implements BasicPluralAttributeElementSource {
private final List<RelationalValueSource> valueSources;
private final ExplicitHibernateTypeSource typeSource;

public BasicPluralAttributeElementSourceImpl(
final JaxbElementElement elementElement,
LocalBindingContext bindingContext) {
MappingDocument sourceMappingDocument,
final JaxbElementElement elementElement) {
super( sourceMappingDocument );
this.valueSources = Helper.buildValueSources(
sourceMappingDocument(),
new Helper.ValueSourcesAdapter() {
@Override
public String getContainingTableName() {
Expand Down Expand Up @@ -74,8 +77,7 @@ public String getFormulaAttribute() {
public List getColumnOrFormulaElements() {
return elementElement.getColumnOrFormula();
}
},
bindingContext
}
);

this.typeSource = new ExplicitHibernateTypeSource() {
Expand Down
Expand Up @@ -34,27 +34,32 @@
*
* @author Steve Ebersole
*/
class ColumnAttributeSourceImpl implements ColumnSource {
class ColumnAttributeSourceImpl
extends AbstractHbmSourceNode
implements ColumnSource {
private final String tableName;
private final String columnName;
private TruthValue includedInInsert;
private TruthValue includedInUpdate;
private TruthValue nullable;

ColumnAttributeSourceImpl(
MappingDocument mappingDocument,
String tableName,
String columnName,
TruthValue includedInInsert,
TruthValue includedInUpdate) {
this( tableName, columnName, includedInInsert, includedInUpdate, TruthValue.UNKNOWN );
this( mappingDocument, tableName, columnName, includedInInsert, includedInUpdate, TruthValue.UNKNOWN );
}

ColumnAttributeSourceImpl(
MappingDocument mappingDocument,
String tableName,
String columnName,
TruthValue includedInInsert,
TruthValue includedInUpdate,
TruthValue nullable) {
super( mappingDocument );
this.tableName = tableName;
this.columnName = columnName;
this.includedInInsert = includedInInsert;
Expand Down
Expand Up @@ -32,27 +32,32 @@
/**
* @author Steve Ebersole
*/
class ColumnSourceImpl implements ColumnSource {
class ColumnSourceImpl
extends AbstractHbmSourceNode
implements ColumnSource {
private final String tableName;
private final JaxbColumnElement columnElement;
private final TruthValue includedInInsert;
private final TruthValue includedInUpdate;
private final TruthValue nullable;

ColumnSourceImpl(
MappingDocument mappingDocument,
String tableName,
JaxbColumnElement columnElement,
TruthValue isIncludedInInsert,
TruthValue isIncludedInUpdate) {
this( tableName, columnElement, isIncludedInInsert, isIncludedInUpdate, TruthValue.UNKNOWN );
this( mappingDocument, tableName, columnElement, isIncludedInInsert, isIncludedInUpdate, TruthValue.UNKNOWN );
}

ColumnSourceImpl(
MappingDocument mappingDocument,
String tableName,
JaxbColumnElement columnElement,
TruthValue isIncludedInInsert,
TruthValue isIncludedInUpdate,
TruthValue nullable) {
super( mappingDocument );
this.tableName = tableName;
this.columnElement = columnElement;
this.nullable = nullable;
Expand Down
Expand Up @@ -39,15 +39,17 @@
/**
* @author Steve Ebersole
*/
public class CompositePluralAttributeElementSourceImpl implements CompositePluralAttributeElementSource {
public class CompositePluralAttributeElementSourceImpl
extends AbstractHbmSourceNode
implements CompositePluralAttributeElementSource {

private final JaxbCompositeElementElement compositeElement;
private final LocalBindingContext bindingContext;

public CompositePluralAttributeElementSourceImpl(
JaxbCompositeElementElement compositeElement,
LocalBindingContext bindingContext) {
MappingDocument mappingDocument,
JaxbCompositeElementElement compositeElement) {
super( mappingDocument );
this.compositeElement = compositeElement;
this.bindingContext = bindingContext;
}

@Override
Expand All @@ -57,12 +59,12 @@ public PluralAttributeElementNature getNature() {

@Override
public String getClassName() {
return bindingContext.qualifyClassName( compositeElement.getClazz() );
return bindingContext().qualifyClassName( compositeElement.getClazz() );
}

@Override
public Value<Class<?>> getClassReference() {
return bindingContext.makeClassReference( getClassName() );
return bindingContext().makeClassReference( getClassName() );
}

@Override
Expand Down Expand Up @@ -103,6 +105,6 @@ public List<AttributeSource> attributeSources() {

@Override
public LocalBindingContext getLocalBindingContext() {
return bindingContext;
return bindingContext();
}
}
Expand Up @@ -32,11 +32,17 @@
/**
* @author Steve Ebersole
*/
public class FetchProfileSourceImpl implements FetchProfileSource {
public class FetchProfileSourceImpl
extends AbstractHbmSourceNode
implements FetchProfileSource {

private final String name;
private final List<AssociationOverrideSource> associationOverrideSources;

public FetchProfileSourceImpl(JaxbFetchProfileElement fetchProfileElement) {
public FetchProfileSourceImpl(
MappingDocument mappingDocument,
JaxbFetchProfileElement fetchProfileElement) {
super( mappingDocument );
this.name = fetchProfileElement.getName();
this.associationOverrideSources = buildAssociationOverrideSources( fetchProfileElement );
}
Expand Down
Expand Up @@ -33,12 +33,17 @@
/**
* @author Steve Ebersole
*/
public class FilterDefinitionSourceImpl implements FilterDefinitionSource {
public class FilterDefinitionSourceImpl
extends AbstractHbmSourceNode
implements FilterDefinitionSource {
private final String name;
private final String condition;
private List<FilterParameterSource> parameterSources;

public FilterDefinitionSourceImpl(JaxbHibernateMapping.JaxbFilterDef filterDefElement) {
public FilterDefinitionSourceImpl(
MappingDocument mappingDocument,
JaxbHibernateMapping.JaxbFilterDef filterDefElement) {
super( mappingDocument );
this.name = filterDefElement.getName();

String conditionAttribute = filterDefElement.getCondition();
Expand Down
Expand Up @@ -29,11 +29,16 @@
/**
* @author Steve Ebersole
*/
public class FilterSourceImpl implements FilterSource {
public class FilterSourceImpl
extends AbstractHbmSourceNode
implements FilterSource {
private final String name;
private final String condition;

public FilterSourceImpl(JaxbFilterElement filterElement) {
public FilterSourceImpl(
MappingDocument mappingDocument,
JaxbFilterElement filterElement) {
super( mappingDocument );
this.name = filterElement.getName();

String conditionAttribute = filterElement.getCondition();
Expand Down

0 comments on commit 8afab9f

Please sign in to comment.