Java Code Examples for org.hibernate.mapping.PersistentClass#getPropertyClosureIterator()

The following examples show how to use org.hibernate.mapping.PersistentClass#getPropertyClosureIterator() . 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
/**
 * Build a LazyFetchGroupMetadata based on the attributes defined for the
 * PersistentClass
 *
 * @param mappedEntity The entity definition
 *
 * @return The built LazyFetchGroupMetadata
 */
public static LazyAttributesMetadata from(PersistentClass mappedEntity) {
	final Map<String, LazyAttributeDescriptor> lazyAttributeDescriptorMap = new LinkedHashMap<>();
	final Map<String, Set<String>> fetchGroupToAttributesMap = new HashMap<>();

	int i = -1;
	int x = 0;
	final Iterator itr = mappedEntity.getPropertyClosureIterator();
	while ( itr.hasNext() ) {
		i++;
		final Property property = (Property) itr.next();
		if ( property.isLazy() ) {
			final LazyAttributeDescriptor lazyAttributeDescriptor = LazyAttributeDescriptor.from( property, i, x++ );
			lazyAttributeDescriptorMap.put( lazyAttributeDescriptor.getName(), lazyAttributeDescriptor );

			final Set<String> attributeSet = fetchGroupToAttributesMap.computeIfAbsent(
					lazyAttributeDescriptor.getFetchGroupName(),
					k -> new LinkedHashSet<>()
			);
			attributeSet.add( lazyAttributeDescriptor.getName() );
		}
	}

	if ( lazyAttributeDescriptorMap.isEmpty() ) {
		return new LazyAttributesMetadata( mappedEntity.getEntityName() );
	}

	for ( Map.Entry<String, Set<String>> entry : fetchGroupToAttributesMap.entrySet() ) {
		entry.setValue( Collections.unmodifiableSet( entry.getValue() ) );
	}

	return new LazyAttributesMetadata(
			mappedEntity.getEntityName(),
			Collections.unmodifiableMap( lazyAttributeDescriptorMap ),
			Collections.unmodifiableMap( fetchGroupToAttributesMap )
	);
}
 
Example 2
public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
		super( entityMetamodel, mappedEntity );
		this.mappedClass = mappedEntity.getMappedClass();
		this.proxyInterface = mappedEntity.getProxyInterface();
		this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
		this.validatableImplementor = Validatable.class.isAssignableFrom( mappedClass );

		Iterator iter = mappedEntity.getPropertyClosureIterator();
		while ( iter.hasNext() ) {
			Property property = (Property) iter.next();
			if ( property.isLazy() ) {
				lazyPropertyNames.add( property.getName() );
			}
		}

		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();
		}

		if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) {
			optimizer = null;
		}
		else {
			// todo : YUCK!!!
			optimizer = Environment.getBytecodeProvider().getReflectionOptimizer( mappedClass, getterNames, setterNames, propTypes );
//			optimizer = getFactory().getSettings().getBytecodeProvider().getReflectionOptimizer(
//					mappedClass, getterNames, setterNames, propTypes
//			);
		}
	
	}
 
Example 3
private void applyCacheSettings(Configuration configuration) {
	if ( settings.getCacheConcurrencyStrategy() != null ) {
		Iterator iter = configuration.getClassMappings();
		while ( iter.hasNext() ) {
			PersistentClass clazz = (PersistentClass) iter.next();
			Iterator props = clazz.getPropertyClosureIterator();
			boolean hasLob = false;
			while ( props.hasNext() ) {
				Property prop = (Property) props.next();
				if ( prop.getValue().isSimpleValue() ) {
					String type = ( ( SimpleValue ) prop.getValue() ).getTypeName();
					if ( "blob".equals(type) || "clob".equals(type) ) {
						hasLob = true;
					}
					if ( Blob.class.getName().equals(type) || Clob.class.getName().equals(type) ) {
						hasLob = true;
					}
				}
			}
			if ( !hasLob && !clazz.isInherited() && settings.overrideCacheStrategy() ) {
				configuration.setCacheConcurrencyStrategy( clazz.getEntityName(), settings.getCacheConcurrencyStrategy() );
			}
		}
		iter = configuration.getCollectionMappings();
		while ( iter.hasNext() ) {
			Collection coll = (Collection) iter.next();
			configuration.setCollectionCacheConcurrencyStrategy( coll.getRole(), settings.getCacheConcurrencyStrategy() );
		}
	}
}
 
Example 4
/**
 * Constructs a new AbstractEntityTuplizer instance.
 *
 * @param entityMetamodel The "interpreted" information relating to the mapped entity.
 * @param mappingInfo The parsed "raw" mapping data relating to the given entity.
 */
public AbstractEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappingInfo) {
	this.entityMetamodel = entityMetamodel;

	if ( !entityMetamodel.getIdentifierProperty().isVirtual() ) {
		idGetter = buildPropertyGetter( mappingInfo.getIdentifierProperty(), mappingInfo );
		idSetter = buildPropertySetter( mappingInfo.getIdentifierProperty(), mappingInfo );
	}
	else {
		idGetter = null;
		idSetter = null;
	}

	propertySpan = entityMetamodel.getPropertySpan();

       getters = new Getter[propertySpan];
	setters = new Setter[propertySpan];

	Iterator iter = mappingInfo.getPropertyClosureIterator();
	boolean foundCustomAccessor=false;
	int i=0;
	while ( iter.hasNext() ) {
		//TODO: redesign how PropertyAccessors are acquired...
		Property property = (Property) iter.next();
		getters[i] = buildPropertyGetter(property, mappingInfo);
		setters[i] = buildPropertySetter(property, mappingInfo);
		if ( !property.isBasicPropertyAccessor() ) foundCustomAccessor = true;
		i++;
	}
	hasCustomAccessors = foundCustomAccessor;

       instantiator = buildInstantiator( mappingInfo );

	if ( entityMetamodel.isLazy() ) {
		proxyFactory = buildProxyFactory( mappingInfo, idGetter, idSetter );
		if (proxyFactory == null) {
			entityMetamodel.setLazy( false );
		}
	}
	else {
		proxyFactory = null;
	}
	
	Component mapper = mappingInfo.getIdentifierMapper();
	identifierMapperType = mapper==null ? null : (AbstractComponentType) mapper.getType();
}
 
Example 5
private void buildSessionFactory() throws Exception {
	if ( getSessions()!=null ) {
		getSessions().close();
	}

	TestCase.dialect = Dialect.getDialect();
	if ( ! appliesTo( getDialect() ) ) {
		return;
	}

	try {

		TestCase.cfg = new Configuration();
		cfg.setProperty( Environment.CACHE_PROVIDER, "org.hibernate.cache.HashtableCacheProvider" );
		if( recreateSchema() ) {
			cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
		}
		addMappings( getMappings(), cfg );
		configure( cfg );

		if ( getCacheConcurrencyStrategy() != null ) {
			Iterator iter = cfg.getClassMappings();
			while ( iter.hasNext() ) {
				PersistentClass clazz = (PersistentClass) iter.next();
				Iterator props = clazz.getPropertyClosureIterator();
				boolean hasLob = false;
				while ( props.hasNext() ) {
					Property prop = (Property) props.next();
					if ( prop.getValue().isSimpleValue() ) {
						String type = ( (SimpleValue) prop.getValue() ).getTypeName();
						if ( "blob".equals(type) || "clob".equals(type) ) hasLob = true;
						if ( Blob.class.getName().equals(type) || Clob.class.getName().equals(type) ) hasLob = true;
					}
				}
				if ( !hasLob && !clazz.isInherited() && overrideCacheStrategy() ) {
					cfg.setCacheConcurrencyStrategy(
							clazz.getEntityName(),
							getCacheConcurrencyStrategy()
						);
				}
			}
			iter = cfg.getCollectionMappings();
			while ( iter.hasNext() ) {
				Collection coll = (Collection) iter.next();
				cfg.setCollectionCacheConcurrencyStrategy(
						coll.getRole(),
						getCacheConcurrencyStrategy()
					);
			}
		}

		// make sure we use the same dialect...
		cfg.setProperty( Environment.DIALECT, TestCase.dialect.getClass().getName() );
		TestCase.sessions = cfg.buildSessionFactory();
		afterSessionFactoryBuilt();
	}
	catch ( Exception e ) {
		e.printStackTrace();
		throw e;
	}
}