@Override
    public void run() {
      // log.info("START");
      try {
        while (execute) {
          int next = random.nextInt(nodesMaxIndex);
          NodeData rndNode = parentNodes[next];
          if (random.nextBoolean()) {
            // put single item
            if (random.nextBoolean()) {
              // node
              cache.put(
                  new TransientNodeData(
                      QPath.makeChildPath(
                          rndNode.getQPath(), InternalQName.parse("[]childNode-" + next)),
                      IdGenerator.generate(),
                      1,
                      Constants.NT_UNSTRUCTURED,
                      new InternalQName[0],
                      1,
                      IdGenerator.generate(),
                      rndNode.getACL()));
            } else {
              TransientPropertyData pd =
                  new TransientPropertyData(
                      QPath.makeChildPath(
                          rndNode.getQPath(), InternalQName.parse("[]property-" + next)),
                      IdGenerator.generate(),
                      1,
                      PropertyType.STRING,
                      rndNode.getIdentifier(),
                      false,
                      new TransientValueData("prop data"));
              cache.put(pd);
            }
            itemsProcessed++;
          } else {
            // put list of childs
            if (random.nextBoolean()) {
              // nodes
              List<NodeData> cn = createNodesData(rndNode, 100);
              cache.addChildNodes(rndNode, cn);
              itemsProcessed += cn.size();
            } else {
              // properties w/o value
              List<PropertyData> cp = createPropertiesData(rndNode, 100);
              cache.addChildProperties(rndNode, cp);
              itemsProcessed += cp.size();
            }
          }

          Thread.sleep(putTimeout);
        }
      } catch (Exception e) {
        log.error(getName() + " " + e, e);
      }
      // log.info("FINISH");
    }
  public Book addBook(Book book) throws DuplicateBookException {
    SessionProvider sProvider = SessionProvider.createSystemProvider();

    String nodeId = IdGenerator.generate();
    book.setId(nodeId);

    try {
      Node parentNode = getNodeByPath(DEFAULT_PARENT_PATH, sProvider);
      Node bookNode = parentNode.addNode(nodeId, BookNodeTypes.EXO_BOOK);
      bookNode.setProperty(BookNodeTypes.EXP_BOOK_NAME, book.getName());
      bookNode.setProperty(
          BookNodeTypes.EXP_BOOK_CATEGORY, Utils.bookCategoryEnumToString(book.getCategory()));
      bookNode.setProperty(BookNodeTypes.EXP_BOOK_CONTENT, book.getContent());

      parentNode.getSession().save();
      return book;
    } catch (PathNotFoundException e) {
      return null;
    } catch (Exception e) {
      log.error("Failed to add book", e);
      return null;
    } finally {
      sProvider.close();
    }
  }
  /** {@inheritDoc} */
  protected ResultSet findNodesAndProperties(String lastNodeId, int offset, int limit)
      throws SQLException {
    String tempTableAName = "tempdb..a" + IdGenerator.generate();

    boolean tempTableACreated = false;

    try {
      // the Sybase is not allowed DDL query (CREATE TABLE, DROP TABLE, etc. ) within a
      // multi-statement transaction
      if (!dbConnection.getAutoCommit()) {
        dbConnection.setAutoCommit(true);
      }

      selectLimitOffsetNodesIntoTemporaryTable =
          dbConnection.prepareStatement(
              SELECT_LIMIT_OFFSET_NODES_INTO_TEMPORARY_TABLE
                  .replaceAll(SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME, tempTableAName)
                  .replace("${TOP}", new Integer(offset + limit).toString()));

      if (findNodesAndProperties != null) {
        findNodesAndProperties.close();
      }

      findNodesAndProperties =
          dbConnection.prepareStatement(
              FIND_NODES_AND_PROPERTIES.replaceAll(
                  SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME, tempTableAName));

      deleteTemporaryTableA =
          dbConnection.prepareStatement(
              DELETE_TEMPORARY_TABLE_A.replaceAll(
                  SybaseJDBCConnectionHelper.TEMP_A_TABLE_NAME, tempTableAName));

      selectLimitOffsetNodesIntoTemporaryTable.setString(1, lastNodeId);
      selectLimitOffsetNodesIntoTemporaryTable.execute();

      tempTableACreated = true;

      return findNodesAndProperties.executeQuery();
    } finally {
      if (tempTableACreated) {
        try {
          deleteTemporaryTableA.execute();
        } catch (SQLException e) {
          LOG.warn("Can not delete temporary table " + tempTableAName);
        }
      }

      // close prepared statement since we always create new
      if (selectLimitOffsetNodesIntoTemporaryTable != null) {
        selectLimitOffsetNodesIntoTemporaryTable.close();
      }

      if (deleteTemporaryTableA != null) {
        deleteTemporaryTableA.close();
      }
    }
  }
  private List<NodeData> createNodesData(NodeData parent, int count) throws Exception {

    List<NodeData> nodes = new ArrayList<NodeData>();

    for (int i = 1; i <= count; i++) {
      nodes.add(
          new TransientNodeData(
              QPath.makeChildPath(parent.getQPath(), InternalQName.parse("[]node" + i)),
              IdGenerator.generate(),
              1,
              Constants.NT_UNSTRUCTURED,
              new InternalQName[0],
              1,
              IdGenerator.generate(),
              parent.getACL()));
    }

    return nodes;
  }
Esempio n. 5
0
 public MessageFilter(String name) {
   this.id_ = Utils.KEY_FILTER + IdGenerator.generate();
   this.name_ = name;
   this.toCondition_ = Utils.CONDITION_CONTAIN;
   this.fromCondition_ = Utils.CONDITION_CONTAIN;
   this.subjectCondition_ = Utils.CONDITION_CONTAIN;
   this.bodyCondition_ = Utils.CONDITION_CONTAIN;
   this.hasAttach_ = false;
   this.hasStar_ = false;
   this.priority_ = 0;
   isAscending_ = false;
   orderBy_ = Utils.EXO_LAST_CHECKED_TIME;
   hasStructure_ = false;
 }
  /**
   * properties w/o value.
   *
   * @param parent
   * @param count
   * @return
   * @throws Exception
   */
  private List<PropertyData> createPropertiesData(NodeData parent, int count) throws Exception {

    List<PropertyData> props = new ArrayList<PropertyData>();

    for (int i = 1; i <= count; i++) {
      TransientPropertyData pd =
          new TransientPropertyData(
              QPath.makeChildPath(parent.getQPath(), InternalQName.parse("[]property-" + i)),
              IdGenerator.generate(),
              1,
              PropertyType.STRING,
              parent.getIdentifier(),
              false,
              new TransientValueData("prop data"));
      props.add(pd);
    }

    return props;
  }
Esempio n. 7
0
 private String getId(String type) {
   return type + IdGenerator.generate();
 }
 /** Constructor for GenericLesson. It uses GateIn to regenerate an id for the lesson */
 public GenericLesson() {
   // set lesson id by ExoPlatform's api
   setId(PREF + IdGenerator.generate());
   documents = new ArrayList<String>();
 }