HHH-7549 Simple refactor
This commit is contained in:
parent
1f80861b16
commit
550f19f3da
|
@ -32,44 +32,41 @@ import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttri
|
|||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class ColumnSourceImpl extends ColumnValuesSourceImpl {
|
||||
private final MappedAttribute attribute;
|
||||
private final String readFragement;
|
||||
private final String writeFragement;
|
||||
private final String checkCondition;
|
||||
|
||||
ColumnSourceImpl(MappedAttribute attribute, AttributeOverride attributeOverride, Column columnValues) {
|
||||
super( columnValues );
|
||||
if ( attributeOverride != null ) {
|
||||
setOverrideColumnValues( attributeOverride.getColumnValues() );
|
||||
}
|
||||
this.attribute = attribute;
|
||||
if(BasicAttribute.class.isInstance( attribute )){
|
||||
BasicAttribute basicAttribute = BasicAttribute.class.cast( attribute );
|
||||
this.readFragement = basicAttribute.getCustomReadFragment();
|
||||
this.writeFragement = basicAttribute.getCustomWriteFragment();
|
||||
this.checkCondition = basicAttribute.getCheckCondition();
|
||||
} else {
|
||||
this.readFragement = null;
|
||||
this.writeFragement = null;
|
||||
this.checkCondition = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReadFragment() {
|
||||
if ( attribute instanceof BasicAttribute ) {
|
||||
return ( ( BasicAttribute ) attribute ).getCustomReadFragment();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return readFragement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWriteFragment() {
|
||||
if ( attribute instanceof BasicAttribute ) {
|
||||
return ( ( BasicAttribute ) attribute ).getCustomWriteFragment();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return writeFragement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCheckCondition() {
|
||||
if ( attribute instanceof BasicAttribute ) {
|
||||
return attribute.getCheckCondition();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
return checkCondition;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.hibernate.metamodel.internal.source.annotations;
|
|||
import java.util.List;
|
||||
|
||||
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
||||
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
|
||||
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
||||
|
@ -20,20 +21,25 @@ public class PluralAttributeIndexSourceImpl implements PluralAttributeIndexSourc
|
|||
}
|
||||
|
||||
@Override
|
||||
public Nature getNature() {
|
||||
public PluralAttributeIndexBinding.Nature getNature() {
|
||||
switch ( indexedPluralAttributeSource.getElementSource().getNature() ){
|
||||
case BASIC:
|
||||
return Nature.BASIC;
|
||||
return PluralAttributeIndexBinding.Nature.BASIC;
|
||||
case COMPONENT:
|
||||
return Nature.COMPOSITE;
|
||||
return PluralAttributeIndexBinding.Nature.COMPOSITE;
|
||||
case MANY_TO_ANY:
|
||||
return Nature.MANY_TO_ANY;
|
||||
return PluralAttributeIndexBinding.Nature.MANY_TO_ANY;
|
||||
case MANY_TO_MANY:
|
||||
return Nature.MANY_TO_MANY;
|
||||
return PluralAttributeIndexBinding.Nature.MANY_TO_MANY;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int base() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExplicitHibernateTypeSource explicitHibernateTypeSource() {
|
||||
return null;
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.Map;
|
|||
import org.hibernate.jaxb.spi.hbm.JaxbColumnElement;
|
||||
import org.hibernate.jaxb.spi.hbm.JaxbIndexElement;
|
||||
import org.hibernate.jaxb.spi.hbm.JaxbListIndexElement;
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
||||
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
|
||||
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
||||
|
@ -136,14 +137,14 @@ public class ListAttributeIndexSource extends AbstractHbmSourceNode implements P
|
|||
public boolean areValuesNullableByDefault() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int base() {
|
||||
return base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Nature getNature() {
|
||||
return Nature.BASIC;
|
||||
public PluralAttributeIndexBinding.Nature getNature() {
|
||||
return PluralAttributeIndexBinding.Nature.BASIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.Map;
|
|||
import org.hibernate.jaxb.spi.hbm.JaxbColumnElement;
|
||||
import org.hibernate.jaxb.spi.hbm.JaxbIndexElement;
|
||||
import org.hibernate.jaxb.spi.hbm.JaxbMapKeyElement;
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
||||
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
|
||||
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
||||
|
@ -37,7 +38,7 @@ import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
|||
*
|
||||
*/
|
||||
public class MapAttributeIndexSource extends AbstractHbmSourceNode implements PluralAttributeIndexSource {
|
||||
private final Nature nature;
|
||||
private final PluralAttributeIndexBinding.Nature nature;
|
||||
private final List<RelationalValueSource> valueSources;
|
||||
private final ExplicitHibernateTypeSource typeSource;
|
||||
|
||||
|
@ -97,7 +98,7 @@ public class MapAttributeIndexSource extends AbstractHbmSourceNode implements Pl
|
|||
: java.util.Collections.<String, String>emptyMap();
|
||||
}
|
||||
};
|
||||
this.nature = Nature.BASIC;
|
||||
this.nature = PluralAttributeIndexBinding.Nature.BASIC;
|
||||
}
|
||||
|
||||
public MapAttributeIndexSource(MappingDocument sourceMappingDocument, final JaxbIndexElement indexElement) {
|
||||
|
@ -139,7 +140,7 @@ public class MapAttributeIndexSource extends AbstractHbmSourceNode implements Pl
|
|||
}
|
||||
};
|
||||
|
||||
this.nature = Nature.BASIC;
|
||||
this.nature = PluralAttributeIndexBinding.Nature.BASIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -158,7 +159,7 @@ public class MapAttributeIndexSource extends AbstractHbmSourceNode implements Pl
|
|||
}
|
||||
|
||||
@Override
|
||||
public Nature getNature() {
|
||||
public PluralAttributeIndexBinding.Nature getNature() {
|
||||
return nature;
|
||||
}
|
||||
|
||||
|
@ -171,4 +172,9 @@ public class MapAttributeIndexSource extends AbstractHbmSourceNode implements Pl
|
|||
public List<RelationalValueSource> relationalValueSources() {
|
||||
return valueSources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int base() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,14 +37,14 @@ import org.hibernate.metamodel.spi.relational.TableSpecification;
|
|||
*/
|
||||
public class PluralAttributeKeyBinding {
|
||||
private final AbstractPluralAttributeBinding pluralAttributeBinding;
|
||||
|
||||
private final SingularAttributeBinding referencedAttributeBinding;
|
||||
private ForeignKey foreignKey;
|
||||
private boolean inverse;
|
||||
private boolean isIncludedInUpdate;
|
||||
|
||||
// this knowledge can be implicitly resolved based on the typing information on the referenced owner attribute
|
||||
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
||||
private final SingularAttributeBinding referencedAttributeBinding;
|
||||
|
||||
|
||||
// todo : this would be nice to have but we do not always know it, especially in HBM case.
|
||||
// private BasicAttributeBinding otherSide;
|
||||
|
|
|
@ -24,9 +24,20 @@
|
|||
package org.hibernate.metamodel.spi.source;
|
||||
|
||||
/**
|
||||
* Contact to define if a plural attribute source is orderable or not.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface Orderable {
|
||||
public boolean isOrdered();
|
||||
public String getOrder();
|
||||
/**
|
||||
* If the source of plural attribute is supposed to be applied the <b>order by</b> when loading.
|
||||
*
|
||||
* @return <code>true</code> for applying the <b>order by</b> or <code>false</code> means not.
|
||||
*/
|
||||
boolean isOrdered();
|
||||
|
||||
/**
|
||||
* @return The <b>order by</b> clause used during loading this plural attribute from DB.
|
||||
*/
|
||||
String getOrder();
|
||||
}
|
||||
|
|
|
@ -23,24 +23,13 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.spi.source;
|
||||
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface PluralAttributeIndexSource extends RelationalValueSourceContainer {
|
||||
Nature getNature();
|
||||
PluralAttributeIndexBinding.Nature getNature();
|
||||
ExplicitHibernateTypeSource explicitHibernateTypeSource();
|
||||
|
||||
/**
|
||||
* Describes the nature of the collection indexes as declared by the sources.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @see {@link org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding.Nature}
|
||||
*/
|
||||
enum Nature {
|
||||
BASIC,
|
||||
COMPOSITE,
|
||||
MANY_TO_MANY,
|
||||
MANY_TO_ANY
|
||||
}
|
||||
int base();
|
||||
}
|
||||
|
|
|
@ -24,10 +24,23 @@
|
|||
package org.hibernate.metamodel.spi.source;
|
||||
|
||||
/**
|
||||
* Contact to define if the source of plural attribute is sortable or not.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface Sortable {
|
||||
public boolean isSorted();
|
||||
public String getComparatorName();
|
||||
/**
|
||||
* If the source of plural attribute is supposed to be sorted.
|
||||
*
|
||||
* @return <code>true</code> the attribute will be sortable or <code>false</code> means not.
|
||||
*/
|
||||
boolean isSorted();
|
||||
|
||||
/**
|
||||
* The comparator class name which will be used to sort the attribute.
|
||||
*
|
||||
* @return Qualified class name which implements {@link java.util.Comparator} contact.
|
||||
*/
|
||||
String getComparatorName();
|
||||
|
||||
}
|
||||
|
|
|
@ -34,5 +34,5 @@ public interface TableSource extends TableSpecificationSource {
|
|||
*
|
||||
* @return The table name, or {@code null} is no name specified.
|
||||
*/
|
||||
public String getExplicitTableName();
|
||||
String getExplicitTableName();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public interface TypeDescriptorSource {
|
|||
*
|
||||
* @return The name.
|
||||
*/
|
||||
public String getName();
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Retrieve the name of the class implementing {@link org.hibernate.type.Type},
|
||||
|
@ -45,7 +45,7 @@ public interface TypeDescriptorSource {
|
|||
*
|
||||
* @return The implementation class name.
|
||||
*/
|
||||
public String getTypeImplementationClassName();
|
||||
String getTypeImplementationClassName();
|
||||
|
||||
/**
|
||||
* For what are termed "basic types" there is a registry that contain the type keyed by various
|
||||
|
@ -58,7 +58,7 @@ public interface TypeDescriptorSource {
|
|||
*
|
||||
* @return The registration keys for the type built from this type def.
|
||||
*/
|
||||
public String[] getRegistrationKeys();
|
||||
String[] getRegistrationKeys();
|
||||
|
||||
/**
|
||||
* Types accept configuration. The values here represent the user supplied values that will be given
|
||||
|
@ -66,5 +66,5 @@ public interface TypeDescriptorSource {
|
|||
*
|
||||
* @return The configuration parameters from the underlying source.
|
||||
*/
|
||||
public Map<String,String> getParameters();
|
||||
Map<String,String> getParameters();
|
||||
}
|
||||
|
|
|
@ -25,13 +25,18 @@ package org.hibernate.metamodel.internal.source.annotations.entity;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor;
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
||||
import org.hibernate.test.annotations.loader.Player;
|
||||
import org.hibernate.test.annotations.loader.Team;
|
||||
import org.hibernate.testing.junit4.BaseAnnotationBindingTestCase;
|
||||
import org.hibernate.testing.junit4.Resources;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Strong Liu <stliu@hibernate.org>
|
||||
|
@ -43,7 +48,19 @@ public class OneToManyBindingTest extends BaseAnnotationBindingTestCase {
|
|||
EntityBinding playerBinding = getEntityBinding( Player.class );
|
||||
assertNotNull( playerBinding );
|
||||
|
||||
AttributeBinding attributeBinding = playerBinding.locateAttributeBinding( "team" );
|
||||
assertTrue( attributeBinding.isAssociation() );
|
||||
|
||||
HibernateTypeDescriptor typeDescriptor = attributeBinding.getHibernateTypeDescriptor();
|
||||
|
||||
EntityBinding teamBinding = getEntityBinding( Team.class );
|
||||
assertNotNull( teamBinding );
|
||||
attributeBinding = teamBinding.locateAttributeBinding( "players" );
|
||||
assertTrue( attributeBinding.isAssociation() );
|
||||
typeDescriptor = attributeBinding.getHibernateTypeDescriptor();
|
||||
|
||||
PluralAttributeBinding pluralAttributeBinding = PluralAttributeBinding.class.cast( attributeBinding );
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue