Example usage for com.vaadin.server VaadinSession getCurrent

List of usage examples for com.vaadin.server VaadinSession getCurrent

Introduction

In this page you can find the example usage for com.vaadin.server VaadinSession getCurrent.

Prototype

public static VaadinSession getCurrent() 

Source Link

Document

Gets the currently used session.

Usage

From source file:com.etest.dao.ItemKeyDAO.java

public static boolean modifyItemOption(int cellItemId, String optionColumn, String optionValue,
        boolean isOptionKeyExist, int itemKeyId) {
    Connection conn = DBConnection.connectToDB();
    PreparedStatement pstmt = null;
    boolean result = false;

    try {//w  w  w .  j av  a2s .  c o m
        conn.setAutoCommit(false);
        pstmt = conn.prepareStatement("UPDATE cell_items SET " + "" + optionColumn + " = '"
                + optionValue.replace("'", "\\'") + "' " + "WHERE cellItemId = " + cellItemId + " ");
        pstmt.executeUpdate();

        if (isOptionKeyExist) {
            pstmt = conn.prepareStatement("UPDATE item_keys SET " + "Answer = '"
                    + optionValue.replace("'", "\\'") + "' " + "WHERE ItemKeyID = " + itemKeyId + " ");
            pstmt.executeUpdate();
        }

        pstmt = conn.prepareStatement(
                "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? ");
        pstmt.setInt(1, CommonUtilities
                .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString()));
        pstmt.setString(2, "Modified item option with CellItemID #" + cellItemId + ", " + optionColumn + ": "
                + optionValue);
        pstmt.executeUpdate();

        conn.commit();
        result = true;
    } catch (SQLException ex) {
        ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
        Logger.getLogger(ItemKeyDAO.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pstmt.close();
            conn.close();
        } catch (SQLException ex) {
            ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
            Logger.getLogger(ItemKeyDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    return result;
}

From source file:com.etest.dao.ItemKeyDAO.java

public static boolean modifyItemKey(int itemKeyId, int cellItemId, String keyValue, String answer,
        boolean isOptionKeyExist, String actionDone, String remarks) {
    Connection conn = DBConnection.connectToDB();
    PreparedStatement pstmt = null;
    boolean result = false;

    try {//from   w  w w .  j  a v a2s.  com
        conn.setAutoCommit(false);
        if (isOptionKeyExist) {
            pstmt = conn.prepareStatement("UPDATE item_keys SET " + "ItemKey = '" + keyValue.replace("'", "\\'")
                    + "' " + "WHERE ItemKeyID = " + itemKeyId + " ");
            pstmt.executeUpdate();
        } else {
            pstmt = conn.prepareStatement(
                    "INSERT item_keys SET " + "CellItemID = ?, " + "ItemKey = ?, " + "Answer = ? ");
            pstmt.setInt(1, cellItemId);
            pstmt.setString(2, keyValue);
            pstmt.setString(3, answer);
            pstmt.executeUpdate();

            remarks = "insert new item key";
            actionDone = "insert";
        }

        pstmt = conn.prepareStatement("INSERT INTO key_log SET " + "ItemKeyID = ?, " + "UserID = ?, "
                + "Remarks = ?, " + "DateRemarked = now(), " + "ActionDone = ? ");
        pstmt.setInt(1, itemKeyId);
        pstmt.setInt(2, CommonUtilities
                .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString()));
        pstmt.setString(3, remarks);
        pstmt.setString(4, actionDone);
        pstmt.executeUpdate();

        pstmt = conn.prepareStatement(
                "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? ");
        pstmt.setInt(1, CommonUtilities
                .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString()));
        pstmt.setString(2, "Modified Item Key with CellItemID #" + cellItemId + ", ItemKey: " + keyValue
                + ", answer: " + answer);
        pstmt.executeUpdate();

        conn.commit();
        result = true;
    } catch (SQLException ex) {
        try {
            conn.rollback();
        } catch (SQLException ex1) {
            ErrorDBNotification.showLoggedErrorOnWindow(ex1.toString());
            Logger.getLogger(ItemKeyDAO.class.getName()).log(Level.SEVERE, null, ex1);
        }
        ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
        Logger.getLogger(ItemKeyDAO.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pstmt.close();
            conn.close();
        } catch (SQLException ex) {
            ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
            Logger.getLogger(ItemKeyDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    return result;
}

From source file:com.etest.dao.ItemKeyDAO.java

public static boolean removeItemKey(int itemKeyId) {
    Connection conn = DBConnection.connectToDB();
    PreparedStatement pstmt = null;
    boolean result = false;

    try {/*from w ww  .j ava2  s.c  om*/
        conn.setAutoCommit(false);
        pstmt = conn.prepareStatement("DELETE FROM item_keys " + "WHERE ItemKeyID = " + itemKeyId + " ");
        pstmt.executeUpdate();

        pstmt = conn.prepareStatement("INSERT INTO key_log SET " + "ItemKeyID = ?, " + "UserID = ?, "
                + "Remarks = ?, " + "DateRemarked = now(), " + "ActionDone = ? ");
        pstmt.setInt(1, itemKeyId);
        pstmt.setInt(2, CommonUtilities
                .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString()));
        pstmt.setString(3, "delete item key");
        pstmt.setString(4, "delete");
        pstmt.executeUpdate();

        pstmt = conn.prepareStatement(
                "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? ");
        pstmt.setInt(1, CommonUtilities
                .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString()));
        pstmt.setString(2, "Removed Item Key with ItemKeyID #" + itemKeyId);
        pstmt.executeUpdate();

        conn.commit();
        result = true;
    } catch (SQLException ex) {
        try {
            conn.rollback();
        } catch (SQLException ex1) {
            ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
            Logger.getLogger(ItemKeyDAO.class.getName()).log(Level.SEVERE, null, ex1);
        }
        ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
        Logger.getLogger(ItemKeyDAO.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pstmt.close();
            conn.close();
        } catch (SQLException ex) {
            ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
            Logger.getLogger(ItemKeyDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    return result;
}

From source file:com.etest.dao.SyllabusDAO.java

public static boolean insertNewSyllabus(Syllabus s) {
    Connection conn = DBConnection.connectToDB();
    PreparedStatement pstmt = null;
    boolean result = false;

    try {/* w w w.  j a  v a 2  s . c  om*/
        pstmt = conn.prepareStatement("INSERT INTO syllabus SET " + "CurriculumID = ?, " + "TopicNo = ?, "
                + "Topic = ?, " + "EstimatedTime = ? ");
        pstmt.setInt(1, s.getCurriculumId());
        pstmt.setInt(2, s.getTopicNo());
        pstmt.setString(3, s.getTopic());
        pstmt.setFloat(4, s.getEstimatedTime());
        pstmt.executeUpdate();

        pstmt = conn.prepareStatement(
                "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? ");
        pstmt.setInt(1, CommonUtilities
                .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString()));
        pstmt.setString(2, "New Syllabus was added with CurriculumID #" + s.getCurriculumId() + ", Topic: "
                + s.getTopic());
        pstmt.executeUpdate();

        result = true;
    } catch (SQLException ex) {
        ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
        Logger.getLogger(SyllabusDAO.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pstmt.close();
            conn.close();
        } catch (SQLException ex) {
            ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
            Logger.getLogger(SyllabusDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    return result;
}

From source file:com.etest.dao.SyllabusDAO.java

public static boolean updateSyllabus(Syllabus s) {
    Connection conn = DBConnection.connectToDB();
    PreparedStatement pstmt = null;
    boolean result = false;

    try {/*  ww w.  j  a v a2s.  c  om*/
        conn.setAutoCommit(false);
        pstmt = conn.prepareStatement("UPDATE syllabus SET " + "CurriculumID = ?, " + "TopicNo = ?, "
                + "Topic = ?, " + "EstimatedTime = ? " + "WHERE SyllabusID = ? ");
        pstmt.setInt(1, s.getCurriculumId());
        pstmt.setInt(2, s.getTopicNo());
        pstmt.setString(3, s.getTopic());
        pstmt.setFloat(4, s.getEstimatedTime());
        pstmt.setInt(5, s.getSyllabusId());
        pstmt.executeUpdate();

        pstmt = conn.prepareStatement(
                "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? ");
        pstmt.setInt(1, CommonUtilities
                .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString()));
        pstmt.setString(2, "Update Syllabus Topic with SyllabusID #" + s.getTopic());
        pstmt.executeUpdate();

        conn.commit();
        result = true;
    } catch (SQLException ex) {
        ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
        Logger.getLogger(SyllabusDAO.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pstmt.close();
            conn.close();
        } catch (SQLException ex) {
            ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
            Logger.getLogger(SyllabusDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    return result;
}

From source file:com.etest.dao.SyllabusDAO.java

public static boolean removeSyllabus(int syllabusId) {
    Connection conn = DBConnection.connectToDB();
    PreparedStatement pstmt = null;
    boolean result = false;

    try {//w w w  .j a va  2 s  .c  o m
        conn.setAutoCommit(false);
        pstmt = conn.prepareStatement("DELETE FROM syllabus " + "WHERE SyllabusID = ? ");
        pstmt.setInt(1, syllabusId);
        pstmt.executeUpdate();

        pstmt = conn.prepareStatement(
                "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? ");
        pstmt.setInt(1, CommonUtilities
                .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString()));
        pstmt.setString(2, "Removed Syllabus with SyllabusID #" + syllabusId);
        pstmt.executeUpdate();

        conn.commit();
        result = true;
    } catch (SQLException ex) {
        ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
        Logger.getLogger(SyllabusDAO.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pstmt.close();
            conn.close();
        } catch (SQLException ex) {
            ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
            Logger.getLogger(SyllabusDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    return result;
}

From source file:com.etest.dao.TeamTeachDAO.java

public static boolean insertNewTeamTeachLeader(TeamTeach tt) {
    Connection conn = DBConnection.connectToDB();
    PreparedStatement pstmt = null;
    Statement stmt = null;/*from w  w  w  . j av a 2s  . co  m*/
    ResultSet rs = null;
    boolean result = false;

    try {
        conn.setAutoCommit(false);
        pstmt = conn.prepareStatement("INSERT INTO team_teach SET " + "CurriculumID = ?, " + "SchoolYear = ?, "
                + "Semester = ?, " + "UserID = ?");
        pstmt.setInt(1, tt.getCurriculumId());
        pstmt.setString(2, tt.getSchoolYear());
        pstmt.setInt(3, tt.getNormCourseOffering());
        pstmt.setInt(4, tt.getUserId());
        pstmt.executeUpdate();

        int teamTeachId = 0;
        stmt = conn.createStatement();
        rs = stmt.executeQuery("SELECT last_insert_id() AS id FROM team_teach ");
        while (rs.next()) {
            teamTeachId = CommonUtilities.convertStringToInt(rs.getString("id"));
        }

        pstmt = conn.prepareStatement("INSERT INTO team_members SET " + "TeamTeachID = ?, " + "FacultyID = ? ");
        pstmt.setInt(1, teamTeachId);
        pstmt.setInt(2, tt.getFacultyId());
        pstmt.executeUpdate();

        pstmt = conn.prepareStatement(
                "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? ");
        pstmt.setInt(1, CommonUtilities
                .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString()));
        pstmt.setString(2, "New TTL was added with FacultyID #" + tt.getFacultyId());
        pstmt.executeUpdate();

        conn.commit();
        result = true;
    } catch (SQLException ex) {
        try {
            conn.rollback();
        } catch (SQLException ex1) {
            ErrorDBNotification.showLoggedErrorOnWindow(ex1.toString());
            Logger.getLogger(TeamTeachDAO.class.getName()).log(Level.SEVERE, null, ex1);
        }
        ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
        Logger.getLogger(TeamTeachDAO.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pstmt.close();
            conn.close();
        } catch (SQLException ex) {
            ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
            Logger.getLogger(TeamTeachDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    return result;
}

From source file:com.etest.dao.TeamTeachDAO.java

public static boolean updateTeamTeachLeader(int teamTeachId, int userId) {
    Connection conn = DBConnection.connectToDB();
    PreparedStatement pstmt = null;
    boolean result = false;

    try {//from   w  ww .jav  a2 s  .c  o  m
        conn.setAutoCommit(false);
        pstmt = conn.prepareStatement("UPDATE team_teach SET " + "UserID = ? " + "WHERE TeamTeachID = ? ");
        pstmt.setInt(1, userId);
        pstmt.setInt(2, teamTeachId);
        pstmt.executeUpdate();

        pstmt = conn.prepareStatement(
                "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? ");
        pstmt.setInt(1, CommonUtilities
                .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString()));
        pstmt.setString(2, "Changed TTL with UserID #" + userId);
        pstmt.executeUpdate();

        conn.commit();
        result = true;
    } catch (SQLException ex) {
        ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
        Logger.getLogger(TeamTeachDAO.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pstmt.close();
            conn.close();
        } catch (SQLException ex) {
            ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
            Logger.getLogger(TeamTeachDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    return result;
}

From source file:com.etest.dao.TeamTeachDAO.java

public static boolean removeSemestralTeam(int teamTeachId) {
    Connection conn = DBConnection.connectToDB();
    PreparedStatement pstmt = null;
    boolean result = false;

    try {/*w w w. ja  v a2 s.  c  o m*/
        pstmt = conn.prepareStatement("DELETE FROM team_teach " + "WHERE TeamTeachID = ? ");
        pstmt.setInt(1, teamTeachId);
        pstmt.executeUpdate();

        pstmt = conn.prepareStatement(
                "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? ");
        pstmt.setInt(1, CommonUtilities
                .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString()));
        pstmt.setString(2, "removed Semestral Team with TeamTeachID #" + teamTeachId);
        pstmt.executeUpdate();

        result = true;
    } catch (SQLException ex) {
        ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
        Logger.getLogger(TeamTeachDAO.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pstmt.close();
            conn.close();
        } catch (SQLException ex) {
            ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
            Logger.getLogger(TeamTeachDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    return result;
}

From source file:com.etest.dao.TeamTeachDAO.java

public static boolean addTeamMember(int teamTeachId, int facultyId) {
    Connection conn = DBConnection.connectToDB();
    PreparedStatement pstmt = null;
    boolean result = false;

    try {/*from w  w w.  ja v  a 2s .c  o  m*/
        pstmt = conn.prepareStatement("INSERT INTO team_members SET " + "TeamTeachID = ?, " + "FacultyID = ? ");
        pstmt.setInt(1, teamTeachId);
        pstmt.setInt(2, facultyId);
        pstmt.executeUpdate();

        pstmt = conn.prepareStatement(
                "INSERT INTO system_logs SET " + "UserID = ?, " + "EntryDateTime = now(), " + "Activity = ? ");
        pstmt.setInt(1, CommonUtilities
                .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString()));
        pstmt.setString(2, "New Team Member was added with FacultyID #" + facultyId);
        pstmt.executeUpdate();

        result = true;
    } catch (SQLException ex) {
        ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
        Logger.getLogger(TeamTeachDAO.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            pstmt.close();
            conn.close();
        } catch (SQLException ex) {
            ErrorDBNotification.showLoggedErrorOnWindow(ex.toString());
            Logger.getLogger(TeamTeachDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    return result;
}