FileDocCategorySizeDatePackage
RMISchedDbaseImpl.javaAPI DocExample6307Tue Jan 20 22:05:02 GMT 1998dcj.examples.dbase

SchedDbaseImpl

public class SchedDbaseImpl extends UnicastRemoteObject implements RMISchedDbase
Source code from "Java Distributed Computing", by Jim Farley. Class: SchedDbaseImpl Example: 7-11 Description: Server implementation of the "factory" object.

Fields Summary
Constructors Summary
public SchedDbaseImpl()

 super(); 
Methods Summary
public java.util.VectorassignmentsFor(int rid)

    Vector ras = new Vector();

    try {
      Statement s = SchedDbaseItem.dbConn.createStatement();
      ResultSet r = s.executeQuery("SELECT task, time FROM "
                                   + "res_assignment where resource = "
                                   + rid);
      while (r.next()) {
        int tid = r.getInt("task");
        Date time = r.getDate("time");
        ResAssignmentImpl ra = new ResAssignmentImpl(rid, tid, time);
        ras.addElement(ra);
      }
    }
    catch (Exception e) {}

    return ras;
  
public java.util.VectorconstraintsFor(int tid)

    Vector constraints = new Vector();

    try {
      Statement s = SchedDbaseItem.dbConn.createStatement();
      ResultSet r = s.executeQuery("SELECT task1, task2, type FROM "
                                   + "time_constraint where task1 = "
                                   + tid + " or task2 = " + tid);
      while (r.next()) {
        int tid1 = r.getInt("task1");
        int tid2 = r.getInt("task2");
        int type = r.getInt("type");
        TimeConstraintImpl c = new TimeConstraintImpl(type, tid1, tid2);
        constraints.addElement(c);
      }
    }
    catch (Exception e) {}

    return constraints;
  
public java.util.VectorgetAllResources()

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

    return resList;
  
public java.util.VectorgetAllTasks()

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

    return taskList;
  
public RMISchedResourcegetResource(int rid)

    SchedResourceImpl res = new SchedResourceImpl(rid);
    return res;
  
public RMISchedTaskgetTask(int id)

    SchedTaskImpl task = new SchedTaskImpl(id);
    return task;
  
public static voidmain(java.lang.String[] argv)

    System.setSecurityManager(new RMISecurityManager());

    try {
      String name = argv[0];
      String dbURL = argv[1];
      System.out.println("Registering SchedDbaseImpl with "
                         + "naming service as " + name);
      SchedDbaseImpl server = new SchedDbaseImpl();
      Class.forName("weblogic.jdbc.oci.Driver");
      SchedDbaseItem.dbConn =
        DriverManager.getConnection("jdbc:weblogic:oracle:hb1",
                                    "user", "passwd");
      Registry r = LocateRegistry.getRegistry(1234);
      r.rebind(name, server);
      System.out.println(name + " ready.");
    }
    catch (Exception e) {
      System.out.println("Exception while registering "
                         + "SchedDbaseImpl: \n");
      e.printStackTrace();
      System.exit(2);
    }
  
public RMITimeConstraintnewConstraint(int type, int t1, int t2)

    TimeConstraintImpl c = new TimeConstraintImpl(type, t1, t2);

    // Create a new record in the database.
    try {
      Statement s = SchedDbaseItem.dbConn.createStatement();
      int numr = s.executeUpdate("INSERT time_constraint SET type = "
                                 + type + " task1 = " + t1
                                 + " task2 = " + t2);
      if (numr != 1)
        c.valid = false;
      else
        c.valid = true;
    }
    catch (SQLException e) {
      c.valid = false;
    }

    return c;
  
public RMIResAssignmentnewResAssignment(int rid, int tid, java.util.Date time)

    ResAssignmentImpl r = new ResAssignmentImpl(rid, tid, time);

    // Create a new record in the database.
    try {
      Statement s = SchedDbaseItem.dbConn.createStatement();
      int numr = s.executeUpdate("INSERT res_assignment SET resource = "
                                 + rid + " task = " + tid
                                 + " time = " + time);
      if (numr != 1)
        r.valid = false;
      else
        r.valid = true;
    }
    catch (SQLException e) {
      r.valid = false;
    }

    return r;
  
public RMISchedResourcenewResource(java.lang.String n, int t, float s)

    SchedResourceImpl res = new SchedResourceImpl(n, t, s);
    return res;
  
public RMISchedTasknewTask(int t, float sz)

    SchedTaskImpl task = new SchedTaskImpl(t, sz);
    return task;