类org.hibernate.persister.entity.PropertyMapping源码实例Demo

下面列出了怎么用org.hibernate.persister.entity.PropertyMapping的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lams   文件: AbstractEmptinessExpression.java
protected QueryableCollection getQueryableCollection(
		String entityName,
		String propertyName,
		SessionFactoryImplementor factory) throws HibernateException {
	final PropertyMapping ownerMapping = (PropertyMapping) factory.getEntityPersister( entityName );
	final Type type = ownerMapping.toType( propertyName );
	if ( !type.isCollectionType() ) {
		throw new MappingException(
				"Property path [" + entityName + "." + propertyName + "] does not reference a collection"
		);
	}

	final String role = ( (CollectionType) type ).getRole();
	try {
		return (QueryableCollection) factory.getCollectionPersister( role );
	}
	catch ( ClassCastException cce ) {
		throw new QueryException( "collection role is not queryable: " + role );
	}
	catch ( Exception e ) {
		throw new QueryException( "collection role not found: " + role );
	}
}
 
源代码2 项目: lams   文件: EntityQuerySpaceImpl.java
@Override
public ExpandingCompositeQuerySpace makeCompositeIdentifierQuerySpace() {
	final String compositeQuerySpaceUid = getUid() + "-id";
	final ExpandingCompositeQuerySpace rhs = getExpandingQuerySpaces().makeCompositeQuerySpace(
			compositeQuerySpaceUid,
			new CompositePropertyMapping(
					(CompositeType) getEntityPersister().getIdentifierType(),
					(PropertyMapping) getEntityPersister(),
					getEntityPersister().getIdentifierPropertyName()
			),
			canJoinsBeRequired()
	);
	final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCompositeJoin(
			this,
			EntityPersister.ENTITY_ID,
			rhs,
			canJoinsBeRequired(),
			(CompositeType) persister.getIdentifierType()
	);
	internalGetJoins().add( join );

	return rhs;
}
 
源代码3 项目: lams   文件: JoinHelper.java
/**
 * Get the qualified (prefixed by alias) names of the columns of the owning entity which are to be used in the join
 *
 * @param associationType The association type for the association that represents the join
 * @param columnQualifier The left-hand side table alias
 * @param propertyIndex The index of the property that represents the association/join
 * @param begin The index for any nested (composites) attributes
 * @param lhsPersister The persister for the left-hand side of the association/join
 * @param mapping The mapping (typically the SessionFactory).
 *
 * @return The qualified column names.
 */
public static String[] getAliasedLHSColumnNames(
		AssociationType associationType,
		String columnQualifier,
		int propertyIndex,
		int begin,
		OuterJoinLoadable lhsPersister,
		Mapping mapping) {
	if ( associationType.useLHSPrimaryKey() ) {
		return StringHelper.qualify( columnQualifier, lhsPersister.getIdentifierColumnNames() );
	}
	else {
		final String propertyName = associationType.getLHSPropertyName();
		if ( propertyName == null ) {
			return ArrayHelper.slice(
					toColumns( lhsPersister, columnQualifier, propertyIndex ),
					begin,
					associationType.getColumnSpan( mapping )
			);
		}
		else {
			//bad cast
			return ( (PropertyMapping) lhsPersister ).toColumns( columnQualifier, propertyName );
		}
	}
}
 
源代码4 项目: lams   文件: QueryTranslatorImpl.java
PropertyMapping getPropertyMapping(String name) throws QueryException {
	PropertyMapping decorator = getDecoratedPropertyMapping( name );
	if ( decorator != null ) {
		return decorator;
	}

	String type = getType( name );
	if ( type == null ) {
		String role = getRole( name );
		if ( role == null ) {
			throw new QueryException( "alias not found: " + name );
		}
		return getCollectionPersister( role ); //.getElementPropertyMapping();
	}
	else {
		Queryable persister = getEntityPersister( type );
		if ( persister == null ) {
			throw new QueryException( "persistent class not found: " + type );
		}
		return persister;
	}
}
 
protected QueryableCollection getQueryableCollection(String entityName, String propertyName, SessionFactoryImplementor factory)
        throws HibernateException {
	PropertyMapping ownerMapping = ( PropertyMapping ) factory.getEntityPersister( entityName );
	Type type = ownerMapping.toType( propertyName );
	if ( !type.isCollectionType() ) {
		throw new MappingException(
		        "Property path [" + entityName + "." + propertyName + "] does not reference a collection"
		);
	}

	String role = ( ( CollectionType ) type ).getRole();
	try {
		return ( QueryableCollection ) factory.getCollectionPersister( role );
	}
	catch ( ClassCastException cce ) {
		throw new QueryException( "collection role is not queryable: " + role );
	}
	catch ( Exception e ) {
		throw new QueryException( "collection role not found: " + role );
	}
}
 
源代码6 项目: cacheonix-core   文件: JoinHelper.java
/**
 * Get the aliased columns of the owning entity which are to 
 * be used in the join
 */
public static String[] getAliasedLHSColumnNames(
		AssociationType type, 
		String alias, 
		int property, 
		int begin, 
		OuterJoinLoadable lhsPersister,
		Mapping mapping
) {
	if ( type.useLHSPrimaryKey() ) {
		return StringHelper.qualify( alias, lhsPersister.getIdentifierColumnNames() );
	}
	else {
		String propertyName = type.getLHSPropertyName();
		if (propertyName==null) {
			return ArrayHelper.slice( 
					lhsPersister.toColumns(alias, property), 
					begin, 
					type.getColumnSpan(mapping) 
				);
		}
		else {
			return ( (PropertyMapping) lhsPersister ).toColumns(alias, propertyName); //bad cast
		}
	}
}
 
源代码7 项目: cacheonix-core   文件: FromElementType.java
/**
 * Returns the type of a property, given it's name (the last part) and the full path.
 *
 * @param propertyName The last part of the full path to the property.
 * @return The type.
 * @0param propertyPath The full property path.
 */
public Type getPropertyType(String propertyName, String propertyPath) {
	checkInitialized();
	Type type = null;
	// If this is an entity and the property is the identifier property, then use getIdentifierType().
	//      Note that the propertyName.equals( propertyPath ) checks whether we have a component
	//      key reference, where the component class property name is the same as the
	//      entity id property name; if the two are not equal, this is the case and
	//      we'd need to "fall through" to using the property mapping.
	if ( persister != null && propertyName.equals( propertyPath ) && propertyName.equals( persister.getIdentifierPropertyName() ) ) {
		type = persister.getIdentifierType();
	}
	else {	// Otherwise, use the property mapping.
		PropertyMapping mapping = getPropertyMapping( propertyName );
		type = mapping.toType( propertyPath );
	}
	if ( type == null ) {
		throw new MappingException( "Property " + propertyName + " does not exist in " +
				( ( queryableCollection == null ) ? "class" : "collection" ) + " "
				+ ( ( queryableCollection == null ) ? fromElement.getClassName() : queryableCollection.getRole() ) );
	}
	return type;
}
 
源代码8 项目: cacheonix-core   文件: FromElementType.java
PropertyMapping getPropertyMapping(String propertyName) {
	checkInitialized();
	if ( queryableCollection == null ) {		// Not a collection?
		return ( PropertyMapping ) persister;	// Return the entity property mapping.
	}
	// If the property is a special collection property name, return a CollectionPropertyMapping.
	if ( CollectionProperties.isCollectionProperty( propertyName ) ) {
		if ( collectionPropertyMapping == null ) {
			collectionPropertyMapping = new CollectionPropertyMapping( queryableCollection );
		}
		return collectionPropertyMapping;
	}
	if ( queryableCollection.getElementType().isAnyType() ) {
		// collection of <many-to-any/> mappings...
		// used to circumvent the component-collection check below...
		return queryableCollection;

	}
	if ( queryableCollection.getElementType().isComponentType() ) {
		// Collection of components.
		if ( propertyName.equals( EntityPersister.ENTITY_ID ) ) {
			return ( PropertyMapping ) queryableCollection.getOwnerEntityPersister();
		}
	}
	return queryableCollection;
}
 
源代码9 项目: cacheonix-core   文件: QueryTranslatorImpl.java
PropertyMapping getPropertyMapping(String name) throws QueryException {
	PropertyMapping decorator = getDecoratedPropertyMapping( name );
	if ( decorator != null ) return decorator;

	String type = getType( name );
	if ( type == null ) {
		String role = getRole( name );
		if ( role == null ) {
			throw new QueryException( "alias not found: " + name );
		}
		return getCollectionPersister( role ); //.getElementPropertyMapping();
	}
	else {
		Queryable persister = getEntityPersister( type );
		if ( persister == null ) throw new QueryException( "persistent class not found: " + type );
		return persister;
	}
}
 
源代码10 项目: lams   文件: CriteriaQueryTranslator.java
private PropertyMapping getPropertyMapping(String entityName) throws MappingException {
	final CriteriaInfoProvider info = nameCriteriaInfoMap.get( entityName );
	if ( info == null ) {
		throw new HibernateException( "Unknown entity: " + entityName );
	}
	return info.getPropertyMapping();
}
 
源代码11 项目: lams   文件: CompositePropertyMapping.java
/**
 * Builds a CompositePropertyMapping
 *
 * @param compositeType The composite being described by this PropertyMapping
 * @param parentPropertyMapping The PropertyMapping of our parent (composites have to have a parent/owner)
 * @param parentPropertyName The name of this composite within the parentPropertyMapping
 */
public CompositePropertyMapping(
		CompositeType compositeType,
		PropertyMapping parentPropertyMapping,
		String parentPropertyName) {
	this.compositeType = compositeType;
	this.parentPropertyMapping = parentPropertyMapping;
	this.parentPropertyName = parentPropertyName;
}
 
源代码12 项目: lams   文件: EntityQuerySpaceImpl.java
@Override
public PropertyMapping getPropertyMapping() {
	// entity persisters are typically PropertyMapping implementors, but this is part of the funky
	// "optional interface hierarchy" for entity persisters.  The internal ones all implement
	// PropertyMapping...
	return (PropertyMapping) persister;
}
 
源代码13 项目: lams   文件: SubselectFetch.java
public String toSubselectString(String ukname) {
	String[] joinColumns = ukname == null
			? StringHelper.qualify( alias, loadable.getIdentifierColumnNames() )
			: ( (PropertyMapping) loadable ).toColumns( alias, ukname );

	return "select " + String.join( ", ", joinColumns ) + queryString;
}
 
源代码14 项目: lams   文件: FromElementType.java
/**
 * Returns the type of a property, given it's name (the last part) and the full path.
 *
 * @param propertyName The last part of the full path to the property.
 *
 * @return The type.
 *
 * @0param getPropertyPath The full property path.
 */
public Type getPropertyType(String propertyName, String propertyPath) {
	checkInitialized();
	Type type = null;
	// If this is an entity and the property is the identifier property, then use getIdentifierType().
	//      Note that the propertyName.equals( getPropertyPath ) checks whether we have a component
	//      key reference, where the component class property name is the same as the
	//      entity id property name; if the two are not equal, this is the case and
	//      we'd need to "fall through" to using the property mapping.
	if ( persister != null && propertyName.equals( propertyPath ) && propertyName.equals( persister.getIdentifierPropertyName() ) ) {
		type = persister.getIdentifierType();
	}
	else {    // Otherwise, use the property mapping.
		PropertyMapping mapping = getPropertyMapping( propertyName );
		type = mapping.toType( propertyPath );
	}
	if ( type == null ) {
		throw new MappingException(
				"Property " + propertyName + " does not exist in " +
						( ( queryableCollection == null ) ? "class" : "collection" ) + " "
						+ ( ( queryableCollection == null ) ?
						fromElement.getClassName() :
						queryableCollection.getRole() )
		);
	}
	return type;
}
 
源代码15 项目: cacheonix-core   文件: SubselectFetch.java
public String toSubselectString(String ukname) {
	
	String[] joinColumns = ukname==null ?
		StringHelper.qualify( alias, loadable.getIdentifierColumnNames() ) :
		( (PropertyMapping) loadable ).toColumns(alias, ukname);
	
	return new StringBuffer()
		.append("select ")
		.append( StringHelper.join(", ", joinColumns) )
		.append(queryString)
		.toString();
}
 
@Override
public PropertyMapping getPropertyMapping() {
	return helper.getCollectionPropertyMapping( role );
}
 
@Override
public PropertyMapping getPropertyMapping() {
	return persister;
}
 
源代码18 项目: lams   文件: EntityCriteriaInfoProvider.java
@Override
public PropertyMapping getPropertyMapping() {
	return persister;
}
 
源代码19 项目: lams   文件: JoinHelper.java
private static String[] determineRhsColumnNames(EntityType entityType, SessionFactoryImplementor sessionFactory) {
	final Joinable persister = entityType.getAssociatedJoinable( sessionFactory );
	return entityType.getRHSUniqueKeyPropertyName() == null ?
			persister.getKeyColumnNames() :
			( (PropertyMapping) persister ).toColumns( entityType.getRHSUniqueKeyPropertyName() );
}
 
源代码20 项目: lams   文件: CompositeQuerySpaceImpl.java
@Override
public PropertyMapping getPropertyMapping() {
	return compositeSubPropertyMapping;
}
 
源代码21 项目: lams   文件: CollectionQuerySpaceImpl.java
@Override
public PropertyMapping getPropertyMapping() {
	return (PropertyMapping) persister;
}
 
源代码22 项目: lams   文件: AbstractCollectionReference.java
private CollectionFetchableIndex buildIndexGraph() {
	final CollectionPersister persister = collectionQuerySpace.getCollectionPersister();
	if ( persister.hasIndex() ) {
		final Type type = persister.getIndexType();
		if ( type.isAssociationType() ) {
			if ( type.isEntityType() ) {
				final EntityPersister indexPersister = persister.getFactory().getEntityPersister(
						( (EntityType) type ).getAssociatedEntityName()
				);

				final ExpandingEntityQuerySpace entityQuerySpace = QuerySpaceHelper.INSTANCE.makeEntityQuerySpace(
						collectionQuerySpace,
						indexPersister,
						CollectionPropertyNames.COLLECTION_INDICES,
						(EntityType) persister.getIndexType(),
						collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(),
						collectionQuerySpace.canJoinsBeRequired(),
						allowIndexJoin
				);
				return new CollectionFetchableIndexEntityGraph( this, entityQuerySpace );
			}
			else if ( type.isAnyType() ) {
				return new CollectionFetchableIndexAnyGraph( this );
			}
		}
		else if ( type.isComponentType() ) {
			final ExpandingCompositeQuerySpace compositeQuerySpace = QuerySpaceHelper.INSTANCE.makeCompositeQuerySpace(
					collectionQuerySpace,
					new CompositePropertyMapping(
							(CompositeType) persister.getIndexType(),
							(PropertyMapping) persister,
							""
					),
					CollectionPropertyNames.COLLECTION_INDICES,
					(CompositeType) persister.getIndexType(),
					collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(),
					collectionQuerySpace.canJoinsBeRequired(),
					allowIndexJoin
			);
			return new CollectionFetchableIndexCompositeGraph( this, compositeQuerySpace );
		}
	}

	return null;
}
 
源代码23 项目: lams   文件: AbstractCollectionReference.java
private CollectionFetchableElement buildElementGraph() {
	final CollectionPersister persister = collectionQuerySpace.getCollectionPersister();
	final Type type = persister.getElementType();
	if ( type.isAssociationType() ) {
		if ( type.isEntityType() ) {
			final EntityPersister elementPersister = persister.getFactory().getEntityPersister(
					( (EntityType) type ).getAssociatedEntityName()
			);
			final ExpandingEntityQuerySpace entityQuerySpace = QuerySpaceHelper.INSTANCE.makeEntityQuerySpace(
					collectionQuerySpace,
					elementPersister,
					CollectionPropertyNames.COLLECTION_ELEMENTS,
					(EntityType) persister.getElementType(),
					collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(),
					collectionQuerySpace.canJoinsBeRequired(),
					allowElementJoin
			);
			return new CollectionFetchableElementEntityGraph( this, entityQuerySpace );
		}
		else if ( type.isAnyType() ) {
			return new CollectionFetchableElementAnyGraph( this );
		}
	}
	else if ( type.isComponentType() ) {
		final ExpandingCompositeQuerySpace compositeQuerySpace = QuerySpaceHelper.INSTANCE.makeCompositeQuerySpace(
				collectionQuerySpace,
				new CompositePropertyMapping(
						(CompositeType) persister.getElementType(),
						(PropertyMapping) persister,
						""
				),
				CollectionPropertyNames.COLLECTION_ELEMENTS,
				(CompositeType) persister.getElementType(),
				collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(),
				collectionQuerySpace.canJoinsBeRequired(),
				allowElementJoin
		);
		return new CollectionFetchableElementCompositeGraph( this, compositeQuerySpace );
	}

	return null;
}
 
源代码24 项目: lams   文件: ComponentJoin.java
@Override
public PropertyMapping getPropertyMapping(String propertyName) {
	return propertyMapping;
}
 
源代码25 项目: lams   文件: ComponentJoin.java
protected PropertyMapping getBasePropertyMapping() {
	return getOrigin().getPropertyMapping( "" );
}
 
源代码26 项目: lams   文件: FromElement.java
public PropertyMapping getPropertyMapping(String propertyName) {
	return elementType.getPropertyMapping( propertyName );
}
 
源代码27 项目: lams   文件: FromElementType.java
String[] toColumns(String tableAlias, String path, boolean inSelect, boolean forceAlias) {
		checkInitialized();
		PropertyMapping propertyMapping = getPropertyMapping( path );

		if ( !inSelect && queryableCollection != null && CollectionProperties.isCollectionProperty( path ) ) {
			// If this from element is a collection and the path is a collection property (maxIndex, etc.)
			// requiring a sub-query then generate a sub-query.
			//h
			// Unless we are in the select clause, because some dialects do not support
			// Note however, that some dialects do not  However, in the case of this being a collection property reference being in the select, not generating the subquery
			// will not generally work.  The specific cases I am thinking about are the minIndex, maxIndex
			// (most likely minElement, maxElement as well) cases.
			//	todo : if ^^ is the case we should thrown an exception here rather than waiting for the sql error
			//		if the dialect supports select-clause subqueries we could go ahead and generate the subquery also

			// we also need to account for cases where the property name is a CollectionProperty, but
			// is also a property on the element-entity.  This is handled inside `#getPropertyMapping`
			// already; here just check for propertyMapping being the same as the entity persister.  Yes
			// this is hacky, but really this is difficult to handle given the current codebase.
			if ( persister != propertyMapping ) {
				// we want the subquery...
//				DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfCollectionPropertiesInHql( path, fromElement.getClassAlias() );
				return getCollectionPropertyReference( path ).toColumns( tableAlias );
			}
		}

		if ( forceAlias ) {
			return propertyMapping.toColumns( tableAlias, path );
		}

		if ( fromElement.getWalker().getStatementType() == HqlSqlTokenTypes.SELECT ) {
			return propertyMapping.toColumns( tableAlias, path );
		}

		if ( fromElement.getWalker().isSubQuery() ) {
			// for a subquery, the alias to use depends on a few things (we
			// already know this is not an overall SELECT):
			// 1) if this FROM_ELEMENT represents a correlation to the
			// outer-most query
			// A) if the outer query represents a multi-table
			// persister, we need to use the given alias
			// in anticipation of one of the multi-table
			// executors being used (as this subquery will
			// actually be used in the "id select" phase
			// of that multi-table executor)
			// B) otherwise, we need to use the persister's
			// table name as the column qualification
			// 2) otherwise (not correlated), use the given alias
			if ( isCorrelation() ) {
				if ( isMultiTable() || isInsertQuery() ) {
					return propertyMapping.toColumns( tableAlias, path );
				}
				return propertyMapping.toColumns( extractTableName(), path );
			}
			return propertyMapping.toColumns( tableAlias, path );
		}

		if ( fromElement.getWalker().getCurrentTopLevelClauseType() == HqlSqlTokenTypes.SELECT ) {
			return propertyMapping.toColumns( tableAlias, path );
		}

		if ( isManipulationQuery() && isMultiTable() && inWhereClause() ) {
			// the actual where-clause will end up being ripped out the update/delete and used in
			// a select to populate the temp table, so its ok to use the table alias to qualify the table refs
			// and safer to do so to protect from same-named columns
			return propertyMapping.toColumns( tableAlias, path );
		}

		String[] columns = propertyMapping.toColumns( path );
		LOG.tracev( "Using non-qualified column reference [{0} -> ({1})]", path, ArrayHelper.toString( columns ) );
		return columns;
	}
 
源代码28 项目: lams   文件: FromElementType.java
PropertyMapping getPropertyMapping(String propertyName) {
	checkInitialized();
	if ( queryableCollection == null ) {        // Not a collection?
		return (PropertyMapping) persister;    // Return the entity property mapping.
	}

	// indexed, many-to-many collections must be treated specially here if the property to
	// be mapped touches on the index as we must adjust the alias to use the alias from
	// the association table (which i different than the one passed in
	if ( queryableCollection.isManyToMany()
			&& queryableCollection.hasIndex()
			&& SPECIAL_MANY2MANY_TREATMENT_FUNCTION_NAMES.contains( propertyName ) ) {
		return new SpecialManyToManyCollectionPropertyMapping();
	}

	// If the property is a special collection property name, return a CollectionPropertyMapping.
	if ( CollectionProperties.isCollectionProperty( propertyName ) ) {
		if ( collectionPropertyMapping == null ) {
			// lets additionally make sure that the property name is not also the name
			// of a property on the element, assuming that the element is an entity.
			// todo : also consider composites?
			if ( persister != null ) {
				try {
					if ( persister.getPropertyType( propertyName ) != null ) {
						return (PropertyMapping) persister;
					}
				}
				catch (QueryException ignore) {
				}
			}
			collectionPropertyMapping = new CollectionPropertyMapping( queryableCollection );
		}
		return collectionPropertyMapping;
	}

	if ( queryableCollection.getElementType().isAnyType() ) {
		// collection of <many-to-any/> mappings...
		// used to circumvent the component-collection check below...
		return queryableCollection;

	}

	if ( queryableCollection.getElementType().isComponentType() ) {
		// Collection of components.
		if ( propertyName.equals( EntityPersister.ENTITY_ID ) ) {
			return (PropertyMapping) queryableCollection.getOwnerEntityPersister();
		}
	}
	return queryableCollection;
}
 
源代码29 项目: lams   文件: FromElementType.java
public CollectionPropertyReference getCollectionPropertyReference(final String propertyName) {
	if ( queryableCollection == null ) {
		throw new QueryException( "Not a collection reference" );
	}

	final PropertyMapping collectionPropertyMapping;

	if ( queryableCollection.isManyToMany()
			&& queryableCollection.hasIndex()
			&& SPECIAL_MANY2MANY_TREATMENT_FUNCTION_NAMES.contains( propertyName ) ) {
		collectionPropertyMapping = new SpecialManyToManyCollectionPropertyMapping();
	}
	else if ( CollectionProperties.isCollectionProperty( propertyName ) ) {
		if ( this.collectionPropertyMapping == null ) {
			this.collectionPropertyMapping = new CollectionPropertyMapping( queryableCollection );
		}
		collectionPropertyMapping = this.collectionPropertyMapping;
	}
	else {
		collectionPropertyMapping = queryableCollection;
	}

	return new CollectionPropertyReference() {
		@Override
		public Type getType() {
			return collectionPropertyMapping.toType( propertyName );
		}

		@Override
		public String[] toColumns(final String tableAlias) {
			if ( propertyName.equalsIgnoreCase( "index" ) ) {
				return collectionPropertyMapping.toColumns( tableAlias, propertyName );
			}

			Map enabledFilters = fromElement.getWalker().getEnabledFilters();
			String subquery = CollectionSubqueryFactory.createCollectionSubquery(
					joinSequence.copyForCollectionProperty().setUseThetaStyle( true ),
					enabledFilters,
					collectionPropertyMapping.toColumns( tableAlias, propertyName )
			);
			LOG.debugf( "toColumns(%s,%s) : subquery = %s", tableAlias, propertyName, subquery );
			return new String[] {"(" + subquery + ")"};
		}
	};
}
 
源代码30 项目: lams   文件: PathExpressionParser.java
private PropertyMapping getPropertyMapping() {
	return currentPropertyMapping;
}
 
 类所在包
 类方法
 同包方法