All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.internal.FilterConfiguration Maven / Gradle / Ivy

There is a newer version: 7.0.0.Alpha1
Show newest version
/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.  All third-party contributions are
 * distributed under license by Red Hat Inc.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.hibernate.internal;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.persister.entity.Joinable;

/**
 *
 * @author Rob Worsnop
 */
public class FilterConfiguration {
	private final String name;
	private final String condition;
	private final boolean autoAliasInjection;
	private final Map aliasTableMap;
	private final Map aliasEntityMap;
	private final PersistentClass persistentClass;
	
	public FilterConfiguration(String name, String condition, boolean autoAliasInjection, Map aliasTableMap, Map aliasEntityMap, PersistentClass persistentClass) {
		this.name = name;
		this.condition = condition;
		this.autoAliasInjection = autoAliasInjection;
		this.aliasTableMap = aliasTableMap;
		this.aliasEntityMap = aliasEntityMap;
		this.persistentClass = persistentClass;
	}

	public String getName() {
		return name;
	}

	public String getCondition() {
		return condition;
	}

	public boolean useAutoAliasInjection() {
		return autoAliasInjection;
	}

	public Map getAliasTableMap(SessionFactoryImplementor factory) {
		Map mergedAliasTableMap = mergeAliasMaps(factory);
		if (!mergedAliasTableMap.isEmpty()){
			return mergedAliasTableMap;
		} else if (persistentClass != null){
			String table = persistentClass.getTable().getQualifiedName(factory.getDialect(), 
					factory.getSettings().getDefaultCatalogName(),
					factory.getSettings().getDefaultSchemaName());
			return Collections.singletonMap(null, table);
		} else{
			return Collections.emptyMap();
		}
	}
	
	private Map mergeAliasMaps(SessionFactoryImplementor factory){
		Map ret = new HashMap();
		if (aliasTableMap != null){
			ret.putAll(aliasTableMap);
		}
		if (aliasEntityMap != null){
			for (Map.Entry entry : aliasEntityMap.entrySet()){
				ret.put(entry.getKey(), 
						Joinable.class.cast(factory.getEntityPersister(entry.getValue())).getTableName());
			}
		}
		return ret;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy