/** Creates a Pooled connection and adds it to the connection pool. */ private void installConnection() throws EmanagerDatabaseException { logger.debug("enter"); PooledConnection connection; try { connection = poolDataSource.getPooledConnection(); connection.addConnectionEventListener(this); connection.getConnection().setAutoCommit(false); synchronized (connectionPool) { connectionPool.add(connection); logger.debug("Database connection added."); } } catch (SQLException ex) { logger.fatal("exception caught while obtaining database " + "connection: ex = " + ex); SQLException ex1 = ex.getNextException(); while (ex1 != null) { logger.fatal("chained sql exception ex1 = " + ex1); SQLException nextEx = ex1.getNextException(); ex1 = nextEx; } String logString; EmanagerDatabaseException ede; logString = EmanagerDatabaseStatusCode.DatabaseConnectionFailure.getStatusCodeDescription() + ex.getMessage(); logger.fatal(logString); ede = new EmanagerDatabaseException( EmanagerDatabaseStatusCode.DatabaseConnectionFailure, logString); throw ede; } }
private boolean AidedIn(SaoWorker w) { BatSQL bSQL = new BatSQL(); boolean success = false; String id = w.getUserID(); String q = "select * from aidedin where USERID='" + id + "'"; ResultSet rs = bSQL.query(q); try { boolean more = rs.next(); if (more) { success = true; } } //end of try catch (SQLException ex) { System.out.println("!*******SQLException caught*******!"); while (ex != null) { System.out.println ("SQLState: " + ex.getSQLState ()); System.out.println ("Message: " + ex.getMessage ()); System.out.println ("Vendor: " + ex.getErrorCode ()); ex = ex.getNextException (); System.out.println (""); } System.exit(0); } //end catching SQLExceptions catch (java.lang.Exception ex) { System.out.println("!*******Exception caught*******!"); System.exit(0); } //end catching other Exceptions bSQL.disconnect(); return success; } //end of AidedIn?
/** * Finds out if an aide is covering for another aide * and makes an entry to the AIDELOG to note that * coverage has ended. * * @param The SaoWorker who might be covering */ public void Covering(final SaoWorker w) { BatSQL bSQL = new BatSQL(); String qc = "select * from AIDEDIN where USERID='" + w.getUserID() + "'"; ResultSet rs = bSQL.query(qc); String cid = new String(); try { rs.next(); cid = rs.getString(2); } catch (SQLException ex) { System.out.println("!*******SQLException caught*******!"); System.out.println("Covering"); while (ex != null) { System.out.println ("SQLState: " + ex.getSQLState ()); System.out.println ("Message: " + ex.getMessage ()); System.out.println ("Vendor: " + ex.getErrorCode ()); ex = ex.getNextException (); System.out.println (""); } System.exit(0); } //end catching SQLExceptions catch (java.lang.Exception ex) { System.out.println("!*******Exception caught*******!"); System.out.println("Covering"); System.exit(0); } //end catching other Exceptions if (!cid.equals("No")) //then covering { String uc = "insert into AIDELOG values ('C', '" + cid + "', \"" + bd.getDate() + "\", " + bd.getStringHours() + bd.getStringMinutes() + ", 'O')"; bSQL.update(uc); } bSQL.disconnect(); } //end of Covering
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); ResultSet rs = null; try { // SET UP Context environment, to look for Data Pooling Resource Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); DataSource ds = (DataSource) envCtx.lookup("jdbc/TestDB"); Connection dbcon = ds.getConnection(); // ########### SEARCH INPUT PARAMETERS, EXECUTE search // ##################################################### Vector<String> params = new Vector<String>(); params.add(request.getParameter("fname")); params.add(request.getParameter("lname")); params.add(request.getParameter("title")); params.add(request.getParameter("year")); params.add(request.getParameter("director")); List<Movie> movies = new ArrayList<Movie>(); movies = SQLServices.getMovies(params.toArray(new String[params.size()]), dbcon); // ########## SET DEFAULT SESSION() PARAMETERS #################################### request.getSession().removeAttribute("movies"); request.getSession().removeAttribute("linkedListMovies"); request.getSession().removeAttribute("hasPaged"); request.getSession().setAttribute("hasPaged", "no"); request.getSession().setAttribute("movies", movies); request.getSession().setAttribute("currentIndex", "0"); request.getSession().setAttribute("defaultN", "5"); // ########## IF MOVIES FROM SEARCH NON-EMPTY ########################################### List<String> fields = Movie.fieldNames(); int count = 1; if (!movies.isEmpty()) { request.setAttribute("movies", movies); for (String field : fields) { request.setAttribute("f" + count++, field); } request.getRequestDispatcher("../movieList.jsp").forward(request, response); } else { out.println("<html><head><title>error</title></head>"); out.println("<body><h1>could not find any movies, try your search again.</h1>"); out.println("<p> we are terribly sorry, please go back. </p>"); out.println("<table border>"); out.println("</table>"); } dbcon.close(); } catch (SQLException ex) { while (ex != null) { System.out.println("SQL Exception: " + ex.getMessage()); ex = ex.getNextException(); } } catch (java.lang.Exception ex) { out.println( "<html>" + "<head><title>" + "moviedb: error" + "</title></head>\n<body>" + "<p>SQL error in doGet: " + ex.getMessage() + "</p></body></html>"); return; } out.close(); }
/** * Handles when aides cover each other. They must tell * us who they're covering so that that poor person * doesn't get a missed shift. This of course means i * have to work on MyHours some more... If they select * a valid userid to cover for makes the appropriate * entry in AIDELOG. * * @param An SaoWorker who is covering someone else */ public void WhoRUCovering(final SaoWorker w) { int i = 0; int h = bd.getHours(); int m = bd.getMinutes(); if (((m >= 20) && (m < 30)) || ((m >= 50) && (m < 60))) { if (m < 30) { m = m + 10; } else { m = m + 10 - 60; h = h + 1; } } int dopp = bd.getDoPP(); if (dopp > 7) { dopp = dopp - 7; } String slotid = bd.getSlot(h, m, dopp); String q = "select * from AIDESCHED where " + slotid + "=1"; final String[] userids = {"", "", "", "", "", "", "", "", "", ""}; final BatSQL bSQL = new BatSQL(); ResultSet rs = bSQL.query(q); try { boolean more = rs.next(); if (more) //because there might be only one person for this slot { while (more) { userids[i] = rs.getString(1); i++; more = rs.next(); } } //end of if more } //end of try catch (SQLException ex) { System.out.println("!*******SQLException caught*******!"); System.out.println("WhoRUCovering"); while (ex != null) { System.out.println ("SQLState: " + ex.getSQLState ()); System.out.println ("Message: " + ex.getMessage ()); System.out.println ("Vendor: " + ex.getErrorCode ()); ex = ex.getNextException (); System.out.println (""); } System.exit(0); } //end catching SQLExceptions catch (java.lang.Exception ex) { System.out.println("!*******Exception caught*******!"); System.out.println("WhoRUCovering"); System.exit(0); } //end catching other Exceptions final Frame coverF = new Frame("Covering?"); final Panel p = new Panel(); final Panel btnP = new Panel(); final List coverL = new List(); Button ok = new Button("Cover"); Button nok = new Button("Cancel"); final int i2 = i; ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String id = coverL.getSelectedItem(); BatSQL bS = new BatSQL(); String a = "insert into aidelog values ('C', \"" + id + "\", \"" + bd.getDate() + "\", " + bd.getStringHours() + bd.getStringMinutes() + ", 'I')"; bS.update(a); a = "update AIDEDIN set COVERING='" + id + "' where USERID='" + w.getUserID() + "'"; bS.update(a); bS.disconnect(); coverF.dispose(); } }); nok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { coverF.dispose(); } }); btnP.setLayout(new FlowLayout()); btnP.add(ok); btnP.add(nok); p.setLayout(new BorderLayout()); p.add(new Label("Who are you covering for?"), BorderLayout.NORTH); int j; for (j = 0; j <= i; j++) { coverL.add(userids[j]); } p.add(coverL, BorderLayout.CENTER); p.add(btnP, BorderLayout.SOUTH); coverL.select(0); coverF.setLayout(new FlowLayout()); coverF.add(p); coverF.pack(); coverF.setLocation(200, 200); coverF.show(); } //end of WhoRUCovering
/** * Finds out if a SaoWorker is supposed to be working now * or not. It consults the tables AIDESCHED for this, and * if they have a entry in the current slot then they're * okay. Otherwise they're covering for somebody.<P> * * Also, if it's 10 minutes before a new slot starts this * looks at the next slot. This is to accomodate for the * fact that sometimes aides will try to Aide In a few * minutes before they're supposed to start working.<P> * * What's more, if the SaoWorker trying to AIDE IN is a * Supervisor or Programmer, the method considers them * always scheduled. How convenient! * * @param w The Aide trying to aide in * @return True scheduled for this slot, or False not */ public boolean Scheduled(SaoWorker w) { BatSQL bSQL = new BatSQL(); String q = "select * from AIDESCHED where USERID='" + w.getUserID() + "'"; ResultSet rs = bSQL.query(q); int h = bd.getHours(); int m = bd.getMinutes(); int slot = 0; int sched = 0; //first check if the worker is a Supervisor or Programmer //these two Titles are always Scheduled to work. if ((w.getTitle().equals("Supervisor")) || (w.getTitle().equals("Programmer"))) { sched = 1; } else { //aides have to be in the correct slot //this is the part where we check if they're early if (((m >= 20) && (m < 30)) || ((m >= 50) && (m < 60))) { if (m > 30) { h = h + 1; m = m + 10 - 60; } else { m = m + 10; } int dopp = bd.getDoPP(); if (dopp > 7) { dopp = dopp - 7; } slot = bd.getIntSlot(h, m, dopp); } else { int dopp = bd.getDoPP(); if (dopp > 7) { dopp = dopp - 7; } slot = bd.getIntSlot(h, m, dopp); } //now we carry on as usual try { rs.next(); sched = rs.getInt(slot+1); //+1 to skip the USERID field! } //end of try catch (SQLException ex) { System.out.println("!*******SQLException caught*******!"); System.out.println("Scheduled"); while (ex != null) { System.out.println ("SQLState: " + ex.getSQLState ()); System.out.println ("Message: " + ex.getMessage ()); System.out.println ("Vendor: " + ex.getErrorCode ()); ex = ex.getNextException (); System.out.println (""); } System.exit(0); } //end catching SQLExceptions catch (java.lang.Exception ex) { System.out.println("!*******Exception caught*******!"); System.out.println("Scheduled"); System.exit(0); } //end catching other Exceptions } //end of else this is an aide boolean scheded = (sched == 1); return scheded; } //end of Scheduled?