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

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


    database.close();
  }

  @Test(dependsOnMethods = "createRecords")
  public void testTransactionRecovery() throws IOException {
    ODatabaseDocumentTx db1 = new ODatabaseDocumentTx(url);
    db1.open("admin", "admin");

    // long tot = db1.countClass("Account");

    db1.begin();

    ODocument record1 = db1.newInstance("Account");
    record1.field("location", "This is the first version").save();

    ODocument record2 = db1.newInstance("Account");
    record2.field("location", "This is the first version").save();

    db1.commit();

    // Assert.assertEquals(db1.getClusterSize(db1.getMetadata().getSchema().getClass("Account").getDefaultClusterId()), rec);

    db1.close();
  }
View Full Code Here


    }
  }

  @Test(dependsOnMethods = "testTransactionOptimisticCacheMgmt2Db")
  public void testTransactionMultipleRecords() throws IOException {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
    db.open("admin", "admin");

    long totalAccounts = db.countClusterElements("Account");

    String json = "{ \"@class\": \"Account\", \"type\": \"Residence\", \"street\": \"Piazza di Spagna\"}";

    db.begin(TXTYPE.OPTIMISTIC);
    for (int g = 0; g < 1000; g++) {
      ODocument doc = new ODocument(db, "Account");
      doc.fromJSON(json);
      doc.field("nr", g);

      doc.save();
    }
    db.commit();

    Assert.assertEquals(db.countClusterElements("Account"), totalAccounts + 1000);

    db.close();
  }
View Full Code Here

    String[] urlParts = checkSyntax(iRequest.url, 2, "Syntax error: database/<database>");

    iRequest.data.commandInfo = "Delete database";
    iRequest.data.commandDetail = urlParts[1];

    ODatabaseDocumentTx db = null;

    try {
      if (!OSharedDocumentDatabase.getDatabasePools().containsKey(urlParts[1]))
        throw new IllegalArgumentException("Invalid database '" + urlParts[1] + "'");

      throw new UnsupportedOperationException("Delete database");

    } finally {
      if (db != null)
        db.close();
    }

    // sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, OHttpUtils.STATUS_OK_DESCRIPTION, null, OHttpUtils.CONTENT_TEXT_PLAIN,
    // null);
  }
View Full Code Here

    return false;
  }

  private boolean authenticate(final OHttpRequest iRequest, final String iDatabaseName) throws IOException {
    ODatabaseDocumentTx db = null;
    try {
      final List<String> parts = OStringSerializerHelper.split(iRequest.authorization, ':');

      db = OSharedDocumentDatabase.acquire(iDatabaseName, parts.get(0), parts.get(1));
View Full Code Here

public class OServerCommandDeleteDocument extends OServerCommandDocumentAbstract {
  private static final String[]  NAMES  = { "DELETE|document/*" };

  @Override
  public boolean execute(final OHttpRequest iRequest) throws Exception {
    ODatabaseDocumentTx db = null;

    try {
      final String[] urlParts = checkSyntax(iRequest.url, 3, "Syntax error: document/<database>/<record-id>");

      iRequest.data.commandInfo = "Delete document";
View Full Code Here

  private ODictionary<Object>  dictionary;
  private OEntityManager      entityManager;
  private boolean              saveOnlyDirty;

  public ODatabaseObjectTx(final String iURL) {
    super(new ODatabaseDocumentTx(iURL));
    underlying.setDatabaseOwner(this);
    entityManager = OEntityManager.getEntityManagerByDatabaseURL(iURL);
    saveOnlyDirty = OGlobalConfiguration.OBJECT_SAVE_ONLY_DIRTY.getValueAsBoolean();
  }
View Full Code Here

    String[] urlParts = checkSyntax(iRequest.url, 4, "Syntax error: property/<database>/<class-name>/<property-name>");

    iRequest.data.commandInfo = "Delete property";
    iRequest.data.commandDetail = urlParts[2] + "." + urlParts[3];

    ODatabaseDocumentTx db = null;

    try {
      db = getProfiledDatabaseInstance(iRequest);

      if (db.getMetadata().getSchema().getClass(urlParts[2]) == null)
        throw new IllegalArgumentException("Invalid class '" + urlParts[2] + "'");

      final OClass cls = db.getMetadata().getSchema().getClass(urlParts[2]);

      cls.removeProperty(urlParts[3]);

      db.getMetadata().getSchema().save();

      sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_TEXT_PLAIN, null);

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

  public boolean execute(final OHttpRequest iRequest) throws Exception {
    final String[] urlParts = checkSyntax(iRequest.url, 2, "Syntax error: document/<database>[/<record-id>]");

    iRequest.data.commandInfo = "Edit Document";

    ODatabaseDocumentTx db = null;
    ORecordId recordId = null;
    final ODocument doc;

    try {
      db = getProfiledDatabaseInstance(iRequest);
View Full Code Here

  private static final String[]  NAMES  = { "GET|fileDownload/*" };

  @Override
  public boolean execute(OHttpRequest iRequest) throws Exception {
    ODatabaseDocumentTx db = getProfiledDatabaseInstance(iRequest);
    String[] urlParts = checkSyntax(iRequest.url, 3, "Syntax error: fileDownload/<database>/rid/[/<fileName>][/<fileType>].");

    final String fileName = urlParts.length > 3 ? encodeResponseText(urlParts[3]) : "unknown";

    final String fileType = urlParts.length > 5 ? encodeResponseText(urlParts[4]) + '/' + encodeResponseText(urlParts[5])
        : (urlParts.length > 4 ? encodeResponseText(urlParts[4]) : "");

    final String rid = urlParts[2];

    iRequest.data.commandInfo = "Download";
    iRequest.data.commandDetail = rid;

    final ORecordBytes response;

    try {

      response = db.load(new ORecordId(rid));
      if (response != null) {
        sendBinaryFileContent(iRequest, OHttpUtils.STATUS_OK_CODE, OHttpUtils.STATUS_OK_DESCRIPTION, fileType, response, fileName);
      } else {
        sendTextContent(iRequest, OHttpUtils.STATUS_INVALIDMETHOD_CODE, "Record requested not exists", null,
            OHttpUtils.CONTENT_TEXT_PLAIN, "Record requestes not exists");
View Full Code Here

        "Syntax error: cluster/<database>/<cluster-name>[/<limit>]<br/>Limit is optional and is setted to 20 by default. Set expressely to 0 to have no limits.");

    iRequest.data.commandInfo = "Browse cluster";
    iRequest.data.commandDetail = urlParts[2];

    ODatabaseDocumentTx db = null;

    try {
      db = getProfiledDatabaseInstance(iRequest);

      if (db.getClusterIdByName(urlParts[2]) == -1)
        throw new IllegalArgumentException("Invalid cluster '" + urlParts[2] + "'");

      final int limit = urlParts.length > 3 ? Integer.parseInt(urlParts[3]) : 20;

      final List<ORecord<?>> response = new ArrayList<ORecord<?>>();
      for (ORecord<?> rec : db.browseCluster(urlParts[2])) {
        if (limit > 0 && response.size() >= limit)
          break;

        response.add(rec);
      }
View Full Code Here

TOP

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

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.