Skip to content

Commit

Permalink
HHH-6504: Added support for index attribute for maps.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpav committed Apr 24, 2012
1 parent a339436 commit ce2f359
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public class ListAttributeIndexSource extends AbstractHbmSourceNode implements P
private final ExplicitHibernateTypeSource typeSource;
private final int base;

public ListAttributeIndexSource( MappingDocument mappingDocument, final JaxbListIndexElement indexElement ) {
super( mappingDocument );
valueSources = Helper.buildValueSources( sourceMappingDocument(), new Helper.ValueSourcesAdapter() {
public ListAttributeIndexSource( MappingDocument sourceMappingDocument, final JaxbListIndexElement indexElement ) {
super( sourceMappingDocument );
valueSources = Helper.buildValueSources( sourceMappingDocument, new Helper.ValueSourcesAdapter() {

List< JaxbColumnElement > columnElements = indexElement.getColumn() == null
? Collections.EMPTY_LIST
Expand Down Expand Up @@ -96,10 +96,9 @@ public Map< String, String > getParameters() {
base = Integer.parseInt( indexElement.getBase() );
}

// TODO: What do we do with the length property?
public ListAttributeIndexSource( MappingDocument mappingDocument, final JaxbIndexElement indexElement ) {
super( mappingDocument );
valueSources = Helper.buildValueSources( sourceMappingDocument(), new Helper.ValueSourcesAdapter() {
public ListAttributeIndexSource( MappingDocument sourceMappingDocument, final JaxbIndexElement indexElement ) {
super( sourceMappingDocument );
valueSources = Helper.buildValueSources( sourceMappingDocument, new Helper.ValueSourcesAdapter() {

@Override
public String getColumnAttribute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;

import org.hibernate.internal.jaxb.mapping.hbm.JaxbIndexElement;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbMapElement.JaxbMapKey;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
Expand All @@ -42,7 +43,6 @@ public class MapAttributeIndexSource extends AbstractHbmSourceNode implements Pl
/**
* @param sourceMappingDocument
*/
// TODO: What do we do with the length property?
public MapAttributeIndexSource( MappingDocument sourceMappingDocument, final JaxbMapKey mapKey ) {
super( sourceMappingDocument );
valueSources = Helper.buildValueSources( sourceMappingDocument(), new Helper.ValueSourcesAdapter() {
Expand Down Expand Up @@ -99,6 +99,54 @@ public Map< String, String > getParameters() {
};
}

public MapAttributeIndexSource( MappingDocument sourceMappingDocument, final JaxbIndexElement indexElement ) {
super( sourceMappingDocument );
valueSources = Helper.buildValueSources( sourceMappingDocument, new Helper.ValueSourcesAdapter() {

@Override
public String getColumnAttribute() {
return indexElement.getColumnAttribute();
}

@Override
public List getColumnOrFormulaElements() {
return indexElement.getColumn();
}

@Override
public String getContainingTableName() {
return null;
}

@Override
public String getFormulaAttribute() {
return null;
}

@Override
public boolean isIncludedInInsertByDefault() {
return areValuesIncludedInInsertByDefault();
}

@Override
public boolean isIncludedInUpdateByDefault() {
return areValuesIncludedInUpdateByDefault();
}
} );
typeSource = new ExplicitHibernateTypeSource() {

@Override
public String getName() {
return indexElement.getType();
}

@Override
public Map< String, String > getParameters() {
return java.util.Collections.< String, String >emptyMap();
}
};
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.hibernate.metamodel.internal.source.hbm;

import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbIndexElement;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbMapElement;
import org.hibernate.internal.jaxb.mapping.hbm.JaxbMapElement.JaxbMapKey;
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
Expand All @@ -48,11 +49,15 @@ public MapAttributeSource(
AttributeSourceContainer container ) {
super( sourceMappingDocument, mapElement, container );
JaxbMapKey mapKey = mapElement.getMapKey();
if ( mapKey == null ) {
if ( mapKey != null ) {
this.indexSource = new MapAttributeIndexSource( sourceMappingDocument, mapKey );
} else {
JaxbIndexElement indexElement = mapElement.getIndex();
if ( indexElement != null ) {
this.indexSource = new MapAttributeIndexSource( sourceMappingDocument, indexElement );
}
throw new NotYetImplementedException(
"<map-key-many-to-many>, <composite-map-key>, <index>, <composite-index>, <index-many-to-many>, and <index-many-to-any>" );
} else {
this.indexSource = new MapAttributeIndexSource( sourceMappingDocument(), mapKey );
}
}

Expand Down

0 comments on commit ce2f359

Please sign in to comment.