FileDocCategorySizeDatePackage
SchedTask.javaAPI DocExample2638Tue Jan 20 21:57:14 GMT 1998dcj.examples.dbase

SchedTask

public class SchedTask extends DatabaseItem
Source code from "Java Distributed Computing", by Jim Farley. Class: SchedTask Example: 7-4 Description: Data pertaining to a task to be scheduled.

Fields Summary
int
tid
int
type
float
size
Constructors Summary
SchedTask(int id)

    tid = id;
    valid = updateFromDbase();
  
SchedTask(int t, float sz)

    type = t;
    size = sz;
    try {
      Statement s = DatabaseItem.dbConn.createStatement();
      int cnt = s.executeUpdate("INSERT INTO task (tid, type, size) "
                  + "VALUES (tidseq.nextval, " + type + ", "
                  + size + ")");
      if (cnt < 1) {
        valid = false;
      }
      else {
        valid = true;
      }
    }
    catch (SQLException e) {
      valid = false;
    }
  
Methods Summary
public static java.util.VectorgetAllTasks()

    Vector taskList = new Vector();

    try {
      Statement s = DatabaseItem.dbConn.createStatement();
      ResultSet r = s.executeQuery("SELECT distinct(tid) FROM task");
      while (r.next()) {
        int id = r.getInt("tid");
        SchedTask task = new SchedTask(id);
        if (task.isValid()) {
          taskList.addElement(task);
        }
      }
    }
    catch (Exception e) {}

    return taskList;
  
public intgetId()

 return tid; 
public floatgetSize()

 return size; 
public intgetType()

 return type; 
public voidsetSize(float s)

 size = s; 
public voidsetType(int t)

 type = t; 
public booleanupdateFromDbase()

    boolean success = true;

    try {
      Statement s = DatabaseItem.dbConn.createStatement();
      ResultSet r =
        s.executeQuery("SELECT type, size FROM task WHERE tid = "
                       + tid);
      if (r.next()) {
        type = r.getInt("type");
        size = r.getFloat("size");
      }
      else {
        success = false;
      }

      s.close();
    }
    catch (SQLException e) {
      success = false;
    }

    return success;
  
public booleanupdateToDbase()

    boolean success = true;

    try {
      Statement s = DatabaseItem.dbConn.createStatement();
      int numr = s.executeUpdate("UPDATE task SET type = "
                                 + type + ", size = " + size
                                 + " WHERE tid = " + tid);
      if (numr < 1) {
        success = false;
      }
    }
    catch (SQLException s) {
      success = false;
    }

    return success;