List of usage examples for com.vaadin.server VaadinSession getCurrent
public static VaadinSession getCurrent()
From source file:com.etest.dao.CellItemDAO.java
public static boolean approveCellItem(int cellItemId) { Connection conn = DBConnection.connectToDB(); PreparedStatement pstmt = null; boolean result = false; try {/*from w ww . j a va 2s . c om*/ conn.setAutoCommit(false); pstmt = conn .prepareStatement("UPDATE cell_items SET " + "ApproveStatus = ? " + "WHERE CellItemID = ? "); pstmt.setInt(1, 1); pstmt.setInt(2, cellItemId); pstmt.executeUpdate(); pstmt = conn.prepareStatement("INSERT INTO item_log SET " + "CellItemID = ?, " + "UserID = ?, " + "Remarks = ?, " + "DateRemarked = now(), " + "ActionDone = ? "); pstmt.setInt(1, cellItemId); pstmt.setInt(2, CommonUtilities .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString())); pstmt.setString(3, "approved cell item"); pstmt.setString(4, "approved"); 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, "Approved cell item with CellItemID #" + cellItemId); pstmt.executeUpdate(); conn.commit(); result = true; } catch (SQLException ex) { try { conn.rollback(); } catch (SQLException ex1) { ErrorDBNotification.showLoggedErrorOnWindow(ex1.toString()); Logger.getLogger(CellItemDAO.class.getName()).log(Level.SEVERE, null, ex1); } ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(CellItemDAO.class.getName()).log(Level.SEVERE, null, ex); } finally { try { pstmt.close(); conn.close(); } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(CellItemDAO.class.getName()).log(Level.SEVERE, null, ex); } } return result; }
From source file:com.etest.dao.CellItemDAO.java
public static boolean removeCellItem(int cellItemId) { Connection conn = DBConnection.connectToDB(); PreparedStatement pstmt = null; Statement stmt = null;/* w ww . j ava 2s.com*/ boolean result = false; try { System.out.println("cell item id: " + cellItemId); conn.setAutoCommit(false); if (!isCellItemIDInItemLog(cellItemId)) { pstmt = conn.prepareStatement("INSERT INTO item_log SET " + "CellItemID = ?, " + "UserID = ?, " + "Remarks = ?, " + "DateRemarked = now(), " + "ActionDone = ? "); pstmt.setInt(1, cellItemId); pstmt.setInt(2, CommonUtilities .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString())); pstmt.setString(3, "insert new item"); pstmt.setString(4, "insert"); pstmt.executeUpdate(); } pstmt = conn.prepareStatement("INSERT INTO cell_items_archive(CellItemID, CellCaseID, BloomsClassID, " + "Item, OptionA, OptionB, OptionC, OptionD, ApproveStatus, DifficultIndex, DiscriminationIndex, " + "AuthoredBy_UserID, DateCreated, CellItemStatus, Analyzed) " + "SELECT ci.* FROM cell_items ci WHERE CellItemID = " + cellItemId + " "); pstmt.executeUpdate(); pstmt = conn.prepareStatement("INSERT INTO item_log SET " + "CellItemID = ?, " + "UserID = ?, " + "Remarks = ?, " + "DateRemarked = now(), " + "ActionDone = ? "); pstmt.setInt(1, cellItemId); pstmt.setInt(2, CommonUtilities .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString())); pstmt.setString(3, "archive cell item"); pstmt.setString(4, "archive"); pstmt.executeUpdate(); pstmt = conn.prepareStatement("INSERT INTO item_log SET " + "CellItemID = ?, " + "UserID = ?, " + "Remarks = ?, " + "DateRemarked = now(), " + "ActionDone = ? "); pstmt.setInt(1, cellItemId); pstmt.setInt(2, CommonUtilities .convertStringToInt(VaadinSession.getCurrent().getAttribute("userId").toString())); pstmt.setString(3, "delete cell item"); pstmt.setString(4, "delete"); pstmt.executeUpdate(); stmt = conn.createStatement(); stmt.addBatch("SET FOREIGN_KEY_CHECKS = 0"); stmt.addBatch("DELETE FROM cell_items WHERE CellItemID = " + cellItemId + " "); stmt.addBatch("SET FOREIGN_KEY_CHECKS = 1"); stmt.executeBatch(); 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 cell item with CellItemID #" + cellItemId); pstmt.executeUpdate(); conn.commit(); result = true; } catch (SQLException ex) { try { conn.rollback(); } catch (SQLException ex1) { ErrorDBNotification.showLoggedErrorOnWindow(ex1.toString()); Logger.getLogger(CellItemDAO.class.getName()).log(Level.SEVERE, null, ex1); } ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(CellItemDAO.class.getName()).log(Level.SEVERE, null, ex); } finally { try { pstmt.close(); conn.close(); } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(CellItemDAO.class.getName()).log(Level.SEVERE, null, ex); } } return result; }
From source file:com.etest.dao.CurriculumDAO.java
public static boolean insertNewCurriculum(Curriculum curriculum) { Connection conn = DBConnection.connectToDB(); PreparedStatement pstmt = null; boolean result = false; try {//from ww w .j a v a 2 s . c o m pstmt = conn.prepareStatement("INSERT INTO curriculum " + "SET YearLevel = ?, " + "CurrSubject = ?, " + "DescriptiveTitle = ?, " + "NormCourseOffering = ?"); pstmt.setInt(1, curriculum.getYearLevel()); pstmt.setString(2, curriculum.getSubject()); pstmt.setString(3, curriculum.getDescriptiveTitle()); pstmt.setInt(4, curriculum.getNormCourseOffering()); 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, "Created new curriculum " + curriculum.getSubject()); pstmt.executeUpdate(); result = true; } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(CurriculumDAO.class.getName()).log(Level.SEVERE, null, ex); } finally { try { pstmt.close(); conn.close(); } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(CurriculumDAO.class.getName()).log(Level.SEVERE, null, ex); } } return result; }
From source file:com.etest.dao.CurriculumDAO.java
public static boolean updateCurriculum(Curriculum curriculum) { Connection conn = DBConnection.connectToDB(); PreparedStatement pstmt = null; boolean result = false; try {/* w ww . j a va 2 s. c om*/ pstmt = conn.prepareStatement("UPDATE curriculum " + "SET YearLevel = ?, " + "CurrSubject = ?, " + "DescriptiveTitle = ?, " + "NormCourseOffering = ? " + "WHERE CurriculumID = ? "); pstmt.setInt(1, curriculum.getYearLevel()); pstmt.setString(2, curriculum.getSubject()); pstmt.setString(3, curriculum.getDescriptiveTitle()); pstmt.setInt(4, curriculum.getNormCourseOffering()); pstmt.setInt(5, curriculum.getCurriculumId()); 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 Curriculum with CurriculumID #" + curriculum.getCurriculumId()); pstmt.executeUpdate(); result = true; } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(CurriculumDAO.class.getName()).log(Level.SEVERE, null, ex); } finally { try { pstmt.close(); conn.close(); } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(CurriculumDAO.class.getName()).log(Level.SEVERE, null, ex); } } return result; }
From source file:com.etest.dao.CurriculumDAO.java
public static boolean removeCurriculum(int curriculumId) { Connection conn = DBConnection.connectToDB(); PreparedStatement pstmt = null; boolean result = false; try {//from w w w . j a v a 2 s .c om pstmt = conn.prepareStatement( "UPDATE curriculum " + "SET CurriculumStatus = ? " + "WHERE CurriculumID = ? "); pstmt.setInt(1, 1); pstmt.setInt(2, curriculumId); 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 Curriculum with CurriculumID #" + curriculumId); pstmt.executeUpdate(); result = true; } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(CurriculumDAO.class.getName()).log(Level.SEVERE, null, ex); } finally { try { pstmt.close(); conn.close(); } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(CurriculumDAO.class.getName()).log(Level.SEVERE, null, ex); } } return result; }
From source file:com.etest.dao.FacultyDAO.java
public static boolean insertNewFaculty(Users users) { Connection conn = DBConnection.connectToDB(); PreparedStatement pstmt = null; Statement stmt = null;// w w w . j a v a2 s .co m ResultSet rs = null; boolean result = false; try { conn.setAutoCommit(false); pstmt = conn.prepareStatement( "INSERT INTO faculty SET " + "Firstname = ?, " + "Middlename = ?, " + "Lastname = ? "); pstmt.setString(1, users.getFirstname()); pstmt.setString(2, users.getMiddlename()); pstmt.setString(3, users.getLastname()); pstmt.executeUpdate(); int facultyId = 0; stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT last_insert_id() AS id FROM faculty "); while (rs.next()) { facultyId = CommonUtilities.convertStringToInt(rs.getString("id")); } pstmt = conn.prepareStatement("INSERT INTO users SET " + "FacultyID = ?, " + "Username_ = ?, " + "Password_ = ?, " + "UserType = ? "); pstmt.setInt(1, facultyId); pstmt.setString(2, users.getUsername_()); pstmt.setString(3, users.getPassword_()); pstmt.setString(4, users.getUserType()); 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 Faculty account was added. " + users.getFirstname() + " " + users.getMiddlename() + " " + users.getLastname()); pstmt.executeUpdate(); conn.commit(); result = true; } catch (SQLException ex) { try { conn.rollback(); } catch (SQLException ex1) { ErrorDBNotification.showLoggedErrorOnWindow(ex1.toString()); Logger.getLogger(FacultyDAO.class.getName()).log(Level.SEVERE, null, ex1); } ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(FacultyDAO.class.getName()).log(Level.SEVERE, null, ex); } return result; }
From source file:com.etest.dao.FacultyDAO.java
public static boolean updateFaculty(Users users) { Connection conn = DBConnection.connectToDB(); PreparedStatement pstmt = null; boolean result = false; try {/*from ww w . ja v a2 s . c om*/ conn.setAutoCommit(false); pstmt = conn.prepareStatement("UPDATE faculty SET " + "Firstname = ?, " + "Middlename = ?, " + "Lastname = ? " + "WHERE FacultyID = ?"); pstmt.setString(1, users.getFirstname()); pstmt.setString(2, users.getMiddlename()); pstmt.setString(3, users.getLastname()); pstmt.setInt(4, users.getFacultyId()); pstmt.executeUpdate(); pstmt = conn.prepareStatement("UPDATE users SET " + "Username_ = ?, " + "Password_ = ?, " + "UserType = ? " + "WHERE FacultyID = ? "); pstmt.setString(1, users.getUsername_()); pstmt.setString(2, users.getPassword_()); pstmt.setInt(3, users.getFacultyId()); pstmt.setString(4, users.getUserType()); 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 faculty account with FacultyID #" + users.getFacultyId()); pstmt.executeUpdate(); conn.commit(); result = true; } catch (SQLException ex) { try { conn.rollback(); } catch (SQLException ex1) { ErrorDBNotification.showLoggedErrorOnWindow(ex1.toString()); Logger.getLogger(FacultyDAO.class.getName()).log(Level.SEVERE, null, ex1); } ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(FacultyDAO.class.getName()).log(Level.SEVERE, null, ex); } return result; }
From source file:com.etest.dao.FacultyDAO.java
public static boolean removeFaculty(int facultyId) { Connection conn = DBConnection.connectToDB(); PreparedStatement pstmt = null; boolean result = false; try {// w w w . ja v a 2 s.com pstmt = conn.prepareStatement("UPDATE faculty SET " + "FacultyStatus = ? " + "WHERE FacultyID = ?"); pstmt.setInt(1, 1); 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, "Removed Faculty with FacultyID #" + facultyId); pstmt.executeUpdate(); result = true; } catch (SQLException ex) { ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(FacultyDAO.class.getName()).log(Level.SEVERE, null, ex); } return result; }
From source file:com.etest.dao.FacultyDAO.java
public static boolean updateFacultyColumnValue(String column, String value, int facultyId) { Connection conn = DBConnection.connectToDB(); PreparedStatement pstmt = null; boolean result = false; try {/*w w w .j ava 2 s .com*/ conn.setAutoCommit(false); pstmt = conn.prepareStatement("UPDATE faculty SET " + "" + column + " = ? " + "WHERE FacultyID = ?"); pstmt.setString(1, value.toLowerCase()); 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, "Update Faculty account with FacultyID #" + facultyId); pstmt.executeUpdate(); conn.commit(); result = true; } catch (SQLException ex) { try { conn.rollback(); } catch (SQLException ex1) { ErrorDBNotification.showLoggedErrorOnWindow(ex1.toString()); Logger.getLogger(FacultyDAO.class.getName()).log(Level.SEVERE, null, ex1); } ErrorDBNotification.showLoggedErrorOnWindow(ex.toString()); Logger.getLogger(FacultyDAO.class.getName()).log(Level.SEVERE, null, ex); } return result; }
From source file:com.etest.dao.ItemKeyDAO.java
public static boolean addItemKey(int cellItemId, String itemKey, String answer) { Connection conn = DBConnection.connectToDB(); PreparedStatement pstmt = null; boolean result = false; try {//from ww w . jav a2 s.com conn.setAutoCommit(false); pstmt = conn.prepareStatement( "INSERT INTO item_keys SET " + "CellItemID = ?, " + "ItemKey = ?, " + "Answer = ? "); pstmt.setInt(1, cellItemId); pstmt.setString(2, itemKey); pstmt.setString(3, answer); 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 Item Key was added with CellItemID #" + cellItemId + " Key value: " + itemKey); 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; }