public ColumnPairElement getColumnPair(DBIdentifier name) {
    ColumnPairElement cpe = (ColumnPairElement) columnPairs.find(name);
    if (cpe == null)
      try {
        String fullName = name.getFullName();
        if (fullName == null) {
          return null;
        }

        int pos = fullName.indexOf(";");
        String firstHalf = fullName.substring(0, pos);
        String secondHalf = fullName.substring(pos + 1);

        ColumnElement lce = getColumn(DBIdentifier.create(firstHalf));

        pos = secondHalf.lastIndexOf(".");
        TableElement te =
            ((TableElement) element)
                .getDeclaringSchema()
                .getTable(DBIdentifier.create(secondHalf.substring(0, pos)));
        if (te == null) return null;

        ColumnElement fce = te.getColumn(DBIdentifier.create(secondHalf));

        if (lce == null || fce == null) return null;

        ColumnPairElementImpl cpei =
            new ColumnPairElementImpl(
                lce.getName().getFullName() + ";" + fce.getName().getFullName()); // NOI18N
        cpe = new ColumnPairElement(cpei, lce, fce, (TableElement) element);
        changeColumnPairs(new ColumnPairElement[] {cpe}, DBElement.Impl.ADD);
      } catch (DBException exc) {
        exc.printStackTrace();
        return null;
      }

    return cpe;
  }
示例#2
0
  public void run() {
    try {
      _db.init();
    } catch (DBException e) {
      e.printStackTrace();
      e.printStackTrace(System.out);
      return;
    }

    try {
      _workloadstate = _workload.initThread(_props, _threadid, _threadcount);
    } catch (WorkloadException e) {
      e.printStackTrace();
      e.printStackTrace(System.out);
      return;
    }

    // spread the thread operations out so they don't all hit the DB at the same time
    try {
      // GH issue 4 - throws exception if _target>1 because random.nextInt argument must be >0
      // and the sleep() doesn't make sense for granularities < 1 ms anyway
      if ((_target > 0) && (_target <= 1.0)) {
        sleep(Utils.random().nextInt((int) (1.0 / _target)));
      }
    } catch (InterruptedException e) {
      // do nothing.
    }

    try {
      if (_dotransactions) {
        long st = System.currentTimeMillis();

        while (((_opcount == 0) || (_opsdone < _opcount)) && !_workload.isStopRequested()) {

          if (!_workload.doTransaction(_db, _workloadstate)) {
            break;
          }

          _opsdone++;

          // throttle the operations
          if (_target > 0) {
            // this is more accurate than other throttling approaches we have tried,
            // like sleeping for (1/target throughput)-operation latency,
            // because it smooths timing inaccuracies (from sleep() taking an int,
            // current time in millis) over many operations
            while (System.currentTimeMillis() - st < ((double) _opsdone) / _target) {
              try {
                sleep(1);
              } catch (InterruptedException e) {
                // do nothing.
              }
            }
          }
        }
      } else {
        long st = System.currentTimeMillis();

        while (((_opcount == 0) || (_opsdone < _opcount)) && !_workload.isStopRequested()) {

          if (!_workload.doInsert(_db, _workloadstate)) {
            break;
          }

          _opsdone++;

          // throttle the operations
          if (_target > 0) {
            // this is more accurate than other throttling approaches we have tried,
            // like sleeping for (1/target throughput)-operation latency,
            // because it smooths timing inaccuracies (from sleep() taking an int,
            // current time in millis) over many operations
            while (System.currentTimeMillis() - st < ((double) _opsdone) / _target) {
              try {
                sleep(1);
              } catch (InterruptedException e) {
                // do nothing.
              }
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      e.printStackTrace(System.out);
      System.exit(0);
    }

    try {
      _db.cleanup();
    } catch (DBException e) {
      e.printStackTrace();
      e.printStackTrace(System.out);
      return;
    }
  }