FileDocCategorySizeDatePackage
SchedResourceImpl.javaAPI DocExample3081Sun Oct 31 18:32:14 GMT 1999dcj.examples.dbase

SchedResourceImpl

public class SchedResourceImpl extends DatabaseItemImpl implements RMISchedResource
Source code from "Java Distributed Computing", by Jim Farley. Class: SchedResourceImpl (for complete set of implementations, please see the file "RMISchedImpls.java" in this source distribution) Example: 7-10 Description: Server implementation of the RMI-based resource object.

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

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

    // How is ID generated?
    try {
      Statement st = DatabaseItemImpl.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 (Exception e) {
      valid = false;
    }
  
Methods Summary
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 = DatabaseItemImpl.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 = DatabaseItemImpl.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;