コード例 #1
0
ファイル: UserDAO.java プロジェクト: app-ad/Baatna-server
  public boolean editProfilePic(int userId, String profilePic) {

    Session session = null;
    try {
      session = DBUtil.getSessionFactory().openSession();

      Transaction transaction = session.beginTransaction();
      String sql =
          "UPDATE USER SET PROFILE_PIC = :profilePic, MODIFIED = :modified   WHERE USERID = :user_id";
      SQLQuery query = session.createSQLQuery(sql);
      query.addEntity(User.class);
      query.setParameter("profilePic", profilePic);
      query.setParameter("user_id", userId);
      query.setParameter("modified", System.currentTimeMillis());
      int result = query.executeUpdate();

      User user = getUserDetails(userId);
      user.setModified(System.currentTimeMillis());

      transaction.commit();
      session.close();

    } catch (HibernateException e) {
      System.out.println(e.getMessage());
      e.printStackTrace();

      System.out.println("error");
      return false;
    } finally {
      if (session != null && session.isOpen()) session.close();
    }

    return true;
  }
コード例 #2
0
ファイル: UserDAO.java プロジェクト: app-ad/Baatna-server
  public boolean verifyUserEmail(User user, boolean isVerified) {

    Session session = null;
    try {
      session = DBUtil.getSessionFactory().openSession();

      Transaction transaction = session.beginTransaction();
      user.setIsVerified(isVerified ? 1 : 0);

      session.save(user);
      transaction.commit();
      session.close();

    } catch (HibernateException e) {
      System.out.println(e.getMessage());
      e.printStackTrace();

      System.out.println("error");
      return false;
    } finally {
      if (session != null && session.isOpen()) session.close();
    }

    return true;
  }
コード例 #3
0
ファイル: UserDAO.java プロジェクト: app-ad/Baatna-server
  public boolean updateInstitution(
      String institutionName,
      String studentId,
      int userId,
      int isInstitutionVerified,
      String branchName,
      int year,
      String phoneNumber) {

    Session session = null;

    try {

      session = DBUtil.getSessionFactory().openSession();

      Transaction transaction = session.beginTransaction();

      String sql = "SELECT * FROM USER WHERE USERID = :userId";
      SQLQuery query = session.createSQLQuery(sql);
      query.addEntity(User.class);
      query.setParameter("userId", userId);
      java.util.List results = (java.util.List) query.list();

      User currentSession = (User) results.get(0);
      currentSession.setInstitutionName(institutionName);
      currentSession.setStudentId(studentId);
      currentSession.setPhoneNumber(phoneNumber);
      currentSession.setYear(year);
      currentSession.setBranchName(branchName);
      currentSession.setIsInstitutionVerified(isInstitutionVerified);
      currentSession.setModified(System.currentTimeMillis());
      session.update(currentSession);
      transaction.commit();
      session.close();
      return true;
    } catch (HibernateException e) {
      System.out.println(e.getMessage());
      System.out.println("error");
      e.printStackTrace();

    } finally {
      if (session != null && session.isOpen()) session.close();
    }

    return false;
  }
コード例 #4
0
ファイル: UserDAO.java プロジェクト: app-ad/Baatna-server
  public boolean editUserDetails(
      int userId,
      String userName,
      String passWord,
      String email,
      String address,
      String phone,
      String bio) {

    Session session = null;
    try {
      session = DBUtil.getSessionFactory().openSession();

      Transaction transaction = session.beginTransaction();
      User user = getUserDetails(userId);

      user.setUserName(userName);
      user.setPassWord(passWord);
      user.setEmail(email);
      user.setPhone(phone);
      user.setAddress(address);
      user.setBio(bio);
      user.setModified(System.currentTimeMillis());

      session.save(user);
      transaction.commit();
      session.close();

    } catch (HibernateException e) {
      System.out.println(e.getMessage());
      e.printStackTrace();

      System.out.println("error");
      return false;
    } finally {
      if (session != null && session.isOpen()) session.close();
    }

    return true;
  }
コード例 #5
0
ファイル: UserDAO.java プロジェクト: app-ad/Baatna-server
  public ArrayList<com.application.baatna.bean.Session> getUsersNotEquals(int userId) {

    ArrayList<com.application.baatna.bean.Session> users = null;

    Session session = null;
    User user;
    boolean shouldAdd = true;
    UserDAO dao = new UserDAO();
    User currentUser = new User();
    currentUser = dao.getUserDetails(userId);
    try {

      session = DBUtil.getSessionFactory().openSession();
      Transaction transaction = session.beginTransaction();
      users = new ArrayList<com.application.baatna.bean.Session>();

      com.application.baatna.bean.Session userSession = dao.getAllSessions(userId).get(0);
      StringBuilder sql = new StringBuilder();
      sql.append("Select * from SESSION");
      boolean locationEnabled = false;
      if (userSession != null
          && userSession.getLocation() != null
          && userSession.getLocation().getLatitude() != 0
          && userSession.getLocation().getLatitude() != 0) {
        locationEnabled = true;
        sql.append(" order by");
        sql.append(
            " 3956 * 2 * ASIN(SQRT(POWER(SIN((:latitude - SESSION.LATITUDE) * pi()/180 / 2), 2) + COS(:latitude * pi()/180) * COS(SESSION.LATITUDE * pi()/180) * POWER(SIN((:longitude - SESSION.LONGITUDE) * pi()/180 / 2), 2)))");
      }
      sql.append(" limit 500");
      SQLQuery query = session.createSQLQuery(sql.toString());
      query.addEntity(com.application.baatna.bean.Session.class);
      if (locationEnabled) {
        query.setParameter("latitude", userSession.getLocation().getLatitude());
        query.setParameter("longitude", userSession.getLocation().getLongitude());
      }
      java.util.List results2 = (java.util.List) query.list();

      for (Iterator iterator = ((java.util.List) results2).iterator(); iterator.hasNext(); ) {
        com.application.baatna.bean.Session currentSesion =
            (com.application.baatna.bean.Session) iterator.next();
        if (CommonLib.isFacebookCheckValid) {
          // get the current user.
          String userSql = "Select * from USER Where USERID = :user_id";
          SQLQuery userQuery = session.createSQLQuery(userSql.toString());
          userQuery.addEntity(User.class);
          userQuery.setParameter("user", userSession.getUserId());
          java.util.List userResults = (java.util.List) userQuery.list();

          if (userResults != null && !userResults.isEmpty()) {
            user = (User) userResults.get(0);
            if (user != null) {
              shouldAdd =
                  Friends.isFriendOnFacebook(
                      user.getFacebookId(), currentUser.getFacebookId(), user.getFacebookToken());
            }
          }
        }
        if (shouldAdd) {
          users.add(currentSesion);
        }

        // users.add(currentSesion);
      }

      transaction.commit();
      session.close();

    } catch (HibernateException e) {
      System.out.println(e.getMessage());
      System.out.println("error");
    } finally {
      if (session != null && session.isOpen()) session.close();
    }
    return users;
  }
コード例 #6
0
ファイル: UserDAO.java プロジェクト: app-ad/Baatna-server
  /** Add user details to the DB for a newly signed up user. Updates User and Session tables. */
  public User addUserDetails(
      String profilePic,
      String userName,
      String passWord,
      String email,
      String address,
      String phone,
      String bio,
      String fbId,
      String fbData,
      String fbToken,
      String fbPermissions) {
    User user;
    Session session = null;
    try {
      session = DBUtil.getSessionFactory().openSession();

      Transaction transaction = session.beginTransaction();
      user = new User();
      user.setUserName(userName);
      user.setPassWord(passWord);
      user.setEmail(email);
      user.setPhone(phone);
      user.setAddress(address);
      user.setProfilePic(profilePic);
      user.setBio(bio);
      user.setFacebookId(fbId);
      user.setFacebookData(fbData);
      user.setFacebookToken(fbToken);
      user.setFbPermission(fbPermissions);
      user.setTimestamp(System.currentTimeMillis());
      user.setModified(0);
      session.save(user);

      transaction.commit();
      session.close();

    } catch (HibernateException e) {
      System.out.println(e.getMessage());
      e.printStackTrace();
      user = null;
      System.out.println("error");
    } finally {
      if (session != null && session.isOpen()) session.close();
    }

    return user;
  }