コード例 #1
0
  public void testIndexMapRemoveItemInTx() throws Exception {
    final ODocument docOne = new ODocument();
    docOne.save();

    final ODocument docTwo = new ODocument();
    docTwo.save();

    final ODocument docThree = new ODocument();
    docThree.save();

    Map<String, ORID> map = new HashMap<String, ORID>();

    map.put("key1", docOne.getIdentity());
    map.put("key2", docTwo.getIdentity());
    map.put("key3", docThree.getIdentity());

    final ODocument document = new ODocument("LinkMapIndexTestClass");
    document.field("linkMap", map);
    document.save();

    try {
      database.begin();
      final ODocument loadedDocument = database.load(document.getIdentity());
      loadedDocument.<Map<String, ORID>>field("linkMap").remove("key2");
      loadedDocument.save();
      database.commit();
    } catch (Exception e) {
      database.rollback();
      throw e;
    }

    final List<ODocument> resultByKey =
        database.command(new OCommandSQL("select key, rid from index:mapIndexTestKey")).execute();

    Assert.assertNotNull(resultByKey);
    Assert.assertEquals(resultByKey.size(), 2);
    for (ODocument d : resultByKey) {
      Assert.assertTrue(d.containsField("key"));
      Assert.assertTrue(d.containsField("rid"));

      if (!d.field("key").equals("key1") && !d.field("key").equals("key3")) {
        Assert.fail("Unknown key found: " + d.field("key"));
      }
    }

    final List<ODocument> resultByValue =
        database.command(new OCommandSQL("select key, rid from index:mapIndexTestValue")).execute();

    Assert.assertNotNull(resultByValue);
    Assert.assertEquals(resultByValue.size(), 2);
    for (ODocument d : resultByValue) {
      Assert.assertTrue(d.containsField("key"));
      Assert.assertTrue(d.containsField("rid"));

      if (!d.field("key").equals(docOne.getIdentity())
          && !d.field("key").equals(docThree.getIdentity())) {
        Assert.fail("Unknown key found: " + d.field("key"));
      }
    }
  }
コード例 #2
0
  public void testIndexMapAddItem() {
    final ODocument docOne = new ODocument();
    docOne.save();

    final ODocument docTwo = new ODocument();
    docTwo.save();

    final ODocument docThree = new ODocument();
    docThree.save();

    Map<String, ORID> map = new HashMap<String, ORID>();

    map.put("key1", docOne.getIdentity());
    map.put("key2", docTwo.getIdentity());

    final ODocument document = new ODocument("LinkMapIndexTestClass");
    document.field("linkMap", map);
    document.save();

    database
        .command(
            new OCommandSQL(
                "UPDATE "
                    + document.getIdentity()
                    + " put linkMap = 'key3', "
                    + docThree.getIdentity()))
        .execute();

    final List<ODocument> resultByKey =
        database.command(new OCommandSQL("select key, rid from index:mapIndexTestKey")).execute();

    Assert.assertNotNull(resultByKey);
    Assert.assertEquals(resultByKey.size(), 3);
    for (ODocument d : resultByKey) {
      Assert.assertTrue(d.containsField("key"));
      Assert.assertTrue(d.containsField("rid"));

      if (!d.field("key").equals("key1")
          && !d.field("key").equals("key2")
          && !d.field("key").equals("key3")) {
        Assert.fail("Unknown key found: " + d.field("key"));
      }
    }

    final List<ODocument> resultByValue =
        database.command(new OCommandSQL("select key, rid from index:mapIndexTestValue")).execute();

    Assert.assertNotNull(resultByValue);
    Assert.assertEquals(resultByValue.size(), 3);
    for (ODocument d : resultByValue) {
      Assert.assertTrue(d.containsField("key"));
      Assert.assertTrue(d.containsField("rid"));

      if (!d.field("key").equals(docOne.getIdentity())
          && !d.field("key").equals(docTwo.getIdentity())
          && !d.field("key").equals(docThree.getIdentity())) {
        Assert.fail("Unknown key found: " + d.field("key"));
      }
    }
  }
コード例 #3
0
  @Override
  public void configure(
      final OETLProcessor iProcessor,
      final ODocument iConfiguration,
      final OCommandContext iContext) {
    super.configure(iProcessor, iConfiguration, iContext);
    clusterName = iConfiguration.field("cluster");

    if (iConfiguration.containsField("class"))
      vertexClass = (String) resolve(iConfiguration.field("class"));
    if (iConfiguration.containsField("skipDuplicates"))
      skipDuplicates = (Boolean) resolve(iConfiguration.field("skipDuplicates"));
  }
コード例 #4
0
  // Returns a section of the JSON document configuration as an ODocument if section is present.
  private ODocument getSection(final String section) {
    ODocument sectionDoc = null;

    try {
      if (configDoc != null) {
        if (configDoc.containsField(section)) {
          sectionDoc = configDoc.field(section);
        }
      } else {
        OLogManager.instance()
            .error(
                this,
                "ODefaultServerSecurity.getSection(%s) Configuration document is null",
                section);
      }
    } catch (Exception ex) {
      OLogManager.instance()
          .error(
              this,
              "ODefaultServerSecurity.getSection(%s) Exception: %s",
              section,
              ex.getMessage());
    }

    return sectionDoc;
  }
コード例 #5
0
  private void reloadAuthMethods() {
    if (authDoc != null) {
      if (authDoc.containsField("allowDefault")) {
        allowDefault = authDoc.field("allowDefault");
      }

      loadAuthenticators(authDoc);
    }
  }
コード例 #6
0
  private void reloadServer() {
    try {
      storePasswords = true;

      if (serverDoc != null) {
        if (serverDoc.containsField("createDefaultUsers")) {
          OGlobalConfiguration.CREATE_DEFAULT_USERS.setValue(serverDoc.field("createDefaultUsers"));
        }

        if (serverDoc.containsField("storePasswords")) {
          storePasswords = serverDoc.field("storePasswords");
        }
      }
    } catch (Exception ex) {
      OLogManager.instance()
          .error(this, "ODefaultServerSecurity.loadServer() Exception: %s", ex.getMessage());
    }
  }
コード例 #7
0
  @Test
  public void queryFunctionRenamed() {
    List<ODocument> result =
        database
            .command(new OSQLSynchQuery<ODocument>("select distinct(name) from City"))
            .execute();

    Assert.assertTrue(result.size() > 1);

    for (ODocument city : result) Assert.assertTrue(city.containsField("distinct"));
  }
コード例 #8
0
  private void loadSecurity() {
    try {
      enabled = false;

      if (configDoc != null) {
        if (configDoc.containsField("enabled")) {
          enabled = configDoc.field("enabled");
        }

        if (configDoc.containsField("debug")) {
          debug = configDoc.field("debug");
        }
      } else {
        OLogManager.instance()
            .error(this, "ODefaultServerSecurity.loadSecurity() jsonConfig is null");
      }
    } catch (Exception ex) {
      OLogManager.instance()
          .error(this, "ODefaultServerSecurity.loadSecurity() Exception: %s", ex.getMessage());
    }
  }
コード例 #9
0
  @Test
  public void queryUnionAllAsInline() {
    List<ODocument> result =
        database
            .command(new OSQLSynchQuery<ODocument>("select unionAll(out, in) as edges from V"))
            .execute();

    Assert.assertTrue(result.size() > 1);
    for (ODocument d : result) {
      Assert.assertEquals(d.fieldNames().length, 1);
      Assert.assertTrue(d.containsField("edges"));
    }
  }
コード例 #10
0
  private boolean isEnabled(final ODocument sectionDoc) {
    boolean enabled = true;

    try {
      if (sectionDoc.containsField("enabled")) {
        enabled = sectionDoc.field("enabled");
      }
    } catch (Exception ex) {
      OLogManager.instance()
          .error(this, "ODefaultServerSecurity.isEnabled() Exception: %s", ex.getMessage());
    }

    return enabled;
  }
コード例 #11
0
ファイル: StorageUtils.java プロジェクト: h4ck4life/baasbox
 public static ByteArrayOutputStream extractFileFromDoc(ODocument doc)
     throws DocumentIsNotAFileException, IOException {
   if (!docIsAFile(doc)) throw new DocumentIsNotAFileException();
   if (!doc.containsField("file"))
     throw new DocumentIsNotAFileException("the file field does not exist");
   ORecordBytes record = null;
   try {
     record = doc.field("file");
   } catch (Exception e) {
     throw new DocumentIsNotAFileException(
         "The file field exists but does not contains a valid file");
   }
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   record.toOutputStream(out);
   return out;
 }
コード例 #12
0
  private Class<?> getClass(final ODocument jsonConfig) {
    Class<?> cls = null;

    try {
      if (jsonConfig.containsField("class")) {
        final String clsName = jsonConfig.field("class");

        if (securityClassMap.containsKey(clsName)) {
          cls = securityClassMap.get(clsName);
        } else {
          cls = Class.forName(clsName);
        }
      }
    } catch (Throwable th) {
      OLogManager.instance().error(this, "ODefaultServerSecurity.getClass() Throwable: ", th);
    }

    return cls;
  }
コード例 #13
0
ファイル: OGroup.java プロジェクト: halestudio/hale
  private void configureDocument(
      ORecordAbstract<?> document, ODatabaseRecord db, DefinitionGroup definition) {
    // configure document

    // as of OrientDB 1.0rc8 the database may no longer be set on the
    // document
    // instead the current database can be set using
    // ODatabaseRecordThreadLocal.INSTANCE.set(db);
    //		document.setDatabase(db);
    if (document instanceof ODocument) {
      // reset class name
      ODocument doc = (ODocument) document;
      /*
       * Attention: Two long class names cause problems as file names will
       * be based on them.
       */
      String className = null;
      if (definition != null) {
        className = ONamespaceMap.encode(determineName(definition));
      } else if (doc.containsField(OSerializationHelper.BINARY_WRAPPER_FIELD)
          || doc.containsField(OSerializationHelper.FIELD_SERIALIZATION_TYPE)) {
        className = OSerializationHelper.BINARY_WRAPPER_CLASSNAME;
      }

      if (className != null) {
        OSchema schema = db.getMetadata().getSchema();
        if (!schema.existsClass(className)) {
          // if the class doesn't exist yet, create a physical cluster
          // manually for it
          int cluster = db.addCluster(className, CLUSTER_TYPE.PHYSICAL);
          schema.createClass(className, cluster);
        }
        doc.setClassName(className);
      }

      // configure children
      for (Entry<String, Object> field : doc) {
        List<ODocument> docs = new ArrayList<ODocument>();
        List<ORecordAbstract<?>> recs = new ArrayList<ORecordAbstract<?>>();
        if (field.getValue() instanceof Collection<?>) {
          for (Object value : (Collection<?>) field.getValue()) {
            if (value instanceof ODocument && !getSpecialFieldNames().contains(field.getKey())) {
              docs.add((ODocument) value);
            } else if (value instanceof ORecordAbstract<?>) {
              recs.add((ORecordAbstract<?>) value);
            }
          }
        } else if (field.getValue() instanceof ODocument
            && !getSpecialFieldNames().contains(field.getKey())) {
          docs.add((ODocument) field.getValue());
        } else if (field.getValue() instanceof ORecordAbstract<?>) {
          recs.add((ORecordAbstract<?>) field.getValue());
        }

        if (definition != null) {
          for (ODocument valueDoc : docs) {
            ChildDefinition<?> child = definition.getChild(decodeProperty(field.getKey()));
            DefinitionGroup childGroup;
            if (child.asProperty() != null) {
              childGroup = child.asProperty().getPropertyType();
            } else if (child.asGroup() != null) {
              childGroup = child.asGroup();
            } else {
              throw new IllegalStateException(
                  "Document is associated neither with a property nor a property group.");
            }
            configureDocument(valueDoc, db, childGroup);
          }
        }

        for (ORecordAbstract<?> fieldRec : recs) {
          configureDocument(fieldRec, db, null);
        }
      }
    }
  }
コード例 #14
0
  private void loadAuthenticators(final ODocument authDoc) {
    synchronized (authenticatorsList) {
      for (OSecurityAuthenticator sa : authenticatorsList) {
        sa.dispose();
      }

      authenticatorsList.clear();

      if (authDoc.containsField("authenticators")) {
        List<ODocument> authMethodsList = authDoc.field("authenticators");

        for (ODocument authMethodDoc : authMethodsList) {
          try {
            if (authMethodDoc.containsField("name")) {
              final String name = authMethodDoc.field("name");

              // defaults to enabled if "enabled" is missing
              boolean enabled = true;

              if (authMethodDoc.containsField("enabled")) enabled = authMethodDoc.field("enabled");

              if (enabled) {
                Class<?> authClass = getClass(authMethodDoc);

                if (authClass != null) {
                  if (OSecurityAuthenticator.class.isAssignableFrom(authClass)) {
                    OSecurityAuthenticator authPlugin =
                        (OSecurityAuthenticator) authClass.newInstance();

                    authPlugin.config(server, serverConfig, authMethodDoc);
                    authPlugin.active();

                    authenticatorsList.add(authPlugin);
                  } else {
                    OLogManager.instance()
                        .error(
                            this,
                            "ODefaultServerSecurity.loadAuthenticators() class is not an OSecurityAuthenticator");
                  }
                } else {
                  OLogManager.instance()
                      .error(
                          this,
                          "ODefaultServerSecurity.loadAuthenticators() authentication class is null for %s",
                          name);
                }
              }
            } else {
              OLogManager.instance()
                  .error(
                      this,
                      "ODefaultServerSecurity.loadAuthenticators() authentication object is missing name");
            }
          } catch (Throwable ex) {
            OLogManager.instance()
                .error(this, "ODefaultServerSecurity.loadAuthenticators() Exception: ", ex);
          }
        }
      }
    }
  }