Java Code Examples for com.orientechnologies.orient.core.record.impl.ODocument#delete()

The following examples show how to use com.orientechnologies.orient.core.record.impl.ODocument#delete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrowseNodeEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Removes the {@link BrowseNode} associated with the given asset id.
 */
public void deleteAssetNode(final ODatabaseDocumentTx db, final EntityId assetId) {
  // a given asset will only appear once in the tree
  ODocument document = getFirst(
      db.command(new OCommandSQL(FIND_BY_ASSET)).execute(
          ImmutableMap.of(P_ASSET_ID, recordIdentity(assetId))), null);

  if (document != null) {
    if (document.containsField(P_COMPONENT_ID)) {
      // component still exists, just remove asset details
      document.removeField(P_ASSET_ID);
      document.save();
    }
    else {
      maybeDeleteParents(db, document.field(P_REPOSITORY_NAME), document.field(P_PARENT_PATH));
      document.delete();
    }
  }
}
 
Example 2
Source File: TestModels.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
@Test
public void testODocumentLinksDataProvider()
{
	ODocument doc1 = new ODocument("ClassA");
	doc1.field("name", "doc1Ext");
	doc1.save();
	ODocument doc2 = new ODocument("ClassA");
	doc2.field("name", "doc2Ext");
	doc2.field("other", Arrays.asList(doc1));
	try {
		ODocumentModel documentModel = new ODocumentModel(doc2);
		OPropertyModel propertyModel = new OPropertyModel("ClassA", "other");
		ODocumentLinksDataProvider provider = new ODocumentLinksDataProvider(documentModel, propertyModel);
		assertEquals(1, provider.size());
		assertEquals(doc1, provider.iterator(0, 1).next());
		doc2.save();
		provider.detach();
		assertEquals(1, provider.size());
		assertEquals(doc1, provider.iterator(0, 1).next());
	} finally {
		doc1.delete();
		doc2.delete();
	}
}
 
Example 3
Source File: OrientDBDocumentAPILiveTest.java    From tutorials with MIT License 6 votes vote down vote up
public void givenDB_whenSavingAuthors_thenWeGetOnesWithLevelSeven() {
    for (ODocument author : db.browseClass("Author")) author.delete();

    ODocument authorOne = new ODocument("Author");
    authorOne.field("firstName", "Leo");
    authorOne.field("level", 7);
    authorOne.save();

    ODocument authorTwo = new ODocument("Author");
    authorTwo.field("firstName", "Lucien");
    authorTwo.field("level", 9);
    authorTwo.save();

    List<ODocument> result = db.query(
        new OSQLSynchQuery<ODocument>("select * from Author where level = 7"));

    assertEquals(1, result.size());
}
 
Example 4
Source File: ComponentDatabaseUpgrade_1_10.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void fixComponent(final ODatabaseDocumentTx db,
                          final ODocument component,
                          final OIdentifiable bucket)
{
  String selectComponentAssetsSql = String.format(SELECT_COMPONENT_ASSETS_SQL, component.getIdentity());
  List<ODocument> componentsAssets = db.query(new OSQLSynchQuery<>(selectComponentAssetsSql));
  if (!componentsAssets.isEmpty()) {
    Map<String, String> formatAttributes = extractFormatAttributes(componentsAssets);

    if (formatAttributes != null && !formatAttributes.isEmpty()) {
      String name = formatAttributes.get("name");
      String version = formatAttributes.get("version");
      String release = formatAttributes.get("release");

      String fullVersion = isNotBlank(release) ? version + "-" + release : version;

      //Skip if already correct
      if (component.field(P_NAME).equals(name) && component.field(P_VERSION).equals(fullVersion)) {
        return;
      }

      ODocument existingComponent = findComponent(db, name, fullVersion, bucket);

      if (existingComponent != null) {
        moveAssetsToComponent(componentsAssets, existingComponent);
        component.delete();
      }
      else {
        component.field(P_NAME, name);
        component.field(P_VERSION, fullVersion);
        component.save();
      }
    }
    else {
      log.warn("Unable to process Yum component because formatAttributes was null or empty. {}", component);
    }
  }
}
 
Example 5
Source File: BrowseNodeEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * remove any parent nodes that only contain 1 child, and if not an asset/component node of course
 */
private void maybeDeleteParents(final ODatabaseDocumentTx db, final String repositoryName, final String parentPath) {
  //count of 1 meaning the node we are currently deleting
  if (!"/".equals(parentPath) && childCountEqualTo(db, repositoryName, parentPath, 1)) {
    ODocument parent = getFirst(db.command(new OCommandSQL(FIND_BY_PARENT_PATH)).execute(ImmutableMap
        .of(P_REPOSITORY_NAME, repositoryName, P_PARENT_PATH, previousParentPath(parentPath), P_NAME,
            previousParentName(parentPath))), null);

    if (parent != null && parent.field(P_COMPONENT_ID) == null && parent.field(P_ASSET_ID) == null) {
      maybeDeleteParents(db, repositoryName, parent.field(P_PARENT_PATH));
      parent.delete();
    }
  }
}
 
Example 6
Source File: OrientDBDao.java    From divide with Apache License 2.0 5 votes vote down vote up
@Override
    public void delete(TransientObject... objects) throws DAOException {
        checkDb();

        if(objects.length == 0) return;

        QueryBuilder.WhereMoreBuilder builder = new QueryBuilder()
                .select()
                .from(objects[0].getClass())
                .where(TransientObject.OBJECT_KEY, OPERAND.EQ, objects[0].getObjectKey());

        for(int x=1;x<objects.length;x++){
            builder.or(TransientObject.OBJECT_KEY, OPERAND.EQ, objects[x].getObjectKey());
        }

        Query q = builder.build();

//        StringBuilder sb = new StringBuilder();
//        sb.append("SELECT * FROM " + objects[0].getClass().getName() + " WHERE ");
//        for(int x=0;x<objects.length;x++){
//            sb.append("meta_data.object_key = '" + objects[x].getObjectKey() +"'");
//            if(x+1<objects.length)
//                sb.append( " OR ");
//        }


        System.out.println("Delete: " + q.getSQL());
        List<ODocument> list = db.query(new OSQLSynchQuery<ODocument>(q.getSQL()));
        for(ODocument w : list){
            System.out.println("Deleting: " + w);
            w.delete();
        }
    }
 
Example 7
Source File: DeleteODocumentCommand.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
protected void perfromSingleAction(AjaxRequestTarget target, ODocument object) {
	object.delete();
}