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

The following examples show how to use org.hibernate.mapping.Component#getPropertySpan() . 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: 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 2
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 3
Source File: MetadataContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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()
						)
				);
			}
		}
	}
}
 
Example 4
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 5
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 6
Source File: AnnotationBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private static PropertyBinder bindComponent(
		PropertyData inferredData,
		PropertyHolder propertyHolder,
		AccessType propertyAccessor,
		EntityBinder entityBinder,
		boolean isIdentifierMapper,
		MetadataBuildingContext buildingContext,
		boolean isComponentEmbedded,
		boolean isId, //is a identifier
		Map<XClass, InheritanceState> inheritanceStatePerClass,
		String referencedEntityName, //is a component who is overridden by a @MapsId
		Ejb3JoinColumn[] columns) {
	Component comp;
	if ( referencedEntityName != null ) {
		comp = createComponent( propertyHolder, inferredData, isComponentEmbedded, isIdentifierMapper, buildingContext );
		SecondPass sp = new CopyIdentifierComponentSecondPass(
				comp,
				referencedEntityName,
				columns,
				buildingContext
		);
		buildingContext.getMetadataCollector().addSecondPass( sp );
	}
	else {
		comp = fillComponent(
				propertyHolder, inferredData, propertyAccessor, !isId, entityBinder,
				isComponentEmbedded, isIdentifierMapper,
				false, buildingContext, inheritanceStatePerClass
		);
	}
	if ( isId ) {
		comp.setKey( true );
		if ( propertyHolder.getPersistentClass().getIdentifier() != null ) {
			throw new AnnotationException(
					comp.getComponentClassName()
							+ " must not have @Id properties when used as an @EmbeddedId: "
							+ BinderHelper.getPath( propertyHolder, inferredData )
			);
		}
		if ( referencedEntityName == null && comp.getPropertySpan() == 0 ) {
			throw new AnnotationException(
					comp.getComponentClassName()
							+ " has no persistent id property: "
							+ BinderHelper.getPath( propertyHolder, inferredData )
			);
		}
	}
	XProperty property = inferredData.getProperty();
	setupComponentTuplizer( property, comp );
	PropertyBinder binder = new PropertyBinder();
	binder.setDeclaringClass(inferredData.getDeclaringClass());
	binder.setName( inferredData.getPropertyName() );
	binder.setValue( comp );
	binder.setProperty( inferredData.getProperty() );
	binder.setAccessType( inferredData.getDefaultAccess() );
	binder.setEmbedded( isComponentEmbedded );
	binder.setHolder( propertyHolder );
	binder.setId( isId );
	binder.setEntityBinder( entityBinder );
	binder.setInheritanceStatePerClass( inheritanceStatePerClass );
	binder.setBuildingContext( buildingContext );
	binder.makePropertyAndBind();
	return binder;
}
 
Example 7
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;
	}
}