Package org.hibernate

Examples of org.hibernate.Criteria


    @PostConstruct
    public void retrieveAllMembersOrderedByName() {

        // using Hibernate Session and Criteria Query via Hibernate Native API
        Session session = (Session) em.getDelegate();
        Criteria cb = session.createCriteria(Member.class);
        cb.addOrder(Order.asc("name"));
        members = (List<Member>) cb.list();

    }
View Full Code Here


    @SuppressWarnings("unchecked")
    public List<Member> findAllOrderedByName() {
        // using Hibernate Session and Criteria Query via Hibernate Native API
        Session session = (Session) em.getDelegate();
        Criteria cb = session.createCriteria(Member.class);
        cb.addOrder(Order.asc("name"));
        return (List<Member>) cb.list();
        // return members;
    }
View Full Code Here

    Session session = null;
    RightsGroup group = null;
    try {
      sessionFactory = HibernateSessionFactory.getInstance();
      session = sessionFactory.openSession();
      Criteria c = session.createCriteria(RightsGroup.class);
      c.add(Restrictions.eq("groupName", groupName));
      List<RightsGroup> lstRights = c.list();
      if(lstRights != null && lstRights.size() > 0) {
        group = lstRights.get(0);
      }
    } catch (Exception a_th) {
      throw new RuntimeException(a_th);
View Full Code Here

    Session session = null;
    RightsGroup group = null;
    try {
      sessionFactory = HibernateSessionFactory.getInstance();
      session = sessionFactory.openSession();
      Criteria c = session.createCriteria(RightsGroup.class);
      c.add(Restrictions.idEq(groupID));
      List<RightsGroup> lstRights = c.list();
      if(lstRights != null && lstRights.size() > 0) {
        group = lstRights.get(0);
      }
    } catch (Exception a_th) {
      throw new RuntimeException(a_th);
View Full Code Here

    Session session = null;
    BaseRight baseRight = null;
    try {
      sessionFactory = HibernateSessionFactory.getInstance();
      session = sessionFactory.openSession();
      Criteria c = session.createCriteria(BaseRight.class);
      c.add(Restrictions.idEq(baseRightID));
      List<BaseRight> lstRights = c.list();
      if(lstRights != null && lstRights.size() > 0) {
        baseRight = lstRights.get(0);
      }
    } catch (Exception a_th) {
      throw new RuntimeException(a_th);
View Full Code Here

    SessionFactory sessionFactory = null;
    Session session = null;
    try {
      sessionFactory = HibernateSessionFactory.getInstance();
      session = sessionFactory.openSession();
      Criteria c = session.createCriteria(AssignedRightsGroup.class);
      if(resource != null) {
        c.add(Restrictions.eq("resourceTypeID", resource.getResourceTypeID()))
      }
     
      if(group != null) {
        c.add(Restrictions.eq("rightGroup", group));
      }
     
      return c.list();
    } catch (Exception a_th) {
      throw new RuntimeException(a_th);
    } finally {
      close(sessionFactory, session);
    }
View Full Code Here

    SessionFactory sessionFactory = null;
    Session session = null;
    try {
      sessionFactory = HibernateSessionFactory.getInstance();
      session = sessionFactory.openSession();
      Criteria criteria = session.createCriteria(Permission.class);
      if(right != null) {
        criteria.add(Restrictions.eq("right", right));
      }
      if(resource != null) {
        DefaultPermisibleResource defaultResource = new DefaultPermisibleResource(resource);
        criteria.add(Restrictions.eq("resource", defaultResource));
      }
      if(entity != null) {
        DefaultPermissionEntity defaultEntity = new DefaultPermissionEntity(entity);
        criteria.add(Restrictions.eq("entity", defaultEntity));
      }
      return criteria.list();   
    } catch (Exception a_th) {
      throw new RuntimeException(a_th);
    } finally {
      close(sessionFactory, session);
    }
View Full Code Here

    if ( entityInfo.idName.equals( hibernateIdentifierProperty ) ) {
      //be sure to get an initialized object but save from ONFE and ENFE
      maybeProxy = session.load( entityInfo.clazz, entityInfo.id );
    }
    else {
      Criteria criteria = session.createCriteria( entityInfo.clazz );
      criteria.add( Restrictions.eq( entityInfo.idName, entityInfo.id ) );
      try {
        maybeProxy = criteria.uniqueResult();
      }
      catch ( HibernateException e ) {
        throw new SearchException(
            "Loading entity of type " + entityInfo.clazz.getName() + " using '"
                + entityInfo.idName
View Full Code Here

      System.out.println("ProjectManagerImpl.getAllProjects()  " + user.getUserType());

      sessionFactory = HibernateSessionFactory.getInstance();
      session = sessionFactory.openSession();

      Criteria criteria = session.createCriteria(BOProject.class);
      // List<BOProject> toProjectList = new ArrayList<BOProject>();

      if (projectStatus != null) {
        criteria.add(Restrictions.eq("projectStatus", projectStatus));
      }

      // List<BOProject> fromProjectList = criteria.list();
      /*
       * if(true) { return fromProjectList; }
       */
      if (user.getUserType() == UserType.Administrator || user.getUserType() == UserType.CEO) {
        System.out.println("ProjectManagerImpl.getAllProjects() Administrator ");
        // toProjectList = fromProjectList;
      } else {
        System.out.println("ProjectManagerImpl.getAllProjects() Others ");

        String departmentsOwned = getAllDepartmentsAndChildDepartmentsForUserAsString(new StringBuilder(), user.getDepartmentsOwned(), 0);

        // criteria.add(Restrictions.sqlRestriction(
        // "select * from projects p where p.project_owner = ? or p.project_id in( select t.task_project  from tasks t, user_tasks ut  where ut.task_id = t.task_id and ( t.task_owner = ? or ut.user_id = ? ))"
        // , 2, Hibernate.LONG));

        String restriction = "(" + "  project_owner = " + user.getUserID() + " " + "  or project_company in " + "  ( " + "    select company.company_id " + "    from companies company "
            + "    where company.company_owner = " + user.getUserID() + " " + "  ) ";

        if (!departmentsOwned.trim().equals("")) {
          restriction += "  or project_id in " + "  ( " + "    select pdept.project_id " + "    from project_departments pdept, departments dept " + "    where pdept.department_id = dept.dept_id "
              + "    and pdept.department_id in ( " + departmentsOwned + ") " + "  ) ";
        }

        restriction += "  or project_id in " + "  ( " + "    select t.task_project" + "    from tasks t, user_tasks ut  " + "    where ut.task_id = t.task_id " + "    and " + "    ("
            + "      t.task_owner = " + user.getUserID() + " " + "      or ut.user_id = " + user.getUserID() + " " + ")" + "  )" + ")";

        criteria.add(Restrictions.sqlRestriction(restriction));
        // fillRelevantProjects(fromProjectList, toProjectList, user,
        // projectStatus);
      }

      System.out.println("ProjectManagerImpl.getAllProjects() ended ");
      return criteria.list();
      // return toProjectList;

    } catch (Exception a_th) {
      throw new RuntimeException(a_th);
    } finally {
View Full Code Here

    Session session = null;
    try {
      sessionFactory = HibernateSessionFactory.getInstance();
      session = sessionFactory.openSession();

      Criteria criteria = session.createCriteria(BOCustomField.class);
      criteria.add(Restrictions.ilike("customFieldModule", "tasks"));
      criteria.add(Restrictions.ilike("customFieldName", "Module"));
      BOCustomField.CustomTaskModule = (BOCustomField) criteria.list().get(0);
    } catch (Exception a_th) {
      throw new RuntimeException(a_th);
    } finally {
      close(sessionFactory, session);
    }
View Full Code Here

TOP

Related Classes of org.hibernate.Criteria

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.