Java Code Examples for org.hibernate.persister.entity.EntityPersister#getQuerySpaces()

The following examples show how to use org.hibernate.persister.entity.EntityPersister#getQuerySpaces() . 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: BulkOperationCleanupAction.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs an action to cleanup "affected cache regions" based on a
 * set of affected table spaces.  This differs from {@link #BulkOperationCleanupAction(SharedSessionContractImplementor, Queryable[])}
 * in that here we have the affected <strong>table names</strong>.  From those
 * we deduce the entity persisters which are affected based on the defined
 * {@link EntityPersister#getQuerySpaces() table spaces}; and from there, we
 * determine the affected collection regions based on any collections
 * in which those entity persisters participate as elements/keys/etc.
 *
 * @param session The session to which this request is tied.
 * @param tableSpaces The table spaces.
 */
@SuppressWarnings({ "unchecked" })
public BulkOperationCleanupAction(SharedSessionContractImplementor session, Set tableSpaces) {
	final LinkedHashSet<String> spacesList = new LinkedHashSet<>();
	spacesList.addAll( tableSpaces );

	final SessionFactoryImplementor factory = session.getFactory();
	for ( EntityPersister persister : factory.getMetamodel().entityPersisters().values() ) {
		final String[] entitySpaces = (String[]) persister.getQuerySpaces();
		if ( affectedEntity( tableSpaces, entitySpaces ) ) {
			spacesList.addAll( Arrays.asList( entitySpaces ) );

			if ( persister.canWriteToCache() ) {
				entityCleanups.add( new EntityCleanup( persister.getCacheAccessStrategy(), session ) );
			}
			if ( persister.hasNaturalIdentifier() && persister.hasNaturalIdCache() ) {
				naturalIdCleanups.add( new NaturalIdCleanup( persister.getNaturalIdCacheAccessStrategy(), session ) );
			}

			final Set<String> roles = session.getFactory().getMetamodel().getCollectionRolesByEntityParticipant( persister.getEntityName() );
			if ( roles != null ) {
				for ( String role : roles ) {
					final CollectionPersister collectionPersister = factory.getMetamodel().collectionPersister( role );
					if ( collectionPersister.hasCache() ) {
						collectionCleanups.add(
								new CollectionCleanup( collectionPersister.getCacheAccessStrategy(), session )
						);
					}
				}
			}
		}
	}

	this.affectedTableSpaces = spacesList.toArray( new String[ spacesList.size() ] );
}
 
Example 2
Source File: BulkOperationCleanupAction.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** Create an action that will evict collection and entity regions based on queryspaces (table names).
 *  TODO: cache the autodetected information and pass it in instead.
 **/
public BulkOperationCleanupAction(SessionImplementor session, Set querySpaces) {
	this.session = session;

	Set tmpSpaces = new HashSet(querySpaces);
	SessionFactoryImplementor factory = session.getFactory();
	Iterator iterator = factory.getAllClassMetadata().entrySet().iterator();
	while ( iterator.hasNext() ) {
		Map.Entry entry = (Map.Entry) iterator.next();
		String entityName = (String) entry.getKey();
		EntityPersister persister = factory.getEntityPersister( entityName );
		Serializable[] entitySpaces = persister.getQuerySpaces();

		if (affectedEntity( querySpaces, entitySpaces )) {
			if ( persister.hasCache() ) {
				affectedEntityNames.add( persister.getEntityName() );
			}
			Set roles = session.getFactory().getCollectionRolesByEntityParticipant( persister.getEntityName() );
			if ( roles != null ) {
				affectedCollectionRoles.addAll( roles );
			}
			for ( int y = 0; y < entitySpaces.length; y++ ) {
				tmpSpaces.add( entitySpaces[y] );
			}
		}

	}
	this.spaces = (Serializable[]) tmpSpaces.toArray( new Serializable[tmpSpaces.size()] );		
}
 
Example 3
Source File: FromElementFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public FromElement createEntityJoin(
			String entityClass,
			String tableAlias,
			JoinSequence joinSequence,
			boolean fetchFlag,
			boolean inFrom,
			EntityType type,
			String role,
			String joinPath) throws SemanticException {
		FromElement elem = createJoin( entityClass, tableAlias, joinSequence, type, false );
		elem.setFetch( fetchFlag );

		if ( joinPath != null ) {
			elem.applyTreatAsDeclarations( fromClause.getWalker().getTreatAsDeclarationsByPath( joinPath ) );
		}

		EntityPersister entityPersister = elem.getEntityPersister();
		int numberOfTables = entityPersister.getQuerySpaces().length;
		if ( numberOfTables > 1 && implied && !elem.useFromFragment() ) {
			LOG.debug( "createEntityJoin() : Implied multi-table entity join" );
			elem.setUseFromFragment( true );
		}

		// If this is an implied join in a FROM clause, then use ANSI-style joining, and set the
		// flag on the FromElement that indicates that it was implied in the FROM clause itself.
		if ( implied && inFrom ) {
			joinSequence.setUseThetaStyle( false );
			elem.setUseFromFragment( true );
			elem.setImpliedInFromClause( true );
		}
		if ( elem.getWalker().isSubQuery() ) {
			// two conditions where we need to transform this to a theta-join syntax:
			//      1) 'elem' is the "root from-element" in correlated subqueries
			//      2) The DotNode.useThetaStyleImplicitJoins has been set to true
			//          and 'elem' represents an implicit join
			if ( elem.getFromClause() != elem.getOrigin().getFromClause() ||
//			        ( implied && DotNode.useThetaStyleImplicitJoins ) ) {
					DotNode.useThetaStyleImplicitJoins ) {
				// the "root from-element" in correlated subqueries do need this piece
				elem.setType( FROM_FRAGMENT );
				joinSequence.setUseThetaStyle( true );
				elem.setUseFromFragment( false );
			}
		}

		elem.setRole( role );

		return elem;
	}
 
Example 4
Source File: FromElementFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
FromElement createEntityJoin(
	        String entityClass,
	        String tableAlias,
	        JoinSequence joinSequence,
	        boolean fetchFlag,
	        boolean inFrom,
	        EntityType type) throws SemanticException {
		FromElement elem = createJoin( entityClass, tableAlias, joinSequence, type, false );
		elem.setFetch( fetchFlag );
		EntityPersister entityPersister = elem.getEntityPersister();
		int numberOfTables = entityPersister.getQuerySpaces().length;
		if ( numberOfTables > 1 && implied && !elem.useFromFragment() ) {
			if ( log.isDebugEnabled() ) {
				log.debug( "createEntityJoin() : Implied multi-table entity join" );
			}
			elem.setUseFromFragment( true );
		}

		// If this is an implied join in a FROM clause, then use ANSI-style joining, and set the
		// flag on the FromElement that indicates that it was implied in the FROM clause itself.
		if ( implied && inFrom ) {
			joinSequence.setUseThetaStyle( false );
			elem.setUseFromFragment( true );
			elem.setImpliedInFromClause( true );
		}
		if ( elem.getWalker().isSubQuery() ) {
			// two conditions where we need to transform this to a theta-join syntax:
			//      1) 'elem' is the "root from-element" in correlated subqueries
			//      2) The DotNode.useThetaStyleImplicitJoins has been set to true
			//          and 'elem' represents an implicit join
			if ( elem.getFromClause() != elem.getOrigin().getFromClause() ||
//			        ( implied && DotNode.useThetaStyleImplicitJoins ) ) {
			        DotNode.useThetaStyleImplicitJoins ) {
				// the "root from-element" in correlated subqueries do need this piece
				elem.setType( FROM_FRAGMENT );
				joinSequence.setUseThetaStyle( true );
				elem.setUseFromFragment( false );
			}
		}

		return elem;
	}