Skip to content

Commit

Permalink
Server side fixes for issue 282
Browse files Browse the repository at this point in the history
git-svn-id: https://sagetv-addons.googlecode.com/svn/trunk/sjq4@1330 4d529e3f-d655-0410-97be-dbb2a4780eb3
  • Loading branch information
[email protected] committed Jan 19, 2011
1 parent d983e95 commit 9a4ec38
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/com/google/code/sagetvaddons/sjq/server/DataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static public final DataStore get() {
static private final String DELETE_TASK = "DelTask";
static private final String CLEAN_QUEUE = "CleanQueue";

static private final int DB_SCHEMA = 2;
static private final int DB_SCHEMA = 3;

static private boolean dbInitialized = false;

Expand Down Expand Up @@ -258,6 +258,13 @@ private void upgradeDb() throws SQLException {
qry = "UPDATE settings SET val = '2' WHERE var = 'schema'";
stmt.executeUpdate(qry);
break;
case 2:
qry = "ALTER TABLE queue ADD COLUMN show_icon BOOLEAN NOT NULL DEFAULT false";
stmt.executeUpdate(qry);

qry = "UPDATE settings SET val = '3' WHERE var = 'schema'";
stmt.executeUpdate(qry);
break;
}
++schema;
}
Expand Down Expand Up @@ -328,7 +335,7 @@ private void prepStatements() throws SQLException {
qry = "SELECT log FROM task_log WHERE id = ? AND type = ?";
stmts.put(READ_LOG, conn.prepareStatement(qry));

qry = "SELECT t.id, t.reqd_resources, t.max_instances, t.schedule, t.exe, t.args, t.max_time, t.max_time_ratio, t.min_rc, t.max_rc, t.test, t.test_args FROM client AS c LEFT OUTER JOIN client_tasks AS t ON (c.host = t.host AND c.port = t.port) WHERE c.host = ? AND c.port = ? AND t.host IS NOT NULL";
qry = "SELECT t.id, t.reqd_resources, t.max_instances, t.schedule, t.exe, t.args, t.max_time, t.max_time_ratio, t.min_rc, t.max_rc, t.test, t.test_args, t.show_icon FROM client AS c LEFT OUTER JOIN client_tasks AS t ON (c.host = t.host AND c.port = t.port) WHERE c.host = ? AND c.port = ? AND t.host IS NOT NULL";
stmts.put(READ_CLNT_TASKS, conn.prepareStatement(qry));

qry = "DELETE FROM settings WHERE var = ?";
Expand Down Expand Up @@ -416,7 +423,7 @@ Task[] getTasksForClient(String host, int port) {
pStmt.setInt(2, port);
rs = pStmt.executeQuery();
while(rs.next())
tasks.add(new Task(rs.getString(1), rs.getInt(2), rs.getInt(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getLong(7), rs.getFloat(8), rs.getInt(9), rs.getInt(10), rs.getString(11), rs.getString(12)));
tasks.add(new Task(rs.getString(1), rs.getInt(2), rs.getInt(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getLong(7), rs.getFloat(8), rs.getInt(9), rs.getInt(10), rs.getString(11), rs.getString(12), rs.getBoolean(13)));
return tasks.toArray(new Task[tasks.size()]);
} catch(SQLException e) {
LOG.error(SQL_ERROR, e);
Expand Down Expand Up @@ -471,7 +478,7 @@ public QueuedTask[] getQueue() {

QueuedTask[] getQueue(boolean activeOnly) {
Collection<QueuedTask> tasks = new ArrayList<QueuedTask>();
String qry = "SELECT q.id, q.job_id, created, assigned, finished, state, reqd_resources, max_instances, schedule, exe, args, max_time, max_time_ratio, min_rc, max_rc, test, test_args, q.host, q.port FROM queue AS q LEFT OUTER JOIN client_tasks AS t ON (q.job_id = t.id AND q.host = t.host AND q.port = t.port)";
String qry = "SELECT q.id, q.job_id, created, assigned, finished, state, reqd_resources, max_instances, schedule, exe, args, max_time, max_time_ratio, min_rc, max_rc, test, test_args, q.host, q.port, q.show_icon FROM queue AS q LEFT OUTER JOIN client_tasks AS t ON (q.job_id = t.id AND q.host = t.host AND q.port = t.port)";
if(activeOnly)
qry = qry.concat(" WHERE state NOT IN ('COMPLETED', 'FAILED', 'SKIPPED')");
Statement stmt = null;
Expand All @@ -480,7 +487,7 @@ QueuedTask[] getQueue(boolean activeOnly) {
stmt = conn.createStatement();
rs = stmt.executeQuery(qry);
while(rs.next())
tasks.add(new QueuedTask(rs.getLong(1), rs.getString(2), rs.getInt(7), rs.getInt(8), rs.getString(9), rs.getString(10), rs.getString(11), rs.getLong(12), rs.getFloat(13), rs.getInt(14), rs.getInt(15), getMetadata(rs.getLong(1)), rs.getTimestamp(3), rs.getTimestamp(4), rs.getTimestamp(5), QueuedTask.State.valueOf(rs.getString(6)), getClient(rs.getString(18), rs.getInt(19)), Global.GetServerAddress(), Integer.parseInt(Configuration.GetServerProperty("sjq4/enginePort", "23347")), rs.getString(16), rs.getString(17), Integer.parseInt(Configuration.GetServerProperty("sagex/api/RMIPort", "1098"))));
tasks.add(new QueuedTask(rs.getLong(1), rs.getString(2), rs.getInt(7), rs.getInt(8), rs.getString(9), rs.getString(10), rs.getString(11), rs.getLong(12), rs.getFloat(13), rs.getInt(14), rs.getInt(15), getMetadata(rs.getLong(1)), rs.getTimestamp(3), rs.getTimestamp(4), rs.getTimestamp(5), QueuedTask.State.valueOf(rs.getString(6)), getClient(rs.getString(18), rs.getInt(19)), Global.GetServerAddress(), Integer.parseInt(Configuration.GetServerProperty("sjq4/enginePort", "23347")), rs.getString(16), rs.getString(17), Integer.parseInt(Configuration.GetServerProperty("sagex/api/RMIPort", "1098")), rs.getBoolean(20)));
return tasks.toArray(new QueuedTask[tasks.size()]);
} catch(SQLException e) {
LOG.error(SQL_ERROR, e);
Expand Down Expand Up @@ -1162,7 +1169,7 @@ public Map<String, Collection<Task>> getAllRegisteredTasks() {
tasks = new ArrayList<Task>();
map.put(c.getDescription(), tasks);
}
tasks.add(new Task(rs.getString(1), rs.getInt(4), rs.getInt(5), rs.getString(6), rs.getString(7), rs.getString(8), rs.getLong(9), rs.getFloat(10), rs.getInt(11), rs.getInt(12), rs.getString(13), rs.getString(14)));
tasks.add(new Task(rs.getString(1), rs.getInt(4), rs.getInt(5), rs.getString(6), rs.getString(7), rs.getString(8), rs.getLong(9), rs.getFloat(10), rs.getInt(11), rs.getInt(12), rs.getString(13), rs.getString(14), false));
}
} catch(SQLException e) {
LOG.error(SQL_ERROR, e);
Expand Down

0 comments on commit 9a4ec38

Please sign in to comment.