Пример #1
0
 /**
  * Returns the PerformanceID of given performance time
  *
  * @param performanceTime Which subversion number to find ID for
  * @return id of Performance. Creates new one if no performanceTime already existed
  */
 public static Long getPerformanceID(String performanceTime) { // Used in saveRun
   Performance performance = find.where().eq("time", performanceTime).findUnique();
   if (performance == null) { // If no Performance was found... add it and return that id
     Performance newPerformance = new Performance();
     newPerformance.time = performanceTime;
     newPerformance.save();
     return newPerformance.id;
   }
   return performance.id;
 }
Пример #2
0
 /**
  * Writes a log message.
  *
  * @param str strings to be written
  * @param time add performance info
  */
 public void log(final boolean time, final Object... str) {
   final Object[] obj = new Object[str.length + (time ? 2 : 1)];
   obj[0] = remote();
   System.arraycopy(str, 0, obj, 1, str.length);
   if (time) obj[obj.length - 1] = perf.toString();
   context.log.write(obj);
 }
Пример #3
0
  /**
   * Runs the command without permission, data and concurrency checks.
   *
   * @param ctx database context
   * @param os output stream
   * @return result of check
   */
  public boolean run(final Context ctx, final OutputStream os) {
    perf = new Performance();
    context = ctx;
    prop = ctx.prop;
    mprop = ctx.mprop;
    out = PrintOutput.get(os);

    try {
      return run();
    } catch (final ProgressException ex) {
      // process was interrupted by the user or server
      abort();
      return error(INTERRUPTED);
    } catch (final Throwable ex) {
      // unexpected error
      Performance.gc(2);
      abort();
      if (ex instanceof OutOfMemoryError) {
        Util.debug(ex);
        return error(OUT_OF_MEM + (createWrite() ? H_OUT_OF_MEM : ""));
      }
      return error(Util.bug(ex) + NL + info.toString());
    } finally {
      // flushes the output
      try {
        if (out != null) out.flush();
      } catch (final IOException ignored) {
      }
    }
  }
Пример #4
0
 /**
  * Parses the query.
  *
  * @param p performance
  * @throws QueryException query exception
  */
 private void parse(final Performance p) throws QueryException {
   qp.http(http);
   for (final Entry<String, String[]> entry : vars.entrySet()) {
     final String name = entry.getKey();
     final String[] value = entry.getValue();
     if (name == null) qp.context(value[0], value[1]);
     else qp.bind(name, value[0], value[1]);
   }
   qp.parse();
   if (p != null) info.parsing += p.time();
 }
Пример #5
0
 @Override
 public void run() {
   try {
     for (int i = 0; i < runs; ++i) {
       Performance.sleep((long) (50 * RND.nextDouble()));
       // Return nth text of the database
       final int n = RND.nextInt() % MAX + 1;
       final String qu = Util.info(QUERY, n);
       new XQuery(qu).execute(context);
     }
   } catch (final BaseXException ex) {
     ex.printStackTrace();
   }
 }
  public void onSelectedArtistChange(int viewId, int time) {
    // check login
    if (!userBean.getLoggedIn()) {
      return;
    }

    // execute action
    Performance p = performances.get(viewId).get(time);

    UltimateFestivalOrganizerSoap ufo = UFOService.getInstance();

    if (p.getId() == 0 && p.getArtist().getId() == 0) {
      return;
    }

    // send to server
    boolean success = true;
    if (p.getId() == 0 && p.getArtist().getId() != 0) {
      success = ufo.addPerformance(p);
    } else if (p.getId() != 0 && p.getArtist().getId() == 0) {
      ufo.deletePerformance(p);
      success = true;
    } else if (p.getId() != 0 && p.getArtist().getId() != 0) {
      success = ufo.updatePerformance(p);
    }

    // message
    FacesContext facesContext = FacesContext.getCurrentInstance();
    FacesMessage facesMessage;
    if (success) {
      facesMessage =
          new FacesMessage(FacesMessage.SEVERITY_INFO, "Saved", "Data was saved on the server.");
    } else {
      facesMessage =
          new FacesMessage(
              FacesMessage.SEVERITY_ERROR,
              "Error",
              "The selected artist was invalid. The item will be reset.");
      reload();
    }
    facesContext.addMessage(null, facesMessage);
  }
Пример #7
0
  /**
   * Authenticate the user and returns a new client {@link Context} instance.
   *
   * @return client context
   * @throws LoginException login exception
   */
  public Context authenticate() throws LoginException {
    final byte[] address = token(req.getRemoteAddr());
    try {
      if (user == null || user.isEmpty() || pass == null || pass.isEmpty())
        throw new LoginException(NOPASSWD);
      final Context ctx = new Context(context(), null);
      ctx.user = ctx.users.get(user);
      if (ctx.user == null || !ctx.user.password.equals(md5(pass))) throw new LoginException();

      context.blocker.remove(address);
      return ctx;
    } catch (final LoginException ex) {
      // delay users with wrong passwords
      for (int d = context.blocker.delay(address); d > 0; d--) Performance.sleep(100);
      throw ex;
    }
  }
Пример #8
0
    @Override
    public void run() {
      try {
        // Perform some queries
        for (int i = 0; i < runs; ++i) {
          Performance.sleep((long) (50 * RND.nextDouble()));

          // Return nth text of the database
          final int n = RND.nextInt() % MAX + 1;
          final String qu = Util.info(QUERY, n);
          session.execute("xquery " + qu);
        }
        session.close();
      } catch (final Exception ex) {
        ex.printStackTrace();
      }
    }
  private void reload() {
    UltimateFestivalOrganizerSoap ufo = UFOService.getInstance();

    venues = ufo.getAllVenues().getVenue();
    artists = ufo.getAllButDeletedArtists().getArtist();

    // Performances
    performances.clear();

    if (performancesSessionBean.getSelectedDate() == null) {
      return;
    }

    // fill with new
    for (Venue v : venues) {
      performances.put(v.getId(), new HashMap<>());

      for (int hour = 14; hour <= 23; ++hour) {
        Performance p = new Performance();
        p.setVenue(v);

        Calendar c = new GregorianCalendar();
        c.setTime(performancesSessionBean.getSelectedDate());
        c.add(Calendar.HOUR_OF_DAY, hour);
        p.setDateTime(dateToGregorian(c.getTime()));

        Artist a = new Artist();
        a.setId(0);
        p.setArtist(a);

        performances.get(v.getId()).put(hour, p);
      }
    }

    // fill with existing
    List<Performance> allPerformances =
        ufo.getPerformancesByDate(dateToGregorian(performancesSessionBean.getSelectedDate()))
            .getPerformance();
    for (Performance p : allPerformances) {
      int venueId = p.getVenue().getId();
      int hour = p.getDateTime().getHour();

      performances.get(venueId).put(hour, p);
    }
  }
Пример #10
0
  /**
   * Evaluates the specified query.
   *
   * @param query query
   * @return success flag
   */
  final boolean query(final String query) {
    final Performance p = new Performance();
    String error;
    if (exception != null) {
      error = Util.message(exception);
    } else {
      try {
        long hits = 0;
        final boolean run = options.get(MainOptions.RUNQUERY);
        final boolean serial = options.get(MainOptions.SERIALIZE);
        final int runs = Math.max(1, options.get(MainOptions.RUNS));
        for (int r = 0; r < runs; ++r) {
          // reuse existing processor instance
          if (r != 0) qp = null;
          qp(query, context);
          parse(p);
          if (r == 0) plan(false);

          qp.compile();
          info.compiling += p.time();
          if (r == 0) plan(true);
          if (!run) continue;

          final PrintOutput po = r == 0 && serial ? out : new NullOutput();
          try (final Serializer ser = qp.getSerializer(po)) {
            if (maxResults >= 0) {
              result = qp.cache(maxResults);
              info.evaluating += p.time();
              result.serialize(ser);
              hits = result.size();
            } else {
              hits = 0;
              final Iter ir = qp.iter();
              info.evaluating += p.time();
              for (Item it; (it = ir.next()) != null; ) {
                ser.serialize(it);
                ++hits;
                checkStop();
              }
            }
          }
          qp.close();
          info.serializing += p.time();
        }
        // dump some query info
        // out.flush();

        // remove string list if global locking is used and if query is updating
        if (soptions.get(StaticOptions.GLOBALLOCK) && qp.updating) {
          info.readLocked = null;
          info.writeLocked = null;
        }
        return info(info.toString(qp, out.size(), hits, options.get(MainOptions.QUERYINFO)));

      } catch (final QueryException | IOException ex) {
        exception = ex;
        error = Util.message(ex);
      } catch (final ProcException ex) {
        error = INTERRUPTED;
      } catch (final StackOverflowError ex) {
        Util.debug(ex);
        error = BASX_STACKOVERFLOW.desc;
      } catch (final RuntimeException ex) {
        extError("");
        Util.debug(info());
        throw ex;
      } finally {
        // close processor after exceptions
        if (qp != null) qp.close();
      }
    }
    return extError(error);
  }
Пример #11
0
 /**
  * Prints performance information if the {@link Prop#debug} flag is set.
  *
  * @param perf performance reference
  */
 public static void memory(final Performance perf) {
   if (!Prop.debug) return;
   errln(" " + perf + " (" + Performance.getMemory() + ')');
 }