id
stringlengths
36
36
text
stringlengths
1
1.25M
67611a2e-188d-478c-ae5b-c43ef6293134
public DatabaseConnection() { // CP: Connection pooling start /* connectionPool = ConnectionPool.getInstance(); try { con =connectionPool.getConnection(); if (!con.isClosed()) System.out.println("Successfully Connected!!!"); }catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } */ // reular without connection pool try { Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/cmpe273", "root", "root"); if (!con.isClosed()) { System.out.println("Successfully Connected!!!"); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
a4ef3a6c-cf62-45b1-a6e4-9d719bb55f51
public Person[] ViewAllPersons() throws SQLException { String query; String querycount; int Count = 0; int index = 0; Person[] allpersons = null; try { query = "select * from person"; querycount = "select count(1) from person"; ps = con.prepareStatement(querycount); rs = ps.executeQuery(); if (rs.next()) { Count = rs.getInt(1); } allpersons = new Person[Count]; ps = con.prepareStatement(query); rs = ps.executeQuery(); while (rs.next()) { Person person = new Person(); person.setPersonId(rs.getLong("idperson")); person.setPassword(rs.getString("pass")); person.setFirstName(rs.getString("fname")); person.setLastName(rs.getString("lname")); person.setAddress(rs.getString("address")); person.setCity(rs.getString("city")); person.setState(rs.getString("state")); person.setZipCode(rs.getString("zipcode")); person.setPersonType(rs.getString("persontype")); allpersons[index] = person; index++; } } catch (SQLException e) { e.printStackTrace(); } finally { try { ps.close(); // connectionPool.free(con); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return allpersons; }
a7ec9af7-bf10-4fd0-a73a-7933802f77b6
public Person[] ViewAllStudents() throws SQLException { String query; String querycount; int Count = 0; int index = 0; Person[] allstudents = null; try { query = "select * from person where persontype = 'S'"; querycount = "select count(1) from person"; ps = con.prepareStatement(querycount); rs = ps.executeQuery(); if (rs.next()) { Count = rs.getInt(1); } allstudents = new Person[Count]; ps = con.prepareStatement(query); rs = ps.executeQuery(); while (rs.next()) { Person student = new Person(); student.setPersonId(rs.getLong("idperson")); student.setPassword(rs.getString("pass")); student.setFirstName(rs.getString("fname")); student.setLastName(rs.getString("lname")); student.setAddress(rs.getString("address")); student.setCity(rs.getString("city")); student.setState(rs.getString("state")); student.setZipCode(rs.getString("zipcode")); student.setPersonType(rs.getString("persontype")); allstudents[index] = student; index++; } } catch (SQLException e) { e.printStackTrace(); } finally { try { ps.close(); // connectionPool.free(con); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return allstudents; }
7f0d97cf-422d-499f-a478-60c0e37f9bef
public Instructor[] ViewAllInstructors() throws SQLException { String query, query2; String querycount; int Count = 0; int index = 0; Instructor[] allinstructor = null; try { query = "select * from person where persontype = 'I'"; querycount = "select count(1) from person"; query2 = "select * from instructor"; ps = con.prepareStatement(querycount); rs = ps.executeQuery(); if (rs.next()) { Count = rs.getInt(1); } allinstructor = new Instructor[Count]; ps = con.prepareStatement(query); rs = ps.executeQuery(); ps1 = con.prepareStatement(query2); rs1 = ps1.executeQuery(); while (rs.next()) { Instructor instructor = new Instructor(); instructor.setPersonId(rs.getLong("idperson")); instructor.setPassword(rs.getString("pass")); instructor.setFirstName(rs.getString("fname")); instructor.setLastName(rs.getString("lname")); instructor.setAddress(rs.getString("address")); instructor.setCity(rs.getString("city")); instructor.setState(rs.getString("state")); instructor.setZipCode(rs.getString("zipcode")); instructor.setPersonType(rs.getString("persontype")); if (rs1.next()) { instructor.setDepartment(rs1.getString("department")); instructor.setOffficeHr(rs1.getString("officeHr")); instructor.setLocation(rs1.getString("location")); } allinstructor[index] = instructor; index++; } } catch (SQLException e) { e.printStackTrace(); } finally { try { ps.close(); ps1.close(); // connectionPool.free(con); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return allinstructor; }
a517be38-bfca-4982-9771-896c31f63b69
public Course CourseDetail(long idcourse) throws SQLException { String query = ""; String query1 = ""; String query2 = ""; String query3 = ""; Course courseInfo = new Course(); List<Instructor> instructorInfo = new ArrayList<Instructor>(); int index = 0; long[] personid = null; try { query = "select * from course where idcourse= ?"; ps = con.prepareStatement(query); ps.setLong(1, idcourse); rs = ps.executeQuery(); if (rs.next()) { courseInfo = new Course(); courseInfo.setCourseId(rs.getInt(1)); courseInfo.setName(rs.getString(2)); courseInfo.setSection(rs.getString(3)); courseInfo.setHours(rs.getString(4)); courseInfo.setLocation(rs.getString(5)); } else { System.out.println("Course with id = " + idcourse + " does not exist."); return null; } query1 = "select idperson from personcoursemap where idcourse = ?"; query2 = "select fname, lname from person where idperson = ? and persontype='I'"; query3 = "select * from instructor where idperson= ?"; // search for the all related person to course ps1 = con.prepareStatement(query1); ps1.setLong(1, idcourse); rs1 = ps1.executeQuery(); // get the count of no of persons related to course int count = 0; while (rs1.next()) { count++; } personid = new long[count]; rs1.beforeFirst();// reset pointer on top of the list while (rs1.next()) { personid[index] = rs1.getInt(1); index++; } for (int i = 0; i < index - 1; i++) { Instructor tempInstructor = new Instructor(); // get instructor name info ps2 = con.prepareStatement(query2); ps2.setLong(1, personid[i]); rs2 = ps2.executeQuery(); if (rs2.next()) { tempInstructor.setFirstName(rs2.getString(1)); tempInstructor.setLastName(rs2.getString(2)); // get instructor official detail ps3 = con.prepareStatement(query3); ps3.setLong(1, personid[i]); rs3 = ps3.executeQuery(); if (rs3.next()) { tempInstructor.setPersonId(rs3.getLong(1)); tempInstructor.setDepartment(rs3.getString(2)); tempInstructor.setOffficeHr(rs3.getString(3)); tempInstructor.setLocation(rs3.getString(4)); } } instructorInfo.add(tempInstructor); } courseInfo.setCourseTeachers(instructorInfo .toArray(new Instructor[instructorInfo.size()])); } catch (SQLException e) { e.printStackTrace(); } finally { try { ps.close(); ps1.close(); ps2.close(); ps3.close(); // connectionPool.free(con); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return courseInfo; }
fb1a3f72-1eed-473e-a914-915b63485ab5
public Person PersonDetail(long idperson) throws SQLException { String query,query1= ""; Person personInfo = null; try { query = "select * from person where idperson= ?"; ps = con.prepareStatement(query); ps.setLong(1, idperson); rs = ps.executeQuery(); if (rs.next()) { personInfo = new Person(); personInfo.setPersonId(rs.getInt(1)); personInfo.setPassword(rs.getString(2)); personInfo.setFirstName(rs.getString(3)); personInfo.setLastName(rs.getString(4)); personInfo.setAddress(rs.getString(5)); personInfo.setCity(rs.getString(6)); personInfo.setState(rs.getString(7)); personInfo.setZipCode(rs.getString(8)); personInfo.setPersonType(rs.getString(9)); if(personInfo.getPersonType().equals("I")) { query1 = "select * from instructor where idperson= ?"; ps1 = con.prepareStatement(query1); ps1.setLong(1, idperson); rs1= ps1.executeQuery(); if(rs1.next()) { Instructor instructorinfo = new Instructor(); instructorinfo.setPersonId(rs1.getLong(1)); instructorinfo.setDepartment(rs1.getString(2)); instructorinfo.setOffficeHr(rs1.getString(3)); instructorinfo.setLocation(rs1.getString(4)); personInfo.setInstructor(instructorinfo); } else { System.out.println("Intsructor detail for Intsructor with id = " + idperson + " didn't found."); } } } else { System.out.println("Person with id = " + idperson + " does not exist."); return null; } } catch (SQLException e) { e.printStackTrace(); } finally { try { ps.close(); ps1.close(); // connectionPool.free(con); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return personInfo; }
abe6768d-e80d-4b43-abf3-7b9253918b1f
public boolean UpdatePerson(long idperson, String pass, String fname, String lname, String address, String city, String state, String zipcode, String persontype, String department, String officeHr, String location) throws SQLException { int rowcount = 0; boolean result = false; String query,query1=""; try { ps = (PreparedStatement) con .prepareStatement("update person set pass=?, fname=?, lname=?, address=?, city=?, state=?, zipCode=?, persontype =? where idperson=?"); ps.setString(1, pass); ps.setString(2, fname); ps.setString(3, lname); ps.setString(4, address); ps.setString(5, city); ps.setString(6, state); ps.setString(7, zipcode); ps.setString(8, persontype); ps.setLong(9, idperson); rowcount = ps.executeUpdate(); if (rowcount > 0) { if(persontype =="I") { query ="select * from instructor where idperson =?"; ps1 =con.prepareStatement(query); ps1.setLong(1, idperson); rs1=ps1.executeQuery(); if(rs1.next()) { query1 = "update instructor set department=?, officeHr=?, location=? where idperson=?"; ps2=con.prepareStatement(query1); ps2.setString(1, department); ps2.setString(2,officeHr); ps2.setString(3, location); ps2.setLong(4, idperson); rowcount =0; rowcount =ps2.executeUpdate(); if(rowcount>0) { result=true; } } else { query1="insert into instructor (idperson,department,officeHr,location) values(?,?,?,?)"; ps2=con.prepareStatement(query1); ps2.setLong(1, idperson); ps2.setString(2, department); ps2.setString(3,officeHr); ps2.setString(4, location); rowcount = 0; rowcount =ps2.executeUpdate(); if(rowcount>0) { result=true; } } } else result= true; } } catch (SQLException e) { e.printStackTrace(); } finally { try { ps.close(); ps1.close(); ps2.close(); // connectionPool.free(con); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; }
41d377a3-308b-4ff5-b89e-d2332653631c
public long createStudent(String pass, String fname, String lname, String address, String city, String state, String zipcode, String persontype) { int rowcount = 0; boolean result = false; long studentId = -1; try { ps = (PreparedStatement) con .prepareStatement("insert into person(pass, fname, lname, address, city, state, zipcode, persontype) VALUES(?,?,?,?,?,?,?,?)"); ps.setString(1, pass); ps.setString(2, fname); ps.setString(3, lname); ps.setString(4, address); ps.setString(5, city); ps.setString(6, state); ps.setString(7, zipcode); ps.setString(8, persontype); rowcount = ps.executeUpdate(); if (rowcount > 0) { result = true; System.out.println("New Student has been created...."); } if(result) { ps = (PreparedStatement) con .prepareStatement("select idperson from person where fname= ? and lname = ? and zipcode = ?"); ps.setString(1, fname); ps.setString(2, lname); ps.setString(3, zipcode); rs = ps.executeQuery(); if (rs.next()) { studentId = rs.getInt(1); } else { System.out.println("Person with fname= " + fname + ", lname= " + lname+ ", zipcode= "+zipcode + " does not exist."); return studentId; } } else { System.out.println("New student unable to create...."); return studentId; } } catch (SQLException e) { e.printStackTrace(); } finally { try { // connectionPool.free(con); ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return studentId; }
92d09257-9a93-4f68-8bac-0fcc199b206a
public boolean removeReplaceInstructor(long removeInsructor, long replaceInstructor, long idcourse) { int rowcount = 0; boolean result = false; try { ps = (PreparedStatement) con .prepareStatement("UPDATE personcoursemap SET idperson= ? WHERE idperson=? and idcourse=?"); ps.setLong(1, replaceInstructor); ps.setLong(2, removeInsructor); ps.setLong(3, idcourse); rowcount = ps.executeUpdate(); if (rowcount > 0) { result = true; System.out.println("Instructor with ID: " + removeInsructor + "has been replaced with" + replaceInstructor + "for course ID: " + idcourse); } } catch (SQLException e) { e.printStackTrace(); } finally { try { // connectionPool.free(con); ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; }
0ce02567-0410-44e8-b9af-eba09344d8b8
public boolean deleteStudent(long idperson) { int rowcount = 0; boolean result = false; try { ps = (PreparedStatement) con .prepareStatement("delete from person where idperson=?"); ps.setLong(1, idperson); rowcount = ps.executeUpdate(); if (rowcount > 0) { result = true; System.out.println("Student with ID: " + idperson + "has been deleted..."); } } catch (SQLException e) { e.printStackTrace(); } finally { try { // connectionPool.free(con); ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; }
c2b35c6d-d843-4e65-be4e-c1296c0708c1
public boolean createInstructor(String pass, String fname, String lname, String address, String city, String state, String zipcode, String persontype, String department, String officeHr, String location) { int rowcount = 0; boolean result = false; try { long idperson = this.createStudent(pass, fname, lname, address, city, state, zipcode, persontype); if(idperson != -1) { } else { System.out.println("Not able to create record into person table........"); } ps = (PreparedStatement) con .prepareStatement("insert into instructor(idperson, department, officeHr, location) VALUES(?,?,?,?)"); ps.setLong(1, idperson); ps.setString(2, department); ps.setString(3, officeHr); ps.setString(4, location); rowcount = ps.executeUpdate(); if (rowcount > 0) { result = true; System.out.println("New Instructor has been created...."); } } catch (SQLException e) { e.printStackTrace(); } finally { try { // connectionPool.free(con); ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; }
bcad540a-fc14-4ab6-bd1b-312c29b26d75
public boolean deleteInstructor(long idperson) { boolean result = false; result = deleteStudent(idperson); if(result) { System.out.println("Instructor: " + idperson + " has been deleted"); } else{ System.out.println("Error in delerint Instructor: " + idperson ); } return result; }
91228e43-b9cc-4e24-b44d-64e95681af72
public boolean assignCourseToInstructor(long idperson, long idcourse) { int rowcount = 0; boolean result = false; long studentId = -1; try { ps = (PreparedStatement) con .prepareStatement("insert into personcoursemap(idperson, idcourse) VALUES(?,?)"); ps.setLong(1, idperson); ps.setLong(2, idcourse); rowcount = ps.executeUpdate(); if (rowcount > 0) { result = true; System.out.println("Course" + idcourse + " has been Assigned to " + idperson); } } catch (SQLException e) { e.printStackTrace(); } finally { try { // connectionPool.free(con); ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; }
1832d7b5-bf3f-439e-8fc8-f2e268c9d3d3
public Course[] viewAllCourse(){ String query; String countQuery; int Count = 0; int index=0; Course[] courseInfo = null; try { query = "select * from course"; countQuery = "select count(1) from course"; ps= con.prepareStatement(countQuery); rs= ps.executeQuery(); if (rs.next()) { Count = rs.getInt(1); } courseInfo = new Course[Count]; ps= con.prepareStatement(query); rs= ps.executeQuery(); while (rs.next()) { Course course = new Course(); course.setCourseId(rs.getInt(1)); course.setName(rs.getString(2)); course.setSection(rs.getString(3)); course.setHours(rs.getString(4)); course.setLocation(rs.getString(5)); courseInfo[index] = course; index++; } } catch (SQLException e) { e.printStackTrace(); } finally { try { // connectionPool.free(con); ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return courseInfo; }
eb4b268a-c447-4176-8f0f-1b0139790180
public String getAdminUname() { return Configuration.ADMIN_UNAME; }
7979fe6d-a8c9-4d67-95d3-3e4bbd2fce7b
public String getAdminPass() { return Configuration.ADMIN_PASS; }
ec928af4-f22a-4f2e-a03d-a8290ff11269
public boolean UpdateCourse(long idcourse, String name, String section, String hours, String loc) throws SQLException { int rowcount = 0; boolean result = false; try { ps = (PreparedStatement) con .prepareStatement("update course set name=?, section=?, hours=?, loc=? where idcourse=?"); ps.setString(1, name); ps.setString(2, section); ps.setString(3, hours); ps.setString(4, loc); ps.setLong(5, idcourse); rowcount = ps.executeUpdate(); if (rowcount > 0) { result = true; } } catch (SQLException e) { e.printStackTrace(); } finally { try { // connectionPool.free(con); ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; }
02361f59-d5e5-45d6-b5f7-55cb75161d21
public boolean deleteCourse(long idcourse) { int rowcount = 0; boolean result = false; try { ps = (PreparedStatement) con .prepareStatement("delete from course where idcourse=?"); ps.setLong(1, idcourse); rowcount = ps.executeUpdate(); if (rowcount > 0) { result = true; System.out.println("Course with ID: " + idcourse + " has been deleted..."); } } catch (SQLException e) { e.printStackTrace(); } finally { try { // connectionPool.free(con); ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; }
f8b17498-5fff-4440-93c9-d470f108b029
public boolean createCourse(String name, String section, String hours, String loc) { int rowcount = 0; boolean result = false; try { ps = (PreparedStatement) con .prepareStatement("insert into course(name, section, hours, loc) VALUES(?,?,?,?)"); ps.setString(1, name); ps.setString(2, section); ps.setString(3, hours); ps.setString(4, loc); rowcount = ps.executeUpdate(); if (rowcount > 0) { result = true; System.out.println("New Course has been created...."); } } catch (SQLException e) { e.printStackTrace(); } finally { try { // connectionPool.free(con); ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; }
c4fd979e-ad6b-497d-a799-cb1a34d38546
public boolean enrollStudent(long idperson, long idcourse) { int rowcount = 0; boolean result = false; try { ps = (PreparedStatement) con.prepareStatement("insert into personcoursemap(idperson, idcourse) VALUES(?,?)"); ps.setLong(1, idperson); ps.setLong(2, idcourse); rowcount = ps.executeUpdate(); if (rowcount > 0) { result = true; System.out.println("Student " + idperson + " has been enrolled to " + idcourse); } } catch (SQLException e) { e.printStackTrace(); } finally { try { // connectionPool.free(con); ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; }
bc74dc4c-de72-454e-9386-72365444a5a9
public boolean unenrollStudent(long idperson, long idcourse) { int rowcount = 0; boolean result = false; try { ps = (PreparedStatement) con.prepareStatement("delete from personcoursemap where idperson =? and idcourse=?"); ps.setLong(1, idperson); ps.setLong(2, idcourse); rowcount = ps.executeUpdate(); if (rowcount > 0) { result = true; System.out.println("Student " + idperson + " has been unenrolled from the course " + idcourse); } } catch (SQLException e) { e.printStackTrace(); } finally { try { // connectionPool.free(con); ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; }
e77b61aa-0054-40dc-a3d5-cd32deac0d78
public Person[] searchPerson(String attributeName, String attributeValue) throws SQLException { String query=""; int index=0, count=0; Person[] personInfo = null; try{ query="select count(1) from person where "+attributeName+" LIKE '"+attributeValue+"%'"; // also check by having % in the beginning ps= con.prepareStatement(query); rs= ps.executeQuery(); System.out.println(query); if (rs.next()) { count = rs.getInt(1); } personInfo = new Person[count]; query = "select * from movie where "+attributeName+" LIKE '"+attributeValue+"%'"; // also check by having % in the beginning ps=con.prepareStatement(query); rs = ps.executeQuery(); while(rs.next()) { Person person = new Person(); person.setPersonId(rs.getLong(1)); person.setPassword(rs.getString(2)); person.setFirstName(rs.getString(3)); person.setAddress(rs.getString(4)); person.setCity(rs.getString(5)); person.setState(rs.getString(6)); person.setPersonType(rs.getString(7)); personInfo[index] = person; index++; System.out.println(person.getPersonId()+" "+person.getPassword()+" "+person.getFirstName()+" "+person.getLastName()+ " " + " "+person.getAddress()+" "+person.getCity()+" "+person.getState()+" "+person.getZipCode()+" "+person.getPersonType()); } if(index>0) { System.out.println("Person found"); } else { System.out.println("Person not found"); return null; } } catch (SQLException e) { e.printStackTrace(); }finally{ //connectionPool.free(con); ps.close(); } return personInfo; }
6b6cd425-f4be-4c58-98cb-1a2bea7ac920
public Course[] searchCourse(String attributeName, String attributeValue) throws SQLException { String query=""; int index=0, count=0; Course[] courseInfo = null; try{ query="select count(1) from course where "+attributeName+" LIKE '"+attributeValue+"%'"; // also check by having % in the beginning ps= con.prepareStatement(query); rs= ps.executeQuery(); System.out.println(query); if (rs.next()) { count = rs.getInt(1); } courseInfo = new Course[count]; query = "select * from movie where "+attributeName+" LIKE '"+attributeValue+"%'"; // also check by having % in the beginning ps=con.prepareStatement(query); rs = ps.executeQuery(); while(rs.next()) { Course course = new Course(); course.setCourseId(rs.getLong(1)); course.setName(rs.getString(2)); course.setSection(rs.getString(3)); course.setHours(rs.getString(4)); course.setLocation(rs.getString(5)); courseInfo[index] = course; index++; System.out.println(course.getCourseId()+" "+course.getName()+" "+course.getSection()+" "+course.getHours()+ " " + " "+course.getLocation()); } if(index>0) { System.out.println("Course found"); } else { System.out.println("Course not found"); return null; } } catch (SQLException e) { e.printStackTrace(); }finally{ //connectionPool.free(con); ps.close(); } return courseInfo; }
44ae59e6-05a4-45c4-a185-e48d5fafea38
private ConnectionPool(){ //below parameters we have to change according every group member's database settings this.SQLdriver = "com.mysql.jdbc.Driver"; this.waitIncaseBusy = true; this.SQLusername = "root"; this.SQLpassword = "root";//password also change this.SQLurl = "jdbc:mysql://localhost:3306/cmpe273";// url change this.maxallowableConnections = 1000; if (initialallowableConnections > maxallowableConnections) { initialallowableConnections = maxallowableConnections; } connectionsAvailable = new Vector(initialallowableConnections); connectionsBusy = new Vector(); for(int i=0; i<initialallowableConnections; i++) { try { connectionsAvailable.addElement(createNewConnection()); } catch (SQLException e) { e.printStackTrace(); } } }
e823bd2f-9263-4e1d-8a57-641d230d27d7
public synchronized Connection getConnection()throws SQLException { System.out.println("Connectionpool class-getConnection is called"); if (!connectionsAvailable.isEmpty()) { Connection connection_existing = (Connection)connectionsAvailable.lastElement(); int Index_Last = connectionsAvailable.size() - 1; connectionsAvailable.removeElementAt(Index_Last); if (connection_existing.isClosed()) { notifyAll(); return(getConnection()); } else { connectionsBusy.addElement(connection_existing); return(connection_existing); } } else { if ((Connections_total() < maxallowableConnections) && !pendingConnection) { createBackgroundConnection(); } else if (!waitIncaseBusy) { throw new SQLException("Connection limit has reached"); } try { wait(); } catch(InterruptedException ie) {} return(getConnection()); } }
1a6b06e0-3c10-4d9d-bce5-fdbea8500f3f
public synchronized int Connections_total() { return(connectionsAvailable.size() + connectionsBusy.size()); }
a42f2593-d539-44bb-a901-9b9999ecedbb
static public synchronized ConnectionPool getInstance(){ if (instance_pool == null){ instance_pool = new ConnectionPool(); } return instance_pool; }
dbf40ede-a6e3-42f0-b56b-7d5ab45154c7
private Connection createNewConnection() throws SQLException { try { Class.forName(SQLdriver); Connection newConnection = DriverManager.getConnection(SQLurl, SQLusername, SQLpassword); return(newConnection); } catch(ClassNotFoundException cnfe) { throw new SQLException("Could't find class for driver: " + SQLdriver); } }
244e1520-0b35-4a27-ace1-712ecd0e86de
public void run() { try { Connection connection = createNewConnection(); synchronized(this) { connectionsAvailable.addElement(connection); pendingConnection = false; notifyAll(); } } catch(Exception e) { } }
3e6c0c98-8c2f-4114-8989-c8a8849d62ba
public synchronized void free(Connection connection) { System.out.println("You are in Connectionpool class -Free method is called..."); connectionsBusy.removeElement(connection); connectionsAvailable.addElement(connection); notifyAll(); }
ff87c284-3ad5-4568-b65e-18d117c55d89
public synchronized void allConnections_Close() { connections_Close(connectionsAvailable); connectionsAvailable = new Vector(); connections_Close(connectionsBusy); connectionsBusy = new Vector(); }
1e6046b2-1256-46d6-94ed-8d663bf1820f
private void connections_Close(Vector connections) { try { for(int i=0; i<connections.size(); i++) { Connection connection = (Connection)connections.elementAt(i); if (!connection.isClosed()) { connection.close(); } } } catch(SQLException se) { } }
4ce9182a-5ceb-4f0b-ab50-cae8deb786aa
private void createBackgroundConnection() { pendingConnection = true; try { Thread connectNewThread = new Thread(this); connectNewThread.start(); } catch(OutOfMemoryError oome) { } }
95362262-ed2d-4aa6-a52b-8bb900231a66
public Person(long idperson, String pass, String fname, String lname, String address, String city, String state, String zipcode, String persontype) { this.idperson = idperson; this.pass = pass; this.fname = fname; this.lname = lname; this.address = address; this.city = city; this.state = state; this.zipcode = zipcode; this.persontype = persontype; }
c18ab508-03dd-479c-9bbb-96bacf12514b
public Person(){ }
a9a6e26e-28f3-489f-9811-c0ddc5402748
public long getPersonId() { return idperson; }
84dda6fb-4b60-4f04-a8a3-ab05e14c86d8
public void setPersonId(long idperson) { this.idperson = idperson; }
fc27c1a5-3cd2-4efd-bae7-349943531384
public String getPassword() { return pass; }
463ce4f7-0275-4bda-83b1-b1dbb3badd79
public void setPassword(String pass) { this.pass = pass; }
ffed6294-c5fd-4735-9bd6-108dc009305c
public String getFirstName() { return fname; }
b577ffa6-297c-4a5e-954e-2b9e65056e95
public void setFirstName(String fname) { this.fname = fname; }
cd7b5b5d-fd09-476a-a009-c6773f3f2d46
public String getLastName() { return lname; }
e3ab25da-8938-4f8d-b33e-e9aed32b2d3c
public void setLastName(String lname) { this.lname = lname; }
d8043eca-9a90-4b5e-80b4-aa0ee5342e34
public String getAddress() { return address; }
48c3f63a-335a-464a-a53f-44d96621ccf2
public void setAddress(String address) { this.address = address; }
71613a86-12b7-48d9-8221-afa7e4b3c807
public String getCity() { return city; }
e3ef7646-c954-4d65-bf49-c19b8c1f7070
public void setCity(String city) { this.city = city; }
e3d7b6f5-0847-4a55-b6bc-4b0d8dc615f9
public String getState() { return state; }
100ca03c-88e2-49dd-b7c8-2c9726e322eb
public void setState(String state) { this.state = state; }
efb8b4a1-e7fa-42fc-911e-4b1735d1017e
public String getZipCode() { return zipcode; }
8481e4b8-3b8b-44e7-a15f-6c7e6a3f9956
public void setZipCode(String zipcode) { this.zipcode = zipcode; }
be7b6ace-bd83-4ab6-9474-03f0bcbfbde0
public String getPersonType() { return persontype; }
c8754f01-05ac-44a8-814d-4fed59942385
public void setPersonType(String persontype) { this.persontype = persontype; }
7b915cee-4337-42a9-aa2f-2ab7da708092
public Instructor getInstructor() { return instructor; }
5a720cbe-7a8c-4f4c-a460-b8a8de1ed4c3
public void setInstructor(Instructor instructor) { this.instructor = instructor; }
176d4cf5-1558-4c5a-9c28-60f9bc3237c8
public Instructor(){ }
5145ce07-e2ae-4df0-bf20-4223fe8d8242
public Instructor(long idperson, String department, String officeHr, String location) { this.idperson = idperson; this.department = department; this.officeHr = officeHr; this.location = location; }
5907ad9a-2fa9-4350-82d5-663c591d5729
public long getPersonId() { return idperson; }
ff4c419e-848c-44e5-8737-635e48001723
public void setPersonId(long idperson) { this.idperson = idperson; }
63ed79eb-2d68-4e63-a964-3a66169a03ac
public String getDepartment() { return department; }
4531f30e-a581-455d-a39b-56958ae139e3
public void setDepartment(String department) { this.department = department; }
af248eb2-305f-454e-8d24-8fb20d87cef3
public String getOfficeHr() { return officeHr; }
ac89f5f6-f24e-47a0-a497-1a72a538c866
public void setOffficeHr(String officeHr) { this.officeHr = officeHr; }
a8ed0343-431d-427c-b0d8-fdbe8ae470b6
public String getLocation() { return location; }
bd3c3c3c-0f56-4970-962f-2bfb19b4ede4
public void setLocation(String location) { this.location = location; }
e5fcd23f-cc4c-42e1-9b32-032aac8d8835
public String getPassword() { return pass; }
61cf637c-16e9-4577-8a2a-a5944ce7b982
public void setPassword(String pass) { this.pass = pass; }
46ff7436-5032-4442-9450-e1c1165b1abd
public String getFirstName() { return fname; }
8dde9423-3df2-42f8-94a2-af1b63eefb09
public void setFirstName(String fname) { this.fname = fname; }
102d864b-c0a7-4381-b374-ffbf3b62f0c7
public String getLastName() { return lname; }
e2970427-af5a-4dca-a04b-f266513d421c
public void setLastName(String lname) { this.lname = lname; }
10bd5745-06f5-4a6e-a106-ea819a2daf21
public String getAddress() { return address; }
b17a5a3c-2659-422d-a509-d4447524f637
public void setAddress(String address) { this.address = address; }
bca76372-c27c-4ba6-bb63-8c7a3dbbf5d7
public String getCity() { return city; }
4071e960-e8a1-4788-b8fa-4e4afc83342f
public void setCity(String city) { this.city = city; }
bf4e08b1-948d-44b4-8435-e19f99a6c0bf
public String getState() { return state; }
a1186db9-6818-4732-8fc6-dd476d8ff981
public void setState(String state) { this.state = state; }
d08545ac-8051-425b-a1f7-186f7ba38cab
public String getZipCode() { return zipcode; }
a1b1f547-1414-446d-9876-548197e94a35
public void setZipCode(String zipcode) { this.zipcode = zipcode; }
8bf99e4e-4efd-4606-9abd-223d63aa7434
public String getPersonType() { return persontype; }
59226011-6615-49b9-b1eb-b263d263a6c4
public void setPersonType(String persontype) { this.persontype = persontype; }
030df275-cdf5-430c-b5d5-e3154ff5f71d
public Course(){ }
e95c366c-7f11-4de9-9a4b-85ee71f33804
public Course(long idcourse, String name, String section, String hours, String loc) { this.idcourse = idcourse; this.name = name; this.section = section; this.hours = hours; this.loc = loc; }
9843382c-5faf-479f-b458-a771278a831d
public long getCourseId() { return idcourse; }
57d0ae88-0fb1-4d90-b5ed-67058d40f127
public void setCourseId(long idcourse) { this.idcourse = idcourse; }
43144f56-afc1-4f4e-8b3e-d9f9702593ca
public String getName() { return name; }
a4d62994-999b-41a4-aa71-9db75fd9a37d
public void setName(String name) { this.name = name; }
cc6471dd-1c4c-42dd-bf0b-84261c4cd3cc
public String getSection() { return section; }
0d95fa79-f069-4936-b22b-c44fa95cda54
public void setSection(String section) { this.section = section; }
158e867c-e0ba-465f-8bc9-e2022562c6ec
public String getHours() { return hours; }
772c0e98-194d-4547-9c7a-be510b7d8e56
public void setHours(String hours) { this.hours = hours; }
982c90d6-d041-423a-b41f-ad0118c47594
public String getLocation() { return loc; }
e04dec9f-9b83-4b17-ade5-72b7bc7e40d6
public void setLocation(String loc) { this.loc = loc; }
cce9643b-c8eb-48b5-9b7a-99e17d627c5a
public Person[] getCourseUsers() { return courseusers; }
24ec4f88-50d9-4ddc-801e-ad5664134165
public void setCourseUsers(Person[] courseusers) { this.courseusers = courseusers; }
89f5ebe5-90bf-4f32-968f-7152c9ea5ec7
public Instructor[] getCourseTeachers() { return courseteachers; }
4382be09-dcdf-45b4-ba32-4ad4ee04f545
public void setCourseTeachers(Instructor[] courseteachers) { this.courseteachers = courseteachers; }
1dcf80c1-d507-4280-a065-e0e364f52b7c
public PersonCourseMap() { }
5ae8dcd3-8c46-4625-8fc2-7a623ff22302
public PersonCourseMap(long idperson,long idcourse) { this.idperson = idperson; this.idcourse = idcourse; }
0dac62c0-e7fd-40b4-b1e5-7f1074e788e3
public long getPersonId() { return idperson; }