本文整理汇总了Java中org.hibernate.engine.FilterDefinition类的典型用法代码示例。如果您正苦于以下问题:Java FilterDefinition类的具体用法?Java FilterDefinition怎么用?Java FilterDefinition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FilterDefinition类属于org.hibernate.engine包,在下文中一共展示了FilterDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseFilterDef
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
private static void parseFilterDef(Element element, Mappings mappings) {
String name = element.attributeValue( "name" );
log.debug( "Parsing filter-def [" + name + "]" );
String defaultCondition = element.getTextTrim();
if ( StringHelper.isEmpty( defaultCondition ) ) {
defaultCondition = element.attributeValue( "condition" );
}
HashMap paramMappings = new HashMap();
Iterator params = element.elementIterator( "filter-param" );
while ( params.hasNext() ) {
final Element param = (Element) params.next();
final String paramName = param.attributeValue( "name" );
final String paramType = param.attributeValue( "type" );
log.debug( "adding filter parameter : " + paramName + " -> " + paramType );
final Type heuristicType = TypeFactory.heuristicType( paramType );
log.debug( "parameter heuristic type : " + heuristicType );
paramMappings.put( paramName, heuristicType );
}
log.debug( "Parsed filter-def [" + name + "]" );
FilterDefinition def = new FilterDefinition( name, defaultCondition, paramMappings );
mappings.addFilterDefinition( def );
}
示例2: testGetFiltersForUsers
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
public void testGetFiltersForUsers() throws Exception {
SessionFactory sf=null;
Configuration configuration = null;
if(null == sf || sf.isClosed()){
configuration = new Configuration().configure(hibernateCfgFileName);
InstanceLevelSecurityHelper.getFiltersForUser(authorizationManager);
sf = configuration.buildSessionFactory();
}
List<FilterDefinition> filterList=InstanceLevelSecurityHelper.getFiltersForGroups(authorizationManager);
sf.close();
for (Object filter:filterList)
{ try {
printObject(filter, false);
} catch (Exception e) {
// TODO: handle exception
}
}
assertEquals("GetFiltersForGroups Method successful",2, filterList.size());
}
示例3: testGetFiltersForGroups
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
private void testGetFiltersForGroups() throws Exception {
SessionFactory sf=null;
Configuration configuration = null;
if(null == sf || sf.isClosed()){
configuration = new Configuration().configure(hibernateCfgFileName);
InstanceLevelSecurityHelper.getFiltersForGroups(authorizationManager);
sf = configuration.buildSessionFactory();
}
List<FilterDefinition> filterList=InstanceLevelSecurityHelper.getFiltersForGroups(authorizationManager);
sf.close();
for (Object filter:filterList)
{ try {
printObject(filter, false);
} catch (Exception e) {
// TODO: handle exception
}
}
assertEquals("GetFiltersForGroups Method successful",2, filterList.size());
}
示例4: newConfiguration
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
@Override
protected Configuration newConfiguration() throws HibernateException {
return new Configuration() {
@Override
public void addFilterDefinition(FilterDefinition definition) {
registeredFilterDefinitions.add(definition);
}
};
}
示例5: getFilterParameterType
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
public Type getFilterParameterType(String filterParameterName) {
errorIfClosed();
checkTransactionSynchStatus();
String[] parsed = parseFilterParameterName(filterParameterName);
FilterDefinition filterDef = factory.getFilterDefinition( parsed[0] );
if (filterDef == null) {
throw new IllegalArgumentException("Filter [" + parsed[0] + "] not defined");
}
Type type = filterDef.getParameterType( parsed[1] );
if (type == null) {
// this is an internal error of some sort...
throw new InternalError("Unable to locate type for filter parameter");
}
return type;
}
示例6: getFilterDefinition
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
FilterDefinition def = ( FilterDefinition ) filters.get( filterName );
if ( def == null ) {
throw new HibernateException( "No such filter configured [" + filterName + "]" );
}
return def;
}
示例7: addFiltersForGroups
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
/**
* This method injects the security filters which are created for this application. It retrieves a list of all the filters which have
* been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object.
* It then retrieves the Persistent Class from the passed Configuration Object using the class name for which the filter is defined.
* It then adds the filter to the persistent class by setting the filtering query.
* @param authorizationManager The CSM AuthorizationManager instance for this application
* @param configuration The Hibernate Configuration initialized for this application
*
*/
public static void addFiltersForGroups(AuthorizationManager authorizationManager,Configuration configuration)
{
boolean needsOptimisation = false;
Properties props = configuration.getProperties();
if(!isExistActiveMappingElement(authorizationManager))
needsOptimisation = isMySQLDatabase(props,true);
FilterClause searchFilterClause = new FilterClause();
searchFilterClause.setClassName("*");
SearchCriteria searchCriteria = new FilterClauseSearchCriteria(searchFilterClause);
List list = authorizationManager.getObjects(searchCriteria);
Iterator iterator = list.iterator();
while (iterator.hasNext())
{
HashMap parameters = new HashMap();
parameters.put("GROUP_NAMES", new StringType());
parameters.put("APPLICATION_ID", new LongType());
FilterClause filterClause = (FilterClause)iterator.next();
FilterDefinition filterDefinition = new FilterDefinition (
filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(), "", parameters);
configuration.addFilterDefinition(filterDefinition);
PersistentClass persistentClass = configuration.getClassMapping(filterClause.getClassName());
persistentClass.addFilter(
filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId()
, optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForGroup()));
}
}
示例8: getFiltersForGroups
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
/**
* This method injects the security filters which are created for this application. It retrieves a list of all the filters which have
* been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object.
*
* @param authorizationManager The CSM AuthorizationManager instance for this application
* @param List<FilterDefinition> The Hibernate FilterDefinition List.
*/
public static List<FilterDefinition> getFiltersForGroups(AuthorizationManager authorizationManager) throws CSException
{
Properties props = new Properties();
ApplicationContext ac = authorizationManager.getApplicationContext();
props.setProperty("hibernate.connection.url", ac.getDatabaseURL());
props.setProperty("hibernate.connection.username", ac.getDatabaseUserName());
props.setProperty("hibernate.connection.password", ac.getDatabasePassword());
props.setProperty("hibernate.connection.driver", ac.getDatabaseDriver());
props.setProperty("hibernate.dialect", ac.getDatabaseDialect());
boolean needsOptimisation = false;
if(!isExistActiveMappingElement(authorizationManager))
needsOptimisation = isMySQLDatabase(props,false);
List<FilterDefinition> filterDefinitionList = new ArrayList<FilterDefinition>();
FilterClause searchFilterClause = new FilterClause();
searchFilterClause.setClassName("*");
SearchCriteria searchCriteria = new FilterClauseSearchCriteria(searchFilterClause);
List list = authorizationManager.getObjects(searchCriteria);
Iterator iterator = list.iterator();
while (iterator.hasNext())
{
HashMap parameters = new HashMap();
parameters.put("GROUP_NAMES", new StringType());
parameters.put("APPLICATION_ID", new LongType());
FilterClause filterClause = (FilterClause)iterator.next();
FilterDefinition filterDefinition = new FilterDefinition (
filterClause.getClassName().substring(
filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(),
optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForGroup()),
parameters);
if(filterDefinition!=null) filterDefinitionList.add(filterDefinition);
}
return filterDefinitionList;
}
示例9: addFilters
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
/**
* This method injects the security filters which are created for this application. It retrieves a list of all the filters which have
* been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object.
* It then retrieves the Persistent Class from the passed Configuration Object using the class name for which the filter is defined.
* It then adds the filter to the persistent class by setting the filtering query.
* @param authorizationManager The CSM AuthorizationManager instance for this application
* @param configuration The Hibernate Configuration initialized for this application
*/
public static void addFilters(AuthorizationManager authorizationManager,Configuration configuration)
{
boolean needsOptimisation = false;
Properties props = configuration.getProperties();
if(!isExistActiveMappingElement(authorizationManager))
needsOptimisation = isMySQLDatabase(props,true);
FilterClause searchFilterClause = new FilterClause();
searchFilterClause.setClassName("*");
SearchCriteria searchCriteria = new FilterClauseSearchCriteria(searchFilterClause);
List list = authorizationManager.getObjects(searchCriteria);
Iterator iterator = list.iterator();
while (iterator.hasNext())
{
HashMap parameters = new HashMap();
parameters.put("USER_NAME", new StringType());
parameters.put("APPLICATION_ID", new LongType());
FilterClause filterClause = (FilterClause)iterator.next();
FilterDefinition filterDefinition = new FilterDefinition (filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(), "", parameters);
configuration.addFilterDefinition(filterDefinition);
PersistentClass persistentClass = configuration.getClassMapping(filterClause.getClassName());
persistentClass.addFilter(
filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId()
,optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForUser()));
}
}
示例10: getFiltersForUser
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
/**
* This method injects the security filters which are created for this application. It retrieves a list of all the filters which have
* been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object.
*
*
* @param authorizationManager The CSM AuthorizationManager instance for this application
* @param List<FilterDefinition> The Hibernate FilterDefinition List.
*/
public static List<FilterDefinition> getFiltersForUser(AuthorizationManager authorizationManager) throws CSException
{
Properties props = new Properties();
ApplicationContext ac = authorizationManager.getApplicationContext();
props.setProperty("hibernate.connection.url", ac.getDatabaseURL());
props.setProperty("hibernate.connection.username", ac.getDatabaseUserName());
props.setProperty("hibernate.connection.password", ac.getDatabasePassword());
props.setProperty("hibernate.connection.driver", ac.getDatabaseDriver());
props.setProperty("hibernate.dialect", ac.getDatabaseDialect());
boolean needsOptimisation = false;
if(!isExistActiveMappingElement(authorizationManager))
needsOptimisation = isMySQLDatabase(props,false);
List<FilterDefinition> filterDefinitionList = new ArrayList<FilterDefinition>();
FilterClause searchFilterClause = new FilterClause();
searchFilterClause.setClassName("*");
SearchCriteria searchCriteria = new FilterClauseSearchCriteria(searchFilterClause);
List list = authorizationManager.getObjects(searchCriteria);
Iterator iterator = list.iterator();
while (iterator.hasNext())
{
HashMap parameters = new HashMap();
parameters.put("USER_NAME", new StringType());
parameters.put("APPLICATION_ID", new LongType());
FilterClause filterClause = (FilterClause)iterator.next();
FilterDefinition filterDefinition = new FilterDefinition (
filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(),
optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForUser()),
parameters);
if(filterDefinition!=null) filterDefinitionList.add(filterDefinition);
}
return filterDefinitionList;
}
示例11: addFiltersForGroups
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
/**
* This method injects the security filters which are created for this application. It retrieves a list of all the filters which have
* been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object.
* It then retrieves the Persistent Class from the passed Configuration Object using the class name for which the filter is defined.
* It then adds the filter to the persistent class by setting the filtering query.
* @param authorizationManager The CSM AuthorizationManager instance for this application
* @param configuration The Hibernate Configuration initialized for this application
*
*/
public static void addFiltersForGroups(AuthorizationManager authorizationManager,Configuration configuration)
{
boolean needsOptimisation = false;
Properties props = configuration.getProperties();
//If using InstanceLevel Query Performance Enhancements of 4.2, then no need to optimize query for MySQL Db.
if(!isExistActiveMappingElement(authorizationManager))
needsOptimisation = isMySQLDatabase(props,true);
// Inject CSM Filters for Group
List list = retriveAllCsmFilterClause(authorizationManager);
Iterator iterator = list.iterator();
while (iterator.hasNext())
{
HashMap parameters = new HashMap();
parameters.put("GROUP_NAMES", new StringType());
parameters.put("APPLICATION_ID", new LongType());
FilterClause filterClause = (FilterClause)iterator.next();
FilterDefinition filterDefinition = new FilterDefinition (
filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(), "", parameters);
configuration.addFilterDefinition(filterDefinition);
PersistentClass persistentClass = configuration.getClassMapping(filterClause.getClassName());
persistentClass.addFilter(
filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId()
, optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForGroup()));
}
}
示例12: getFiltersForGroups
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
/**
* This method injects the security filters which are created for this application. It retrieves a list of all the filters which have
* been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object.
*
* @param authorizationManager The CSM AuthorizationManager instance for this application
* @param List<FilterDefinition> The Hibernate FilterDefinition List.
*/
public static List<FilterDefinition> getFiltersForGroups(AuthorizationManager authorizationManager) throws CSException
{
Properties props = new Properties();
ApplicationContext ac = authorizationManager.getApplicationContext();
props.setProperty("hibernate.connection.url", ac.getDatabaseURL());
props.setProperty("hibernate.connection.username", ac.getDatabaseUserName());
props.setProperty("hibernate.connection.password", ac.getDatabasePassword());
props.setProperty("hibernate.connection.driver", ac.getDatabaseDriver());
props.setProperty("hibernate.dialect", ac.getDatabaseDialect());
boolean needsOptimisation = false;
if(!isExistActiveMappingElement(authorizationManager))
needsOptimisation = isMySQLDatabase(props,false);
List<FilterDefinition> filterDefinitionList = new ArrayList<FilterDefinition>();
List list = retriveAllCsmFilterClause(authorizationManager);
Iterator iterator = list.iterator();
while (iterator.hasNext())
{
HashMap parameters = new HashMap();
parameters.put("GROUP_NAMES", new StringType());
parameters.put("APPLICATION_ID", new LongType());
FilterClause filterClause = (FilterClause)iterator.next();
FilterDefinition filterDefinition = new FilterDefinition (
filterClause.getClassName().substring(
filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(),
optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForGroup()),
parameters);
if(filterDefinition!=null) filterDefinitionList.add(filterDefinition);
}
return filterDefinitionList;
}
示例13: addFilters
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
/**
* This method injects the security filters which are created for this application. It retrieves a list of all the filters which have
* been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object.
* It then retrieves the Persistent Class from the passed Configuration Object using the class name for which the filter is defined.
* It then adds the filter to the persistent class by setting the filtering query.
* @param authorizationManager The CSM AuthorizationManager instance for this application
* @param configuration The Hibernate Configuration initialized for this application
*/
public static void addFilters(AuthorizationManager authorizationManager,Configuration configuration)
{
boolean needsOptimisation = false;
Properties props = configuration.getProperties();
if(!isExistActiveMappingElement(authorizationManager))
needsOptimisation = isMySQLDatabase(props,true);
// Inject CSM defined Filters
List list = retriveAllCsmFilterClause(authorizationManager);
Iterator iterator = list.iterator();
while (iterator.hasNext())
{
HashMap parameters = new HashMap();
parameters.put("USER_NAME", new StringType());
parameters.put("APPLICATION_ID", new LongType());
FilterClause filterClause = (FilterClause)iterator.next();
FilterDefinition filterDefinition = new FilterDefinition (filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(), "", parameters);
configuration.addFilterDefinition(filterDefinition);
PersistentClass persistentClass = configuration.getClassMapping(filterClause.getClassName());
persistentClass.addFilter(
filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId()
,optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForUser()));
}
}
示例14: getFiltersForUser
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
/**
* This method injects the security filters which are created for this application. It retrieves a list of all the filters which have
* been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object.
*
*
* @param authorizationManager The CSM AuthorizationManager instance for this application
* @param List<FilterDefinition> The Hibernate FilterDefinition List.
*/
public static List<FilterDefinition> getFiltersForUser(AuthorizationManager authorizationManager) throws CSException
{
Properties props = new Properties();
ApplicationContext ac = authorizationManager.getApplicationContext();
props.setProperty("hibernate.connection.url", ac.getDatabaseURL());
props.setProperty("hibernate.connection.username", ac.getDatabaseUserName());
props.setProperty("hibernate.connection.password", ac.getDatabasePassword());
props.setProperty("hibernate.connection.driver", ac.getDatabaseDriver());
props.setProperty("hibernate.dialect", ac.getDatabaseDialect());
boolean needsOptimisation = false;
if(!isExistActiveMappingElement(authorizationManager))
needsOptimisation = isMySQLDatabase(props,false);
List<FilterDefinition> filterDefinitionList = new ArrayList<FilterDefinition>();
List list = retriveAllCsmFilterClause(authorizationManager);
Iterator iterator = list.iterator();
while (iterator.hasNext())
{
HashMap parameters = new HashMap();
parameters.put("USER_NAME", new StringType());
parameters.put("APPLICATION_ID", new LongType());
FilterClause filterClause = (FilterClause)iterator.next();
FilterDefinition filterDefinition = new FilterDefinition (
filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(),
optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForUser()),
parameters);
if(filterDefinition!=null) filterDefinitionList.add(filterDefinition);
}
return filterDefinitionList;
}
示例15: disableFilters
import org.hibernate.engine.FilterDefinition; //导入依赖的package包/类
private void disableFilters(Session session) {
Set<String> filters = session.getSessionFactory().getDefinedFilterNames();
for (String filterName : filters) {
// we only want to disable the security filters. assume security filters are ones
// with GROUP_NAMES and APPLICATION_ID parameters
FilterDefinition fd = session.getSessionFactory().getFilterDefinition(filterName);
if (fd.getParameterNames().contains("GROUP_NAMES") && fd.getParameterNames().contains("APPLICATION_ID")) {
session.disableFilter(filterName);
}
}
}