Java源码示例:org.hibernate.mapping.Component
示例1
@SuppressWarnings("unchecked")
String propertyName(Iterator<org.hibernate.mapping.Property> it, org.hibernate.mapping.Property identifierProperty,
String colName) {
if (identifierProperty != null && propertyMatches(identifierProperty, colName)) {
return identifierProperty.getName();
}
while (it.hasNext()) {
org.hibernate.mapping.Property property = it.next();
if (propertyMatches(property, colName)) {
if (property.isComposite()) {
Component comp = (Component) property.getValue();
Iterator<org.hibernate.mapping.Property> compIt = comp.getPropertyIterator();
return propertyName(compIt, null, colName);
} else {
return property.getName();
}
}
}
return null;
}
示例2
public void addProperty(Property prop, XClass declaringClass) {
if ( prop.getValue() instanceof Component ) {
//TODO handle quote and non quote table comparison
String tableName = prop.getValue().getTable().getName();
if ( getJoinsPerRealTableName().containsKey( tableName ) ) {
final Join join = getJoinsPerRealTableName().get( tableName );
addPropertyToJoin( prop, declaringClass, join );
}
else {
addPropertyToPersistentClass( prop, declaringClass );
}
}
else {
addPropertyToPersistentClass( prop, declaringClass );
}
}
示例3
public static Component fillComponent(
PropertyHolder propertyHolder,
PropertyData inferredData,
AccessType propertyAccessor,
boolean isNullable,
EntityBinder entityBinder,
boolean isComponentEmbedded,
boolean isIdentifierMapper,
boolean inSecondPass,
MetadataBuildingContext buildingContext,
Map<XClass, InheritanceState> inheritanceStatePerClass) {
return fillComponent(
propertyHolder,
inferredData,
null,
propertyAccessor,
isNullable,
entityBinder,
isComponentEmbedded,
isIdentifierMapper,
inSecondPass,
buildingContext,
inheritanceStatePerClass
);
}
示例4
public static Component createComponent(
PropertyHolder propertyHolder,
PropertyData inferredData,
boolean isComponentEmbedded,
boolean isIdentifierMapper,
MetadataBuildingContext context) {
Component comp = new Component( context, propertyHolder.getPersistentClass() );
comp.setEmbedded( isComponentEmbedded );
//yuk
comp.setTable( propertyHolder.getTable() );
//FIXME shouldn't identifier mapper use getClassOrElementName? Need to be checked.
if ( isIdentifierMapper || ( isComponentEmbedded && inferredData.getPropertyName() == null ) ) {
comp.setComponentClassName( comp.getOwner().getClassName() );
}
else {
comp.setComponentClassName( inferredData.getClassOrElementName() );
}
return comp;
}
示例5
protected AbstractComponentTuplizer(Component component) {
setComponentClass( component );
propertySpan = component.getPropertySpan();
getters = new Getter[propertySpan];
setters = new Setter[propertySpan];
Iterator iter = component.getPropertyIterator();
boolean foundCustomAccessor=false;
int i = 0;
while ( iter.hasNext() ) {
Property prop = ( Property ) iter.next();
getters[i] = buildGetter( component, prop );
setters[i] = buildSetter( component, prop );
if ( !prop.isBasicPropertyAccessor() ) {
foundCustomAccessor = true;
}
i++;
}
hasCustomAccessors = foundCustomAccessor;
instantiator = buildInstantiator( component );
}
示例6
private void bindComponent(
MappingDocument sourceDocument,
EmbeddableSource embeddableSource,
Component component,
String containingClassName,
String propertyName,
String xmlNodeName,
boolean isVirtual) {
final String fullRole = embeddableSource.getAttributeRoleBase().getFullPath();
final String explicitComponentClassName = extractExplicitComponentClassName( embeddableSource );
bindComponent(
sourceDocument,
fullRole,
embeddableSource,
component,
explicitComponentClassName,
containingClassName,
propertyName,
isVirtual,
embeddableSource.isDynamic(),
xmlNodeName
);
}
示例7
public static void bindComposite(Element node, Component component, String path,
boolean isNullable, Mappings mappings, java.util.Map inheritedMetas)
throws MappingException {
bindComponent(
node,
component,
null,
null,
path,
isNullable,
false,
mappings,
inheritedMetas,
false
);
}
示例8
public PojoInstantiator(Component component, ReflectionOptimizer.InstantiationOptimizer optimizer) {
this.mappedClass = component.getComponentClass();
this.optimizer = optimizer;
this.proxyInterface = null;
this.embeddedIdentifier = false;
try {
constructor = ReflectHelper.getDefaultConstructor(mappedClass);
}
catch ( PropertyNotFoundException pnfe ) {
log.info(
"no default (no-argument) constructor for class: " +
mappedClass.getName() +
" (class must be instantiated by Interceptor)"
);
constructor = null;
}
}
示例9
public ComponentMetamodel(Component component) {
// this.sessionFactory = sessionFactory;
this.role = component.getRoleName();
this.isKey = component.isKey();
propertySpan = component.getPropertySpan();
properties = new StandardProperty[propertySpan];
Iterator itr = component.getPropertyIterator();
int i = 0;
while ( itr.hasNext() ) {
Property property = ( Property ) itr.next();
properties[i] = PropertyFactory.buildStandardProperty( property, false );
propertyIndexes.put( property.getName(), new Integer( i ) );
i++;
}
tuplizerMapping = new ComponentEntityModeToTuplizerMapping( component );
}
示例10
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
super.afterConfigurationBuilt( mappings, dialect );
// Oracle and Postgres do not have year() functions, so we need to
// redefine the 'User.person.yob' formula
//
// consider temporary until we add the capability to define
// mapping foprmulas which can use dialect-registered functions...
PersistentClass user = mappings.getClass( User.class.getName() );
org.hibernate.mapping.Property personProperty = user.getProperty( "person" );
Component component = ( Component ) personProperty.getValue();
Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next();
SQLFunction yearFunction = ( SQLFunction ) dialect.getFunctions().get( "year" );
if ( yearFunction == null ) {
// the dialect not know to support a year() function, so rely on the
// ANSI SQL extract function
f.setFormula( "extract( year from dob )");
}
else {
List args = new ArrayList();
args.add( "dob" );
f.setFormula( yearFunction.render( args, null ) );
}
}
示例11
public void testProperCallbacks() {
ValueVisitor vv = new ValueVisitorValidator();
new Any(new Table()).accept(vv);
new Array(new RootClass()).accept(vv);
new Bag(new RootClass()).accept(vv);
new Component(new RootClass()).accept(vv);
new DependantValue(null,null).accept(vv);
new IdentifierBag(null).accept(vv);
new List(null).accept(vv);
new ManyToOne(null).accept(vv);
new Map(null).accept(vv);
new OneToMany(null).accept(vv);
new OneToOne(null, new RootClass() ).accept(vv);
new PrimitiveArray(null).accept(vv);
new Set(null).accept(vv);
new SimpleValue().accept(vv);
}
示例12
@Override
public boolean isInPrimaryKey() {
if ( entityClassName == null ) return false;
final PersistentClass persistentClass = buildingContext.getMetadataCollector().getEntityBinding( entityClassName );
Property property = persistentClass.getIdentifierProperty();
if ( path == null ) {
return false;
}
else if ( property != null) {
//try explicit identifier property
return path.startsWith( property.getName() + "." );
}
else {
//try the embedded property
//embedded property starts their path with 'id.' See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor
if ( path.startsWith( "id." ) ) {
KeyValue valueIdentifier = persistentClass.getIdentifier();
String localPath = path.substring( 3 );
if ( valueIdentifier instanceof Component ) {
Iterator it = ( (Component) valueIdentifier ).getPropertyIterator();
while ( it.hasNext() ) {
Property idProperty = (Property) it.next();
if ( localPath.startsWith( idProperty.getName() ) ) return true;
}
}
}
}
return false;
}
示例13
private static void applyDDL(
String prefix,
PersistentClass persistentClass,
Class<?> clazz,
ValidatorFactory factory,
Set<Class<?>> groups,
boolean activateNotNull,
Dialect dialect) {
final BeanDescriptor descriptor = factory.getValidator().getConstraintsForClass( clazz );
//no bean level constraints can be applied, go to the properties
for ( PropertyDescriptor propertyDesc : descriptor.getConstrainedProperties() ) {
Property property = findPropertyByName( persistentClass, prefix + propertyDesc.getPropertyName() );
boolean hasNotNull;
if ( property != null ) {
hasNotNull = applyConstraints(
propertyDesc.getConstraintDescriptors(), property, propertyDesc, groups, activateNotNull, dialect
);
if ( property.isComposite() && propertyDesc.isCascaded() ) {
Class<?> componentClass = ( (Component) property.getValue() ).getComponentClass();
/*
* we can apply not null if the upper component let's us activate not null
* and if the property is not null.
* Otherwise, all sub columns should be left nullable
*/
final boolean canSetNotNullOnColumns = activateNotNull && hasNotNull;
applyDDL(
prefix + propertyDesc.getPropertyName() + ".",
persistentClass, componentClass, factory, groups,
canSetNotNullOnColumns,
dialect
);
}
//FIXME add collection of components
}
}
}
示例14
public ComponentPropertyHolder(
Component component,
String path,
PropertyData inferredData,
PropertyHolder parent,
MetadataBuildingContext context) {
super( path, parent, inferredData.getPropertyClass(), context );
final XProperty embeddedXProperty = inferredData.getProperty();
setCurrentProperty( embeddedXProperty );
this.component = component;
this.isOrWithinEmbeddedId =
parent.isOrWithinEmbeddedId()
|| ( embeddedXProperty != null &&
( embeddedXProperty.isAnnotationPresent( Id.class )
|| embeddedXProperty.isAnnotationPresent( EmbeddedId.class ) ) );
this.isWithinElementCollection = parent.isWithinElementCollection() ||
parent instanceof CollectionPropertyHolder;
if ( embeddedXProperty != null ) {
// this.virtual = false;
this.embeddedAttributeName = embeddedXProperty.getName();
this.attributeConversionInfoMap = processAttributeConversions( embeddedXProperty );
}
else {
// could be either:
// 1) virtual/dynamic component
// 2) collection element/key
// temp
// this.virtual = true;
this.embeddedAttributeName = "";
this.attributeConversionInfoMap = processAttributeConversions( inferredData.getClassOrElement() );
}
}
示例15
public CopyIdentifierComponentSecondPass(
Component comp,
String referencedEntityName,
Ejb3JoinColumn[] joinColumns,
MetadataBuildingContext buildingContext) {
this.component = comp;
this.referencedEntityName = referencedEntityName;
this.buildingContext = buildingContext;
this.joinColumns = joinColumns;
}
示例16
/**
* build a component property holder
*
* @param component component to wrap
* @param path component path
* @param context
* @return PropertyHolder
*/
public static PropertyHolder buildPropertyHolder(
Component component,
String path,
PropertyData inferredData,
PropertyHolder parent,
MetadataBuildingContext context) {
return new ComponentPropertyHolder( component, path, inferredData, parent, context );
}
示例17
private <X> void applyIdMetadata(PersistentClass persistentClass, EntityTypeImpl<X> jpaEntityType) {
if ( persistentClass.hasIdentifierProperty() ) {
final Property declaredIdentifierProperty = persistentClass.getDeclaredIdentifierProperty();
if ( declaredIdentifierProperty != null ) {
jpaEntityType.getBuilder().applyIdAttribute(
attributeFactory.buildIdAttribute( jpaEntityType, declaredIdentifierProperty )
);
}
}
else if ( persistentClass.hasIdentifierMapper() ) {
@SuppressWarnings("unchecked")
Iterator<Property> propertyIterator = persistentClass.getIdentifierMapper().getPropertyIterator();
Set<SingularAttribute<? super X, ?>> attributes = buildIdClassAttributes( jpaEntityType, propertyIterator );
jpaEntityType.getBuilder().applyIdClassAttributes( attributes );
}
else {
final KeyValue value = persistentClass.getIdentifier();
if ( value instanceof Component ) {
final Component component = (Component) value;
if ( component.getPropertySpan() > 1 ) {
//FIXME we are an Hibernate embedded id (ie not type)
}
else {
//FIXME take care of declared vs non declared property
jpaEntityType.getBuilder().applyIdAttribute(
attributeFactory.buildIdAttribute(
jpaEntityType,
(Property) component.getPropertyIterator().next()
)
);
}
}
}
}
示例18
private void internalInitSubclassPropertyAliasesMap(String path, Iterator propertyIterator) {
while ( propertyIterator.hasNext() ) {
Property prop = (Property) propertyIterator.next();
String propname = path == null ? prop.getName() : path + "." + prop.getName();
if ( prop.isComposite() ) {
Component component = (Component) prop.getValue();
Iterator compProps = component.getPropertyIterator();
internalInitSubclassPropertyAliasesMap( propname, compProps );
}
else {
String[] aliases = new String[prop.getColumnSpan()];
String[] cols = new String[prop.getColumnSpan()];
Iterator colIter = prop.getColumnIterator();
int l = 0;
while ( colIter.hasNext() ) {
Selectable thing = (Selectable) colIter.next();
aliases[l] = thing.getAlias( getFactory().getDialect(), prop.getValue().getTable() );
cols[l] = thing.getText( getFactory().getDialect() ); // TODO: skip formulas?
l++;
}
subclassPropertyAliases.put( propname, aliases );
subclassPropertyColumnNames.put( propname, cols );
}
}
}
示例19
private static GenerationStrategyPair buildGenerationStrategyPair(
final SessionFactoryImplementor sessionFactory,
final Property mappingProperty) {
final ValueGeneration valueGeneration = mappingProperty.getValueGenerationStrategy();
if ( valueGeneration != null && valueGeneration.getGenerationTiming() != GenerationTiming.NEVER ) {
// the property is generated in full. build the generation strategy pair.
if ( valueGeneration.getValueGenerator() != null ) {
// in-memory generation
return new GenerationStrategyPair(
FullInMemoryValueGenerationStrategy.create( valueGeneration )
);
}
else {
// in-db generation
return new GenerationStrategyPair(
create(
sessionFactory,
mappingProperty,
valueGeneration
)
);
}
}
else if ( mappingProperty.getValue() instanceof Component ) {
final CompositeGenerationStrategyPairBuilder builder = new CompositeGenerationStrategyPairBuilder( mappingProperty );
interpretPartialCompositeValueGeneration( sessionFactory, (Component) mappingProperty.getValue(), builder );
return builder.buildPair();
}
return NO_GEN_PAIR;
}
示例20
private static void interpretPartialCompositeValueGeneration(
SessionFactoryImplementor sessionFactory,
Component composite,
CompositeGenerationStrategyPairBuilder builder) {
Iterator subProperties = composite.getPropertyIterator();
while ( subProperties.hasNext() ) {
final Property subProperty = (Property) subProperties.next();
builder.addPair( buildGenerationStrategyPair( sessionFactory, subProperty ) );
}
}
示例21
private void mapPropertyToIndex(Property prop, int i) {
propertyIndexes.put( prop.getName(), i );
if ( prop.getValue() instanceof Component ) {
Iterator iter = ( (Component) prop.getValue() ).getPropertyIterator();
while ( iter.hasNext() ) {
Property subprop = (Property) iter.next();
propertyIndexes.put(
prop.getName() + '.' + subprop.getName(),
i
);
}
}
}
示例22
/**
* Construct an instance of the given tuplizer class.
*
* @param tuplizerClass The tuplizer class to instantiate
* @param metadata The metadata for the component.
*
* @return The instantiated tuplizer
*
* @throws HibernateException if the {@link java.lang.reflect.Constructor#newInstance} call fails.
*/
public ComponentTuplizer constructTuplizer(Class<? extends ComponentTuplizer> tuplizerClass, Component metadata) {
Constructor<? extends ComponentTuplizer> constructor = getProperConstructor( tuplizerClass );
assert constructor != null : "Unable to locate proper constructor for tuplizer [" + tuplizerClass.getName() + "]";
try {
return constructor.newInstance( metadata );
}
catch ( Throwable t ) {
throw new HibernateException( "Unable to instantiate default tuplizer [" + tuplizerClass.getName() + "]", t );
}
}
示例23
private ComponentMetamodel(Component component, ComponentTuplizerFactory componentTuplizerFactory){
this.role = component.getRoleName();
this.isKey = component.isKey();
propertySpan = component.getPropertySpan();
properties = new StandardProperty[propertySpan];
Iterator itr = component.getPropertyIterator();
int i = 0;
while ( itr.hasNext() ) {
Property property = ( Property ) itr.next();
properties[i] = PropertyFactory.buildStandardProperty( property, false );
propertyIndexes.put( property.getName(), i );
i++;
}
entityMode = component.hasPojoRepresentation() ? EntityMode.POJO : EntityMode.MAP;
// todo : move this to SF per HHH-3517; also see HHH-1907 and ComponentMetamodel
final String tuplizerClassName = component.getTuplizerImplClassName( entityMode );
this.componentTuplizer = tuplizerClassName == null ? componentTuplizerFactory.constructDefaultTuplizer(
entityMode,
component
) : componentTuplizerFactory.constructTuplizer( tuplizerClassName, component );
final ConfigurationService cs = component.getMetadata().getMetadataBuildingOptions().getServiceRegistry()
.getService(ConfigurationService.class);
this.createEmptyCompositesEnabled = ConfigurationHelper.getBoolean(
Environment.CREATE_EMPTY_COMPOSITES_ENABLED,
cs.getSettings(),
false
);
}
示例24
public PojoComponentTuplizer(Component component) {
super( component );
String[] getterNames = new String[propertySpan];
String[] setterNames = new String[propertySpan];
Class[] propTypes = new Class[propertySpan];
for ( int i = 0; i < propertySpan; i++ ) {
getterNames[i] = getters[i].getMethodName();
setterNames[i] = setters[i].getMethodName();
propTypes[i] = getters[i].getReturnType();
}
final String parentPropertyName = component.getParentProperty();
if ( parentPropertyName == null ) {
parentSetter = null;
parentGetter = null;
}
else {
final PropertyAccess propertyAccess = PropertyAccessStrategyBasicImpl.INSTANCE.buildPropertyAccess(
componentClass,
parentPropertyName
);
parentSetter = propertyAccess.getSetter();
parentGetter = propertyAccess.getGetter();
}
if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) {
optimizer = null;
}
else {
// TODO: here is why we need to make bytecode provider global :(
// TODO : again, fix this after HHH-1907 is complete
optimizer = Environment.getBytecodeProvider().getReflectionOptimizer(
componentClass, getterNames, setterNames, propTypes
);
}
}
示例25
protected Instantiator buildInstantiator(Component component) {
if ( component.isEmbedded() && ReflectHelper.isAbstractClass( this.componentClass ) ) {
return new ProxiedInstantiator( this.componentClass );
}
if ( optimizer == null ) {
return new PojoInstantiator( this.componentClass, null );
}
else {
return new PojoInstantiator( this.componentClass, optimizer.getInstantiationOptimizer() );
}
}
示例26
private void finishBindingCompositeIdentifier(
MappingDocument sourceDocument,
RootClass rootEntityDescriptor,
CompositeIdentifierSource identifierSource,
Component cid,
String propertyName) {
if ( propertyName == null ) {
rootEntityDescriptor.setEmbeddedIdentifier( cid.isEmbedded() );
if ( cid.isEmbedded() ) {
// todo : what is the implication of this?
cid.setDynamic( !rootEntityDescriptor.hasPojoRepresentation() );
/*
* Property prop = new Property(); prop.setName("id");
* prop.setPropertyAccessorName("embedded"); prop.setValue(id);
* entity.setIdentifierProperty(prop);
*/
}
}
else {
Property prop = new Property();
prop.setValue( cid );
bindProperty(
sourceDocument,
( (IdentifierSourceAggregatedComposite) identifierSource ).getIdentifierAttributeSource(),
prop
);
rootEntityDescriptor.setIdentifierProperty( prop );
rootEntityDescriptor.setDeclaredIdentifierProperty( prop );
}
makeIdentifier(
sourceDocument,
identifierSource.getIdentifierGeneratorDescriptor(),
null,
cid
);
}
示例27
private void prepareComponentType(
MappingDocument sourceDocument,
String fullRole,
Component componentBinding,
String explicitComponentClassName,
String containingClassName,
String propertyName,
boolean isVirtual,
boolean isDynamic) {
}
示例28
private static void bindCompositeId(Element idNode, RootClass entity, Mappings mappings,
java.util.Map inheritedMetas) throws MappingException {
String propertyName = idNode.attributeValue( "name" );
Component id = new Component( entity );
entity.setIdentifier( id );
bindCompositeId( idNode, id, entity, propertyName, mappings, inheritedMetas );
if ( propertyName == null ) {
entity.setEmbeddedIdentifier( id.isEmbedded() );
if ( id.isEmbedded() ) {
// todo : what is the implication of this?
id.setDynamic( !entity.hasPojoRepresentation() );
/*
* Property prop = new Property(); prop.setName("id");
* prop.setPropertyAccessorName("embedded"); prop.setValue(id);
* entity.setIdentifierProperty(prop);
*/
}
}
else {
Property prop = new Property();
prop.setValue( id );
bindProperty( idNode, prop, mappings, inheritedMetas );
entity.setIdentifierProperty( prop );
}
makeIdentifier( idNode, id, mappings );
}
示例29
private void internalInitSubclassPropertyAliasesMap(String path, Iterator propertyIterator) {
while ( propertyIterator.hasNext() ) {
Property prop = ( Property ) propertyIterator.next();
String propname = path == null ? prop.getName() : path + "." + prop.getName();
if ( prop.isComposite() ) {
Component component = ( Component ) prop.getValue();
Iterator compProps = component.getPropertyIterator();
internalInitSubclassPropertyAliasesMap( propname, compProps );
}
else {
String[] aliases = new String[prop.getColumnSpan()];
String[] cols = new String[prop.getColumnSpan()];
Iterator colIter = prop.getColumnIterator();
int l = 0;
while ( colIter.hasNext() ) {
Selectable thing = ( Selectable ) colIter.next();
aliases[l] = thing.getAlias( getFactory().getDialect(), prop.getValue().getTable() );
cols[l] = thing.getText( getFactory().getDialect() ); // TODO: skip formulas?
l++;
}
subclassPropertyAliases.put( propname, aliases );
subclassPropertyColumnNames.put( propname, cols );
}
}
}
示例30
private ValueInclusion determineInsertValueGenerationType(Property mappingProperty, StandardProperty runtimeProperty) {
if ( runtimeProperty.isInsertGenerated() ) {
return ValueInclusion.FULL;
}
else if ( mappingProperty.getValue() instanceof Component ) {
if ( hasPartialInsertComponentGeneration( ( Component ) mappingProperty.getValue() ) ) {
return ValueInclusion.PARTIAL;
}
}
return ValueInclusion.NONE;
}