Skip to content

Commit

Permalink
db module rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
codingsnippets committed Mar 18, 2013
1 parent c6718e1 commit d4625ae
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 75 deletions.
15 changes: 15 additions & 0 deletions branch/proto/SchedulerPull.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import java.util.ArrayList;


public interface SchedulerPull {

public ArrayList<String> PullMajors();

public ArrayList<String> PullConcentrations(String MajorCode);

public ArrayList<Schedule> PullSchedule(Term termName, SessionInfo userSession);

public void filterConflicts(SessionInfo userSession);

}
72 changes: 0 additions & 72 deletions branch/proto/course_db_connect.java

This file was deleted.

9 changes: 6 additions & 3 deletions branch/proto/dbcredential.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@


public class dbcredential {

private String ost="cs451dbremote.db.10419053.hostedresource.com";
private String ost="jdbc:mysql://cs451dbremote.db.10419053.hostedresource.com/";
private String dbname= "cs451dbremote";
private String dbpass= "S4aw6WRA4u!";
private String dbdriver = "com.mysql.jdbc.Driver";

protected String getDbpass() {
return dbpass;
Expand All @@ -18,5 +17,9 @@ protected String getOst() {
return ost;
}

protected String getDbdriver(){
return dbdriver;
}


}
90 changes: 90 additions & 0 deletions branch/proto/mysqlDBExecute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;


public class mysqlDBExecute {

public static ArrayList<String> PullMajors(){
ArrayList<String> majors = new ArrayList<String>();

ArrayList<ArrayList<String>> records = mysqlStatement.startConnection("Select distinct `Subject`", "schedule", "");

for( ArrayList<String> currentMajor : records){
majors.add(currentMajor.toString());
}

return majors;
}

public static ArrayList<String> PullConcentrations(String MajorCode){
ArrayList<String> concentrations = new ArrayList<String>();
String table="track";
String fields="track_name";

ArrayList<ArrayList<String>> records = mysqlStatement.startConnection("Select `track_name`", "track", "");

for( ArrayList<String> thisTrack : records){
concentrations.add(thisTrack.toString());
}

return concentrations;
}

public static ArrayList<Schedule> PullSchedule(Term termName, SessionInfo userSession){

ArrayList<Schedule> scheduleCollection = new ArrayList<Schedule>();

// based off termName

String constraints = "where `Term` = \"" + termName + "\"";

ArrayList<ArrayList<String>> records = mysqlStatement.startConnection("SELECT *", "schedule", constraints);

for( ArrayList<String> thisSchedule : records){

Schedule thisCourse = new Schedule();

thisCourse.CRN = Integer.parseInt(thisSchedule.get(0));
thisCourse.Subject = thisSchedule.get(1);
thisCourse.Course_no = Integer.parseInt(thisSchedule.get(2));
thisCourse.Term = thisSchedule.get(3);
thisCourse.Section = Integer.parseInt(thisSchedule.get(4));
thisCourse.Instruction_type = thisSchedule.get(5);
thisCourse.Instructor = thisSchedule.get(6);
thisCourse.Location = thisSchedule.get(7);
thisCourse.Weekday = thisSchedule.get(8);
thisCourse.Start_time = thisSchedule.get(9);
thisCourse.End_time =thisSchedule.get(10);
//thisCourse.CourseName = 11


// Special treatment for the time slot information
String timeSlots = thisSchedule.get(12);
StringTokenizer stArr = new StringTokenizer(timeSlots, ", ");
ArrayList<Integer> timeIndices = new ArrayList<Integer>();
while(stArr.hasMoreTokens()){
timeIndices.add(Integer.parseInt(stArr.nextToken()));
}
thisCourse.Times = timeIndices;


//List<String> timeIndexes = Arrays.asList(slotsTaken);
//thisCourse.Times =

scheduleCollection.add(thisCourse);

}



return scheduleCollection;

}

public void filterConflicts(SessionInfo userSession){

}

}
56 changes: 56 additions & 0 deletions branch/proto/mysqlStatement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

import java.sql.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

/**
* Author: Kevin Huang
* Date: 3/17/13 , 6:23 PM
* Copyright Reserved 2013
*/
public class mysqlStatement {
protected static ArrayList<ArrayList<String >> startConnection(String queryStatement,String DBTable, String queryContraints)
{
Connection conn = null;


dbcredential database = new dbcredential();


String url = database.getOst();
String dbName = database.getDbname();
String driver = database.getDbdriver();
String userName = database.getDbname();
String password = database.getDbpass();

ArrayList<ArrayList<String >> recordSet = new ArrayList<ArrayList<String >>();

try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);

Statement statementSQL = conn.createStatement();
statementSQL.execute(queryStatement + " FROM " + DBTable + " " + queryContraints);
ResultSet rs = statementSQL.getResultSet();

while (rs.next()) {
Integer i ;
ArrayList<String> oneRow = new ArrayList<String>();
for( i = 1 ; i <= rs.getMetaData().getColumnCount(); i++){
oneRow.add(rs.getString(i));
}
recordSet.add(oneRow);

}

conn.close();
return recordSet;
} catch (Exception e) {
System.out.println("Connection failed, check your statement!");
return null;
}
}

}

0 comments on commit d4625ae

Please sign in to comment.