Beispiel #1
0
        public void Dispose()
        {
            importRepo.Dispose();
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["PrismDatabase"];

            HibernateUtil.Initialize(settings.ConnectionString, false);
        }
Beispiel #2
0
 public FirstSetupRepo()
 {
     this.session             = HibernateUtil.OpenSession(false);
     this.userRepo            = new UserRepository(session);
     this.projectRepo         = new ProjectRepository(session);
     this.certificateTypeRepo = new InspectorCertificateTypeRepository(session);
     this.seemTypeRepo        = new SeamTypeRepository(session);
     this.permissionRepo      = new PermissionRepository(session);
     this.roleRepo            = new RoleRepository(session);
     this.categoryRepo        = new CategoryRepository(session);
     this.jointOperationRepo  = new JointOperationRepository(session);
     this.pipeTestsRepo       = new PipeTestRepository(session);
     this.sizeTypeRepo        = new MillPipeSizeTypeRepository(session);
     this.plateManRepo        = new PlateManufacturerRepository(session);
     this.heatRepo            = new HeatRepository(session);
     this.plateRepo           = new PlateRepository(session);
     this.purchaseRepo        = new PurchaseOrderRepository(session);
     this.railRepo            = new RailcarRepository(session);
     this.pipeRepo            = new PipeRepository(session);
     this.inspectorRepo       = new InspectorRepository(session);
     this.pipeTestResultRepo  = new PipeTestResultRepository(session);
     this.welderRepo          = new WelderRepository(session);
     componentTypeRepo        = new ComponentTypeRepository(session);
     componentRepo            = new ComponentRepository(session);
     releaseRepo            = new ReleaseNoteRepository(session);
     this.cannedMessageRepo = new CannedMessageRepository(session);
 }
Beispiel #3
0
        public IList GetByHQL(string hql, ArrayList lists)
        {
            try
            {
                ISession session = HibernateUtil.OpenSession();
                IQuery   query   = session.CreateQuery(hql);

                for (int i = 0; i < lists.Count; i++)
                {
                    query.SetParameter(i, lists[i]);
                }

                return(query.List());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                HibernateUtil.CloseSession();
            }

            return(null);
        }
Beispiel #4
0
 public TEntity GetById(int id)
 {
     using (var session = HibernateUtil.SessionFactory(connectionString).OpenSession())
     {
         return(session.Get <TEntity>(id));
     }
 }
Beispiel #5
0
 public List <TEntity> GetAll()
 {
     using (var session = HibernateUtil.SessionFactory(connectionString).OpenSession())
     {
         return(session.Query <TEntity>().ToList());
     }
 }
Beispiel #6
0
        public IEnumerable <ServidorAtivo> ListaServidoresAtivos()
        {
            using (var s = HibernateUtil.GetSessionFactory().OpenSession())
            {
                var sql = new StringBuilder();


                sql.AppendLine(
                    "SELECT [Nome],[categoriaDescricao][Categoria],[Matricula],[cargoDescricao][CargoEfetivo],")
                .AppendLine("[cargoComissaoDescricao][CargoEmComissao],[LotacaoAtual],[admissao] [Nomeacao],")
                .AppendLine("[posse][Exercicio],[AprovadoNoEstagio] [Estavel] FROM [organizador].[dbo].[vwPessoa]")
                .AppendLine("  where vinculo = 1 and categoria in(1,2,3,4)");

                var query = s.CreateSQLQuery(sql.ToString());


                query.AddScalar("Nome", NHibernateUtil.String)
                .AddScalar("Categoria", NHibernateUtil.String)
                .AddScalar("Matricula", NHibernateUtil.String)
                .AddScalar("CargoEfetivo", NHibernateUtil.String)
                .AddScalar("CargoEmComissao", NHibernateUtil.String)
                .AddScalar("LotacaoAtual", NHibernateUtil.String)
                .AddScalar("Nomeacao", NHibernateUtil.DateTime)
                .AddScalar("Exercicio", NHibernateUtil.DateTime)
                .AddScalar("Estavel", NHibernateUtil.String)

                .SetResultTransformer(Transformers.AliasToBean(typeof(ServidorAtivo)));

                return(query.List <ServidorAtivo>() as List <ServidorAtivo>);
            }
        }
Beispiel #7
0
 public IList <Employee> GetEmployeesByName(string name)
 {
     using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
     {
         return(s.Query <Employee>().Where(e => e.Name.Contains(name)).ToList());
     }
 }
Beispiel #8
0
 public IList <TEntity> GetAll()
 {
     using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
     {
         return(s.Query <TEntity>().ToList());
     }
 }
Beispiel #9
0
 public TEntity GetById(Guid id)
 {
     using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
     {
         return(s.Get <TEntity>(id));
     }
 }
 public int QttyOfDependentsForEachEmployee(Guid id)
 {
     using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
     {
         return(s.Query <Dependent>().Where(d => d.Employee.Id == id).Count());
     }
 }
 /// <summary>
 /// Implementação do método genérico para listar todas as informaçõed de uma consulta específica do banco
 /// </summary>
 /// <param name="id">Identificador do registro</param>
 /// <returns></returns>
 public T ObterPorId(K id)
 {
     using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
     {
         return(ObterPorId(s, id));
     }
 }
 /// <summary>
 /// Implementação do método genérico para listar todos as informações de uma consulta do banco
 /// </summary>
 public ICollection <T> ListarTodos()
 {
     using (ISession sessao = HibernateUtil.GetSessionFactory().OpenSession())
     {
         return(ListarTodos(sessao));
     }
 }
 public T Find(int Id)
 {
     using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
     {
         return((T)s.Get(typeof(T), Id));
     }
 }
Beispiel #14
0
        public IEnumerable <AntiguidadeDefensor> ListaAntiguidadeDefensores()
        {
            using (var s = HibernateUtil.GetSessionFactory().OpenSession())
            {
                var query = s.CreateSQLQuery(
                    "SELECT [IdQuadroCargo],[Ocupado],[Ordem],[IdCargo],[InicioCargo],[SiglaCargo],[DescricaoCargo],[NomeDefensor],[DataPosse],[DataUltimaPromocao],[TotalDiasEstado],[TotalDiasPublico],[TotalDiasAposentado] FROM [" +
                    DbSci + "].[SITE].[VW_CONSULTA_ANTIGUIDADE_DEFENSOR] ORDER BY IdCargo, Ordem");


                query.AddScalar("IdQuadroCargo", NHibernateUtil.Int32)
                .AddScalar("Ocupado", NHibernateUtil.Int32)
                .AddScalar("Ordem", NHibernateUtil.Int32)
                .AddScalar("IdCargo", NHibernateUtil.Int32)
                .AddScalar("InicioCargo", NHibernateUtil.DateTime)
                .AddScalar("SiglaCargo", NHibernateUtil.String)
                .AddScalar("DescricaoCargo", NHibernateUtil.String)
                .AddScalar("NomeDefensor", NHibernateUtil.String)
                .AddScalar("DataPosse", NHibernateUtil.DateTime)
                .AddScalar("DataUltimaPromocao", NHibernateUtil.DateTime)
                .AddScalar("TotalDiasEstado", NHibernateUtil.Int32)
                .AddScalar("TotalDiasPublico", NHibernateUtil.Int32)
                .AddScalar("TotalDiasAposentado", NHibernateUtil.Int32)
                .SetResultTransformer(Transformers.AliasToBean(typeof(AntiguidadeDefensor)));

                return(query.List <AntiguidadeDefensor>() as List <AntiguidadeDefensor>);
            }
        }
 public List <TarefaDto> FindAll(DateTime DataIni, DateTime DataFim, int IdUsuario)
 {
     using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
     {
         var query = from t in s.Query <Tarefa>()
                     where t.DataHoraInicio >= DataIni &&
                     t.DataHoraInicio <= DataFim &&
                     t.Usuario.IdUsuario == IdUsuario
                     orderby t.DataHoraInicio ascending
                     select t;
         List <TarefaDto> lista = new List <TarefaDto>();
         foreach (var t in query.ToList())
         {
             lista.Add(
                 new TarefaDto()
             {
                 Codigo         = t.IdTarefa,
                 Titulo         = t.Titulo,
                 Descricao      = t.Descricao,
                 DataHoraInicio = t.DataHoraInicio,
                 DataHoraFim    = t.DataHoraFim,
                 Categoria      = t.Categoria.Nome,
                 Usuario        = t.Usuario.Nome
             }
                 );
         }
         return(lista);
     }
 }
Beispiel #16
0
        public DataImporter(IImportRepository importRepo, IHasher hasher, IEncryptor encryptor)
            : base(hasher, encryptor)
        {
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["PrismDatabase"];

            HibernateUtil.Initialize(settings.ConnectionString, true);
            this.importRepo = Program.Kernel.Get <IImportRepository>();
        }
Beispiel #17
0
 public ActionResult Index()
 {
     using (ISession session = HibernateUtil.OpenSession())
     {
         ViewData["employees"] = session.QueryOver <Employee>().List();
     }
     return(View("Home"));
 }
Beispiel #18
0
        public IQuery BuildQuery(string queryst, object[] parameters, ISession session, bool native = false, string queryAlias = null)
        {
            var result = HibernateUtil.TranslateQueryString(queryst, parameters);

            queryst    = result.query;
            parameters = result.Parameters;

            var query = native ? session.CreateSQLQuery(queryst) : session.CreateQuery(queryst);

            if (!native)
            {
                query.SetFlushMode(FlushMode.Never);
            }
            query.SetTimeout(MetadataProvider.GlobalProperties.QueryTimeout());
            LogQuery(queryst, queryAlias, parameters);
            if (result.Parameters == null)
            {
                return(query);
            }
            for (var i = 0; i < result.Parameters.Length; i++)
            {
                if (queryst.Contains(":p" + i))
                {
                    if (parameters[i] == null)
                    {
                        query.SetParameter("p" + i, parameters[i], NHibernateUtil.String);
                    }
                    else
                    {
                        var asEnumerable = parameters[i] as IEnumerable;
                        if (asEnumerable != null)
                        {
                            query.SetParameterList("p" + i, (IEnumerable)parameters[i]);
                        }
                        else
                        {
                            query.SetParameter("p" + i, parameters[i]);
                        }
                    }
                }
                else
                {
                    if (parameters[i] != null)
                    {
                        if (parameters[i] is Int32)
                        {
                            query.SetParameter(i, parameters[i], new Int32Type());
                        }
                        else
                        {
                            query.SetParameter(i, parameters[i]);
                        }
                    }
                }
            }

            return(query);
        }
Beispiel #19
0
 public void Insert(TEntity obj)
 {
     using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
     {
         ITransaction t = s.BeginTransaction();
         s.Save(obj);
         t.Commit();
     }
 }
Beispiel #20
0
 public void Remove(TEntity obj)
 {
     using (var session = HibernateUtil.SessionFactory(connectionString).OpenSession())
     {
         var transaction = session.BeginTransaction();
         session.Delete(obj);
         transaction.Commit();
     }
 }
        public Guid GetRoleIdByType(string roleType)
        {
            using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
            {
                var result = s.Query <Role>().SingleOrDefault(r => r.RoleType == roleType);

                return(result.Id);
            }
        }
Beispiel #22
0
 public void Delete(Produto p)
 {    //Não é necessario dar new pois o objeto é statico
     using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
     {
         ITransaction t = s.BeginTransaction();
         s.Delete(p);
         t.Commit();
     }
 }
 public void Update(T obj)
 {
     using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
     {
         ITransaction t = s.BeginTransaction();
         s.Update(obj);
         t.Commit();
     }
 }
 /// <summary>
 /// Implementação do método genérico para alteração de informações de um objeto em banco
 /// </summary>
 /// <param name="obj">Modelo a ser alterado</param>
 public void Alterar(T obj)
 {
     using (ISession sessao = HibernateUtil.GetSessionFactory().OpenSession())
     {
         ITransaction transacao = sessao.BeginTransaction();
         Alterar(sessao, obj);
         transacao.Commit();
     }
 }
Beispiel #25
0
 public Produto FindById(int IdProduto)
 {
     using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
     {
         var query = from p in s.Query <Produto>()
                     where p.IdProduto == IdProduto
                     select p;
         return(query.FirstOrDefault());
     }
 }
Beispiel #26
0
        public List <Produto> FindAll()
        {
            using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
            {
                var query = from p in s.Query <Produto>()
                            select p;

                return(query.ToList());
            }
        }
 public ICollection <T> FindAll()
 {
     using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
     {
         //LINQ - Language Integrated Query
         var query = from obj in s.Query <T>()
                     select obj;
         //retornar os dados...
         return(query.ToList());
     }
 }
Beispiel #28
0
        public Estoque ObterPorIdComposto(int IdProd, int IdFreezer)
        {
            using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
            {
                var query = s.Query <Estoque>()
                            .Where(p => p.Produto.Id == IdProd && p.Freezer.Id == IdFreezer)
                            .FirstOrDefault();

                return(query);
            }
        }
Beispiel #29
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            HibernateUtil.Init();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Beispiel #30
0
 public bool HasLogin(string Login)
 {
     using (ISession s = HibernateUtil.GetSessionFactory().OpenSession())
     {
         //SQL -> select count(*) from Usuario where Login = ?
         var query = from u in s.Query <Usuario>()
                     where u.Login.Equals(Login)
                     select u;
         //retornar a quantidade obtida...
         return(query.Count() > 0);
     }
 }
Beispiel #31
0
 internal static IDA0 GetInstance(string configFileName)
 {
     HibernateUtil util = null;
     try
     {
         if (LoggingService.IsDebugEnabled)
         {
             LoggingService.DebugFormatted("将获得配置文件为'{0}.cfg.xml'DAO对象", new object[] { configFileName });
         }
         util = new HibernateUtil(configFileName);
     }
     catch (Exception exception)
     {
         LoggingService.Error("Cannot create dao : " + configFileName + "\r\n", exception);
         throw exception;
     }
     return util;
 }