protected Iterator<? extends OIdentifiable> searchInClasses(
      final OClass iCls, final boolean iPolymorphic, final boolean iAscendentOrder) {

    final ODatabaseDocumentInternal database = getDatabase();
    database.checkSecurity(
        ORule.ResourceGeneric.CLASS, ORole.PERMISSION_READ, iCls.getName().toLowerCase());

    final ORID[] range = getRange();
    if (iAscendentOrder)
      return new ORecordIteratorClass<ORecord>(
              database, database, iCls.getName(), iPolymorphic, isUseCache(), false)
          .setRange(range[0], range[1]);
    else
      return new ORecordIteratorClassDescendentOrder<ORecord>(
              database, database, iCls.getName(), iPolymorphic)
          .setRange(range[0], range[1]);
  }
Ejemplo n.º 2
0
 @Override
 protected OIndex<?> loadInstance() {
   OClass oClass = classModel != null ? classModel.getObject() : null;
   OIndexManager indexManager =
       OrientDbWebSession.get().getDatabase().getMetadata().getIndexManager();
   return oClass != null
       ? indexManager.getClassIndex(oClass.getName(), indexName)
       : indexManager.getIndex(indexName);
 }
Ejemplo n.º 3
0
  private void createEdge(List<ODocument> documents, OClass edgeClass) {
    OrientGraph tx = null;
    try {
      tx = new OrientGraphFactory(getDatabase().getURL()).getTx();
      for (ODocument createTo : documents) {
        tx.addEdge(
            null,
            tx.getVertex(documentModel.getObject().getIdentity()),
            tx.getVertex(createTo.getIdentity()),
            edgeClass.getName());
      }

    } finally {
      if (tx != null) tx.shutdown();
    }
  }
  /**
   * Checks class definition of the document that presents Snapshot Event instance in OrientDb.
   *
   * <p>For class description look at {@link SnapshotEventEntry} JavaDoc.
   *
   * @param eventClass Document class to be checked.
   */
  public static void assertSnapshotEventSchema(OClass eventClass) {
    assertNotNull(eventClass);
    assertEquals(SnapshotEventEntry.SNAPSHOT_EVENT_CLASS, eventClass.getName());

    final OProperty aggregateTypeProperty = eventClass.getProperty("aggregateType");
    assertNotNull(aggregateTypeProperty);
    assertTrue(aggregateTypeProperty.isMandatory());
    assertTrue(aggregateTypeProperty.isNotNull());
    assertEquals(OType.STRING, aggregateTypeProperty.getType());

    final OProperty aggregateIdentifierProperty = eventClass.getProperty("aggregateIdentifier");
    assertNotNull(aggregateIdentifierProperty);
    assertTrue(aggregateIdentifierProperty.isMandatory());
    assertTrue(aggregateIdentifierProperty.isNotNull());
    assertEquals(OType.STRING, aggregateIdentifierProperty.getType());

    final OProperty sequenceNumberProperty = eventClass.getProperty("sequenceNumber");
    assertNotNull(sequenceNumberProperty);
    assertTrue(sequenceNumberProperty.isMandatory());
    assertTrue(sequenceNumberProperty.isNotNull());
    assertEquals(OType.LONG, sequenceNumberProperty.getType());

    final OProperty timestampProperty = eventClass.getProperty("timestamp");
    assertNotNull(timestampProperty);
    assertTrue(timestampProperty.isMandatory());
    assertTrue(timestampProperty.isNotNull());
    assertEquals("29", timestampProperty.getMin());
    assertEquals("29", timestampProperty.getMax());
    assertEquals(OType.STRING, timestampProperty.getType());

    final OProperty bodyProperty = eventClass.getProperty("body");
    assertNotNull(bodyProperty);
    assertTrue(bodyProperty.isMandatory());
    assertTrue(bodyProperty.isNotNull());
    assertEquals(OType.BINARY, bodyProperty.getType());

    final OClass parent = eventClass.getSuperClass();
    assertDomainEventSchema(parent);
  }
Ejemplo n.º 5
0
  @SuppressWarnings("unchecked")
  public OCommandExecutorSQLInsert parse(final OCommandRequest iRequest) {
    final ODatabaseRecord database = getDatabase();
    database.checkSecurity(ODatabaseSecurityResources.COMMAND, ORole.PERMISSION_READ);

    init((OCommandRequestText) iRequest);

    className = null;
    newRecords = null;
    content = null;

    parserRequiredKeyword("INSERT");
    parserRequiredKeyword("INTO");

    String subjectName =
        parserRequiredWord(true, "Invalid subject name. Expected cluster, class or index");
    if (subjectName.startsWith(OCommandExecutorSQLAbstract.CLUSTER_PREFIX))
      // CLUSTER
      clusterName = subjectName.substring(OCommandExecutorSQLAbstract.CLUSTER_PREFIX.length());
    else if (subjectName.startsWith(OCommandExecutorSQLAbstract.INDEX_PREFIX))
      // INDEX
      indexName = subjectName.substring(OCommandExecutorSQLAbstract.INDEX_PREFIX.length());
    else {
      // CLASS
      if (subjectName.startsWith(OCommandExecutorSQLAbstract.CLASS_PREFIX))
        subjectName = subjectName.substring(OCommandExecutorSQLAbstract.CLASS_PREFIX.length());

      final OClass cls = database.getMetadata().getSchema().getClass(subjectName);
      if (cls == null) throwParsingException("Class " + subjectName + " not found in database");

      className = cls.getName();
    }

    parserSkipWhiteSpaces();
    if (parserIsEnded())
      throwSyntaxErrorException(
          "Set of fields is missed. Example: (name, surname) or SET name = 'Bill'");

    final String temp = parseOptionalWord(true);
    if (temp.equals("CLUSTER")) {
      clusterName = parserRequiredWord(false);

      parserSkipWhiteSpaces();
      if (parserIsEnded())
        throwSyntaxErrorException(
            "Set of fields is missed. Example: (name, surname) or SET name = 'Bill'");
    } else parserGoBack();

    newRecords = new ArrayList<Map<String, Object>>();
    if (parserGetCurrentChar() == '(') {
      parseValues();
    } else {
      parserNextWord(true, " ,\r\n");

      if (parserGetLastWord().equals(KEYWORD_CONTENT)) {
        newRecords = null;
        parseContent();
      } else if (parserGetLastWord().equals(KEYWORD_SET)) {
        final LinkedHashMap<String, Object> fields = new LinkedHashMap<String, Object>();
        newRecords.add(fields);
        parseSetFields(fields);
      }
    }

    return this;
  }