FileDocCategorySizeDatePackage
SchedResource.javaAPI DocExample2955Tue Jan 20 21:56:34 GMT 1998dcj.examples.dbase

SchedResource

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

Fields Summary
int
rid
String
name
int
type
float
size
Constructors Summary
public SchedResource(int id)

    rid = id;
    valid = updateFromDbase();
  
public SchedResource(String n, int t, float s)

    // How is ID generated?
    try {
      Statement st = DatabaseItem.dbConn.createStatement();
      int rcnt = st.executeUpdate("INSERT INTO resource "
                   + "(rid, name, type, size) VALUES "
                   + "(ridseq.nextval, " + n + ", "
                   + t + ", " + s + ")");
      if (rcnt == 1)
        valid = true;
      else
        valid = false;
    }
    catch (SQLException e) {
      valid = false;
    }
  
Methods Summary
public static java.util.VectorgetAllResources()

    Vector resList = new Vector();
    try {
      Statement s = DatabaseItem.dbConn.createStatement();
      ResultSet r = s.executeQuery("SELECT distinct(rid) FROM resource");
      while (r.next()) {
        int id = r.getInt("rid");
        SchedResource res = new SchedResource(id);
        if (res.isValid()) {
          resList.addElement(res);
        }
      }
    }
    catch (Exception e) {};

    return resList;
  
public intgetId()

 return rid; 
public java.lang.StringgetName()

 return name; 
public floatgetSize()

 return size; 
public intgetType()

 return type; 
public voidsetName(java.lang.String n)

 name = n; updateToDbase(); 
public voidsetSize(float s)

 size = s; updateToDbase(); 
public voidsetType(int t)

 type = t; updateToDbase(); 
public booleanupdateFromDbase()

    boolean success = true;

    try {
      Statement s = DatabaseItem.dbConn.createStatement();
      ResultSet r =
        s.executeQuery("SELECT name, type, size FROM resource WHERE rid = "
                       + rid);
      if (r.next()) {
        name = r.getString("name");
        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 resource SET name = " + name
                                 + ", type = " + type + ", size = " + size
                                 + " WHERE rid = " + rid);
      if (numr < 1) {
        success = false;
      }
    }
    catch (SQLException s) {
      success = false;
    }

    return success;