public static void NHibernateConfiguration(TestContext context)
        {
            log4net.Config.XmlConfigurator.Configure();

            Configuration = new Configuration();
            // lendo o arquivo hibernate.cfg.xml
            Configuration.Configure();

            FilterDefinition filterDef = new FilterDefinition(
                "Empresa","EMPRESA = :EMPRESA",
                new Dictionary<string, IType>() {{"EMPRESA", NHibernateUtil.Int32}}, false);
            Configuration.AddFilterDefinition(filterDef);
            filterDef = new FilterDefinition(
                "Ativa", "ATIVO = 'Y'",
                new Dictionary<string, IType>(), false);
            Configuration.AddFilterDefinition(filterDef);

            // Mapeamento por código
            var mapper = new ModelMapper();
            mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
            HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
            Configuration.AddMapping(mapping);

            // Gerar o XML a partir do mapeamento de codigo.
            //var mappingXMl = mapping.AsString();

            // Mapeamento por arquivo, in resource.
            Configuration.AddAssembly(Assembly.GetExecutingAssembly());

            // Gerando o SessionFactory
            SessionFactory = Configuration.BuildSessionFactory();
        }
        public Configuration GetConfiguration()
        {
            var config = new Configuration();

            string configName = "WebNHibernate.config".ToAbsolute();

            config.Configure(configName);

            var filterDef = new FilterDefinition(
                cultureFilter,
                null, // or your default condition
                new Dictionary<string, IType> {{"cultureId", NHibernateUtil.String}},
                false);
            config.AddFilterDefinition(filterDef);

            HbmMapping mapping = NHibernateMappingRepository.GetMappings();
            config.AddDeserializedMapping(mapping, "NHSchemaTest");

            SchemaMetadataUpdater.QuoteTableAndColumns(config);

            return config;
        }
        /// <summary>
        /// Initializes the filter definitions.
        /// </summary>
        public void AfterPropertiesSet()
        {
#if NH_2_1
            this.filterDefinition = new FilterDefinition(this.filterName, this.defaultFilterCondition, this.parameterTypeMap, true);
#else
            this.filterDefinition = new FilterDefinition(this.filterName, this.defaultFilterCondition, this.parameterTypeMap);
#endif
        }
		public void AddFilterDefinition(FilterDefinition definition)
		{
			FilterDefinition fd;
			if (filterDefinitions.TryGetValue(definition.FilterName, out fd))
			{
				if(fd!=null)
				{
					throw new MappingException("Duplicated filter-def named: " + definition.FilterName);
				}
			}
			filterDefinitions[definition.FilterName] = definition;
		}
Example #5
0
		public FilterImpl(FilterDefinition configuration)
		{
			definition = configuration;
		}
Example #6
0
		public void AfterDeserialize(FilterDefinition factoryDefinition)
		{
			definition = factoryDefinition;
		}
Example #7
0
 public void AddFilterDefinition(FilterDefinition definition);
		public void AddFilterDefinition(FilterDefinition definition)
		{
			filterDefinitions.Add(definition.FilterName, definition);
		}
 /// <summary>
 /// Initializes the filter definitions.
 /// </summary>
 public void AfterPropertiesSet()
 {
     this.filterDefinition = new FilterDefinition(this.filterName, this.defaultFilterCondition, this.parameterTypeMap, true);
 }
		private void InitializeFilters (Configuration cfg) {

			var filterDef = new FilterDefinition (
				"contextFilter",
				null, // or your default condition
				new Dictionary<string, IType> { { "current", NHibernateUtil.Int32 } },
				false);

			cfg.AddFilterDefinition (filterDef);
		
		
		}
		public FilterImpl(FilterDefinition configuration)
		{
			this.definition = configuration;
			filterName = definition.FilterName;
		}
		private static void ParseFilterDef(XmlNode element, Mappings mappings)
		{
			string name = GetPropertyName(element);
			log.Debug("Parsing filter-def [" + name + "]");
			string defaultCondition = element.InnerText;
			if (defaultCondition == null || StringHelper.IsEmpty(defaultCondition.Trim()))
			{
				if (element.Attributes != null)
				{
					XmlAttribute propertyNameNode = element.Attributes["condition"];
					defaultCondition = (propertyNameNode == null) ? null : propertyNameNode.Value;
				}
			}
			Hashtable paramMappings = new Hashtable();
			foreach (XmlNode param in element.SelectNodes(HbmConstants.nsFilterParam, nsmgr))
			{
				string paramName = GetPropertyName(param);
				string paramType = param.Attributes["type"].Value;
				log.Debug("adding filter parameter : " + paramName + " -> " + paramType);
				IType heuristicType = TypeFactory.HeuristicType(paramType);
				log.Debug("parameter heuristic type : " + heuristicType);
				paramMappings.Add(paramName, heuristicType);
			}
			log.Debug("Parsed filter-def [" + name + "]");
			FilterDefinition def = new FilterDefinition(name, defaultCondition, paramMappings);
			mappings.AddFilterDefinition(def);
		}