コード例 #1
0
 /**
  * Creates a new DbManager which manages access to the underlying persistency layer(s).
  * Instantiates the underlying storage system to use.
  *
  * @param server The Restlet server instance.
  */
 public DbManager(Server server) {
   // Defaults to: "org.hackystat.sensorbase.db.derby.DerbyImplementation"
   String dbClassName = server.getServerProperties().get(DB_IMPL_KEY);
   Class<?> dbClass = null;
   // First, try to find the class specified in the sensorbase.properties file (or the default)
   try {
     dbClass = Class.forName(dbClassName);
   } catch (ClassNotFoundException e) {
     String msg = "DB error instantiating " + dbClassName + ". Could not find this class.";
     server.getLogger().warning(msg + "\n" + StackTrace.toString(e));
     throw new IllegalArgumentException(e);
   }
   // Next, try to find a constructor that accepts a Server as its parameter.
   Class<?>[] constructorParam = {org.itu.thesis.server.Server.class};
   Constructor<?> dbConstructor = null;
   try {
     dbConstructor = dbClass.getConstructor(constructorParam);
   } catch (Exception e) {
     String msg = "DB error instantiating " + dbClassName + ". Could not find Constructor(server)";
     server.getLogger().warning(msg + "\n" + StackTrace.toString(e));
     throw new IllegalArgumentException(e);
   }
   // Next, try to create an instance of DbImplementation from the Constructor.
   Object[] serverArg = {server};
   try {
     this.dbImpl = (DbImplementation) dbConstructor.newInstance(serverArg);
   } catch (Exception e) {
     String msg = "DB error instantiating " + dbClassName + ". Could not create instance.";
     server.getLogger().warning(msg + "\n" + StackTrace.toString(e));
     throw new IllegalArgumentException(e);
   }
   this.dbImpl.initialize();
 }
コード例 #2
0
 /**
  * Used by the SdtSummary link to indicate how the model should be updated.
  *
  * @param sdtName The sdtName.
  * @param tool The tool.
  * @param start The start time.
  */
 public void setSensorDataDetailsProvider(String sdtName, String tool, long start) {
   detailsList.clear();
   SensorBaseClient client = ProjectBrowserSession.get().getSensorBaseClient();
   SensorDataSession session = ProjectBrowserSession.get().getSensorDataSession();
   String projectName = session.getProject().getName();
   String owner = session.getProject().getOwner();
   XMLGregorianCalendar startTime = Tstamp.makeTimestamp(start);
   XMLGregorianCalendar endTime = Tstamp.incrementDays(startTime, 1);
   try {
     SensorDataIndex index =
         client.getProjectSensorData(owner, projectName, startTime, endTime, sdtName, tool);
     for (SensorDataRef ref : index.getSensorDataRef()) {
       detailsList.add(new SensorDataDetails(ref));
     }
   } catch (Exception e) {
     System.out.println("Error getting sensor data: " + StackTrace.toString(e));
   }
 }