Package com.orientechnologies.orient.core.db.document

Examples of com.orientechnologies.orient.core.db.document.ODatabaseDocument


        if (stg.userPassword == null)
          stg.userPassword = "admin";

        type = stg.path.substring(0, stg.path.indexOf(':'));

        ODatabaseDocument db = null;
        try {
          db = new ODatabaseDocumentTx(stg.path);

          if (db.exists())
            db.open(stg.userName, stg.userPassword);
          else
            db.create();

          OLogManager.instance().info(this, "-> Loaded " + type + " database '" + stg.name + "'");
        } catch (Exception e) {
          OLogManager.instance().error(this, "-> Can't load " + type + " database '" + stg.name + "': " + e);

        } finally {
          if (db != null)
            db.close();
        }
      }
  }
View Full Code Here


        if (stg.userPassword == null)
          stg.userPassword = "admin";

        type = stg.path.substring(0, stg.path.indexOf(':'));

        ODatabaseDocument db = null;
        try {
          db = new ODatabaseDocumentTx(stg.path);

          if (db.exists())
            db.open(stg.userName, stg.userPassword);
          else
            db.create();

          OLogManager.instance().info(this, "-> Loaded " + type + " database '" + stg.name + "'");
        } catch (Exception e) {
          OLogManager.instance().error(this, "-> Can't load " + type + " database '" + stg.name + "': " + e);

        } finally {
          if (db != null)
            db.close();
        }
      }
  }
View Full Code Here

        if (stg.userPassword == null)
          stg.userPassword = "admin";

        type = stg.path.substring(0, stg.path.indexOf(':'));

        ODatabaseDocument db = null;
        try {
          db = new ODatabaseDocumentTx(stg.path);

          if (db.exists())
            db.open(stg.userName, stg.userPassword);
          else
            db.create();

          OLogManager.instance().info(this, "-> Loaded " + type + " database '" + stg.name + "'");
        } catch (Exception e) {
          OLogManager.instance().error(this, "-> Can't load " + type + " database '" + stg.name + "': " + e);

        } finally {
          if (db != null)
            db.close();
        }
      }
  }
View Full Code Here

    return fromStream(iDatabase, iSource, null);
  }

  public ORecordInternal<?> fromStream(ODatabaseRecord iDatabase, byte[] iSource, ORecordInternal<?> iRecord) {
    ODocument record = (ODocument) iRecord;
    ODatabaseDocument database = (ODatabaseDocument) iDatabase;

    if (iRecord == null)
      record = new ODocument(database);

    ByteArrayInputStream stream = null;
View Full Code Here

    return fromStream(iDatabase, iSource, null);
  }

  public ORecordInternal<?> fromStream(ODatabaseRecord iDatabase, byte[] iSource, ORecordInternal<?> iRecord) {
    ODocument record = (ODocument) iRecord;
    ODatabaseDocument database = (ODatabaseDocument) iDatabase;

    if (iRecord == null)
      record = new ODocument(database);

    ByteArrayInputStream stream = null;
View Full Code Here

        if (stg.userPassword == null)
          stg.userPassword = "admin";

        type = stg.path.substring(0, stg.path.indexOf(':'));

        ODatabaseDocument db = null;
        try {
          db = new ODatabaseDocumentTx(stg.path);

          if (db.exists())
            db.open(stg.userName, stg.userPassword);
          else
            db.create();

          OLogManager.instance().info(this, "-> Loaded " + type + " database '" + stg.name + "'");
        } catch (Exception e) {
          OLogManager.instance().error(this, "-> Can't load " + type + " database '" + stg.name + "': " + e);

        } finally {
          if (db != null)
            db.close();
        }
      }
  }
View Full Code Here

          OLogManager.instance().error(this, "-> Invalid path '" + stg.path + "' for database '" + stg.name + "'");
          return;
        }
        type = stg.path.substring(0, idx);

        ODatabaseDocument db = null;
        try {
          db = new ODatabaseDocumentTx(stg.path);

          if (db.exists())
            db.open(stg.userName, stg.userPassword);
          else {
            db.create();
            if (stg.userName.equals(OUser.ADMIN)) {
              if (!stg.userPassword.equals(OUser.ADMIN))
                // CHANGE ADMIN PASSWORD
                db.getMetadata().getSecurity().getUser(OUser.ADMIN).setPassword(stg.userPassword);
            } else {
              // CREATE A NEW USER AS ADMIN AND REMOVE THE DEFAULT ONE
              db.getMetadata().getSecurity().createUser(stg.userName, stg.userPassword, ORole.ADMIN);
              db.getMetadata().getSecurity().dropUser(OUser.ADMIN);
              db.close();
              db.open(stg.userName, stg.userPassword);
            }
          }

          OLogManager.instance().info(this, "-> Loaded " + type + " database '" + stg.name + "'");
        } catch (Exception e) {
          OLogManager.instance().error(this, "-> Cannot load " + type + " database '" + stg.name + "': " + e);

        } finally {
          if (db != null)
            db.close();
        }
      }
  }
View Full Code Here

    assertEquals(extr.field("listMixed"), document.field("listMixed"));
  }

  @Test
  public void testLinkCollections() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:ODocumentSchemalessBinarySerializationTest").create();
    try {
      ODocument document = new ODocument();
      Set<ORecordId> linkSet = new HashSet<ORecordId>();
      linkSet.add(new ORecordId(10, new OClusterPositionLong(20)));
      linkSet.add(new ORecordId(10, new OClusterPositionLong(21)));
      linkSet.add(new ORecordId(10, new OClusterPositionLong(22)));
      linkSet.add(new ORecordId(11, new OClusterPositionLong(22)));
      document.field("linkSet", linkSet, OType.LINKSET);

      List<ORecordId> linkList = new ArrayList<ORecordId>();
      linkList.add(new ORecordId(10, new OClusterPositionLong(20)));
      linkList.add(new ORecordId(10, new OClusterPositionLong(21)));
      linkList.add(new ORecordId(10, new OClusterPositionLong(22)));
      linkList.add(new ORecordId(11, new OClusterPositionLong(22)));
      document.field("linkList", linkList, OType.LINKLIST);
      byte[] res = serializer.toStream(document, false);
      ODocument extr = (ODocument) serializer.fromStream(res, new ODocument(), new String[] {});

      assertEquals(extr.fields(), document.fields());
      assertEquals(((Set<?>) extr.field("linkSet")).size(), ((Set<?>) document.field("linkSet")).size());
      assertTrue(((Set<?>) extr.field("linkSet")).containsAll((Set<?>) document.field("linkSet")));
      assertEquals(extr.field("linkList"), document.field("linkList"));
    } finally {
      db.drop();
    }

  }
View Full Code Here

  }

  @Test
  public void testMapOfLink() {
    // needs a database because of the lazy loading
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:ODocumentSchemalessBinarySerializationTest").create();
    try {
      ODocument document = new ODocument();

      Map<String, OIdentifiable> map = new HashMap<String, OIdentifiable>();
      map.put("link", new ORecordId(0, new OClusterPositionLong(0)));
      document.field("map", map, OType.LINKMAP);

      byte[] res = serializer.toStream(document, false);
      ODocument extr = (ODocument) serializer.fromStream(res, new ODocument(), new String[] {});
      assertEquals(extr.fields(), document.fields());
      assertEquals(extr.field("map"), document.field("map"));
    } finally {
      db.drop();
    }
  }
View Full Code Here

    }
  }

  @Test
  public void testDocumentWithClassName() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:ODocumentSchemalessBinarySerializationTest").create();
    try {
      ODocument document = new ODocument("TestClass");
      document.field("test", "test");
      byte[] res = serializer.toStream(document, false);
      ODocument extr = (ODocument) serializer.fromStream(res, new ODocument(), new String[] {});
      assertEquals(extr.getClassName(), document.getClassName());
      assertEquals(extr.fields(), document.fields());
      assertEquals(extr.field("test"), document.field("test"));
    } finally {
      db.drop();
    }
  }
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.core.db.document.ODatabaseDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.