Java Code Examples for org.hibernate.mapping.Property#getValue()

The following examples show how to use org.hibernate.mapping.Property#getValue() . 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: ClassPropertyHolder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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 );
	}
}
 
Example 2
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 3
Source File: EntityMetamodel.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: EntityMetamodel.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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
				);
		}
	}
}
 
Example 5
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 6
Source File: EntityMetamodel.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
}
 
Example 7
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 8
Source File: EntityMetamodel.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ValueInclusion determineUpdateValueGenerationType(Property mappingProperty, StandardProperty runtimeProperty) {
	if ( runtimeProperty.isUpdateGenerated() ) {
		return ValueInclusion.FULL;
	}
	else if ( mappingProperty.getValue() instanceof Component ) {
		if ( hasPartialUpdateComponentGeneration( ( Component ) mappingProperty.getValue() ) ) {
			return ValueInclusion.PARTIAL;
		}
	}
	return ValueInclusion.NONE;
}
 
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: EntityMetamodel.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void mapPropertyToIndex(Property prop, int i) {
	propertyIndexes.put( prop.getName(), new Integer(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(),
					new Integer(i)
				);
		}
	}
}
 
Example 11
Source File: NonReflectiveBinderTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testComparator() {
	PersistentClass cm = cfg.getClassMapping("org.hibernate.test.legacy.Wicked");
	
	Property property = cm.getProperty("sortedEmployee");
	Collection col = (Collection) property.getValue();
	assertEquals(col.getComparatorClassName(),"org.hibernate.test.legacy.NonExistingComparator");
}
 
Example 12
Source File: CollectionBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * bind the inverse FK of a ManyToMany
 * If we are in a mappedBy case, read the columns from the associated
 * collection element
 * Otherwise delegates to the usual algorithm
 */
public static void bindManytoManyInverseFk(
		PersistentClass referencedEntity,
		Ejb3JoinColumn[] columns,
		SimpleValue value,
		boolean unique,
		MetadataBuildingContext buildingContext) {
	final String mappedBy = columns[0].getMappedBy();
	if ( StringHelper.isNotEmpty( mappedBy ) ) {
		final Property property = referencedEntity.getRecursiveProperty( mappedBy );
		Iterator mappedByColumns;
		if ( property.getValue() instanceof Collection ) {
			mappedByColumns = ( (Collection) property.getValue() ).getKey().getColumnIterator();
		}
		else {
			//find the appropriate reference key, can be in a join
			Iterator joinsIt = referencedEntity.getJoinIterator();
			KeyValue key = null;
			while ( joinsIt.hasNext() ) {
				Join join = (Join) joinsIt.next();
				if ( join.containsProperty( property ) ) {
					key = join.getKey();
					break;
				}
			}
			if ( key == null ) key = property.getPersistentClass().getIdentifier();
			mappedByColumns = key.getColumnIterator();
		}
		while ( mappedByColumns.hasNext() ) {
			Column column = (Column) mappedByColumns.next();
			columns[0].linkValueUsingAColumnCopy( column, value );
		}
		String referencedPropertyName =
				buildingContext.getMetadataCollector().getPropertyReferencedAssociation(
						"inverse__" + referencedEntity.getEntityName(), mappedBy
				);
		if ( referencedPropertyName != null ) {
			//TODO always a many to one?
			( (ManyToOne) value ).setReferencedPropertyName( referencedPropertyName );
			buildingContext.getMetadataCollector().addUniquePropertyReference(
					referencedEntity.getEntityName(),
					referencedPropertyName
			);
		}
		( (ManyToOne) value ).setReferenceToPrimaryKey( referencedPropertyName == null );
		value.createForeignKey();
	}
	else {
		BinderHelper.createSyntheticPropertyReference( columns, referencedEntity, null, value, true, buildingContext );
		TableBinder.bindFk( referencedEntity, null, columns, value, unique, buildingContext );
	}
}