org.hibernate.type.EntityType#getAssociatedEntityName ( )源码实例Demo

下面列出了org.hibernate.type.EntityType#getAssociatedEntityName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lams   文件: SQLQueryReturnProcessor.java
private void processJoinReturn(NativeSQLQueryJoinReturn fetchReturn) {
		String alias = fetchReturn.getAlias();
//		if ( alias2Persister.containsKey( alias ) || collectionAliases.contains( alias ) ) {
		if ( alias2Persister.containsKey( alias ) || alias2CollectionPersister.containsKey( alias ) ) {
			// already been processed...
			return;
		}

		String ownerAlias = fetchReturn.getOwnerAlias();

		// Make sure the owner alias is known...
		if ( !alias2Return.containsKey( ownerAlias ) ) {
			throw new HibernateException( "Owner alias [" + ownerAlias + "] is unknown for alias [" + alias + "]" );
		}

		// If this return's alias has not been processed yet, do so b4 further processing of this return
		if ( !alias2Persister.containsKey( ownerAlias ) ) {
			NativeSQLQueryNonScalarReturn ownerReturn = ( NativeSQLQueryNonScalarReturn ) alias2Return.get(ownerAlias);
			processReturn( ownerReturn );
		}

		SQLLoadable ownerPersister = ( SQLLoadable ) alias2Persister.get( ownerAlias );
		Type returnType = ownerPersister.getPropertyType( fetchReturn.getOwnerProperty() );

		if ( returnType.isCollectionType() ) {
			String role = ownerPersister.getEntityName() + '.' + fetchReturn.getOwnerProperty();
			addCollection( role, alias, fetchReturn.getPropertyResultsMap() );
//			collectionOwnerAliases.add( ownerAlias );
		}
		else if ( returnType.isEntityType() ) {
			EntityType eType = ( EntityType ) returnType;
			String returnEntityName = eType.getAssociatedEntityName();
			SQLLoadable persister = getSQLLoadable( returnEntityName );
			addPersister( alias, fetchReturn.getPropertyResultsMap(), persister );
		}

	}
 
源代码2 项目: lams   文件: ForeignKeys.java
/**
 * Return null if the argument is an "unsaved" entity (ie. one with no existing database row), or the
 * input argument otherwise.  This is how Hibernate avoids foreign key constraint violations.
 *
 * @param value An entity attribute value
 * @param type An entity attribute type
 *
 * @return {@code null} if the argument is an unsaved entity; otherwise return the argument.
 */
private Object nullifyTransientReferences(final Object value, final Type type) {
	if ( value == null ) {
		return null;
	}
	else if ( type.isEntityType() ) {
		final EntityType entityType = (EntityType) type;
		if ( entityType.isOneToOne() ) {
			return value;
		}
		else {
			final String entityName = entityType.getAssociatedEntityName();
			return isNullifiable( entityName, value ) ? null : value;
		}
	}
	else if ( type.isAnyType() ) {
		return isNullifiable( null, value ) ? null : value;
	}
	else if ( type.isComponentType() ) {
		final CompositeType actype = (CompositeType) type;
		final Object[] subvalues = actype.getPropertyValues( value, session );
		final Type[] subtypes = actype.getSubtypes();
		boolean substitute = false;
		for ( int i = 0; i < subvalues.length; i++ ) {
			final Object replacement = nullifyTransientReferences( subvalues[i], subtypes[i] );
			if ( replacement != subvalues[i] ) {
				substitute = true;
				subvalues[i] = replacement;
			}
		}
		if ( substitute ) {
			// todo : need to account for entity mode on the CompositeType interface :(
			actype.setPropertyValues( value, subvalues, EntityMode.POJO );
		}
		return value;
	}
	else {
		return value;
	}
}
 
源代码3 项目: cacheonix-core   文件: SQLQueryReturnProcessor.java
private void processJoinReturn(NativeSQLQueryJoinReturn fetchReturn) {
		String alias = fetchReturn.getAlias();
//		if ( alias2Persister.containsKey( alias ) || collectionAliases.contains( alias ) ) {
		if ( alias2Persister.containsKey( alias ) || alias2CollectionPersister.containsKey( alias ) ) {
			// already been processed...
			return;
		}

		String ownerAlias = fetchReturn.getOwnerAlias();

		// Make sure the owner alias is known...
		if ( !alias2Return.containsKey( ownerAlias ) ) {
			throw new HibernateException( "Owner alias [" + ownerAlias + "] is unknown for alias [" + alias + "]" );
		}

		// If this return's alias has not been processed yet, do so b4 further processing of this return
		if ( !alias2Persister.containsKey( ownerAlias ) ) {
			NativeSQLQueryNonScalarReturn ownerReturn = ( NativeSQLQueryNonScalarReturn ) alias2Return.get(ownerAlias);
			processReturn( ownerReturn );
		}

		SQLLoadable ownerPersister = ( SQLLoadable ) alias2Persister.get( ownerAlias );
		Type returnType = ownerPersister.getPropertyType( fetchReturn.getOwnerProperty() );

		if ( returnType.isCollectionType() ) {
			String role = ownerPersister.getEntityName() + '.' + fetchReturn.getOwnerProperty();
			addCollection( role, alias, fetchReturn.getPropertyResultsMap() );
//			collectionOwnerAliases.add( ownerAlias );
		}
		else if ( returnType.isEntityType() ) {
			EntityType eType = ( EntityType ) returnType;
			String returnEntityName = eType.getAssociatedEntityName();
			SQLLoadable persister = getSQLLoadable( returnEntityName );
			addPersister( alias, fetchReturn.getPropertyResultsMap(), persister );
		}

	}
 
源代码4 项目: cacheonix-core   文件: ForeignKeys.java
/**
 * Return null if the argument is an "unsaved" entity (ie. 
 * one with no existing database row), or the input argument 
 * otherwise. This is how Hibernate avoids foreign key constraint
 * violations.
 */
private Object nullifyTransientReferences(final Object value, final Type type) 
throws HibernateException {
	if ( value == null ) {
		return null;
	}
	else if ( type.isEntityType() ) {
		EntityType entityType = (EntityType) type;
		if ( entityType.isOneToOne() ) {
			return value;
		}
		else {
			String entityName = entityType.getAssociatedEntityName();
			return isNullifiable(entityName, value) ? null : value;
		}
	}
	else if ( type.isAnyType() ) {
		return isNullifiable(null, value) ? null : value;
	}
	else if ( type.isComponentType() ) {
		AbstractComponentType actype = (AbstractComponentType) type;
		Object[] subvalues = actype.getPropertyValues(value, session);
		Type[] subtypes = actype.getSubtypes();
		boolean substitute = false;
		for ( int i = 0; i < subvalues.length; i++ ) {
			Object replacement = nullifyTransientReferences( subvalues[i], subtypes[i] );
			if ( replacement != subvalues[i] ) {
				substitute = true;
				subvalues[i] = replacement;
			}
		}
		if (substitute) actype.setPropertyValues( value, subvalues, session.getEntityMode() );
		return value;
	}
	else {
		return value;
	}
}
 
源代码5 项目: cacheonix-core   文件: PathExpressionParser.java
private void dereferenceEntity(String propertyName, EntityType propertyType, QueryTranslatorImpl q)
		throws QueryException {
	//NOTE: we avoid joining to the next table if the named property is just the foreign key value

	//if its "id"
	boolean isIdShortcut = EntityPersister.ENTITY_ID.equals( propertyName ) &&
			propertyType.isReferenceToPrimaryKey();

	//or its the id property name
	final String idPropertyName;
	try {
		idPropertyName = propertyType.getIdentifierOrUniqueKeyPropertyName( q.getFactory() );
	}
	catch ( MappingException me ) {
		throw new QueryException( me );
	}
	boolean isNamedIdPropertyShortcut = idPropertyName != null
			&& idPropertyName.equals( propertyName )
			&& propertyType.isReferenceToPrimaryKey();

	if ( isIdShortcut || isNamedIdPropertyShortcut ) {
		// special shortcut for id properties, skip the join!
		// this must only occur at the _end_ of a path expression
		if ( componentPath.length() > 0 ) componentPath.append( '.' );
		componentPath.append( propertyName );
	}
	else {
		String entityClass = propertyType.getAssociatedEntityName();
		String name = q.createNameFor( entityClass );
		q.addType( name, entityClass );
		addJoin( name, propertyType );
		if ( propertyType.isOneToOne() ) oneToOneOwnerName = currentName;
		ownerAssociationType = propertyType;
		currentName = name;
		currentProperty = propertyName;
		q.addPathAliasAndJoin( path.substring( 0, path.toString().lastIndexOf( '.' ) ), name, joinSequence.copy() );
		componentPath.setLength( 0 );
		currentPropertyMapping = q.getEntityPersister( entityClass );
	}
}
 
源代码6 项目: lams   文件: PathExpressionParser.java
private void dereferenceEntity(String propertyName, EntityType propertyType, QueryTranslatorImpl q)
		throws QueryException {
	//NOTE: we avoid joining to the next table if the named property is just the foreign key value

	//if its "id"
	boolean isIdShortcut = EntityPersister.ENTITY_ID.equals( propertyName )
			&& propertyType.isReferenceToPrimaryKey();

	//or its the id property name
	final String idPropertyName;
	try {
		idPropertyName = propertyType.getIdentifierOrUniqueKeyPropertyName( q.getFactory() );
	}
	catch ( MappingException me ) {
		throw new QueryException( me );
	}
	boolean isNamedIdPropertyShortcut = idPropertyName != null
			&& idPropertyName.equals( propertyName )
			&& propertyType.isReferenceToPrimaryKey();


	if ( isIdShortcut || isNamedIdPropertyShortcut ) {
		// special shortcut for id properties, skip the join!
		// this must only occur at the _end_ of a path expression
		if ( componentPath.length() > 0 ) {
			componentPath.append( '.' );
		}
		componentPath.append( propertyName );
	}
	else {
		String entityClass = propertyType.getAssociatedEntityName();
		String name = q.createNameFor( entityClass );
		q.addType( name, entityClass );
		addJoin( name, propertyType );
		if ( propertyType.isOneToOne() ) {
			oneToOneOwnerName = currentName;
		}
		ownerAssociationType = propertyType;
		currentName = name;
		currentProperty = propertyName;
		q.addPathAliasAndJoin( path.substring( 0, path.toString().lastIndexOf( '.' ) ), name, joinSequence.copy() );
		componentPath.setLength( 0 );
		currentPropertyMapping = q.getEntityPersister( entityClass );
	}
}
 
源代码7 项目: cacheonix-core   文件: DotNode.java
private void dereferenceEntityJoin(String classAlias, EntityType propertyType, boolean impliedJoin, AST parent) 
	throws SemanticException {
		dereferenceType = DEREF_ENTITY;
		if ( log.isDebugEnabled() ) {
			log.debug( "dereferenceEntityJoin() : generating join for " + propertyName + " in "
					+ getFromElement().getClassName() + " "
					+ ( ( classAlias == null ) ? "{no alias}" : "(" + classAlias + ")" )
					+ " parent = " + ASTUtil.getDebugString( parent )
			);
		}
		// Create a new FROM node for the referenced class.
		String associatedEntityName = propertyType.getAssociatedEntityName();
		String tableAlias = getAliasGenerator().createName( associatedEntityName );

		String[] joinColumns = getColumns();
		String joinPath = getPath();

		if ( impliedJoin && getWalker().isInFrom() ) {
			joinType = getWalker().getImpliedJoinType();
		}

		FromClause currentFromClause = getWalker().getCurrentFromClause();
		FromElement elem = currentFromClause.findJoinByPath( joinPath );

///////////////////////////////////////////////////////////////////////////////
//
// This is the piece which recognizes the condition where an implicit join path
// resolved earlier in a correlated subquery is now being referenced in the
// outer query.  For 3.0final, we just let this generate a second join (which
// is exactly how the old parser handles this).  Eventually we need to add this
// logic back in and complete the logic in FromClause.promoteJoin; however,
// FromClause.promoteJoin has its own difficulties (see the comments in
// FromClause.promoteJoin).
//
//		if ( elem == null ) {
//			// see if this joinPath has been used in a "child" FromClause, and if so
//			// promote that element to the outer query
//			FromClause currentNodeOwner = getFromElement().getFromClause();
//			FromClause currentJoinOwner = currentNodeOwner.locateChildFromClauseWithJoinByPath( joinPath );
//			if ( currentJoinOwner != null && currentNodeOwner != currentJoinOwner ) {
//				elem = currentJoinOwner.findJoinByPathLocal( joinPath );
//				if ( elem != null ) {
//					currentFromClause.promoteJoin( elem );
//					// EARLY EXIT!!!
//					return;
//				}
//			}
//		}
//
///////////////////////////////////////////////////////////////////////////////

		if ( elem == null ) {
			// If this is an implied join in a from element, then use the impled join type which is part of the
			// tree parser's state (set by the gramamar actions).
			JoinSequence joinSequence = getSessionFactoryHelper()
				.createJoinSequence( impliedJoin, propertyType, tableAlias, joinType, joinColumns );

			FromElementFactory factory = new FromElementFactory(
			        currentFromClause,
					getLhs().getFromElement(),
					joinPath, 
					classAlias, 
					joinColumns, 
					impliedJoin
			);
			elem = factory.createEntityJoin( 
					associatedEntityName, 
					tableAlias, 
					joinSequence, 
					fetch, 
					getWalker().isInFrom(), 
					propertyType
			);
		}
		else {
			currentFromClause.addDuplicateAlias(classAlias, elem);
		}
		setImpliedJoin( elem );
		getWalker().addQuerySpaces( elem.getEntityPersister().getQuerySpaces() );
		setFromElement( elem );	// This 'dot' expression now refers to the resulting from element.
	}