Java Code Examples for org.hibernate.mapping.Component#getPropertyIterator()

The following examples show how to use org.hibernate.mapping.Component#getPropertyIterator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewBuilder.java    From teiid-spring-boot with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: AbstractComponentTuplizer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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 );
}
 
Example 3
Source File: ComponentMetamodel.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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 );
	}
 
Example 4
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 );
		}
	}

}
 
Example 5
Source File: EntityMetamodel.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 ) );
	}
}
 
Example 6
Source File: ComponentMetamodel.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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
	);
}
 
Example 7
Source File: AbstractEntityPersister.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 );
		}
	}

}
 
Example 8
Source File: EntityMetamodel.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean hasPartialInsertComponentGeneration(Component component) {
	Iterator subProperties = component.getPropertyIterator();
	while ( subProperties.hasNext() ) {
		Property prop = ( Property ) subProperties.next();
		if ( prop.getGeneration() == PropertyGeneration.ALWAYS || prop.getGeneration() == PropertyGeneration.INSERT ) {
			return true;
		}
		else if ( prop.getValue() instanceof Component ) {
			if ( hasPartialInsertComponentGeneration( ( Component ) prop.getValue() ) ) {
				return true;
			}
		}
	}
	return false;
}
 
Example 9
Source File: EntityMetamodel.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean hasPartialUpdateComponentGeneration(Component component) {
	Iterator subProperties = component.getPropertyIterator();
	while ( subProperties.hasNext() ) {
		Property prop = ( Property ) subProperties.next();
		if ( prop.getGeneration() == PropertyGeneration.ALWAYS ) {
			return true;
		}
		else if ( prop.getValue() instanceof Component ) {
			if ( hasPartialUpdateComponentGeneration( ( Component ) prop.getValue() ) ) {
				return true;
			}
		}
	}
	return false;
}
 
Example 10
Source File: AbstractComponentTuplizer.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected AbstractComponentTuplizer(Component 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;

	String[] getterNames = new String[propertySpan];
	String[] setterNames = new String[propertySpan];
	Class[] propTypes = new Class[propertySpan];
	for ( int j = 0; j < propertySpan; j++ ) {
		getterNames[j] = getters[j].getMethodName();
		setterNames[j] = setters[j].getMethodName();
		propTypes[j] = getters[j].getReturnType();
	}
	instantiator = buildInstantiator( component );
}
 
Example 11
Source File: AttributeFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <Y> Type<Y> getMetaModelType(ValueContext typeContext) {
	switch ( typeContext.getValueClassification() ) {
		case BASIC: {
			return new BasicTypeImpl<Y>(
					typeContext.getBindableType(),
					Type.PersistenceType.BASIC
			);
		}
		case ENTITY: {
			final org.hibernate.type.EntityType type = (EntityType) typeContext.getValue().getType();
			return (Type<Y>) context.locateEntityType( type.getAssociatedEntityName() );
		}
		case EMBEDDABLE: {
			final Component component = (Component) typeContext.getValue();
			Class javaType;
			if ( component.getComponentClassName() == null ) {
				javaType = typeContext.getBindableType();
			}
			else {
				javaType = component.getComponentClass();
			}
			final EmbeddableTypeImpl<Y> embeddableType = new EmbeddableTypeImpl<Y>(
					javaType,
					typeContext.getAttributeMetadata().getOwnerType(),
					(ComponentType) typeContext.getValue().getType()
			);
			context.registerEmbeddedableType( embeddableType );
			final Iterator<Property> subProperties = component.getPropertyIterator();
			while ( subProperties.hasNext() ) {
				final Property property = subProperties.next();
				final AttributeImplementor<Y, Object> attribute = buildAttribute( embeddableType, property );
				if ( attribute != null ) {
					embeddableType.getBuilder().addAttribute( attribute );
				}
			}
			embeddableType.lock();
			return embeddableType;
		}
		default: {
			throw new AssertionFailure( "Unknown type : " + typeContext.getValueClassification() );
		}
	}
}
 
Example 12
Source File: EntityMetamodel.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public GenerationStrategyPair buildPair() {
	if ( hadInMemoryGeneration && hadInDatabaseGeneration ) {
		throw new ValueGenerationStrategyException(
				"Composite attribute [" + mappingProperty.getName() + "] contained both in-memory"
						+ " and in-database value generation"
		);
	}
	else if ( hadInMemoryGeneration ) {
		throw new NotYetImplementedException( "Still need to wire in composite in-memory value generation" );

	}
	else if ( hadInDatabaseGeneration ) {
		final Component composite = (Component) mappingProperty.getValue();

		// we need the numbers to match up so we can properly handle 'referenced sql column values'
		if ( inDatabaseStrategies.size() != composite.getPropertySpan() ) {
			throw new ValueGenerationStrategyException(
					"Internal error : mismatch between number of collected in-db generation strategies" +
							" and number of attributes for composite attribute : " + mappingProperty.getName()
			);
		}

		// the base-line values for the aggregated InDatabaseValueGenerationStrategy we will build here.
		GenerationTiming timing = GenerationTiming.INSERT;
		boolean referenceColumns = false;
		String[] columnValues = new String[ composite.getColumnSpan() ];

		// start building the aggregate values
		int propertyIndex = -1;
		int columnIndex = 0;
		Iterator subProperties = composite.getPropertyIterator();
		while ( subProperties.hasNext() ) {
			propertyIndex++;
			final Property subProperty = (Property) subProperties.next();
			final InDatabaseValueGenerationStrategy subStrategy = inDatabaseStrategies.get( propertyIndex );

			if ( subStrategy.getGenerationTiming() == GenerationTiming.ALWAYS ) {
				// override the base-line to the more often "ALWAYS"...
				timing = GenerationTiming.ALWAYS;

			}
			if ( subStrategy.referenceColumnsInSql() ) {
				// override base-line value
				referenceColumns = true;
			}
			if ( subStrategy.getReferencedColumnValues() != null ) {
				if ( subStrategy.getReferencedColumnValues().length != subProperty.getColumnSpan() ) {
					throw new ValueGenerationStrategyException(
							"Internal error : mismatch between number of collected 'referenced column values'" +
									" and number of columns for composite attribute : " + mappingProperty.getName() +
									'.' + subProperty.getName()
					);
				}
				System.arraycopy(
						subStrategy.getReferencedColumnValues(),
						0,
						columnValues,
						columnIndex,
						subProperty.getColumnSpan()
				);
			}
		}

		// then use the aggregated values to build the InDatabaseValueGenerationStrategy
		return new GenerationStrategyPair(
				new InDatabaseValueGenerationStrategyImpl( timing, referenceColumns, columnValues )
		);
	}
	else {
		return NO_GEN_PAIR;
	}
}